##// END OF EJS Templates
Code cleanup....
Jean-Philippe Lang -
r8159:914f9b603ef6
parent child
Show More
@@ -1,171 +1,170
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
23
24 include ActionController::Assertions::SelectorAssertions
25 fixtures :projects, :trackers, :issue_statuses, :issues,
24 fixtures :projects, :trackers, :issue_statuses, :issues,
26 :enumerations, :users, :issue_categories,
25 :enumerations, :users, :issue_categories,
27 :projects_trackers,
26 :projects_trackers,
28 :roles,
27 :roles,
29 :member_roles,
28 :member_roles,
30 :members,
29 :members,
31 :enabled_modules,
30 :enabled_modules,
32 :workflows
31 :workflows
33
32
34 def setup
33 def setup
35 super
34 super
36 set_language_if_valid('en')
35 set_language_if_valid('en')
37 User.current = nil
36 User.current = nil
38 end
37 end
39
38
40 def test_issue_heading
39 def test_issue_heading
41 assert_equal "Bug #1", issue_heading(Issue.find(1))
40 assert_equal "Bug #1", issue_heading(Issue.find(1))
42 end
41 end
43
42
44 def test_issues_destroy_confirmation_message_with_one_root_issue
43 def test_issues_destroy_confirmation_message_with_one_root_issue
45 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1))
44 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find(1))
46 end
45 end
47
46
48 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
47 def test_issues_destroy_confirmation_message_with_an_arrayt_of_root_issues
49 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
48 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
50 end
49 end
51
50
52 def test_issues_destroy_confirmation_message_with_one_parent_issue
51 def test_issues_destroy_confirmation_message_with_one_parent_issue
53 Issue.find(2).update_attribute :parent_issue_id, 1
52 Issue.find(2).update_attribute :parent_issue_id, 1
54 assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1),
53 assert_equal l(:text_issues_destroy_confirmation) + "\n" + l(:text_issues_destroy_descendants_confirmation, :count => 1),
55 issues_destroy_confirmation_message(Issue.find(1))
54 issues_destroy_confirmation_message(Issue.find(1))
56 end
55 end
57
56
58 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
57 def test_issues_destroy_confirmation_message_with_one_parent_issue_and_its_child
59 Issue.find(2).update_attribute :parent_issue_id, 1
58 Issue.find(2).update_attribute :parent_issue_id, 1
60 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
59 assert_equal l(:text_issues_destroy_confirmation), issues_destroy_confirmation_message(Issue.find([1, 2]))
61 end
60 end
62
61
63 context "IssuesHelper#show_detail" do
62 context "IssuesHelper#show_detail" do
64 context "with no_html" do
63 context "with no_html" do
65 should 'show a changing attribute' do
64 should 'show a changing attribute' do
66 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
65 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
67 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
66 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
68 end
67 end
69
68
70 should 'show a new attribute' do
69 should 'show a new attribute' do
71 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
70 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
72 assert_equal "% Done set to 100", show_detail(@detail, true)
71 assert_equal "% Done set to 100", show_detail(@detail, true)
73 end
72 end
74
73
75 should 'show a deleted attribute' do
74 should 'show a deleted attribute' do
76 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
75 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
77 assert_equal "% Done deleted (50)", show_detail(@detail, true)
76 assert_equal "% Done deleted (50)", show_detail(@detail, true)
78 end
77 end
79 end
78 end
80
79
81 context "with html" do
80 context "with html" do
82 should 'show a changing attribute with HTML highlights' do
81 should 'show a changing attribute with HTML highlights' do
83 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
82 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
84 html = show_detail(@detail, false)
83 html = show_detail(@detail, false)
85
84
86 assert_include '<strong>% Done</strong>', html
85 assert_include '<strong>% Done</strong>', html
87 assert_include '<i>40</i>', html
86 assert_include '<i>40</i>', html
88 assert_include '<i>100</i>', html
87 assert_include '<i>100</i>', html
89 end
88 end
90
89
91 should 'show a new attribute with HTML highlights' do
90 should 'show a new attribute with HTML highlights' do
92 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
91 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
93 html = show_detail(@detail, false)
92 html = show_detail(@detail, false)
94
93
95 assert_include '<strong>% Done</strong>', html
94 assert_include '<strong>% Done</strong>', html
96 assert_include '<i>100</i>', html
95 assert_include '<i>100</i>', html
97 end
96 end
98
97
99 should 'show a deleted attribute with HTML highlights' do
98 should 'show a deleted attribute with HTML highlights' do
100 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
99 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
101 html = show_detail(@detail, false)
100 html = show_detail(@detail, false)
102
101
103 assert_include '<strong>% Done</strong>', html
102 assert_include '<strong>% Done</strong>', html
104 assert_include '<strike><i>50</i></strike>', html
103 assert_include '<strike><i>50</i></strike>', html
105 end
104 end
106 end
105 end
107
106
108 context "with a start_date attribute" do
107 context "with a start_date attribute" do
109 should "format the current date" do
108 should "format the current date" do
110 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
109 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
111 assert_match "01/31/2010", show_detail(@detail, true)
110 assert_match "01/31/2010", show_detail(@detail, true)
112 end
111 end
113
112
114 should "format the old date" do
113 should "format the old date" do
115 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
114 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
116 assert_match "01/01/2010", show_detail(@detail, true)
115 assert_match "01/01/2010", show_detail(@detail, true)
117 end
116 end
118 end
117 end
119
118
120 context "with a due_date attribute" do
119 context "with a due_date attribute" do
121 should "format the current date" do
120 should "format the current date" do
122 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
121 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
123 assert_match "01/31/2010", show_detail(@detail, true)
122 assert_match "01/31/2010", show_detail(@detail, true)
124 end
123 end
125
124
126 should "format the old date" do
125 should "format the old date" do
127 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
126 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
128 assert_match "01/01/2010", show_detail(@detail, true)
127 assert_match "01/01/2010", show_detail(@detail, true)
129 end
128 end
130 end
129 end
131
130
132 context "with a project attribute" do
131 context "with a project attribute" do
133 should_show_the_old_and_new_values_for('project_id', Project)
132 should_show_the_old_and_new_values_for('project_id', Project)
134 end
133 end
135
134
136 context "with a issue status attribute" do
135 context "with a issue status attribute" do
137 should_show_the_old_and_new_values_for('status_id', IssueStatus)
136 should_show_the_old_and_new_values_for('status_id', IssueStatus)
138 end
137 end
139
138
140 context "with a tracker attribute" do
139 context "with a tracker attribute" do
141 should_show_the_old_and_new_values_for('tracker_id', Tracker)
140 should_show_the_old_and_new_values_for('tracker_id', Tracker)
142 end
141 end
143
142
144 context "with a assigned to attribute" do
143 context "with a assigned to attribute" do
145 should_show_the_old_and_new_values_for('assigned_to_id', User)
144 should_show_the_old_and_new_values_for('assigned_to_id', User)
146 end
145 end
147
146
148 context "with a priority attribute" do
147 context "with a priority attribute" do
149 should_show_the_old_and_new_values_for('priority_id', IssuePriority) do
148 should_show_the_old_and_new_values_for('priority_id', IssuePriority) do
150 @old_value = IssuePriority.generate!(:type => 'IssuePriority')
149 @old_value = IssuePriority.generate!(:type => 'IssuePriority')
151 @new_value = IssuePriority.generate!(:type => 'IssuePriority')
150 @new_value = IssuePriority.generate!(:type => 'IssuePriority')
152 end
151 end
153 end
152 end
154
153
155 context "with a category attribute" do
154 context "with a category attribute" do
156 should_show_the_old_and_new_values_for('category_id', IssueCategory)
155 should_show_the_old_and_new_values_for('category_id', IssueCategory)
157 end
156 end
158
157
159 context "with a fixed version attribute" do
158 context "with a fixed version attribute" do
160 should_show_the_old_and_new_values_for('fixed_version_id', Version)
159 should_show_the_old_and_new_values_for('fixed_version_id', Version)
161 end
160 end
162
161
163 context "with a estimated hours attribute" do
162 context "with a estimated hours attribute" do
164 should "format the time into two decimal places"
163 should "format the time into two decimal places"
165 should "format the old time into two decimal places"
164 should "format the old time into two decimal places"
166 end
165 end
167
166
168 should "test custom fields"
167 should "test custom fields"
169 should "test attachments"
168 should "test attachments"
170 end
169 end
171 end
170 end
General Comments 0
You need to be logged in to leave comments. Login now