From b29c01ea8914422c6f7e0bb5c65d3b8610dc54d1 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 24 Jan 2005 11:39:23 +0000 Subject: Added that has_and_belongs_to_many associations with additional attributes also can be created between unsaved objects and only committed to the database when Base#save is called on the associator #524 [Eric Anderson] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@484 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activerecord/test/associations_test.rb') diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 420fae069b..7ede042879 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -724,6 +724,27 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase assert_equal 2, aridridel.projects(true).size end + def test_habtm_adding_before_save_with_join_attributes + no_of_devels = Developer.count + no_of_projects = Project.count + now = Date.today + ken = Developer.new("name" => "Ken") + ken.projects.push_with_attributes( Project.find(1), :joined_on => now ) + p = Project.new("name" => "Foomatic") + ken.projects.push_with_attributes( p, :joined_on => now ) + assert ken.new_record? + assert p.new_record? + assert ken.save + assert !ken.new_record? + assert_equal no_of_devels+1, Developer.count + assert_equal no_of_projects+1, Project.count + assert_equal 2, ken.projects.size + assert_equal 2, ken.projects(true).size + + kenReloaded = Developer.find_by_name 'Ken' + kenReloaded.projects.each { |prj| assert_equal(now.to_s, prj.joined_on.to_s) } + end + def test_build devel = Developer.find(1) proj = devel.projects.build("name" => "Projekt") -- cgit v1.2.3