diff options
author | Sam Stephenson <sam@37signals.com> | 2006-06-20 22:48:52 +0000 |
---|---|---|
committer | Sam Stephenson <sam@37signals.com> | 2006-06-20 22:48:52 +0000 |
commit | d19e46421cbead18ab1a9f79081b99bf3e97dde5 (patch) | |
tree | b545b00f7fb45437e0947b6ae839840ecaa2cf13 /activerecord/test/finder_test.rb | |
parent | ef77ec77109a22361b5ee30b851eb3e5c8871eaa (diff) | |
download | rails-d19e46421cbead18ab1a9f79081b99bf3e97dde5.tar.gz rails-d19e46421cbead18ab1a9f79081b99bf3e97dde5.tar.bz2 rails-d19e46421cbead18ab1a9f79081b99bf3e97dde5.zip |
Added find_or_initialize_by_X which works like find_or_create_by_X but doesn't save the newly instantiated record
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4473 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/finder_test.rb')
-rw-r--r-- | activerecord/test/finder_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 20898237d1..23b6508f99 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -336,6 +336,7 @@ class FinderTest < Test::Unit::TestCase sig38 = Company.find_or_create_by_name("38signals") assert_equal number_of_companies + 1, Company.count assert_equal sig38, Company.find_or_create_by_name("38signals") + assert !sig38.new_record? end def test_find_or_create_from_two_attributes @@ -343,6 +344,20 @@ class FinderTest < Test::Unit::TestCase another = Topic.find_or_create_by_title_and_author_name("Another topic","John") assert_equal number_of_topics + 1, Topic.count assert_equal another, Topic.find_or_create_by_title_and_author_name("Another topic", "John") + assert !another.new_record? + end + + def test_find_or_initialize_from_one_attribute + sig38 = Company.find_or_initialize_by_name("38signals") + assert_equal "38signals", sig38.name + assert sig38.new_record? + end + + def test_find_or_initialize_from_two_attributes + another = Topic.find_or_initialize_by_title_and_author_name("Another topic","John") + assert_equal "Another topic", another.title + assert_equal "John", another.author_name + assert another.new_record? end def test_find_with_bad_sql |