提交 5d1d5f28 编写于 作者: A Andrew White

Raise ArgumentError when passing a truthy value to merge

In b71e08f8 we started raising when nil or false was passed to merge to
fix #12264, however we should also do this for truthy values that are
invalid like true.
上级 35ca78a0
......@@ -40,10 +40,12 @@ def merge(other)
def merge!(other) # :nodoc:
if other.is_a?(Hash)
Relation::HashMerger.new(self, other).merge
elsif other.is_a?(Relation)
Relation::Merger.new(self, other).merge
elsif other.respond_to?(:to_proc)
instance_exec(&other)
else
Relation::Merger.new(self, other).merge
raise ArgumentError, "#{other.inspect} is not an ActiveRecord::Relation"
end
end
......
......@@ -24,10 +24,6 @@ def self.table_name
def self.sanitize_sql_for_order(sql)
sql
end
def self.arel_table
Post.arel_table
end
end
def test_construction
......@@ -239,6 +235,13 @@ def test_relation_merging_with_joins_as_join_dependency_pick_proper_parent
assert_equal 3, relation.where(id: post.id).pluck(:id).size
end
def test_merge_raises_with_invalid_argument
assert_raises ArgumentError do
relation = Relation.new(FakeKlass, :b, nil)
relation.merge(true)
end
end
def test_respond_to_for_non_selected_element
post = Post.select(:title).first
assert_equal false, post.respond_to?(:body), "post should not respond_to?(:body) since invoking it raises exception"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册