commit fc74100de67a48ad17d8a109b66b213afba143d1 Author: toby cabot Date: Tue Sep 28 16:06:29 2010 -0400 test that find_or_create_by via an association yields to a provided block diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 05ed7a4..a1b917c 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -80,6 +80,12 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal 2, post.comments.length end + def test_find_or_create_by_with_block + post = Post.create! :title => 'test_find_or_create_by_with_additional_parameters', :body => 'this is the body' + comment = post.comments.find_or_create_by_body('other test comment body') { |comment| comment.type = 'test' } + assert_equal 'test', comment.type + end + def test_find_or_create person = Person.create! :first_name => 'tenderlove' post = Post.find :first