diff options
-rw-r--r-- | app/models/issue_query.rb | 5 | ||||
-rw-r--r-- | app/models/query.rb | 9 | ||||
-rw-r--r-- | test/unit/query_test.rb | 22 |
3 files changed, 35 insertions, 1 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index e208b64ad..b167c5d9f 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -544,6 +544,11 @@ class IssueQuery < Query "(#{sql})" end + def find_assigned_to_id_filter_values(values) + Principal.visible.where(:id => values).map {|p| [p.name, p.id.to_s]} + end + alias :find_author_id_filter_values :find_assigned_to_id_filter_values + IssueRelation::TYPES.keys.each do |relation_type| alias_method "sql_for_#{relation_type}_field".to_sym, :sql_for_relations end diff --git a/app/models/query.rb b/app/models/query.rb index fbcf2e646..ed59c5526 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -311,7 +311,14 @@ class Query < ActiveRecord::Base def available_filters_as_json json = {} available_filters.each do |field, options| - json[field] = options.slice(:type, :name, :values).stringify_keys + options = options.slice(:type, :name, :values) + if options[:values] && values_for(field) + missing = Array(values_for(field)).select(&:present?) - options[:values].map(&:last) + if missing.any? && respond_to?(method = "find_#{field}_filter_values") + options[:values] += send(method, missing) + end + end + json[field] = options.stringify_keys end json end diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 30db3abd7..00c3d9a39 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -948,6 +948,28 @@ class QueryTest < ActiveSupport::TestCase assert_nil q.statement end + def test_available_filters_as_json_should_include_missing_assigned_to_id_values + user = User.generate! + with_current_user User.find(1) do + q = IssueQuery.new + q.filters = {"assigned_to_id" => {:operator => '=', :values => user.id.to_s}} + + filters = q.available_filters_as_json + assert_include [user.name, user.id.to_s], filters['assigned_to_id']['values'] + end + end + + def test_available_filters_as_json_should_include_missing_author_id_values + user = User.generate! + with_current_user User.find(1) do + q = IssueQuery.new + q.filters = {"author_id" => {:operator => '=', :values => user.id.to_s}} + + filters = q.available_filters_as_json + assert_include [user.name, user.id.to_s], filters['author_id']['values'] + end + end + def test_default_columns q = IssueQuery.new assert q.columns.any? |