aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-06-29 15:42:06 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-06-29 16:13:40 -0700
commit3f563f169612ec340816f0a549fe9db7ff95c238 (patch)
treeb825e646170355d6e15c895b0c0abcb9cc61b023 /activerecord/test/cases
parentd7c2e52c6c04dec4e4665c8f0f9988bfe913cb15 (diff)
downloadrails-3f563f169612ec340816f0a549fe9db7ff95c238.tar.gz
rails-3f563f169612ec340816f0a549fe9db7ff95c238.tar.bz2
rails-3f563f169612ec340816f0a549fe9db7ff95c238.zip
AssociationCollection#create_by_*, find_or_create_by_* work properly now. [#1108 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb62
1 files changed, 62 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 45c7498013..5e3ba778f3 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -21,6 +21,68 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
Client.destroyed_client_ids.clear
end
+ def test_create_by
+ person = Person.create! :first_name => 'tenderlove'
+ post = Post.find :first
+
+ assert_equal [], person.readers
+ assert_nil person.readers.find_by_post_id post.id
+
+ reader = person.readers.create_by_post_id post.id
+
+ assert_equal 1, person.readers.count
+ assert_equal 1, person.readers.length
+ assert_equal post, person.readers.first.post
+ assert_equal person, person.readers.first.person
+ end
+
+ def test_create_by_multi
+ person = Person.create! :first_name => 'tenderlove'
+ post = Post.find :first
+
+ assert_equal [], person.readers
+
+ reader = person.readers.create_by_post_id_and_skimmer post.id, false
+
+ assert_equal 1, person.readers.count
+ assert_equal 1, person.readers.length
+ assert_equal post, person.readers.first.post
+ assert_equal person, person.readers.first.person
+ end
+
+ def test_find_or_create_by
+ person = Person.create! :first_name => 'tenderlove'
+ post = Post.find :first
+
+ assert_equal [], person.readers
+ assert_nil person.readers.find_by_post_id post.id
+
+ reader = person.readers.find_or_create_by_post_id post.id
+
+ assert_equal 1, person.readers.count
+ assert_equal 1, person.readers.length
+ assert_equal post, person.readers.first.post
+ assert_equal person, person.readers.first.person
+ end
+
+ def test_find_or_create
+ person = Person.create! :first_name => 'tenderlove'
+ post = Post.find :first
+
+ assert_equal [], person.readers
+ assert_nil person.readers.find(:first, :conditions => {
+ :post_id => post.id
+ })
+
+ reader = person.readers.find_or_create :post_id => post.id
+
+ assert_equal 1, person.readers.count
+ assert_equal 1, person.readers.length
+ assert_equal post, person.readers.first.post
+ assert_equal person, person.readers.first.person
+ end
+
+
def force_signal37_to_load_all_clients_of_firm
companies(:first_firm).clients_of_firm.each {|f| }
end