aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/finder_test.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-03-14 01:08:45 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-03-14 01:08:45 +0000
commit14cc8d2faf28f103c4f0c850be2bc45f15b5d1e6 (patch)
treeea26feb3fe840196164cde5feb7b17aad81b08f9 /activerecord/test/finder_test.rb
parent5219aa90083a76832c6691bdef6fe3dc51a69281 (diff)
downloadrails-14cc8d2faf28f103c4f0c850be2bc45f15b5d1e6.tar.gz
rails-14cc8d2faf28f103c4f0c850be2bc45f15b5d1e6.tar.bz2
rails-14cc8d2faf28f103c4f0c850be2bc45f15b5d1e6.zip
find_or_create_by_* takes a hash so you can create with more attributes than are in the method name. Closes #7368.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6420 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/finder_test.rb')
-rw-r--r--activerecord/test/finder_test.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index abf7f65733..bee7c23025 100644
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -385,6 +385,17 @@ class FinderTest < Test::Unit::TestCase
assert !another.new_record?
end
+ def test_find_or_create_from_one_attribute_and_hash
+ number_of_companies = Company.count
+ sig38 = Company.find_or_create_by_name({: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({:name => "38signals", :firm_id => 17, :client_of => 23})
+ assert !sig38.new_record?
+ assert_equal "38signals", sig38.name
+ assert_equal 17, sig38.firm_id
+ assert_equal 23, sig38.client_of
+ end
+
def test_find_or_initialize_from_one_attribute
sig38 = Company.find_or_initialize_by_name("38signals")
assert_equal "38signals", sig38.name
@@ -397,6 +408,14 @@ class FinderTest < Test::Unit::TestCase
assert_equal "John", another.author_name
assert another.new_record?
end
+
+ def test_find_or_initialize_from_one_attribute_and_hash
+ sig38 = Company.find_or_initialize_by_name({:name => "38signals", :firm_id => 17, :client_of => 23})
+ assert_equal "38signals", sig38.name
+ assert_equal 17, sig38.firm_id
+ assert_equal 23, sig38.client_of
+ assert sig38.new_record?
+ end
def test_find_with_bad_sql
assert_raises(ActiveRecord::StatementInvalid) { Topic.find_by_sql "select 1 from badtable" }