pull/2673/head
Jan Sandbrink 10 years ago
parent 3fc5770fc0
commit f0197b4323
  1. 2
      lib/api/decorators/single.rb
  2. 1
      lib/api/v3/types/type_representer.rb
  3. 24
      lib/plugins/acts_as_customizable/lib/acts_as_customizable.rb
  4. 4
      spec/requests/api/v3/work_packages/form/work_package_form_resource_spec.rb

@ -103,8 +103,6 @@ module API
private
def datetime_formatter
API::V3::Utilities::DateTimeFormatter
end

@ -31,7 +31,6 @@ module API
module V3
module Types
class TypeRepresenter < ::API::Decorators::Single
self_link
property :id

@ -82,12 +82,21 @@ module Redmine
@custom_field_values_changed = true
values = values.stringify_keys
custom_field_values.each do |custom_value|
custom_value.value = values[custom_value.custom_field_id.to_s] if values.has_key?(custom_value.custom_field_id.to_s)
if values.has_key?(custom_value.custom_field_id.to_s)
custom_value.value = values[custom_value.custom_field_id.to_s]
end
end if values.is_a?(Hash)
end
def custom_field_values
@custom_field_values ||= available_custom_fields.map { |x| custom_values.detect { |v| v.custom_field == x } || custom_values.build(customized: self, custom_field: x, value: nil) }
@custom_field_values ||= available_custom_fields.map do |custom_field|
existing_cv = custom_values.detect { |v| v.custom_field == custom_field }
if existing_cv
existing_cv
else
custom_values.build(customized: self, custom_field: custom_field, value: nil)
end
end
end
def visible_custom_field_values
@ -113,14 +122,17 @@ module Redmine
def reset_custom_values!
@custom_field_values = nil
@custom_field_values_changed = true
values = custom_values.inject({}) { |h, v| h[v.custom_field_id] = v.value; h }
values = custom_values.inject({}) do |hash, custom_value|
hash[custom_value.custom_field_id] = custom_value.value
hash
end
custom_values.each { |cv| cv.destroy unless custom_field_values.include?(cv) }
end
def validate_custom_values
custom_field_values.reject(&:marked_for_destruction?).select(&:invalid?).each do |custom_value|
custom_value.errors.each do |_, message|
errors.add(custom_value.custom_field.accessor_name.to_sym, message)
custom_field_values.reject(&:marked_for_destruction?).select(&:invalid?).each do |cv|
cv.errors.each do |_, message|
errors.add(cv.custom_field.accessor_name.to_sym, message)
end
end
end

@ -647,9 +647,9 @@ describe 'API v3 Work package form resource', type: :request do
it 'should list the types' do
expect(subject.body).to be_json_eql(type_link.to_json)
.at_path("#{links_path}/allowedValues/1/href")
.at_path("#{links_path}/allowedValues/1/href")
expect(subject.body).to be_json_eql(other_type_link.to_json)
.at_path("#{links_path}/allowedValues/0/href")
.at_path("#{links_path}/allowedValues/0/href")
end
end

Loading…
Cancel
Save