diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-04-12 17:55:39 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-04-12 17:57:54 +0100 |
commit | 8c2c60511beaad05a218e73c4918ab89fb1804f0 (patch) | |
tree | 761212dd7e1a8661f4ab30b814f2d3c4b2e86078 /activerecord/test | |
parent | 5c51cd0b2f7ac28825bdeb1f2f49f4647be12e52 (diff) | |
download | rails-8c2c60511beaad05a218e73c4918ab89fb1804f0.tar.gz rails-8c2c60511beaad05a218e73c4918ab89fb1804f0.tar.bz2 rails-8c2c60511beaad05a218e73c4918ab89fb1804f0.zip |
Add bang versions of relation query methods.
The main reason for this is that I want to separate the code that does
the mutating from the code that does the cloning.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relation_test.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_test.rb b/activerecord/test/cases/relation_test.rb index ac6dee3c6a..4b18c37d27 100644 --- a/activerecord/test/cases/relation_test.rb +++ b/activerecord/test/cases/relation_test.rb @@ -155,4 +155,56 @@ module ActiveRecord assert_equal ['foo'], relation.references_values end end + + class RelationMutationTest < ActiveSupport::TestCase + def relation + @relation ||= Relation.new :a, :b + end + + (Relation::ASSOCIATION_METHODS + Relation::MULTI_VALUE_METHODS - [:references]).each do |method| + test "##{method}!" do + assert relation.public_send("#{method}!", :foo).equal?(relation) + assert_equal [:foo], relation.public_send("#{method}_values") + end + end + + test '#references!' do + assert relation.references!(:foo).equal?(relation) + assert relation.references_values.include?('foo') + end + + (Relation::SINGLE_VALUE_METHODS - [:lock, :reordering, :reverse_order]).each do |method| + test "##{method}!" do + assert relation.public_send("#{method}!", :foo).equal?(relation) + assert_equal :foo, relation.public_send("#{method}_value") + end + end + + test '#lock!' do + assert relation.lock!('foo').equal?(relation) + assert_equal 'foo', relation.lock_value + end + + test '#reorder!' do + relation = self.relation.order('foo') + + assert relation.reorder!('bar').equal?(relation) + assert_equal ['bar'], relation.order_values + assert relation.reordering_value + end + + test 'reverse_order!' do + assert relation.reverse_order!.equal?(relation) + assert relation.reverse_order_value + relation.reverse_order! + assert !relation.reverse_order_value + end + + test 'extending!' do + mod = Module.new + + assert relation.extending!(mod).equal?(relation) + assert relation.is_a?(mod) + end + end end |