Fixed shot filter expression parsing depending upon field operators (#8371).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@7624 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
765978871d
commit
a118c4ccb0
@ -308,9 +308,12 @@ class Query < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_short_filter(field, expression)
|
def add_short_filter(field, expression)
|
||||||
return unless expression
|
return unless expression && available_filters.has_key?(field)
|
||||||
parms = expression.scan(/^(o|c|!\*|!|\*)?(.*)$/).first
|
field_type = available_filters[field][:type]
|
||||||
add_filter field, (parms[0] || "="), [parms[1] || ""]
|
@@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
|
end
|
||||||
|
|
||||||
# Add multiple filters using +add_filter+
|
# Add multiple filters using +add_filter+
|
||||||
|
@ -144,6 +144,80 @@ class IssuesControllerTest < ActionController::TestCase
|
|||||||
assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
|
assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
|
||||||
end
|
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
|
def test_index_with_project_and_empty_filters
|
||||||
get :index, :project_id => 1, :set_filter => 1, :fields => ['']
|
get :index, :project_id => 1, :set_filter => 1, :fields => ['']
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
Loading…
x
Reference in New Issue
Block a user