##// END OF EJS Templates
Fixes tracker_id and custom_field_values assignment order for issues (#4353)....
Jean-Philippe Lang -
r3025:f2520385e445
parent child
Show More
@@ -142,8 +142,22 class Issue < ActiveRecord::Base
142 def tracker_id=(tid)
142 def tracker_id=(tid)
143 self.tracker = nil
143 self.tracker = nil
144 write_attribute(:tracker_id, tid)
144 write_attribute(:tracker_id, tid)
145 result = write_attribute(:tracker_id, tid)
146 @custom_field_values = nil
147 result
145 end
148 end
146
149
150 # Overrides attributes= so that tracker_id gets assigned first
151 def attributes_with_tracker_first=(new_attributes, *args)
152 return if new_attributes.nil?
153 new_tracker_id = new_attributes['tracker_id'] || new_attributes[:tracker_id]
154 if new_tracker_id
155 self.tracker_id = new_tracker_id
156 end
157 self.attributes_without_tracker_first = new_attributes, *args
158 end
159 alias_method_chain :attributes=, :tracker_first
160
147 def estimated_hours=(h)
161 def estimated_hours=(h)
148 write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
162 write_attribute :estimated_hours, (h.is_a?(String) ? h.to_hours : h)
149 end
163 end
@@ -164,6 +164,23 class IssueTest < ActiveSupport::TestCase
164 assert_equal custom_value.id, issue.custom_value_for(field).id
164 assert_equal custom_value.id, issue.custom_value_for(field).id
165 end
165 end
166
166
167 def test_assigning_tracker_id_should_reload_custom_fields_values
168 issue = Issue.new(:project => Project.find(1))
169 assert issue.custom_field_values.empty?
170 issue.tracker_id = 1
171 assert issue.custom_field_values.any?
172 end
173
174 def test_assigning_attributes_should_assign_tracker_id_first
175 attributes = ActiveSupport::OrderedHash.new
176 attributes['custom_field_values'] = { '1' => 'MySQL' }
177 attributes['tracker_id'] = '1'
178 issue = Issue.new(:project => Project.find(1))
179 issue.attributes = attributes
180 assert_not_nil issue.custom_value_for(1)
181 assert_equal 'MySQL', issue.custom_value_for(1).value
182 end
183
167 def test_should_update_issue_with_disabled_tracker
184 def test_should_update_issue_with_disabled_tracker
168 p = Project.find(1)
185 p = Project.find(1)
169 issue = Issue.find(1)
186 issue = Issue.find(1)
General Comments 0
You need to be logged in to leave comments. Login now