diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-09-07 13:08:03 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-09-18 20:49:19 +0200 |
commit | 9401fa0b9c89f51e3ec0f7aaeee7404b4a14ada8 (patch) | |
tree | a1e3b668a3de2c6c54a639839ec0d739a0e3757c /activerecord/test | |
parent | 8ae913664ff721e10dfc2c057998a38fd6f76edf (diff) | |
download | rails-9401fa0b9c89f51e3ec0f7aaeee7404b4a14ada8.tar.gz rails-9401fa0b9c89f51e3ec0f7aaeee7404b4a14ada8.tar.bz2 rails-9401fa0b9c89f51e3ec0f7aaeee7404b4a14ada8.zip |
expanding the test to include both type of order declaration
while declaring default_scope
Also added test for unscoped using block style with four different
combinations
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 28 | ||||
-rw-r--r-- | activerecord/test/models/car.rb | 11 | ||||
-rw-r--r-- | activerecord/test/models/engine.rb | 1 |
3 files changed, 32 insertions, 8 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index d43ba31814..3bc3671b77 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -680,19 +680,35 @@ class RelationTest < ActiveRecord::TestCase end def test_order_with_find_with_order - assert_equal 'zyke', Car.order('name desc').find(:first, :order => 'id').name + assert_equal 'zyke', CoolCar.order('name desc').find(:first, :order => 'id').name + assert_equal 'zyke', FastCar.order('name desc').find(:first, :order => 'id').name end def test_default_scope_order_with_named_scope_order - assert_equal 'zyke', Car.order_using_new_style.limit(1).first.name - assert_equal 'zyke', Car.order_using_old_style.limit(1).first.name + assert_equal 'zyke', CoolCar.order_using_new_style.limit(1).first.name + assert_equal 'zyke', CoolCar.order_using_old_style.limit(1).first.name + assert_equal 'zyke', FastCar.order_using_new_style.limit(1).first.name + assert_equal 'zyke', FastCar.order_using_old_style.limit(1).first.name end def test_order_using_scoping - car = Car.order('id DESC').scoping do - Car.find(:first, :order => 'id asc') + car1 = CoolCar.order('id DESC').scoping do + CoolCar.find(:first, :order => 'id asc') end - assert_equal 'zyke', car.name + assert_equal 'zyke', car1.name + + car2 = FastCar.order('id DESC').scoping do + FastCar.find(:first, :order => 'id asc') + end + assert_equal 'zyke', car2.name + end + + def test_unscoped_block_style + assert_equal 'honda', CoolCar.unscoped { CoolCar.order_using_new_style.limit(1).first.name} + assert_equal 'honda', CoolCar.unscoped { CoolCar.order_using_old_style.limit(1).first.name} + + assert_equal 'honda', FastCar.unscoped { FastCar.order_using_new_style.limit(1).first.name} + assert_equal 'honda', FastCar.unscoped { FastCar.order_using_old_style.limit(1).first.name} end def test_intersection_with_array diff --git a/activerecord/test/models/car.rb b/activerecord/test/models/car.rb index a1e351b54e..e7db3d3423 100644 --- a/activerecord/test/models/car.rb +++ b/activerecord/test/models/car.rb @@ -1,4 +1,5 @@ class Car < ActiveRecord::Base + has_many :bulbs has_many :tyres has_many :engines @@ -7,9 +8,15 @@ class Car < ActiveRecord::Base scope :incl_tyres, includes(:tyres) scope :incl_engines, includes(:engines) - default_scope :order => 'name desc' - scope :order_using_new_style, order('name asc') scope :order_using_old_style, :order => 'name asc' end + +class CoolCar < Car + default_scope :order => 'name desc' +end + +class FastCar < Car + default_scope order('name desc') +end diff --git a/activerecord/test/models/engine.rb b/activerecord/test/models/engine.rb index 751c3f02d1..851ff8c22b 100644 --- a/activerecord/test/models/engine.rb +++ b/activerecord/test/models/engine.rb @@ -1,3 +1,4 @@ class Engine < ActiveRecord::Base belongs_to :my_car, :class_name => 'Car', :foreign_key => 'car_id', :counter_cache => :engines_count end + |