@@ -308,9 +308,12 class Query < ActiveRecord::Base | |||||
308 | end |
|
308 | end | |
309 |
|
309 | |||
310 | def add_short_filter(field, expression) |
|
310 | def add_short_filter(field, expression) | |
311 | return unless expression |
|
311 | return unless expression && available_filters.has_key?(field) | |
312 | parms = expression.scan(/^(o|c|!\*|!|\*)?(.*)$/).first |
|
312 | field_type = available_filters[field][:type] | |
313 | add_filter field, (parms[0] || "="), [parms[1] || ""] |
|
313 | @@operators_by_filter_type[field_type].sort.reverse.detect do |operator| | |
|
314 | next unless expression =~ /^#{Regexp.escape(operator)}(.*)$/ | |||
|
315 | add_filter field, operator, $1.present? ? $1.split('|') : [''] | |||
|
316 | end || add_filter(field, '=', expression.split('|')) | |||
314 | end |
|
317 | end | |
315 |
|
318 | |||
316 | # Add multiple filters using +add_filter+ |
|
319 | # Add multiple filters using +add_filter+ |
@@ -144,6 +144,80 class IssuesControllerTest < ActionController::TestCase | |||||
144 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) |
|
144 | assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) | |
145 | end |
|
145 | end | |
146 |
|
146 | |||
|
147 | def test_index_with_short_filters | |||
|
148 | ||||
|
149 | to_test = { | |||
|
150 | 'status_id' => { | |||
|
151 | 'o' => { :op => 'o', :values => [''] }, | |||
|
152 | 'c' => { :op => 'c', :values => [''] }, | |||
|
153 | '7' => { :op => '=', :values => ['7'] }, | |||
|
154 | '7|3|4' => { :op => '=', :values => ['7', '3', '4'] }, | |||
|
155 | '=7' => { :op => '=', :values => ['7'] }, | |||
|
156 | '!3' => { :op => '!', :values => ['3'] }, | |||
|
157 | '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }}, | |||
|
158 | 'subject' => { | |||
|
159 | 'This is a subject' => { :op => '=', :values => ['This is a subject'] }, | |||
|
160 | 'o' => { :op => '=', :values => ['o'] }, | |||
|
161 | '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] }, | |||
|
162 | '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }}, | |||
|
163 | 'tracker_id' => { | |||
|
164 | '3' => { :op => '=', :values => ['3'] }, | |||
|
165 | '=3' => { :op => '=', :values => ['3'] }, | |||
|
166 | '*' => { :op => '=', :values => ['*'] }, | |||
|
167 | '!*' => { :op => '!', :values => ['*'] }}, | |||
|
168 | 'start_date' => { | |||
|
169 | '2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |||
|
170 | '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] }, | |||
|
171 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |||
|
172 | '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] }, | |||
|
173 | '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] }, | |||
|
174 | '<t+2' => { :op => '<t+', :values => ['2'] }, | |||
|
175 | '>t+2' => { :op => '>t+', :values => ['2'] }, | |||
|
176 | 't+2' => { :op => 't+', :values => ['2'] }, | |||
|
177 | 't' => { :op => 't', :values => [''] }, | |||
|
178 | 'w' => { :op => 'w', :values => [''] }, | |||
|
179 | '>t-2' => { :op => '>t-', :values => ['2'] }, | |||
|
180 | '<t-2' => { :op => '<t-', :values => ['2'] }, | |||
|
181 | 't-2' => { :op => 't-', :values => ['2'] }}, | |||
|
182 | 'created_on' => { | |||
|
183 | '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] }, | |||
|
184 | '<t+2' => { :op => '=', :values => ['<t+2'] }, | |||
|
185 | '>t+2' => { :op => '=', :values => ['>t+2'] }, | |||
|
186 | 't+2' => { :op => 't', :values => ['+2'] }}, | |||
|
187 | 'cf_1' => { | |||
|
188 | 'c' => { :op => '=', :values => ['c'] }, | |||
|
189 | '!c' => { :op => '!', :values => ['c'] }, | |||
|
190 | '!*' => { :op => '!*', :values => [''] }, | |||
|
191 | '*' => { :op => '*', :values => [''] }}, | |||
|
192 | 'estimated_hours' => { | |||
|
193 | '=13.4' => { :op => '=', :values => ['13.4'] }, | |||
|
194 | '>=45' => { :op => '>=', :values => ['45'] }, | |||
|
195 | '<=125' => { :op => '<=', :values => ['125'] }, | |||
|
196 | '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] }, | |||
|
197 | '!*' => { :op => '!*', :values => [''] }, | |||
|
198 | '*' => { :op => '*', :values => [''] }} | |||
|
199 | } | |||
|
200 | ||||
|
201 | default_filter = { 'status_id' => {:operator => 'o', :values => [''] }} | |||
|
202 | ||||
|
203 | to_test.each do |field, expression_and_expected| | |||
|
204 | expression_and_expected.each do |filter_expression, expected| | |||
|
205 | ||||
|
206 | get :index, :set_filter => 1, field => filter_expression | |||
|
207 | ||||
|
208 | assert_response :success | |||
|
209 | assert_template 'index' | |||
|
210 | assert_not_nil assigns(:issues) | |||
|
211 | ||||
|
212 | query = assigns(:query) | |||
|
213 | assert_not_nil query | |||
|
214 | assert query.has_filter?(field) | |||
|
215 | assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters) | |||
|
216 | end | |||
|
217 | end | |||
|
218 | ||||
|
219 | end | |||
|
220 | ||||
147 | def test_index_with_project_and_empty_filters |
|
221 | def test_index_with_project_and_empty_filters | |
148 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] |
|
222 | get :index, :project_id => 1, :set_filter => 1, :fields => [''] | |
149 | assert_response :success |
|
223 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now