@@ -238,17 +238,21 class Issue < ActiveRecord::Base | |||||
238 | write_attribute(:description, arg) |
|
238 | write_attribute(:description, arg) | |
239 | end |
|
239 | end | |
240 |
|
240 | |||
241 |
# Overrides attributes= so that tracker |
|
241 | # Overrides attributes= so that project and tracker get assigned first | |
242 | def attributes_with_tracker_first=(new_attributes, *args) |
|
242 | def attributes_with_project_and_tracker_first=(new_attributes, *args) | |
243 | return if new_attributes.nil? |
|
243 | return if new_attributes.nil? | |
244 | new_tracker_id = new_attributes['tracker_id'] || new_attributes[:tracker_id] |
|
244 | attrs = new_attributes.dup | |
245 | if new_tracker_id |
|
245 | attrs.stringify_keys! | |
246 | self.tracker_id = new_tracker_id |
|
246 | ||
|
247 | %w(project project_id tracker tracker_id).each do |attr| | |||
|
248 | if attrs.has_key?(attr) | |||
|
249 | send "#{attr}=", attrs.delete(attr) | |||
|
250 | end | |||
247 | end |
|
251 | end | |
248 |
send :attributes_without_tracker_first=, |
|
252 | send :attributes_without_project_and_tracker_first=, attrs, *args | |
249 | end |
|
253 | end | |
250 | # Do not redefine alias chain on reload (see #4838) |
|
254 | # Do not redefine alias chain on reload (see #4838) | |
251 | alias_method_chain(:attributes=, :tracker_first) unless method_defined?(:attributes_without_tracker_first=) |
|
255 | alias_method_chain(:attributes=, :project_and_tracker_first) unless method_defined?(:attributes_without_project_and_tracker_first=) | |
252 |
|
256 | |||
253 | def estimated_hours=(h) |
|
257 | def estimated_hours=(h) | |
254 | write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h) |
|
258 | write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h) |
@@ -279,10 +279,7 class IssueTest < ActiveSupport::TestCase | |||||
279 | end |
|
279 | end | |
280 |
|
280 | |||
281 | def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields |
|
281 | def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields | |
282 | issue = Issue.new(:project_id => 1) |
|
282 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'Test', :custom_field_values => {'2' => 'Test'}) | |
283 | issue.attributes = {:tracker_id => 1, :author_id => 1, :status_id => 1, :subject => 'Test', :custom_field_values => {'2' => 'Test'}} |
|
|||
284 | issue.save! |
|
|||
285 |
|
||||
286 | assert !Tracker.find(2).custom_field_ids.include?(2) |
|
283 | assert !Tracker.find(2).custom_field_ids.include?(2) | |
287 |
|
284 | |||
288 | issue = Issue.find(issue.id) |
|
285 | issue = Issue.find(issue.id) | |
@@ -301,7 +298,16 class IssueTest < ActiveSupport::TestCase | |||||
301 | assert issue.custom_field_values.any? |
|
298 | assert issue.custom_field_values.any? | |
302 | end |
|
299 | end | |
303 |
|
300 | |||
304 |
def test_assigning_attributes_should_assign_tracker |
|
301 | def test_assigning_attributes_should_assign_project_and_tracker_first | |
|
302 | seq = sequence('seq') | |||
|
303 | issue = Issue.new | |||
|
304 | issue.expects(:project_id=).in_sequence(seq) | |||
|
305 | issue.expects(:tracker_id=).in_sequence(seq) | |||
|
306 | issue.expects(:subject=).in_sequence(seq) | |||
|
307 | issue.attributes = {:tracker_id => 2, :project_id => 1, :subject => 'Test'} | |||
|
308 | end | |||
|
309 | ||||
|
310 | def test_assigning_tracker_and_custom_fields_should_assign_custom_fields | |||
305 | attributes = ActiveSupport::OrderedHash.new |
|
311 | attributes = ActiveSupport::OrderedHash.new | |
306 | attributes['custom_field_values'] = { '1' => 'MySQL' } |
|
312 | attributes['custom_field_values'] = { '1' => 'MySQL' } | |
307 | attributes['tracker_id'] = '1' |
|
313 | attributes['tracker_id'] = '1' |
General Comments 0
You need to be logged in to leave comments.
Login now