]> source.dussan.org Git - redmine.git/commitdiff
Support for updating custom fields using the received custom_fields array (#6345...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 10 Dec 2010 10:48:16 +0000 (10:48 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 10 Dec 2010 10:48:16 +0000 (10:48 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4481 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/issue.rb
test/fixtures/issues.yml
test/integration/api_test/issues_test.rb
vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb

index 0b08f0c16e392401d7ffa606b4639be371786d01..1cd1b92f0d3b46f829545c842647325ba58dbd7d 100644 (file)
@@ -229,6 +229,7 @@ class Issue < ActiveRecord::Base
     done_ratio
     estimated_hours
     custom_field_values
+    custom_fields
     lock_version
   ) unless const_defined?(:SAFE_ATTRIBUTES)
   
index eec014ff4fb2592c8248f9fd938cd575ccfad8c4..15fb5b271c1a02db2c1c6d4aeaa7f5530215397a 100644 (file)
@@ -54,7 +54,7 @@ issues_003:
   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
index c57b51eeac91739e2786d175427e21a5d7b0f796..a5281e5ebdf8bd5d765ebe76f8917a16895cfb29 100644 (file)
@@ -284,6 +284,23 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
     
   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 => ''}}
index 03b36f69879b78c9397f83568841bcfeb3ff244f..9ed9fe3765b4ffc78b955b0fb9f350e78bdbc64f 100644 (file)
@@ -50,6 +50,21 @@ module Redmine
                                  :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