Commit 3a9b6571 authored by emassip's avatar emassip

Fixed shot filter expression parsing depending upon field operators (#8371).

git-svn-id: https://svn.redmine.org/redmine/trunk@7624 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent a66d05ba
......@@ -308,9 +308,12 @@ class Query < ActiveRecord::Base
end
def add_short_filter(field, expression)
return unless expression
parms = expression.scan(/^(o|c|!\*|!|\*)?(.*)$/).first
add_filter field, (parms[0] || "="), [parms[1] || ""]
return unless expression && available_filters.has_key?(field)
field_type = available_filters[field][:type]
@@operators_by_filter_type[field_type].sort.reverse.detect do |operator|
next unless expression =~ /^#{Regexp.escape(operator)}(.*)$/
add_filter field, operator, $1.present? ? $1.split('|') : ['']
end || add_filter(field, '=', expression.split('|'))
end
# Add multiple filters using +add_filter+
......
......@@ -144,6 +144,80 @@ class IssuesControllerTest < ActionController::TestCase
assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
end
def test_index_with_short_filters
to_test = {
'status_id' => {
'o' => { :op => 'o', :values => [''] },
'c' => { :op => 'c', :values => [''] },
'7' => { :op => '=', :values => ['7'] },
'7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
'=7' => { :op => '=', :values => ['7'] },
'!3' => { :op => '!', :values => ['3'] },
'!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
'subject' => {
'This is a subject' => { :op => '=', :values => ['This is a subject'] },
'o' => { :op => '=', :values => ['o'] },
'~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
'!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
'tracker_id' => {
'3' => { :op => '=', :values => ['3'] },
'=3' => { :op => '=', :values => ['3'] },
'*' => { :op => '=', :values => ['*'] },
'!*' => { :op => '!', :values => ['*'] }},
'start_date' => {
'2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
'=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
'>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
'<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
'><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
'<t+2' => { :op => '<t+', :values => ['2'] },
'>t+2' => { :op => '>t+', :values => ['2'] },
't+2' => { :op => 't+', :values => ['2'] },
't' => { :op => 't', :values => [''] },
'w' => { :op => 'w', :values => [''] },
'>t-2' => { :op => '>t-', :values => ['2'] },
'<t-2' => { :op => '<t-', :values => ['2'] },
't-2' => { :op => 't-', :values => ['2'] }},
'created_on' => {
'>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
'<t+2' => { :op => '=', :values => ['<t+2'] },
'>t+2' => { :op => '=', :values => ['>t+2'] },
't+2' => { :op => 't', :values => ['+2'] }},
'cf_1' => {
'c' => { :op => '=', :values => ['c'] },
'!c' => { :op => '!', :values => ['c'] },
'!*' => { :op => '!*', :values => [''] },
'*' => { :op => '*', :values => [''] }},
'estimated_hours' => {
'=13.4' => { :op => '=', :values => ['13.4'] },
'>=45' => { :op => '>=', :values => ['45'] },
'<=125' => { :op => '<=', :values => ['125'] },
'><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
'!*' => { :op => '!*', :values => [''] },
'*' => { :op => '*', :values => [''] }}
}
default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
to_test.each do |field, expression_and_expected|
expression_and_expected.each do |filter_expression, expected|
get :index, :set_filter => 1, field => filter_expression
assert_response :success
assert_template 'index'
assert_not_nil assigns(:issues)
query = assigns(:query)
assert_not_nil query
assert query.has_filter?(field)
assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
end
end
end
def test_index_with_project_and_empty_filters
get :index, :project_id => 1, :set_filter => 1, :fields => ['']
assert_response :success
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment