@@ -174,9 +174,9 class Query < ActiveRecord::Base | |||
|
174 | 174 | if values_for(field) |
|
175 | 175 | case type_for(field) |
|
176 | 176 | when :integer |
|
177 | add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+$/) } | |
|
177 | add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+$/) } | |
|
178 | 178 | when :float |
|
179 | add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^\d+(\.\d*)?$/) } | |
|
179 | add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+(\.\d*)?$/) } | |
|
180 | 180 | when :date, :date_past |
|
181 | 181 | case operator_for(field) |
|
182 | 182 | when "=", ">=", "<=", "><" |
@@ -178,6 +178,20 class QueryTest < ActiveSupport::TestCase | |||
|
178 | 178 | assert_equal 2, issues.first.id |
|
179 | 179 | end |
|
180 | 180 | |
|
181 | def test_operator_is_on_integer_custom_field_should_accept_negative_value | |
|
182 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_for_all => true, :is_filter => true) | |
|
183 | CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7') | |
|
184 | CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '-12') | |
|
185 | CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '') | |
|
186 | ||
|
187 | query = Query.new(:name => '_') | |
|
188 | query.add_filter("cf_#{f.id}", '=', ['-12']) | |
|
189 | assert query.valid? | |
|
190 | issues = find_issues_with_query(query) | |
|
191 | assert_equal 1, issues.size | |
|
192 | assert_equal 2, issues.first.id | |
|
193 | end | |
|
194 | ||
|
181 | 195 | def test_operator_is_on_float_custom_field |
|
182 | 196 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true) |
|
183 | 197 | CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7.3') |
@@ -191,6 +205,20 class QueryTest < ActiveSupport::TestCase | |||
|
191 | 205 | assert_equal 2, issues.first.id |
|
192 | 206 | end |
|
193 | 207 | |
|
208 | def test_operator_is_on_float_custom_field_should_accept_negative_value | |
|
209 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'float', :is_filter => true, :is_for_all => true) | |
|
210 | CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '7.3') | |
|
211 | CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '-12.7') | |
|
212 | CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '') | |
|
213 | ||
|
214 | query = Query.new(:name => '_') | |
|
215 | query.add_filter("cf_#{f.id}", '=', ['-12.7']) | |
|
216 | assert query.valid? | |
|
217 | issues = find_issues_with_query(query) | |
|
218 | assert_equal 1, issues.size | |
|
219 | assert_equal 2, issues.first.id | |
|
220 | end | |
|
221 | ||
|
194 | 222 | def test_operator_is_on_multi_list_custom_field |
|
195 | 223 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'list', :is_filter => true, :is_for_all => true, |
|
196 | 224 | :possible_values => ['value1', 'value2', 'value3'], :multiple => true) |
General Comments 0
You need to be logged in to leave comments.
Login now