Created
May 14, 2011 02:33
-
-
Save AquaGeek/971728 to your computer and use it in GitHub Desktop.
Rails Lighthouse ticket #5983
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d560d2f2ae667dbc221ed7372008bcd9447b744a Mon Sep 17 00:00:00 2001 | |
From: Szymon Nowak <szimek@gmail.com> | |
Date: Tue, 16 Nov 2010 14:08:45 +0100 | |
Subject: [PATCH] Test case for bug with find_or_create_by with protected attributes. | |
--- | |
.../associations/has_many_associations_test.rb | 15 +++++++++++++++ | |
1 files changed, 15 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 47b0f1e..a70bfab 100644 | |
--- a/activerecord/test/cases/associations/has_many_associations_test.rb | |
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb | |
@@ -65,6 +65,21 @@ class HasManyAssociationsTest < ActiveRecord::TestCase | |
assert_equal person, person.readers.first.person | |
end | |
+ def test_find_or_create_by_with_protected_attribute | |
+ topic = Topic.create! | |
+ bonus_time = Time.now # bonus_time is not in Reply.attr_accessible list | |
+ | |
+ assert_equal [], topic.replies | |
+ assert_nil topic.replies.find_by_bonus_time(bonus_time) | |
+ | |
+ reply = topic.replies.find_or_create_by_bonus_time_and_title_and_content(bonus_time, "Title", "Content") | |
+ | |
+ assert_equal 1, topic.replies.count | |
+ assert_equal 1, topic.replies.length | |
+ assert_equal bonus_time, topic.replies.first.bonus_time | |
+ assert_equal topic, topic.replies.first.topic | |
+ end | |
+ | |
def test_find_or_create_by_with_additional_parameters | |
post = Post.create! :title => 'test_find_or_create_by_with_additional_parameters', :body => 'this is the body' | |
comment = post.comments.create! :body => 'test comment body', :type => 'test' | |
-- | |
1.7.3.2 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment