Makes project and tracker assigned first in #attributes=

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8131 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-12-08 20:37:12 +00:00
parent d75bc5774f
commit 42d2bf0baf
2 changed files with 22 additions and 12 deletions

View File

@ -238,17 +238,21 @@ class Issue < ActiveRecord::Base
write_attribute(:description, arg)
end
# Overrides attributes= so that tracker_id gets assigned first
def attributes_with_tracker_first=(new_attributes, *args)
# Overrides attributes= so that project and tracker get assigned first
def attributes_with_project_and_tracker_first=(new_attributes, *args)
return if new_attributes.nil?
new_tracker_id = new_attributes['tracker_id'] || new_attributes[:tracker_id]
if new_tracker_id
self.tracker_id = new_tracker_id
attrs = new_attributes.dup
attrs.stringify_keys!
%w(project project_id tracker tracker_id).each do |attr|
if attrs.has_key?(attr)
send "#{attr}=", attrs.delete(attr)
end
send :attributes_without_tracker_first=, new_attributes, *args
end
send :attributes_without_project_and_tracker_first=, attrs, *args
end
# Do not redefine alias chain on reload (see #4838)
alias_method_chain(:attributes=, :tracker_first) unless method_defined?(:attributes_without_tracker_first=)
alias_method_chain(:attributes=, :project_and_tracker_first) unless method_defined?(:attributes_without_project_and_tracker_first=)
def estimated_hours=(h)
write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)

View File

@ -279,10 +279,7 @@ class IssueTest < ActiveSupport::TestCase
end
def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields
issue = Issue.new(:project_id => 1)
issue.attributes = {:tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'Test', :custom_field_values => {'2' => 'Test'}}
issue.save!
issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'Test', :custom_field_values => {'2' => 'Test'})
assert !Tracker.find(2).custom_field_ids.include?(2)
issue = Issue.find(issue.id)
@ -301,7 +298,16 @@ class IssueTest < ActiveSupport::TestCase
assert issue.custom_field_values.any?
end
def test_assigning_attributes_should_assign_tracker_id_first
def test_assigning_attributes_should_assign_project_and_tracker_first
seq = sequence('seq')
issue = Issue.new
issue.expects(:project_id=).in_sequence(seq)
issue.expects(:tracker_id=).in_sequence(seq)
issue.expects(:subject=).in_sequence(seq)
issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'}
end
def test_assigning_tracker_and_custom_fields_should_assign_custom_fields
attributes = ActiveSupport::OrderedHash.new
attributes['custom_field_values'] = { '1' => 'MySQL' }
attributes['tracker_id'] = '1'