Merge pull request #1488 from netfighter/feature/10232_wp_filters_from_plugins_not_displayed

pull/1458/head
Hagen Schink 11 years ago
commit 8b3fb481ef
  1. 6
      app/models/queries/work_packages/filter.rb
  2. 12
      spec/models/queries/work_packages/filter_spec.rb

@ -49,5 +49,9 @@ class Queries::WorkPackages::Filter < Queries::Filter
watcher_id: :list
)
validates :field, inclusion: { in: self.filter_types_by_field.keys, message: "%(value) is not a valid filter" }, unless: Proc.new {|filter| filter.field.to_s.starts_with?('cf_')}
validates :field, inclusion: { in: Proc.new { self.filter_types_by_field.keys }, message: "%(value) is not a valid filter" }, unless: Proc.new {|filter| filter.field.to_s.starts_with?('cf_')}
def self.add_filter_type_by_field(field, filter_type)
self.filter_types_by_field[field.to_sym] = filter_type.to_sym
end
end

@ -129,6 +129,18 @@ describe Queries::WorkPackages::Filter do
it { should be_valid }
end
# this context tests the case when a new item is injected in
# the filter_types_by_field hash afterwards
# from within some plugins that patch Queries::WorkPackages::Filter
context 'and the field is whitelisted afterwards' do
before do
filter.field = :some_new_key
filter.class.add_filter_type_by_field('some_new_key', 'list')
end
it { should be_valid }
end
context 'and the field is not whitelisted and no custom field key' do
before { filter.field = :any_key }

Loading…
Cancel
Save