Fixed: error when serializing back objects with custom fields using ActiveResource (#6403).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4480 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
8524d505c5
commit
0e19aa4362
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue