summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-10 18:09:40 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2011-07-10 18:09:40 +0000
commitbf15b06d98a8db28d610e38f8266d03d018a3b9f (patch)
tree3d565031e6c12a4ce2939d6556914c77aa7b8945
parent4507aa5014184081f2bdce175bac7a9c20fcd8b4 (diff)
downloadredmine-bf15b06d98a8db28d610e38f8266d03d018a3b9f.tar.gz
redmine-bf15b06d98a8db28d610e38f8266d03d018a3b9f.zip
Fixes filters on float values.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6227 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/query.rb13
-rw-r--r--test/unit/query_test.rb29
2 files changed, 30 insertions, 12 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index 7746af88e..33fe2ec5f 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -123,6 +123,7 @@ class Query < ActiveRecord::Base
:date_past => [ "=", ">=", "<=", "><", ">t-", "<t-", "t-", "t", "w" ],
:string => [ "=", "~", "!", "!~" ],
:text => [ "~", "!~" ],
+ # TODO: should be :numeric
:integer => [ "=", ">=", "<=", "><", "!*", "*" ] }
cattr_reader :operators_by_filter_type
@@ -633,9 +634,9 @@ class Query < ActiveRecord::Base
sql = date_clause(db_table, db_field, (Date.parse(value.first) rescue nil), nil)
else
if is_custom_filter
- sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) >= #{value.first.to_i}"
+ sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) >= #{value.first.to_f}"
else
- sql = "#{db_table}.#{db_field} >= #{value.first.to_i}"
+ sql = "#{db_table}.#{db_field} >= #{value.first.to_f}"
end
end
when "<="
@@ -643,9 +644,9 @@ class Query < ActiveRecord::Base
sql = date_clause(db_table, db_field, nil, (Date.parse(value.first) rescue nil))
else
if is_custom_filter
- sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) <= #{value.first.to_i}"
+ sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) <= #{value.first.to_f}"
else
- sql = "#{db_table}.#{db_field} <= #{value.first.to_i}"
+ sql = "#{db_table}.#{db_field} <= #{value.first.to_f}"
end
end
when "><"
@@ -653,9 +654,9 @@ class Query < ActiveRecord::Base
sql = date_clause(db_table, db_field, (Date.parse(value[0]) rescue nil), (Date.parse(value[1]) rescue nil))
else
if is_custom_filter
- sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) BETWEEN #{value[0].to_i} AND #{value[1].to_i}"
+ sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) BETWEEN #{value[0].to_f} AND #{value[1].to_f}"
else
- sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_i} AND #{value[1].to_i}"
+ sql = "#{db_table}.#{db_field} BETWEEN #{value[0].to_f} AND #{value[1].to_f}"
end
end
when "o"
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 31dfa488e..d1d55bb2a 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -101,10 +101,27 @@ class QueryTest < ActiveSupport::TestCase
find_issues_with_query(query)
end
+ def test_operator_is_on_float
+ Issue.update_all("estimated_hours = 171.2", "id=2")
+
+ query = Query.new(:name => '_')
+ query.add_filter('estimated_hours', '=', ['171.20'])
+ issues = find_issues_with_query(query)
+ assert_equal 1, issues.size
+ assert_equal 2, issues.first.id
+ end
+
def test_operator_greater_than
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('done_ratio', '>=', ['40'])
- assert query.statement.include?("#{Issue.table_name}.done_ratio >= 40")
+ assert query.statement.include?("#{Issue.table_name}.done_ratio >= 40.0")
+ find_issues_with_query(query)
+ end
+
+ def test_operator_greater_than_a_float
+ query = Query.new(:project => Project.find(1), :name => '_')
+ query.add_filter('estimated_hours', '>=', ['40.5'])
+ assert query.statement.include?("#{Issue.table_name}.estimated_hours >= 40.5")
find_issues_with_query(query)
end
@@ -112,14 +129,14 @@ class QueryTest < ActiveSupport::TestCase
f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true)
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter("cf_#{f.id}", '>=', ['40'])
- assert query.statement.include?("CAST(custom_values.value AS decimal(60,3)) >= 40")
+ assert query.statement.include?("CAST(custom_values.value AS decimal(60,3)) >= 40.0")
find_issues_with_query(query)
end
def test_operator_lesser_than
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('done_ratio', '<=', ['30'])
- assert query.statement.include?("#{Issue.table_name}.done_ratio <= 30")
+ assert query.statement.include?("#{Issue.table_name}.done_ratio <= 30.0")
find_issues_with_query(query)
end
@@ -127,14 +144,14 @@ class QueryTest < ActiveSupport::TestCase
f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true)
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter("cf_#{f.id}", '<=', ['30'])
- assert query.statement.include?("CAST(custom_values.value AS decimal(60,3)) <= 30")
+ assert query.statement.include?("CAST(custom_values.value AS decimal(60,3)) <= 30.0")
find_issues_with_query(query)
end
def test_operator_between
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('done_ratio', '><', ['30', '40'])
- assert_include "#{Issue.table_name}.done_ratio BETWEEN 30 AND 40", query.statement
+ assert_include "#{Issue.table_name}.done_ratio BETWEEN 30.0 AND 40.0", query.statement
find_issues_with_query(query)
end
@@ -142,7 +159,7 @@ class QueryTest < ActiveSupport::TestCase
f = IssueCustomField.create!(:name => 'filter', :field_format => 'int', :is_filter => true, :is_for_all => true)
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter("cf_#{f.id}", '><', ['30', '40'])
- assert_include "CAST(custom_values.value AS decimal(60,3)) BETWEEN 30 AND 40", query.statement
+ assert_include "CAST(custom_values.value AS decimal(60,3)) BETWEEN 30.0 AND 40.0", query.statement
find_issues_with_query(query)
end