aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJosh Kalderimis <josh.kalderimis@gmail.com>2011-06-01 00:42:02 +0200
committerJon Leighton <j@jonathanleighton.com>2011-06-01 00:01:35 +0100
commiteb7ef2ccd618bc87451b980722ec73ee41c203a1 (patch)
tree72cc2db8eaa60a5bd5be48b70dbe0cedfed89f81 /activerecord/test/cases
parent1f34a79373854e36c7bf77ffa70688cda6d27a5c (diff)
downloadrails-eb7ef2ccd618bc87451b980722ec73ee41c203a1.tar.gz
rails-eb7ef2ccd618bc87451b980722ec73ee41c203a1.tar.bz2
rails-eb7ef2ccd618bc87451b980722ec73ee41c203a1.zip
added an alias for new to build to the AR collection proxy, this corrects an issue where the collection proxies were not consistent
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb15
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb10
2 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
index 839a7852fc..e5735988d0 100644
--- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -245,6 +245,21 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase
assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated
end
+ def test_new_aliased_to_build
+ devel = Developer.find(1)
+ proj = assert_no_queries { devel.projects.new("name" => "Projekt") }
+ assert !devel.projects.loaded?
+
+ assert_equal devel.projects.last, proj
+ assert devel.projects.loaded?
+
+ assert !proj.persisted?
+ devel.save
+ assert proj.persisted?
+ assert_equal devel.projects.last, proj
+ assert_equal Developer.find(1).projects.sort_by(&:id).last, proj # prove join table is updated
+ end
+
def test_build_by_new_record
devel = Developer.new(:name => "Marcel", :salary => 75000)
devel.projects.build(:name => "Make bed")
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index a493ea9974..49999630b6 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -537,6 +537,16 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal 3, companies(:first_firm).clients_of_firm(true).size
end
+ def test_new_aliased_to_build
+ company = companies(:first_firm)
+ new_client = assert_no_queries { company.clients_of_firm.new("name" => "Another Client") }
+ assert !company.clients_of_firm.loaded?
+
+ assert_equal "Another Client", new_client.name
+ assert !new_client.persisted?
+ assert_equal new_client, company.clients_of_firm.last
+ end
+
def test_build
company = companies(:first_firm)
new_client = assert_no_queries { company.clients_of_firm.build("name" => "Another Client") }