aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_test.rb
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-06-21 12:58:27 +0000
committerJamis Buck <jamis@37signals.com>2005-06-21 12:58:27 +0000
commit361be5a7dd1d70e55d6b003b987794e94b2f9c1e (patch)
tree5749b77591749af6a12c3a133ce8db11ad04cadb /activerecord/test/associations_test.rb
parentc88ce046621b77e6d39ae60edd4996066414801a (diff)
downloadrails-361be5a7dd1d70e55d6b003b987794e94b2f9c1e.tar.gz
rails-361be5a7dd1d70e55d6b003b987794e94b2f9c1e.tar.bz2
rails-361be5a7dd1d70e55d6b003b987794e94b2f9c1e.zip
Removed the AR::Recursion module--it broke more code than it fixed
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1470 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_test.rb')
-rwxr-xr-xactiverecord/test/associations_test.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 214b582f56..6fb8757153 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -774,6 +774,32 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
end
+class ProjectWithAfterCreateHook < ActiveRecord::Base
+ set_table_name 'projects'
+ has_and_belongs_to_many :developers,
+ :class_name => "DeveloperForProjectWithAfterCreateHook",
+ :join_table => "developers_projects",
+ :foreign_key => "project_id",
+ :association_foreign_key => "developer_id"
+
+ after_create :add_david
+
+ def add_david
+ david = DeveloperForProjectWithAfterCreateHook.find_by_name('David')
+ david.projects << self
+ end
+end
+
+class DeveloperForProjectWithAfterCreateHook < ActiveRecord::Base
+ set_table_name 'developers'
+ has_and_belongs_to_many :projects,
+ :class_name => "ProjectWithAfterCreateHook",
+ :join_table => "developers_projects",
+ :association_foreign_key => "project_id",
+ :foreign_key => "developer_id"
+end
+
+
class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
fixtures :accounts, :companies, :developers, :projects, :developers_projects
@@ -1018,6 +1044,18 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase
assert_equal developers(:david), active_record.developers.find(developers(:david).id), "Ruby find"
end
+ def test_new_with_values_in_collection
+ jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis')
+ david = DeveloperForProjectWithAfterCreateHook.find_by_name('David')
+ project = ProjectWithAfterCreateHook.new(:name => "Cooking with Bertie")
+ project.developers << jamis
+ project.save!
+ project.reload
+
+ assert project.developers.include?(jamis)
+ assert project.developers.include?(david)
+ end
+
def xtest_find_in_association_with_options
developers = projects(:active_record).developers.find(:all)
assert_equal 2, developers.size