"(#{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
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
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?