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 / .svn / pristine / ce / ce3436e583ff12a4824d53281463f89ddea0a5e7.svn-base @ 1297:0a574315af3e

History | View | Annotate | Download (6.89 KB)

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 IssuesHelperTest < HelperTestCase
21
  include ApplicationHelper
22
  include IssuesHelper
23

    
24
  include ActionController::Assertions::SelectorAssertions
25
  fixtures :projects, :trackers, :issue_statuses, :issues,
26
           :enumerations, :users, :issue_categories,
27
           :projects_trackers,
28
           :roles,
29
           :member_roles,
30
           :members,
31
           :enabled_modules,
32
           :workflows
33

    
34
  # Used by assert_select
35
  def html_document
36
    HTML::Document.new(@response.body)
37
  end
38

    
39
  def setup
40
    super
41
    set_language_if_valid('en')
42
    User.current = nil
43
    @response = ActionController::TestResponse.new
44
  end
45

    
46
  def controller
47
    @controller ||= IssuesController.new
48
  end
49

    
50
  def request
51
    @request ||= ActionController::TestRequest.new
52
  end
53

    
54
  def test_issue_heading
55
    assert_equal "Bug #1", issue_heading(Issue.find(1))
56
  end
57

    
58
  def test_issues_destroy_confirmation_message_with_one_root_issue
59
    assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1))
60
  end
61

    
62
  def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
63
    assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
64
  end
65

    
66
  def test_issues_destroy_confirmation_message_with_one_parent_issue
67
    Issue.find(2).update_attribute :parent_issue_id, 1
68
    assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1),
69
      issues_destroy_confirmation_message(Issue.find(1))
70
  end
71

    
72
  def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
73
    Issue.find(2).update_attribute :parent_issue_id, 1
74
    assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
75
  end
76

    
77
  context "IssuesHelper#show_detail" do
78
    context "with no_html" do
79
      should 'show a changing attribute' do
80
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
81
        assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
82
      end
83

    
84
      should 'show a new attribute' do
85
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
86
        assert_equal "% Done set to 100", show_detail(@detail, true)
87
      end
88

    
89
      should 'show a deleted attribute' do
90
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
91
        assert_equal "% Done deleted (50)", show_detail(@detail, true)
92
      end
93
    end
94

    
95
    context "with html" do
96
      should 'show a changing attribute with HTML highlights' do
97
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
98
        @response.body = show_detail(@detail, false)
99

    
100
        assert_select 'strong', :text => '% Done'
101
        assert_select 'i', :text => '40'
102
        assert_select 'i', :text => '100'
103
      end
104

    
105
      should 'show a new attribute with HTML highlights' do
106
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
107
        @response.body = show_detail(@detail, false)
108

    
109
        assert_select 'strong', :text => '% Done'
110
        assert_select 'i', :text => '100'
111
      end
112

    
113
      should 'show a deleted attribute with HTML highlights' do
114
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
115
        @response.body = show_detail(@detail, false)
116

    
117
        assert_select 'strong', :text => '% Done'
118
        assert_select 'strike' do
119
          assert_select 'i', :text => '50'
120
        end
121
      end
122
    end
123

    
124
    context "with a start_date attribute" do
125
      should "format the current date" do
126
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
127
        assert_match "01/31/2010", show_detail(@detail, true)
128
      end
129

    
130
      should "format the old date" do
131
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
132
        assert_match "01/01/2010", show_detail(@detail, true)
133
      end
134
    end
135

    
136
    context "with a due_date attribute" do
137
      should "format the current date" do
138
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
139
        assert_match "01/31/2010", show_detail(@detail, true)
140
      end
141

    
142
      should "format the old date" do
143
        @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
144
        assert_match "01/01/2010", show_detail(@detail, true)
145
      end
146
    end
147

    
148
    context "with a project attribute" do
149
      should_show_the_old_and_new_values_for('project_id', Project)
150
    end
151

    
152
    context "with a issue status attribute" do
153
      should_show_the_old_and_new_values_for('status_id', IssueStatus)
154
    end
155

    
156
    context "with a tracker attribute" do
157
      should_show_the_old_and_new_values_for('tracker_id', Tracker)
158
    end
159

    
160
    context "with a assigned to attribute" do
161
      should_show_the_old_and_new_values_for('assigned_to_id', User)
162
    end
163

    
164
    context "with a priority attribute" do
165
      should_show_the_old_and_new_values_for('priority_id', IssuePriority) do
166
        @old_value = IssuePriority.generate!(:type => 'IssuePriority')
167
        @new_value = IssuePriority.generate!(:type => 'IssuePriority')
168
      end
169
    end
170

    
171
    context "with a category attribute" do
172
      should_show_the_old_and_new_values_for('category_id', IssueCategory)
173
    end
174

    
175
    context "with a fixed version attribute" do
176
      should_show_the_old_and_new_values_for('fixed_version_id', Version)
177
    end
178

    
179
    context "with a estimated hours attribute" do
180
      should "format the time into two decimal places"
181
      should "format the old time into two decimal places"
182
    end
183

    
184
    should "test custom fields"
185
    should "test attachments"
186

    
187
  end
188

    
189
end