aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-24 11:39:23 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-24 11:39:23 +0000
commitb29c01ea8914422c6f7e0bb5c65d3b8610dc54d1 (patch)
tree42d4e9154911756823bf1197708177b58dd5fd31 /activerecord/test/associations_test.rb
parent1d618455870cac504256cd762cd0787c739dfe1f (diff)
downloadrails-b29c01ea8914422c6f7e0bb5c65d3b8610dc54d1.tar.gz
rails-b29c01ea8914422c6f7e0bb5c65d3b8610dc54d1.tar.bz2
rails-b29c01ea8914422c6f7e0bb5c65d3b8610dc54d1.zip
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
Diffstat (limited to 'activerecord/test/associations_test.rb')
-rwxr-xr-xactiverecord/test/associations_test.rb21
1 files changed, 21 insertions, 0 deletions
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")