Skip to content

Instantly share code, notes, and snippets.

@bdimcheff
Created December 11, 2010 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdimcheff/737211 to your computer and use it in GitHub Desktop.
Save bdimcheff/737211 to your computer and use it in GitHub Desktop.
From c4a38b39430be495cd5b131d660e1b145280148f Mon Sep 17 00:00:00 2001
From: Brandon Dimcheff <bdimchef-git@wieldim.com>
Date: Sat, 11 Dec 2010 01:34:04 -0500
Subject: [PATCH] find_or_create_by doesn't set proper values when using a hash
---
.../associations/has_many_associations_test.rb | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 3996b84..61f42d8 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -81,6 +81,15 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 4, post.comments.count
assert_equal 4, post.comments.length
end
+
+ def test_find_or_create_by_with_hash_sets_proper_attributes
+ post = Post.create! :title => 'test_find_or_create_by_with_hash_sets_proper_attributes', :body => 'this is the body'
+ comment = post.comments.find_or_create_by_body(:body => 'other test comment body', :type => 'test')
+ comment.reload
+
+ assert_equal 'other test comment body', comment.body
+ assert_equal 'test', comment.type
+ 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'
--
1.7.0.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment