aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorPaul McMahon <paul@mobalean.com>2012-01-25 17:27:42 +0900
committerPaul McMahon <paul@mobalean.com>2012-01-27 09:37:14 +0900
commit7b9baeed7cbcd896bbd4345ce3d9e95fb51ecb99 (patch)
tree1f2ce9e75645cb81f6e2f2262cab0a7ff4d5159a /activerecord/test
parentf1baf8f5a4fe0dc98b36380498db747d3be5d316 (diff)
downloadrails-7b9baeed7cbcd896bbd4345ce3d9e95fb51ecb99.tar.gz
rails-7b9baeed7cbcd896bbd4345ce3d9e95fb51ecb99.tar.bz2
rails-7b9baeed7cbcd896bbd4345ce3d9e95fb51ecb99.zip
Fix regression from Rails 3.1
Under Rails 3.1, you were allowed to pass a hash to a find_or_create method with multiple attribute names, but this was broken as the arguments were being improperly validated.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/finder_test.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 7d80a56858..76c041397a 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -881,6 +881,17 @@ class FinderTest < ActiveRecord::TestCase
assert_equal 23, sig38.client_of
end
+ def test_find_or_create_from_two_attributes_and_hash
+ number_of_companies = Company.count
+ sig38 = Company.find_or_create_by_name_and_firm_id({:name => "38signals", :firm_id => 17, :client_of => 23})
+ assert_equal number_of_companies + 1, Company.count
+ assert_equal sig38, Company.find_or_create_by_name_and_firm_id({:name => "38signals", :firm_id => 17, :client_of => 23})
+ assert sig38.persisted?
+ assert_equal "38signals", sig38.name
+ assert_equal 17, sig38.firm_id
+ assert_equal 23, sig38.client_of
+ end
+
def test_find_or_create_from_one_aggregate_attribute
number_of_customers = Customer.count
created_customer = Customer.find_or_create_by_balance(Money.new(123))