aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relation_test.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb
index 5eca3e05c4..a38255eda6 100644
--- a/activerecord/test/cases/relation_test.rb
+++ b/activerecord/test/cases/relation_test.rb
@@ -21,9 +21,10 @@ module ActiveRecord
def test_initialize_single_values
relation = Relation.new :a, :b
- Relation::SINGLE_VALUE_METHODS.each do |method|
+ (Relation::SINGLE_VALUE_METHODS - [:create_with]).each do |method|
assert_nil relation.send("#{method}_value"), method.to_s
end
+ assert_equal({}, relation.create_with_value)
end
def test_multi_value_initialize
@@ -132,6 +133,18 @@ module ActiveRecord
relation = relation.apply_finder_options(:references => :foo)
assert_equal ['foo'], relation.references_values
end
+
+ test 'merging a hash into a relation' do
+ relation = Relation.new :a, :b
+ relation = relation.merge where: ['lol'], readonly: true
+
+ assert_equal ['lol'], relation.where_values
+ assert_equal true, relation.readonly_value
+ end
+
+ test 'merging an empty hash into a relation' do
+ assert_equal [], Relation.new(:a, :b).merge({}).where_values
+ end
end
class RelationMutationTest < ActiveSupport::TestCase
@@ -151,7 +164,7 @@ module ActiveRecord
assert relation.references_values.include?('foo')
end
- (Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order]).each do |method|
+ (Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order, :create_with]).each do |method|
test "##{method}!" do
assert relation.public_send("#{method}!", :foo).equal?(relation)
assert_equal :foo, relation.public_send("#{method}_value")
@@ -184,5 +197,10 @@ module ActiveRecord
assert relation.extending!(mod).equal?(relation)
assert relation.is_a?(mod)
end
+
+ test 'create_with!' do
+ assert relation.create_with!(foo: 'bar').equal?(relation)
+ assert_equal({foo: 'bar'}, relation.create_with_value)
+ end
end
end