Fixes "less than", "greater than" filters on custom fields with postgres (#6180).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6216 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2011-07-09 21:34:35 +00:00
parent c7c062a981
commit 4a4a71349a
2 changed files with 33 additions and 2 deletions

View 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 ">="
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 "<="
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"

View File

@ -108,6 +108,29 @@ class QueryTest < ActiveSupport::TestCase
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))
query = Query.new(:project => Project.find(1), :name => '_')