Project

General

Profile

Patch #1678 ยป include_estimated_hours_in_filters.patch

Artem Vasiliev, 2008-07-24 12:19

View differences:

app/models/query.rb (working copy)
88 88
                                 :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
89 89
                                 :string => [ "=", "~", "!", "!~" ],
90 90
                                 :text => [  "~", "!~" ],
91
                                 :integer => [ "=", ">=", "<=" ] }
91
                                 :integer => [ "=", ">=", "<=", "!*" ] }
92 92

  
93 93
  cattr_reader :operators_by_filter_type
94 94

  
......
152 152
                           "updated_on" => { :type => :date_past, :order => 10 },
153 153
                           "start_date" => { :type => :date, :order => 11 },
154 154
                           "due_date" => { :type => :date, :order => 12 },
155
                           "done_ratio" =>  { :type => :integer, :order => 13 }}                          
155
                           "estimated_hours" => { :type => :date, :order => 13 },
156
                           "done_ratio" =>  { :type => :integer, :order => 14 }}
156 157
    
157 158
    user_values = []
158 159
    user_values << ["<< #{l(:label_me)} >>", "me"] if User.current.logged?
test/unit/query_test.rb (working copy)
26 26
    assert !query.available_filters.has_key?('cf_3')
27 27
  end
28 28
  
29
  def find_issues_with_query(query)
30
    Issue.find :all,
31
      :include => [ :assigned_to, :status, :tracker, :project, :priority ], 
32
      :conditions => query.statement
33
  end
34
  
29 35
  def test_query_with_multiple_custom_fields
30 36
    query = Query.find(1)
31 37
    assert query.valid?
32 38
    assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')")
33
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
39
    issues = find_issues_with_query(query)
34 40
    assert_equal 1, issues.length
35 41
    assert_equal Issue.find(3), issues.first
36 42
  end
......
41 47
    query.add_filter('cf_1', '!*', [''])
42 48
    assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NULL")
43 49
    assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''")
44
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
50
    find_issues_with_query(query)
45 51
  end
46 52
  
53
  def test_operator_none_for_integer
54
    query = Query.new(:project => Project.find(1), :name => '_')
55
    query.add_filter('estimated_hours', '!*', [''])
56
    issues = find_issues_with_query(query)
57
    assert !issues.empty?
58
    assert issues.all? {|i| !i.estimated_hours}
59
  end
60

  
47 61
  def test_operator_all
48 62
    query = Query.new(:project => Project.find(1), :name => '_')
49 63
    query.add_filter('fixed_version_id', '*', [''])
50 64
    query.add_filter('cf_1', '*', [''])
51 65
    assert query.statement.include?("#{Issue.table_name}.fixed_version_id IS NOT NULL")
52 66
    assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''")
53
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
67
    find_issues_with_query(query)
54 68
  end
55 69
  
56 70
  def test_operator_greater_than
57 71
    query = Query.new(:project => Project.find(1), :name => '_')
58 72
    query.add_filter('done_ratio', '>=', ['40'])
59 73
    assert query.statement.include?("#{Issue.table_name}.done_ratio >= 40")
60
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
74
    find_issues_with_query(query)
61 75
  end
62 76

  
63 77
  def test_operator_in_more_than
64 78
    query = Query.new(:project => Project.find(1), :name => '_')
65 79
    query.add_filter('due_date', '>t+', ['15'])
66 80
    assert query.statement.include?("#{Issue.table_name}.due_date >=")
67
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
81
    find_issues_with_query(query)
68 82
  end
69 83

  
70 84
  def test_operator_in_less_than
71 85
    query = Query.new(:project => Project.find(1), :name => '_')
72 86
    query.add_filter('due_date', '<t+', ['15'])
73 87
    assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
74
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
88
    find_issues_with_query(query)
75 89
  end
76 90

  
77 91
  def test_operator_today
78 92
    query = Query.new(:project => Project.find(1), :name => '_')
79 93
    query.add_filter('due_date', 't', [''])
80 94
    assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
81
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
95
    find_issues_with_query(query)
82 96
  end
83 97

  
84 98
  def test_operator_this_week_on_date
85 99
    query = Query.new(:project => Project.find(1), :name => '_')
86 100
    query.add_filter('due_date', 'w', [''])
87 101
    assert query.statement.include?("#{Issue.table_name}.due_date BETWEEN")
88
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
102
    find_issues_with_query(query)
89 103
  end
90 104

  
91 105
  def test_operator_this_week_on_datetime
92 106
    query = Query.new(:project => Project.find(1), :name => '_')
93 107
    query.add_filter('created_on', 'w', [''])
94 108
    assert query.statement.include?("#{Issue.table_name}.created_on BETWEEN")
95
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
109
    find_issues_with_query(query)
96 110
  end
97 111

  
98 112
  def test_operator_contains
99 113
    query = Query.new(:project => Project.find(1), :name => '_')
100 114
    query.add_filter('subject', '~', ['string'])
101 115
    assert query.statement.include?("#{Issue.table_name}.subject LIKE '%string%'")
102
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
116
    find_issues_with_query(query)
103 117
  end
104 118
  
105 119
  def test_operator_does_not_contains
106 120
    query = Query.new(:project => Project.find(1), :name => '_')
107 121
    query.add_filter('subject', '!~', ['string'])
108 122
    assert query.statement.include?("#{Issue.table_name}.subject NOT LIKE '%string%'")
109
    issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
123
    find_issues_with_query(query)
110 124
  end
111 125
  
112 126
  def test_default_columns
    (1-1/1)