done_ratio
estimated_hours
custom_field_values
+ custom_fields
lock_version
) unless const_defined?(:SAFE_ATTRIBUTES)
author_id: 2
status_id: 1
start_date: <%= 1.day.from_now.to_date.to_s(:db) %>
- due_date: <%= 40.day.ago.to_date.to_s(:db) %>
+ due_date: <%= 40.day.from_now.to_date.to_s(:db) %>
root_id: 3
lft: 1
rgt: 2
end
+ context "PUT /issues/3.xml with custom fields" do
+ setup do
+ @parameters = {:issue => {:custom_fields => [{'id' => '1', 'value' => 'PostgreSQL' }, {'id' => '2', 'value' => '150'}]}}
+ @headers = { :authorization => credentials('jsmith') }
+ end
+
+ should "update custom fields" do
+ assert_no_difference('Issue.count') do
+ put '/issues/3.xml', @parameters, @headers
+ end
+
+ issue = Issue.find(3)
+ assert_equal '150', issue.custom_value_for(2).value
+ assert_equal 'PostgreSQL', issue.custom_value_for(1).value
+ end
+ end
+
context "PUT /issues/6.xml with failed update" do
setup do
@parameters = {:issue => {:subject => ''}}
:order => 'position')
end
+ # Sets the values of the object's custom fields
+ # values is an array like [{'id' => 1, 'value' => 'foo'}, {'id' => 2, 'value' => 'bar'}]
+ def custom_fields=(values)
+ values_to_hash = values.inject({}) do |hash, v|
+ v = v.stringify_keys
+ if v['id'] && v.has_key?('value')
+ hash[v['id']] = v['value']
+ end
+ hash
+ end
+ self.custom_field_values = values_to_hash
+ end
+
+ # Sets the values of the object's custom fields
+ # values is a hash like {'1' => 'foo', 2 => 'bar'}
def custom_field_values=(values)
@custom_field_values_changed = true
values = values.stringify_keys