adapt list custom field filter to alterations caused by multi select

pull/5219/head
Jens Ulferts 8 years ago
parent 464e8325ee
commit d80d8b1ecc
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 28
      app/models/queries/work_packages/filter/custom_field_filter.rb
  2. 2
      lib/api/v3/queries/filters/query_filter_instance_representer.rb
  3. 2
      lib/api/v3/queries/schemas/string_object_filter_dependency_representer.rb
  4. 2
      spec/lib/api/v3/queries/schemas/string_object_filter_dependency_representer_spec.rb
  5. 31
      spec/models/queries/work_packages/filter/custom_field_filter_spec.rb

@ -111,7 +111,7 @@ class Queries::WorkPackages::Filter::CustomFieldFilter <
end
def ar_object_filter?
%w{user version}.include? custom_field.field_format
%w{user version list}.include? custom_field.field_format
end
def value_objects
@ -120,6 +120,8 @@ class Queries::WorkPackages::Filter::CustomFieldFilter <
User.find(values)
when 'version'
Version.find(values)
when 'list'
value_objects_for_list
else
super
end
@ -153,4 +155,28 @@ class Queries::WorkPackages::Filter::CustomFieldFilter <
!self.class.custom_fields(context)
.map(&:id).include? custom_field.id
end
def value_objects_for_list
objects = allowed_values.select do |value|
values.include? value.last.to_s
end
objects.map do |value|
Queries::StringObject.new(value.last, value.first)
end
end
end
#
# This object is only used to transport the values tothe query filter instance
# representer which expects a class and deduces the path from the classes' name.
#
class Queries::StringObject
attr_accessor :id,
:name
def initialize(id, name)
self.id = [name, id]
self.name = name
end
end

@ -55,7 +55,7 @@ module API
represented.value_objects.map do |value_object|
{
href: api_v3_paths.send(value_object.class.name.underscore, value_object.id),
href: api_v3_paths.send(value_object.class.name.demodulize.underscore, value_object.id),
title: value_object.name
}
end

@ -41,7 +41,7 @@ module API
required: true,
visibility: false,
values_callback: ->(*) {
represented.allowed_values.map(&:last)
represented.allowed_values
},
value_representer: StringObjects::StringObjectRepresenter,
link_factory: ->(value) {

@ -55,7 +55,7 @@ describe ::API::V3::Queries::Schemas::StringObjectFilterDependencyRepresenter do
let(:type) { '[]StringObject' }
let(:hrefs) do
filter.allowed_values.each_with_object([]) do |value, array|
array << api_v3_paths.string_object(value.last)
array << api_v3_paths.string_object(value)
end
end

@ -398,7 +398,36 @@ describe Queries::WorkPackages::Filter::CustomFieldFilter, type: :model do
context 'list cf' do
let(:custom_field) { list_wp_custom_field }
it_behaves_like 'non ar filter'
describe '#ar_object_filter?' do
it 'is true' do
expect(instance)
.to be_ar_object_filter
end
end
describe '#value_objects' do
before do
instance.values = [custom_field.custom_options.last.id,
custom_field.custom_options.first.id]
end
it 'returns an array with custom classes' do
expect(instance.value_objects.length)
.to eql(2)
expect(instance.value_objects[0].id)
.to match_array([custom_field.custom_options.first.value,
custom_field.custom_options.first.id])
expect(instance.value_objects[0].name)
.to eql(custom_field.custom_options.first.value)
expect(instance.value_objects[1].id)
.to match_array([custom_field.custom_options.last.value,
custom_field.custom_options.last.id])
expect(instance.value_objects[1].name)
.to eql(custom_field.custom_options.last.value)
end
end
end
context 'bool cf' do

Loading…
Cancel
Save