提交 800b899f 编写于 作者: J Jeremy Kemper

Remove deprecated push_with_attributes.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6997 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 813e8ba9
......@@ -68,23 +68,6 @@ def find(*args)
end
end
# Deprecated as of Rails 1.2. If your associations require attributes
# you should be using has_many :through
def push_with_attributes(record, join_attributes = {})
raise_on_type_mismatch(record)
join_attributes.each { |key, value| record[key.to_s] = value }
callback(:before_add, record)
insert_record(record) unless @owner.new_record?
@target << record
callback(:after_add, record)
self
end
deprecate :push_with_attributes => "consider using has_many :through instead"
alias :concat_with_attributes :push_with_attributes
protected
def count_records
load_target.size
......
......@@ -109,18 +109,5 @@ def test_dont_add_if_before_callback_raises_exception
@david.reload
assert !@david.unchangable_posts.include?(@authorless)
end
def test_push_with_attributes
assert_deprecated 'push_with_attributes' do
david = developers(:david)
activerecord = projects(:active_record)
assert activerecord.developers_log.empty?
activerecord.developers_with_callbacks.push_with_attributes(david, {})
assert_equal ["before_adding#{david.id}", "after_adding#{david.id}"], activerecord.developers_log
activerecord.developers_with_callbacks.push_with_attributes(david, {})
assert_equal ["before_adding#{david.id}", "after_adding#{david.id}", "before_adding#{david.id}",
"after_adding#{david.id}"], activerecord.developers_log
end
end
end
......@@ -1469,18 +1469,6 @@ def test_adding_uses_default_values_on_join_table
assert_equal 1, project.access_level.to_i
end
def test_adding_uses_explicit_values_on_join_table
ac = projects(:action_controller)
assert !developers(:jamis).projects.include?(ac)
assert_deprecated do
developers(:jamis).projects.push_with_attributes(ac, :access_level => 3)
end
assert developers(:jamis, :reload).projects.include?(ac)
project = developers(:jamis).projects.detect { |p| p == ac }
assert_equal 3, project.access_level.to_i
end
def test_hatbm_attribute_access_and_respond_to
project = developers(:jamis).projects[0]
assert project.has_attribute?("name")
......@@ -1512,31 +1500,6 @@ def test_habtm_adding_before_save
assert_equal 2, aredridel.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")
assert_deprecated do
ken.projects.push_with_attributes( Project.find(1), :joined_on => now )
end
p = Project.new("name" => "Foomatic")
assert_deprecated do
ken.projects.push_with_attributes( p, :joined_on => now )
end
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_date_from_db(now, prj.joined_on.to_date)}
end
def test_habtm_saving_multiple_relationships
new_project = Project.new("name" => "Grimetime")
amount_of_developers = 4
......@@ -1686,12 +1649,9 @@ def test_destroy_all
def test_rich_association
jamis = developers(:jamis)
assert_deprecated 'push_with_attributes' do
assert_raise(NoMethodError) do
jamis.projects.push_with_attributes(projects(:action_controller), :joined_on => Date.today)
end
assert_date_from_db Date.today, jamis.projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on
assert_date_from_db Date.today, developers(:jamis).projects.select { |p| p.name == projects(:action_controller).name }.first.joined_on
end
def test_associations_with_conditions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册