diff options
author | Henry Hsu <henry@qlane.com> | 2010-02-26 11:06:55 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-02-26 11:09:43 +0100 |
commit | bf9a0ae12b701cba7a8aac2955ce243866ac7bf6 (patch) | |
tree | 4ac2eb2e2410b6c7ed72cefde5f914712474c69f /activerecord/test | |
parent | 79c47abe6ce0bdcc81c35aa30da8a05c3650d04d (diff) | |
download | rails-bf9a0ae12b701cba7a8aac2955ce243866ac7bf6.tar.gz rails-bf9a0ae12b701cba7a8aac2955ce243866ac7bf6.tar.bz2 rails-bf9a0ae12b701cba7a8aac2955ce243866ac7bf6.zip |
Fix a bug where default_scope was overriding attributes given on model initialization [#3218 status:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/method_scoping_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 5 |
2 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index 1081aa40a9..3151457440 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -663,6 +663,16 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal 2, posts.count assert_equal posts(:thinking), posts.first end + + def test_create_attribute_overwrites_default_scoping + assert_equal 'David', PoorDeveloperCalledJamis.create!(:name => 'David').name + assert_equal 200000, PoorDeveloperCalledJamis.create!(:name => 'David', :salary => 200000).salary + end + + def test_create_attribute_overwrites_default_values + assert_equal nil, PoorDeveloperCalledJamis.create!(:salary => nil).salary + assert_equal 50000, PoorDeveloperCalledJamis.create!(:name => 'David').salary + end end =begin diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index e7a1e110d7..e35de3b9b0 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -99,3 +99,8 @@ class DeveloperCalledJamis < ActiveRecord::Base self.table_name = 'developers' default_scope :conditions => { :name => 'Jamis' } end + +class PoorDeveloperCalledJamis < ActiveRecord::Base + self.table_name = 'developers' + default_scope :conditions => { :name => 'Jamis', :salary => 50000 } +end
\ No newline at end of file |