##// END OF EJS Templates
test: include ERB::Util at test/unit/helpers/issues_helper_test.rb...
Toshi MARUYAMA -
r8193:4ee21931129b
parent child
Show More
@@ -1,170 +1,171
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.expand_path('../../../test_helper', __FILE__)
18 require File.expand_path('../../../test_helper', __FILE__)
19
19
20 class IssuesHelperTest < ActionView::TestCase
20 class IssuesHelperTest < ActionView::TestCase
21 include ApplicationHelper
21 include ApplicationHelper
22 include IssuesHelper
22 include IssuesHelper
23 include ERB::Util
23
24
24 fixtures :projects, :trackers, :issue_statuses, :issues,
25 fixtures :projects, :trackers, :issue_statuses, :issues,
25 :enumerations, :users, :issue_categories,
26 :enumerations, :users, :issue_categories,
26 :projects_trackers,
27 :projects_trackers,
27 :roles,
28 :roles,
28 :member_roles,
29 :member_roles,
29 :members,
30 :members,
30 :enabled_modules,
31 :enabled_modules,
31 :workflows
32 :workflows
32
33
33 def setup
34 def setup
34 super
35 super
35 set_language_if_valid('en')
36 set_language_if_valid('en')
36 User.current = nil
37 User.current = nil
37 end
38 end
38
39
39 def test_issue_heading
40 def test_issue_heading
40 assert_equal "Bug #1", issue_heading(Issue.find(1))
41 assert_equal "Bug #1", issue_heading(Issue.find(1))
41 end
42 end
42
43
43 def test_issues_destroy_confirmation_message_with_one_root_issue
44 def test_issues_destroy_confirmation_message_with_one_root_issue
44 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1))
45 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1))
45 end
46 end
46
47
47 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
48 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
48 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
49 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
49 end
50 end
50
51
51 def test_issues_destroy_confirmation_message_with_one_parent_issue
52 def test_issues_destroy_confirmation_message_with_one_parent_issue
52 Issue.find(2).update_attribute :parent_issue_id, 1
53 Issue.find(2).update_attribute :parent_issue_id, 1
53 assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1),
54 assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1),
54 issues_destroy_confirmation_message(Issue.find(1))
55 issues_destroy_confirmation_message(Issue.find(1))
55 end
56 end
56
57
57 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
58 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
58 Issue.find(2).update_attribute :parent_issue_id, 1
59 Issue.find(2).update_attribute :parent_issue_id, 1
59 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
60 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
60 end
61 end
61
62
62 context "IssuesHelper#show_detail" do
63 context "IssuesHelper#show_detail" do
63 context "with no_html" do
64 context "with no_html" do
64 should 'show a changing attribute' do
65 should 'show a changing attribute' do
65 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
66 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
66 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
67 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
67 end
68 end
68
69
69 should 'show a new attribute' do
70 should 'show a new attribute' do
70 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
71 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
71 assert_equal "% Done set to 100", show_detail(@detail, true)
72 assert_equal "% Done set to 100", show_detail(@detail, true)
72 end
73 end
73
74
74 should 'show a deleted attribute' do
75 should 'show a deleted attribute' do
75 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
76 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
76 assert_equal "% Done deleted (50)", show_detail(@detail, true)
77 assert_equal "% Done deleted (50)", show_detail(@detail, true)
77 end
78 end
78 end
79 end
79
80
80 context "with html" do
81 context "with html" do
81 should 'show a changing attribute with HTML highlights' do
82 should 'show a changing attribute with HTML highlights' do
82 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
83 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
83 html = show_detail(@detail, false)
84 html = show_detail(@detail, false)
84
85
85 assert_include '<strong>% Done</strong>', html
86 assert_include '<strong>% Done</strong>', html
86 assert_include '<i>40</i>', html
87 assert_include '<i>40</i>', html
87 assert_include '<i>100</i>', html
88 assert_include '<i>100</i>', html
88 end
89 end
89
90
90 should 'show a new attribute with HTML highlights' do
91 should 'show a new attribute with HTML highlights' do
91 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
92 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
92 html = show_detail(@detail, false)
93 html = show_detail(@detail, false)
93
94
94 assert_include '<strong>% Done</strong>', html
95 assert_include '<strong>% Done</strong>', html
95 assert_include '<i>100</i>', html
96 assert_include '<i>100</i>', html
96 end
97 end
97
98
98 should 'show a deleted attribute with HTML highlights' do
99 should 'show a deleted attribute with HTML highlights' do
99 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
100 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
100 html = show_detail(@detail, false)
101 html = show_detail(@detail, false)
101
102
102 assert_include '<strong>% Done</strong>', html
103 assert_include '<strong>% Done</strong>', html
103 assert_include '<strike><i>50</i></strike>', html
104 assert_include '<strike><i>50</i></strike>', html
104 end
105 end
105 end
106 end
106
107
107 context "with a start_date attribute" do
108 context "with a start_date attribute" do
108 should "format the current date" do
109 should "format the current date" do
109 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
110 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
110 assert_match "01/31/2010", show_detail(@detail, true)
111 assert_match "01/31/2010", show_detail(@detail, true)
111 end
112 end
112
113
113 should "format the old date" do
114 should "format the old date" do
114 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
115 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
115 assert_match "01/01/2010", show_detail(@detail, true)
116 assert_match "01/01/2010", show_detail(@detail, true)
116 end
117 end
117 end
118 end
118
119
119 context "with a due_date attribute" do
120 context "with a due_date attribute" do
120 should "format the current date" do
121 should "format the current date" do
121 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
122 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
122 assert_match "01/31/2010", show_detail(@detail, true)
123 assert_match "01/31/2010", show_detail(@detail, true)
123 end
124 end
124
125
125 should "format the old date" do
126 should "format the old date" do
126 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
127 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
127 assert_match "01/01/2010", show_detail(@detail, true)
128 assert_match "01/01/2010", show_detail(@detail, true)
128 end
129 end
129 end
130 end
130
131
131 context "with a project attribute" do
132 context "with a project attribute" do
132 should_show_the_old_and_new_values_for('project_id', Project)
133 should_show_the_old_and_new_values_for('project_id', Project)
133 end
134 end
134
135
135 context "with a issue status attribute" do
136 context "with a issue status attribute" do
136 should_show_the_old_and_new_values_for('status_id', IssueStatus)
137 should_show_the_old_and_new_values_for('status_id', IssueStatus)
137 end
138 end
138
139
139 context "with a tracker attribute" do
140 context "with a tracker attribute" do
140 should_show_the_old_and_new_values_for('tracker_id', Tracker)
141 should_show_the_old_and_new_values_for('tracker_id', Tracker)
141 end
142 end
142
143
143 context "with a assigned to attribute" do
144 context "with a assigned to attribute" do
144 should_show_the_old_and_new_values_for('assigned_to_id', User)
145 should_show_the_old_and_new_values_for('assigned_to_id', User)
145 end
146 end
146
147
147 context "with a priority attribute" do
148 context "with a priority attribute" do
148 should_show_the_old_and_new_values_for('priority_id', IssuePriority) do
149 should_show_the_old_and_new_values_for('priority_id', IssuePriority) do
149 @old_value = IssuePriority.generate!(:type => 'IssuePriority')
150 @old_value = IssuePriority.generate!(:type => 'IssuePriority')
150 @new_value = IssuePriority.generate!(:type => 'IssuePriority')
151 @new_value = IssuePriority.generate!(:type => 'IssuePriority')
151 end
152 end
152 end
153 end
153
154
154 context "with a category attribute" do
155 context "with a category attribute" do
155 should_show_the_old_and_new_values_for('category_id', IssueCategory)
156 should_show_the_old_and_new_values_for('category_id', IssueCategory)
156 end
157 end
157
158
158 context "with a fixed version attribute" do
159 context "with a fixed version attribute" do
159 should_show_the_old_and_new_values_for('fixed_version_id', Version)
160 should_show_the_old_and_new_values_for('fixed_version_id', Version)
160 end
161 end
161
162
162 context "with a estimated hours attribute" do
163 context "with a estimated hours attribute" do
163 should "format the time into two decimal places"
164 should "format the time into two decimal places"
164 should "format the old time into two decimal places"
165 should "format the old time into two decimal places"
165 end
166 end
166
167
167 should "test custom fields"
168 should "test custom fields"
168 should "test attachments"
169 should "test attachments"
169 end
170 end
170 end
171 end
General Comments 0
You need to be logged in to leave comments. Login now