Adds estimated hours to issue filters (#1678).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1696 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-07-26 09:05:26 +00:00
parent 9f92554319
commit 6ddea3396b
2 changed files with 28 additions and 13 deletions

View File

@ -88,7 +88,7 @@ class Query < ActiveRecord::Base
:date_past => [ ">t-", "<t-", "t-", "t", "w" ], :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
:string => [ "=", "~", "!", "!~" ], :string => [ "=", "~", "!", "!~" ],
:text => [ "~", "!~" ], :text => [ "~", "!~" ],
:integer => [ "=", ">=", "<=" ] } :integer => [ "=", ">=", "<=", "!*", "*" ] }
cattr_reader :operators_by_filter_type cattr_reader :operators_by_filter_type
@ -152,7 +152,8 @@ class Query < ActiveRecord::Base
"updated_on" => { :type => :date_past, :order => 10 }, "updated_on" => { :type => :date_past, :order => 10 },
"start_date" => { :type => :date, :order => 11 }, "start_date" => { :type => :date, :order => 11 },
"due_date" => { :type => :date, :order => 12 }, "due_date" => { :type => :date, :order => 12 },
"done_ratio" => { :type => :integer, :order => 13 }} "estimated_hours" => { :type => :integer, :order => 13 },
"done_ratio" => { :type => :integer, :order => 14 }}
user_values = [] user_values = []
user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged? user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?

View File

@ -26,11 +26,17 @@ class QueryTest < Test::Unit::TestCase
assert !query.available_filters.has_key?('cf_3') assert !query.available_filters.has_key?('cf_3')
end end
def find_issues_with_query(query)
Issue.find :all,
:include => [ :assigned_to, :status, :tracker, :project, :priority ],
:conditions => query.statement
end
def test_query_with_multiple_custom_fields def test_query_with_multiple_custom_fields
query = Query.find(1) query = Query.find(1)
assert query.valid? assert query.valid?
assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')") assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement issues = find_issues_with_query(query)
assert_equal 1, issues.length assert_equal 1, issues.length
assert_equal Issue.find(3), issues.first assert_equal Issue.find(3), issues.first
end end
@ -41,7 +47,15 @@ class QueryTest < Test::Unit::TestCase
query.add_filter('cf_1', '!*', ['']) query.add_filter('cf_1', '!*', [''])
assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NULL") assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NULL")
assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''") assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end
def test_operator_none_for_integer
query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('estimated_hours', '!*', [''])
issues = find_issues_with_query(query)
assert !issues.empty?
assert issues.all? {|i| !i.estimated_hours}
end end
def test_operator_all def test_operator_all
@ -50,63 +64,63 @@ class QueryTest < Test::Unit::TestCase
query.add_filter('cf_1', '*', ['']) query.add_filter('cf_1', '*', [''])
assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NOT NULL") assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NOT NULL")
assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''") assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_greater_than def test_operator_greater_than
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('done_ratio', '>=', ['40']) 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")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_in_more_than def test_operator_in_more_than
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('due_date', '>t+', ['15']) query.add_filter('due_date', '>t+', ['15'])
assert query.statement.include?("#{Issue.table_name}.due_date >=") assert query.statement.include?("#{Issue.table_name}.due_date >=")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_in_less_than def test_operator_in_less_than
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('due_date', '<t+', ['15']) query.add_filter('due_date', '<t+', ['15'])
assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN") assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_today def test_operator_today
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('due_date', 't', ['']) query.add_filter('due_date', 't', [''])
assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN") assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_this_week_on_date def test_operator_this_week_on_date
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('due_date', 'w', ['']) query.add_filter('due_date', 'w', [''])
assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN") assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_this_week_on_datetime def test_operator_this_week_on_datetime
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('created_on', 'w', ['']) query.add_filter('created_on', 'w', [''])
assert query.statement.include?("#{Issue.table_name}.created_on BETWEEN") assert query.statement.include?("#{Issue.table_name}.created_on BETWEEN")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_contains def test_operator_contains
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('subject', '~', ['string']) query.add_filter('subject', '~', ['string'])
assert query.statement.include?("#{Issue.table_name}.subject LIKE '%string%'") assert query.statement.include?("#{Issue.table_name}.subject LIKE '%string%'")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_operator_does_not_contains def test_operator_does_not_contains
query = Query.new(:project => Project.find(1), :name => '_') query = Query.new(:project => Project.find(1), :name => '_')
query.add_filter('subject', '!~', ['string']) query.add_filter('subject', '!~', ['string'])
assert query.statement.include?("#{Issue.table_name}.subject NOT LIKE '%string%'") assert query.statement.include?("#{Issue.table_name}.subject NOT LIKE '%string%'")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement find_issues_with_query(query)
end end
def test_default_columns def test_default_columns