aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorTobias Lütke <tobias.luetke@gmail.com>2007-01-12 21:14:36 +0000
committerTobias Lütke <tobias.luetke@gmail.com>2007-01-12 21:14:36 +0000
commite24d2f72344baecbcd6fbb76fe3a3171762182e0 (patch)
tree1fce45c301782722656b2aaa5313c4bc0e2207ef /activerecord/test
parentdd6826eba34769d2af45d45ef91e359cd64eeb00 (diff)
downloadrails-e24d2f72344baecbcd6fbb76fe3a3171762182e0.tar.gz
rails-e24d2f72344baecbcd6fbb76fe3a3171762182e0.tar.bz2
rails-e24d2f72344baecbcd6fbb76fe3a3171762182e0.zip
Apply scoping during initialize instead of create. Fixes setting of foreign key when using find_or_initialize_by with scoping.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5913 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/associations_test.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 522a0739e6..4315570c5c 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -750,6 +750,13 @@ class HasManyAssociationsTest < Test::Unit::TestCase
companies(:first_firm).clients_of_firm.create([{"name" => "Another Client"}, {"name" => "Another Client II"}])
assert_equal 3, companies(:first_firm).clients_of_firm(true).size
end
+
+ def test_find_or_initialize
+ the_client = companies(:first_firm).clients.find_or_initialize_by_name("Yet another client")
+ assert_equal companies(:first_firm).id, the_client.firm_id
+ assert_equal "Yet another client", the_client.name
+ assert the_client.new_record?
+ end
def test_find_or_create
number_of_clients = companies(:first_firm).clients.size