To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / test / unit / helpers / issues_helper_test.rb @ 442:753f1380d6bc

History | View | Annotate | Download (6.65 KB)

1 0:513646585e45 Chris
# Redmine - project management software
2 441:cbce1fd3b1b7 Chris
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
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 441:cbce1fd3b1b7 Chris
#
9 0:513646585e45 Chris
# 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 441:cbce1fd3b1b7 Chris
#
14 0:513646585e45 Chris
# 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 119:8661b858af72 Chris
require File.expand_path('../../../test_helper', __FILE__)
19 0:513646585e45 Chris
20
class IssuesHelperTest < HelperTestCase
21
  include ApplicationHelper
22
  include IssuesHelper
23
24
  include ActionController::Assertions::SelectorAssertions
25
  fixtures :all
26
27
  # Used by assert_select
28
  def html_document
29
    HTML::Document.new(@response.body)
30
  end
31
32
  def setup
33
    super
34
    set_language_if_valid('en')
35
    User.current = nil
36
    @response = ActionController::TestResponse.new
37
  end
38
39
  def controller
40
    @controller ||= IssuesController.new
41
  end
42
43
  def request
44
    @request ||= ActionController::TestRequest.new
45
  end
46
47 441:cbce1fd3b1b7 Chris
  def test_issue_heading
48
    assert_equal "Bug #1", issue_heading(Issue.find(1))
49
  end
50
51
  def test_issues_destroy_confirmation_message_with_one_root_issue
52
    assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1))
53
  end
54
55
  def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
56
    assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
57
  end
58
59
  def test_issues_destroy_confirmation_message_with_one_parent_issue
60
    Issue.find(2).update_attribute :parent_issue_id, 1
61
    assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1),
62
      issues_destroy_confirmation_message(Issue.find(1))
63
  end
64
65
  def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
66
    Issue.find(2).update_attribute :parent_issue_id, 1
67
    assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
68
  end
69
70 0:513646585e45 Chris
  context "IssuesHelper#show_detail" do
71
    context "with no_html" do
72
      should 'show a changing attribute' do
73
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
74
        assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
75
      end
76
77
      should 'show a new attribute' do
78
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
79
        assert_equal "% Done set to 100", show_detail(@detail, true)
80
      end
81
82
      should 'show a deleted attribute' do
83
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
84
        assert_equal "% Done deleted (50)", show_detail(@detail, true)
85
      end
86
    end
87
88
    context "with html" do
89
      should 'show a changing attribute with HTML highlights' do
90
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
91
        @response.body = show_detail(@detail, false)
92
93
        assert_select 'strong', :text => '% Done'
94
        assert_select 'i', :text => '40'
95
        assert_select 'i', :text => '100'
96
      end
97
98
      should 'show a new attribute with HTML highlights' do
99
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
100
        @response.body = show_detail(@detail, false)
101
102
        assert_select 'strong', :text => '% Done'
103
        assert_select 'i', :text => '100'
104
      end
105
106
      should 'show a deleted attribute with HTML highlights' do
107
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
108
        @response.body = show_detail(@detail, false)
109
110
        assert_select 'strong', :text => '% Done'
111
        assert_select 'strike' do
112
          assert_select 'i', :text => '50'
113
        end
114
      end
115
    end
116
117
    context "with a start_date attribute" do
118
      should "format the current date" do
119
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
120
        assert_match "01/31/2010", show_detail(@detail, true)
121
      end
122
123
      should "format the old date" do
124
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
125
        assert_match "01/01/2010", show_detail(@detail, true)
126
      end
127
    end
128
129
    context "with a due_date attribute" do
130
      should "format the current date" do
131
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
132
        assert_match "01/31/2010", show_detail(@detail, true)
133
      end
134
135
      should "format the old date" do
136
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
137
        assert_match "01/01/2010", show_detail(@detail, true)
138
      end
139
    end
140
141
    context "with a project attribute" do
142
      should_show_the_old_and_new_values_for('project_id', Project)
143
    end
144
145
    context "with a issue status attribute" do
146
      should_show_the_old_and_new_values_for('status_id', IssueStatus)
147
    end
148
149
    context "with a tracker attribute" do
150
      should_show_the_old_and_new_values_for('tracker_id', Tracker)
151
    end
152
153
    context "with a assigned to attribute" do
154
      should_show_the_old_and_new_values_for('assigned_to_id', User)
155
    end
156
157
    context "with a priority attribute" do
158
      should_show_the_old_and_new_values_for('priority_id', IssuePriority) do
159
        @old_value = IssuePriority.generate!(:type => 'IssuePriority')
160
        @new_value = IssuePriority.generate!(:type => 'IssuePriority')
161
      end
162
    end
163
164
    context "with a category attribute" do
165
      should_show_the_old_and_new_values_for('category_id', IssueCategory)
166
    end
167
168
    context "with a fixed version attribute" do
169
      should_show_the_old_and_new_values_for('fixed_version_id', Version)
170
    end
171
172
    context "with a estimated hours attribute" do
173
      should "format the time into two decimal places"
174
      should "format the old time into two decimal places"
175
    end
176
177
    should "test custom fields"
178
    should "test attachments"
179
180
  end
181
182
end