Revision 442:753f1380d6bc test/unit/lib/redmine/helpers

View differences:

test/unit/lib/redmine/helpers/.svn/entries
1 1
10
2 2

  
3 3
dir
4
4993
5
http://redmine.rubyforge.org/svn/trunk/test/unit/lib/redmine/helpers
4
6000
5
http://redmine.rubyforge.org/svn/branches/1.2-stable/test/unit/lib/redmine/helpers
6 6
http://redmine.rubyforge.org/svn
7 7

  
8 8

  
9 9

  
10
2010-12-29T20:29:42.467534Z
11
4582
10
2011-03-28T17:35:20.425352Z
11
5236
12 12
jplang
13 13

  
14 14

  
......
26 26

  
27 27
e93f8b46-1217-0410-a6f0-8f06a7374b81
28 28

29
calendar_test.rb
30
file
31

  
32

  
33

  
34

  
35
2011-06-06T13:18:32.000000Z
36
5d9bda2d9476a944a5ff5e2c61cb41c8
37
2011-03-27T16:49:35.269584Z
38
5231
39
jplang
40
has-props
41

  
42

  
43

  
44

  
45

  
46

  
47

  
48

  
49

  
50

  
51

  
52

  
53

  
54

  
55

  
56

  
57

  
58

  
59

  
60

  
61
2371
62

29 63
gantt_test.rb
30 64
file
31 65

  
32 66

  
33 67

  
34 68

  
35
2011-03-03T11:05:08.000000Z
36
1d6b4373836fef676ab3a28235c140b8
37
2010-12-29T20:29:42.467534Z
38
4582
69
2011-06-06T13:18:32.000000Z
70
7eeeaf89c44d3c361193d131cc931b9b
71
2011-03-28T17:35:20.425352Z
72
5236
39 73
jplang
40 74

  
41 75

  
......
58 92

  
59 93

  
60 94

  
61
28117
95
29243
62 96

test/unit/lib/redmine/helpers/.svn/text-base/gantt_test.rb.svn-base
1
# redMine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 3
#
4 4
# This program is free software; you can redistribute it and/or
5 5
# modify it under the terms of the GNU General Public License
......
95 95
    setup do
96 96
      create_gantt
97 97
    end
98
    
99
    should "clear the @query.project so cross-project issues and versions can be counted" do
100
      assert @gantt.query.project
101
      @gantt.number_of_rows_on_project(@project)
102
      assert_nil @gantt.query.project
103
    end
104 98

  
105
    should "count 1 for the project itself" do
106
      assert_equal 1, @gantt.number_of_rows_on_project(@project)
99
    should "count 0 for an empty the project" do
100
      assert_equal 0, @gantt.number_of_rows_on_project(@project)
107 101
    end
108 102

  
109 103
    should "count the number of issues without a version" do
......
111 105
      assert_equal 2, @gantt.number_of_rows_on_project(@project)
112 106
    end
113 107

  
114
    should "count the number of versions" do
115
      @project.versions << Version.generate!
116
      @project.versions << Version.generate!
117
      assert_equal 3, @gantt.number_of_rows_on_project(@project)
118
    end
119

  
120 108
    should "count the number of issues on versions, including cross-project" do
121 109
      version = Version.generate!
122 110
      @project.versions << version
......
124 112
      
125 113
      assert_equal 3, @gantt.number_of_rows_on_project(@project)
126 114
    end
127
    
128
    should "recursive and count the number of rows on each subproject" do
129
      @project.versions << Version.generate! # +1
130

  
131
      @subproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
132
      @subproject.set_parent!(@project)
133
      @subproject.issues << Issue.generate_for_project!(@subproject) # +1
134
      @subproject.issues << Issue.generate_for_project!(@subproject) # +1
135

  
136
      @subsubproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
137
      @subsubproject.set_parent!(@subproject)
138
      @subsubproject.issues << Issue.generate_for_project!(@subsubproject) # +1
139

  
140
      assert_equal 7, @gantt.number_of_rows_on_project(@project) # +1 for self
141
    end
142 115
  end
143 116

  
144 117
  # TODO: more of an integration test
......
183 156
        @response.body = @gantt.subjects
184 157
        assert_select "div.version-name[style*=left:24px]"
185 158
      end
159
      
160
      context "without assigned issues" do
161
        setup do
162
          @version = Version.generate!(:effective_date => 2.week.from_now.to_date, :sharing => 'none', :name => 'empty_version')
163
          @project.versions << @version
164
        end
165
      
166
        should "not be rendered" do
167
          @response.body = @gantt.subjects
168
          assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0
169
        end
170
      end
186 171
    end
187 172
  
188 173
    context "issue" do
......
196 181
        assert_select "div.issue-subject[style*=left:44px]"
197 182
      end
198 183
      
184
      context "assigned to a shared version of another project" do
185
        setup do
186
          p = Project.generate!
187
          p.trackers << @tracker
188
          p.enabled_module_names = [:issue_tracking]
189
          @shared_version = Version.generate!(:sharing => 'system')
190
          p.versions << @shared_version
191
          # Reassign the issue to a shared version of another project
192
          
193
          @issue = Issue.generate!(:fixed_version => @shared_version,
194
                                   :subject => "gantt#assigned_to_shared_version",
195
                                   :tracker => @tracker,
196
                                   :project => @project,
197
                                   :done_ratio => 30,
198
                                   :start_date => Date.yesterday,
199
                                   :due_date => 1.week.from_now.to_date)
200
          @project.issues << @issue
201
        end
202
        
203
        should "be rendered" do
204
          @response.body = @gantt.subjects
205
          assert_select "div.issue-subject", /#{@issue.subject}/
206
        end
207
      end
208
      
199 209
      context "with subtasks" do
200 210
        setup do
201 211
          attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version}
......
537 547
          assert_select "div.version.task_done[style*=left:28px]", true, @response.body
538 548
        end
539 549

  
540
        should "Be the total done width of the version"  do
550
        should "be the total done width of the version"  do
541 551
          @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
542
          assert_select "div.version.task_done[style*=width:18px]", true, @response.body
552
          assert_select "div.version.task_done[style*=width:16px]", true, @response.body
543 553
        end
544 554
      end
545 555

  
......
697 707
          assert_select "div.task_done[style*=left:28px]", true, @response.body
698 708
        end
699 709

  
700
        should "Be the total done width of the issue"  do
710
        should "be the total done width of the issue"  do
701 711
          @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
702
          assert_select "div.task_done[style*=width:18px]", true, @response.body
712
          # 15 days * 4 px * 30% - 2 px for borders = 16 px
713
          assert_select "div.task_done[style*=width:16px]", true, @response.body
703 714
        end
704 715

  
705 716
        should "not be the total done width if the chart starts after issue start date"  do
......
707 718
          
708 719
          @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
709 720
          assert_select "div.task_done[style*=left:0px]", true, @response.body
710
          assert_select "div.task_done[style*=width:10px]", true, @response.body
721
          assert_select "div.task_done[style*=width:8px]", true, @response.body
722
        end
723
        
724
        context "for completed issue" do
725
          setup do
726
            @issue.done_ratio = 100
727
          end
728

  
729
          should "be the total width of the issue"  do
730
            @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
731
            assert_select "div.task_done[style*=width:58px]", true, @response.body
732
          end
733
  
734
          should "be the total width of the issue with due_date=start_date"  do
735
            @issue.due_date = @issue.start_date
736
            @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
737
            assert_select "div.task_done[style*=width:2px]", true, @response.body
738
          end
711 739
        end
712 740
      end
713 741

  
test/unit/lib/redmine/helpers/calendar_test.rb
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
# 
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
# 
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

  
18
require File.expand_path('../../../../../test_helper', __FILE__)
19

  
20
class CalendarTest < ActiveSupport::TestCase
21
  
22
  def test_monthly
23
    c = Redmine::Helpers::Calendar.new(Date.today, :fr, :month)
24
    assert_equal [1, 7], [c.startdt.cwday, c.enddt.cwday]
25
    
26
    c = Redmine::Helpers::Calendar.new('2007-07-14'.to_date, :fr, :month)
27
    assert_equal ['2007-06-25'.to_date, '2007-08-05'.to_date], [c.startdt, c.enddt]   
28
     
29
    c = Redmine::Helpers::Calendar.new(Date.today, :en, :month)
30
    assert_equal [7, 6], [c.startdt.cwday, c.enddt.cwday]
31
  end
32

  
33
  def test_weekly
34
    c = Redmine::Helpers::Calendar.new(Date.today, :fr, :week)
35
    assert_equal [1, 7], [c.startdt.cwday, c.enddt.cwday]
36
    
37
    c = Redmine::Helpers::Calendar.new('2007-07-14'.to_date, :fr, :week)
38
    assert_equal ['2007-07-09'.to_date, '2007-07-15'.to_date], [c.startdt, c.enddt]
39

  
40
    c = Redmine::Helpers::Calendar.new(Date.today, :en, :week)
41
    assert_equal [7, 6], [c.startdt.cwday, c.enddt.cwday]
42
  end
43
  
44
  def test_monthly_start_day
45
    [1, 6, 7].each do |day|
46
      with_settings :start_of_week => day do
47
        c = Redmine::Helpers::Calendar.new(Date.today, :en, :month)
48
        assert_equal day , c.startdt.cwday
49
        assert_equal (day + 5) % 7 + 1, c.enddt.cwday
50
      end
51
    end
52
  end
53
  
54
  def test_weekly_start_day
55
    [1, 6, 7].each do |day|
56
      with_settings :start_of_week => day do
57
        c = Redmine::Helpers::Calendar.new(Date.today, :en, :week)
58
        assert_equal day, c.startdt.cwday
59
        assert_equal (day + 5) % 7 + 1, c.enddt.cwday
60
      end
61
    end
62
  end
63
end
test/unit/lib/redmine/helpers/gantt_test.rb
1
# redMine - project management software
2
# Copyright (C) 2006-2008  Jean-Philippe Lang
1
# Redmine - project management software
2
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 3
#
4 4
# This program is free software; you can redistribute it and/or
5 5
# modify it under the terms of the GNU General Public License
......
95 95
    setup do
96 96
      create_gantt
97 97
    end
98
    
99
    should "clear the @query.project so cross-project issues and versions can be counted" do
100
      assert @gantt.query.project
101
      @gantt.number_of_rows_on_project(@project)
102
      assert_nil @gantt.query.project
103
    end
104 98

  
105
    should "count 1 for the project itself" do
106
      assert_equal 1, @gantt.number_of_rows_on_project(@project)
99
    should "count 0 for an empty the project" do
100
      assert_equal 0, @gantt.number_of_rows_on_project(@project)
107 101
    end
108 102

  
109 103
    should "count the number of issues without a version" do
......
111 105
      assert_equal 2, @gantt.number_of_rows_on_project(@project)
112 106
    end
113 107

  
114
    should "count the number of versions" do
115
      @project.versions << Version.generate!
116
      @project.versions << Version.generate!
117
      assert_equal 3, @gantt.number_of_rows_on_project(@project)
118
    end
119

  
120 108
    should "count the number of issues on versions, including cross-project" do
121 109
      version = Version.generate!
122 110
      @project.versions << version
......
124 112
      
125 113
      assert_equal 3, @gantt.number_of_rows_on_project(@project)
126 114
    end
127
    
128
    should "recursive and count the number of rows on each subproject" do
129
      @project.versions << Version.generate! # +1
130

  
131
      @subproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
132
      @subproject.set_parent!(@project)
133
      @subproject.issues << Issue.generate_for_project!(@subproject) # +1
134
      @subproject.issues << Issue.generate_for_project!(@subproject) # +1
135

  
136
      @subsubproject = Project.generate!(:enabled_module_names => ['issue_tracking']) # +1
137
      @subsubproject.set_parent!(@subproject)
138
      @subsubproject.issues << Issue.generate_for_project!(@subsubproject) # +1
139

  
140
      assert_equal 7, @gantt.number_of_rows_on_project(@project) # +1 for self
141
    end
142 115
  end
143 116

  
144 117
  # TODO: more of an integration test
......
183 156
        @response.body = @gantt.subjects
184 157
        assert_select "div.version-name[style*=left:24px]"
185 158
      end
159
      
160
      context "without assigned issues" do
161
        setup do
162
          @version = Version.generate!(:effective_date => 2.week.from_now.to_date, :sharing => 'none', :name => 'empty_version')
163
          @project.versions << @version
164
        end
165
      
166
        should "not be rendered" do
167
          @response.body = @gantt.subjects
168
          assert_select "div.version-name a", :text => /#{@version.name}/, :count => 0
169
        end
170
      end
186 171
    end
187 172
  
188 173
    context "issue" do
......
196 181
        assert_select "div.issue-subject[style*=left:44px]"
197 182
      end
198 183
      
184
      context "assigned to a shared version of another project" do
185
        setup do
186
          p = Project.generate!
187
          p.trackers << @tracker
188
          p.enabled_module_names = [:issue_tracking]
189
          @shared_version = Version.generate!(:sharing => 'system')
190
          p.versions << @shared_version
191
          # Reassign the issue to a shared version of another project
192
          
193
          @issue = Issue.generate!(:fixed_version => @shared_version,
194
                                   :subject => "gantt#assigned_to_shared_version",
195
                                   :tracker => @tracker,
196
                                   :project => @project,
197
                                   :done_ratio => 30,
198
                                   :start_date => Date.yesterday,
199
                                   :due_date => 1.week.from_now.to_date)
200
          @project.issues << @issue
201
        end
202
        
203
        should "be rendered" do
204
          @response.body = @gantt.subjects
205
          assert_select "div.issue-subject", /#{@issue.subject}/
206
        end
207
      end
208
      
199 209
      context "with subtasks" do
200 210
        setup do
201 211
          attrs = {:project => @project, :tracker => @tracker, :fixed_version => @version}
......
537 547
          assert_select "div.version.task_done[style*=left:28px]", true, @response.body
538 548
        end
539 549

  
540
        should "Be the total done width of the version"  do
550
        should "be the total done width of the version"  do
541 551
          @response.body = @gantt.line_for_version(@version, {:format => :html, :zoom => 4})
542
          assert_select "div.version.task_done[style*=width:18px]", true, @response.body
552
          assert_select "div.version.task_done[style*=width:16px]", true, @response.body
543 553
        end
544 554
      end
545 555

  
......
697 707
          assert_select "div.task_done[style*=left:28px]", true, @response.body
698 708
        end
699 709

  
700
        should "Be the total done width of the issue"  do
710
        should "be the total done width of the issue"  do
701 711
          @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
702
          assert_select "div.task_done[style*=width:18px]", true, @response.body
712
          # 15 days * 4 px * 30% - 2 px for borders = 16 px
713
          assert_select "div.task_done[style*=width:16px]", true, @response.body
703 714
        end
704 715

  
705 716
        should "not be the total done width if the chart starts after issue start date"  do
......
707 718
          
708 719
          @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
709 720
          assert_select "div.task_done[style*=left:0px]", true, @response.body
710
          assert_select "div.task_done[style*=width:10px]", true, @response.body
721
          assert_select "div.task_done[style*=width:8px]", true, @response.body
722
        end
723
        
724
        context "for completed issue" do
725
          setup do
726
            @issue.done_ratio = 100
727
          end
728

  
729
          should "be the total width of the issue"  do
730
            @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
731
            assert_select "div.task_done[style*=width:58px]", true, @response.body
732
          end
733
  
734
          should "be the total width of the issue with due_date=start_date"  do
735
            @issue.due_date = @issue.start_date
736
            @response.body = @gantt.line_for_issue(@issue, {:format => :html, :zoom => 4})
737
            assert_select "div.task_done[style*=width:2px]", true, @response.body
738
          end
711 739
        end
712 740
      end
713 741

  

Also available in: Unified diff