]> source.dussan.org Git - redmine.git/commitdiff
Fixed: error when serializing back objects with custom fields using ActiveResource...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 10 Dec 2010 10:12:19 +0000 (10:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 10 Dec 2010 10:12:19 +0000 (10:12 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4480 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/custom_fields_helper.rb
app/views/issues/index.api.rsb
app/views/issues/show.api.rsb
app/views/projects/index.api.rsb
app/views/projects/show.api.rsb
app/views/users/index.api.rsb
app/views/users/show.api.rsb
test/integration/api_test/issues_test.rb

index 189467409d27a79b38cd814d6341b4faef475831..107d0ac873b73d25a186bead6301c93d31d61e06 100644 (file)
@@ -104,4 +104,15 @@ module CustomFieldsHelper
   def custom_field_formats_for_select
     Redmine::CustomFieldFormat.as_select
   end
+  
+  # Renders the custom_values in api views
+  def render_api_custom_values(custom_values, api)
+    api.array :custom_fields do
+      custom_values.each do |custom_value|
+        api.custom_field :id => custom_value.custom_field_id, :name => custom_value.custom_field.name do
+          api.value custom_value.value
+        end
+      end
+    end unless custom_values.empty?
+  end
 end
index a63b07a09181d27e7038f96b9c003e81eb703de2..f30ee55bba31346f3737727df2daf83d8c9b54b5 100644 (file)
@@ -19,11 +19,7 @@ api.array :issues do
       api.done_ratio   issue.done_ratio
       api.estimated_hours issue.estimated_hours
       
-      api.array :custom_fields do
-       issue.custom_field_values.each do |custom_value|
-               api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
-       end
-      end
+      render_api_custom_values issue.custom_field_values, api
       
       api.created_on issue.created_on
       api.updated_on issue.updated_on
index 001cabe11b091660f5e78bbb9162398f23ef069a..02e7fdd297015ecfb6a34f4c903375c0d2a97a7b 100644 (file)
@@ -20,11 +20,7 @@ api.issue do
        api.spent_hours         @issue.spent_hours
        end
   
-  api.array :custom_fields do
-       @issue.custom_field_values.each do |custom_value|
-               api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
-       end
-  end unless @issue.custom_field_values.empty?
+  render_api_custom_values @issue.custom_field_values, api
   
   api.created_on @issue.created_on
   api.updated_on @issue.updated_on
index e65477a2367fc33c3d4a554d862b92e645ebd314..4ffee934fa6edba986f5a8fac6a479766ce8c615 100644 (file)
@@ -6,11 +6,9 @@ api.array :projects do
       api.identifier  project.identifier
       api.description project.description
       api.parent(:id => project.parent_id, :name => project.parent.name) unless project.parent.nil?
-      api.array :custom_fields do
-        project.visible_custom_field_values.each do |custom_value|
-          api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
-        end
-      end unless project.custom_field_values.empty?
+      
+      render_api_custom_values project.visible_custom_field_values, api
+      
       api.created_on  project.created_on
       api.updated_on  project.updated_on
     end
index 4479e500f6d07bd22b7aea9ad77d814922d9b7b0..dc02637124e9becba30d493816ace1c4db3e9594 100644 (file)
@@ -5,11 +5,7 @@ api.project do
   api.description @project.description
   api.homepage    @project.homepage
   
-  api.array :custom_fields do
-    @project.visible_custom_field_values.each do |custom_value|
-      api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
-    end
-  end unless @project.custom_field_values.empty?
+  render_api_custom_values @project.visible_custom_field_values, api
   
   api.created_on @project.created_on
   api.updated_on @project.updated_on
index 815abef2bb7f1975f5a7e6504848c85985fe271d..722b44ac1ecca39c1e5fa02661cc1e2a138d5412 100644 (file)
@@ -9,11 +9,7 @@ api.array :users do
       api.created_on user.created_on
       api.last_login_on user.last_login_on
 
-      api.array :custom_fields do
-        user.visible_custom_field_values.each do |custom_value|
-          api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
-        end
-      end unless user.visible_custom_field_values.empty?
+      render_api_custom_values user.visible_custom_field_values, api
     end
   end
 end
index 6c3dd901888fb84869ad2e93c87bb53757802df9..c177d49e9672eba108f532d446332ae2816fa969 100644 (file)
@@ -7,11 +7,7 @@ api.user do
   api.created_on @user.created_on
   api.last_login_on @user.last_login_on
   
-  api.array :custom_fields do
-    @user.visible_custom_field_values.each do |custom_value|
-      api.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
-    end
-  end unless @user.visible_custom_field_values.empty?
+  render_api_custom_values @user.visible_custom_field_values, api
   
   api.array :memberships do
     @memberships.each do |membership|
index 0ef9de8e242433fe571b3b0430c58b5063e8fc03..c57b51eeac91739e2786d175427e21a5d7b0f796 100644 (file)
@@ -91,6 +91,32 @@ class ApiTest::IssuesTest < ActionController::IntegrationTest
   end
   
   context "GET /issues/:id" do
+    context "with custom fields" do
+      context ".xml" do
+        should "display custom fields" do
+          get '/issues/3.xml'
+          
+          assert_tag :tag => 'issue', 
+            :child => {
+              :tag => 'custom_fields',
+              :attributes => { :type => 'array' },
+              :child => {
+                :tag => 'custom_field',
+                :attributes => { :id => '1'},
+                :child => {
+                  :tag => 'value',
+                  :content => 'MySQL'
+                }
+              }
+            }
+            
+          assert_nothing_raised do
+            Hash.from_xml(response.body).to_xml
+          end
+        end
+      end
+    end
+    
     context "with subtasks" do
       setup do
         @c1 = Issue.generate!(:status_id => 1, :subject => "child c1", :tracker_id => 1, :project_id => 1, :parent_issue_id => 1)