diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-10-19 15:56:18 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-10-19 15:56:18 +0100 |
commit | 0096f53b25e68c3fc79429253f816fff4a4ee596 (patch) | |
tree | fc417451449721484ace89a60c896ec3361c0989 /activerecord/test/cases/relations_test.rb | |
parent | 45d585e82759e02d6fa1032c835ff290b1cd2bf2 (diff) | |
download | rails-0096f53b25e68c3fc79429253f816fff4a4ee596.tar.gz rails-0096f53b25e68c3fc79429253f816fff4a4ee596.tar.bz2 rails-0096f53b25e68c3fc79429253f816fff4a4ee596.zip |
nodoc the first_or_create methods and document alternatives
Diffstat (limited to 'activerecord/test/cases/relations_test.rb')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 7504da01d5..5f96145b47 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1067,6 +1067,16 @@ class RelationTest < ActiveRecord::TestCase assert_equal bird, Bird.find_or_create_by(name: 'bob') end + def test_find_or_create_by_with_create_with + assert_nil Bird.find_by(name: 'bob') + + bird = Bird.create_with(color: 'green').find_or_create_by(name: 'bob') + assert bird.persisted? + assert_equal 'green', bird.color + + assert_equal bird, Bird.create_with(color: 'blue').find_or_create_by(name: 'bob') + end + def test_find_or_create_by! assert_raises(ActiveRecord::RecordInvalid) { Bird.find_or_create_by!(color: 'green') } end |