Merge pull request #21987 from yui-knk/refactor_where
Green version of moving the handling of supported arguments to `where`
This commit is contained in:
commit
09f057d193
@ -552,8 +552,6 @@ def where(opts = :chain, *rest)
|
||||
WhereChain.new(spawn)
|
||||
elsif opts.blank?
|
||||
self
|
||||
elsif !opts.is_a?(String) && !opts.respond_to?(:to_h)
|
||||
raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
|
||||
else
|
||||
spawn.where!(opts, *rest)
|
||||
end
|
||||
|
@ -20,8 +20,10 @@ def build(opts, other)
|
||||
attributes, binds = predicate_builder.create_binds(attributes)
|
||||
|
||||
parts = predicate_builder.build_from_hash(attributes)
|
||||
else
|
||||
when Arel::Nodes::Node
|
||||
parts = [opts]
|
||||
else
|
||||
raise ArgumentError, "Unsupported argument type: #{opts} (#{opts.class})"
|
||||
end
|
||||
|
||||
WhereClause.new(parts, binds)
|
||||
|
@ -57,9 +57,6 @@ def test_extensions
|
||||
def test_empty_where_values_hash
|
||||
relation = Relation.new(FakeKlass, :b, nil)
|
||||
assert_equal({}, relation.where_values_hash)
|
||||
|
||||
relation.where! :hello
|
||||
assert_equal({}, relation.where_values_hash)
|
||||
end
|
||||
|
||||
def test_has_values
|
||||
@ -153,10 +150,10 @@ def test_references_values_dont_duplicate
|
||||
end
|
||||
|
||||
test 'merging a hash into a relation' do
|
||||
relation = Relation.new(FakeKlass, :b, nil)
|
||||
relation = relation.merge where: :lol, readonly: true
|
||||
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder)
|
||||
relation = relation.merge where: {name: :lol}, readonly: true
|
||||
|
||||
assert_equal Relation::WhereClause.new([:lol], []), relation.where_clause
|
||||
assert_equal({"name"=>:lol}, relation.where_clause.to_h)
|
||||
assert_equal true, relation.readonly_value
|
||||
end
|
||||
|
||||
@ -185,7 +182,7 @@ def test_references_values_dont_duplicate
|
||||
end
|
||||
|
||||
test '#values returns a dup of the values' do
|
||||
relation = Relation.new(FakeKlass, :b, nil).where! :foo
|
||||
relation = Relation.new(Post, Post.arel_table, Post.predicate_builder).where!(name: :foo)
|
||||
values = relation.values
|
||||
|
||||
values[:where] = nil
|
||||
|
Loading…
Reference in New Issue
Block a user