]> source.dussan.org Git - redmine.git/commitdiff
Fixes "less than", "greater than" filters on custom fields with postgres (#6180).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Jul 2011 21:34:35 +0000 (21:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 9 Jul 2011 21:34:35 +0000 (21:34 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6216 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/unit/query_test.rb

index 2b0776cbe0c6d0c0b2c25296e3bcf6352330ad93..165bbac849c48dcc2bcd1bc211f3e96d4d831841 100644 (file)
@@ -616,9 +616,17 @@ class Query < ActiveRecord::Base
       sql = "#{db_table}.#{db_field} IS NOT NULL"
       sql << " AND #{db_table}.#{db_field} <> ''" if is_custom_filter
     when ">="
-      sql = "#{db_table}.#{db_field} >= #{value.first.to_i}"
+      if is_custom_filter
+        sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) >= #{value.first.to_i}"
+      else
+        sql = "#{db_table}.#{db_field} >= #{value.first.to_i}"
+      end
     when "<="
-      sql = "#{db_table}.#{db_field} <= #{value.first.to_i}"
+      if is_custom_filter
+        sql = "CAST(#{db_table}.#{db_field} AS decimal(60,3)) <= #{value.first.to_i}"
+      else
+        sql = "#{db_table}.#{db_field} <= #{value.first.to_i}"
+      end
     when "o"
       sql = "#{IssueStatus.table_name}.is_closed=#{connection.quoted_false}" if field == "status_id"
     when "c"
index 646e4099f5370c163dbc50b52a21d0f493b593af..55a67f26a8d02792b3a064b5bb333ef6c00a1901 100644 (file)
@@ -107,6 +107,29 @@ class QueryTest < ActiveSupport::TestCase
     assert query.statement.include?("#{Issue.table_name}.done_ratio >= 40")
     find_issues_with_query(query)
   end
+  
+  def test_operator_greater_than_on_custom_field
+    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")
+    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")
+    find_issues_with_query(query)
+  end
+  
+  def test_operator_lesser_than_on_custom_field
+    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")
+    find_issues_with_query(query)
+  end
 
   def test_operator_in_more_than
     Issue.find(7).update_attribute(:due_date, (Date.today + 15))