Mercurial > hg > soundsoftware-site
comparison test/unit/helpers/issues_helper_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 261b3d9a4903 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 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. |
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 < HelperTestCase | 20 class IssuesHelperTest < ActionView::TestCase |
21 include ApplicationHelper | 21 include ApplicationHelper |
22 include IssuesHelper | 22 include IssuesHelper |
23 | 23 include CustomFieldsHelper |
24 include ActionController::Assertions::SelectorAssertions | 24 include ERB::Util |
25 | |
25 fixtures :projects, :trackers, :issue_statuses, :issues, | 26 fixtures :projects, :trackers, :issue_statuses, :issues, |
26 :enumerations, :users, :issue_categories, | 27 :enumerations, :users, :issue_categories, |
27 :projects_trackers, | 28 :projects_trackers, |
28 :roles, | 29 :roles, |
29 :member_roles, | 30 :member_roles, |
30 :members, | 31 :members, |
31 :enabled_modules, | 32 :enabled_modules, |
32 :workflows | 33 :workflows, |
33 | 34 :custom_fields, |
34 # Used by assert_select | 35 :attachments, |
35 def html_document | 36 :versions |
36 HTML::Document.new(@response.body) | |
37 end | |
38 | 37 |
39 def setup | 38 def setup |
40 super | 39 super |
41 set_language_if_valid('en') | 40 set_language_if_valid('en') |
42 User.current = nil | 41 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 | 42 end |
53 | 43 |
54 def test_issue_heading | 44 def test_issue_heading |
55 assert_equal "Bug #1", issue_heading(Issue.find(1)) | 45 assert_equal "Bug #1", issue_heading(Issue.find(1)) |
56 end | 46 end |
75 end | 65 end |
76 | 66 |
77 context "IssuesHelper#show_detail" do | 67 context "IssuesHelper#show_detail" do |
78 context "with no_html" do | 68 context "with no_html" do |
79 should 'show a changing attribute' do | 69 should 'show a changing attribute' do |
80 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') | 70 @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') |
81 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true) | 71 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true) |
82 end | 72 end |
83 | 73 |
84 should 'show a new attribute' do | 74 should 'show a new attribute' do |
85 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') | 75 @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') |
86 assert_equal "% Done set to 100", show_detail(@detail, true) | 76 assert_equal "% Done set to 100", show_detail(@detail, true) |
87 end | 77 end |
88 | 78 |
89 should 'show a deleted attribute' do | 79 should 'show a deleted attribute' do |
90 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') | 80 @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') |
91 assert_equal "% Done deleted (50)", show_detail(@detail, true) | 81 assert_equal "% Done deleted (50)", show_detail(@detail, true) |
92 end | 82 end |
93 end | 83 end |
94 | 84 |
95 context "with html" do | 85 context "with html" do |
96 should 'show a changing attribute with HTML highlights' do | 86 should 'show a changing attribute with HTML highlights' do |
97 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') | 87 @detail = JournalDetail.new(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio') |
98 @response.body = show_detail(@detail, false) | 88 html = show_detail(@detail, false) |
99 | 89 |
100 assert_select 'strong', :text => '% Done' | 90 assert_include '<strong>% Done</strong>', html |
101 assert_select 'i', :text => '40' | 91 assert_include '<i>40</i>', html |
102 assert_select 'i', :text => '100' | 92 assert_include '<i>100</i>', html |
103 end | 93 end |
104 | 94 |
105 should 'show a new attribute with HTML highlights' do | 95 should 'show a new attribute with HTML highlights' do |
106 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') | 96 @detail = JournalDetail.new(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio') |
107 @response.body = show_detail(@detail, false) | 97 html = show_detail(@detail, false) |
108 | 98 |
109 assert_select 'strong', :text => '% Done' | 99 assert_include '<strong>% Done</strong>', html |
110 assert_select 'i', :text => '100' | 100 assert_include '<i>100</i>', html |
111 end | 101 end |
112 | 102 |
113 should 'show a deleted attribute with HTML highlights' do | 103 should 'show a deleted attribute with HTML highlights' do |
114 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') | 104 @detail = JournalDetail.new(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio') |
115 @response.body = show_detail(@detail, false) | 105 html = show_detail(@detail, false) |
116 | 106 |
117 assert_select 'strong', :text => '% Done' | 107 assert_include '<strong>% Done</strong>', html |
118 assert_select 'strike' do | 108 assert_include '<del><i>50</i></del>', html |
119 assert_select 'i', :text => '50' | |
120 end | |
121 end | 109 end |
122 end | 110 end |
123 | 111 |
124 context "with a start_date attribute" do | 112 context "with a start_date attribute" do |
125 should "format the current date" do | 113 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') | 114 @detail = JournalDetail.new( |
127 assert_match "01/31/2010", show_detail(@detail, true) | 115 :property => 'attr', |
116 :old_value => '2010-01-01', | |
117 :value => '2010-01-31', | |
118 :prop_key => 'start_date' | |
119 ) | |
120 with_settings :date_format => '%m/%d/%Y' do | |
121 assert_match "01/31/2010", show_detail(@detail, true) | |
122 end | |
128 end | 123 end |
129 | 124 |
130 should "format the old date" do | 125 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') | 126 @detail = JournalDetail.new( |
132 assert_match "01/01/2010", show_detail(@detail, true) | 127 :property => 'attr', |
128 :old_value => '2010-01-01', | |
129 :value => '2010-01-31', | |
130 :prop_key => 'start_date' | |
131 ) | |
132 with_settings :date_format => '%m/%d/%Y' do | |
133 assert_match "01/01/2010", show_detail(@detail, true) | |
134 end | |
133 end | 135 end |
134 end | 136 end |
135 | 137 |
136 context "with a due_date attribute" do | 138 context "with a due_date attribute" do |
137 should "format the current date" do | 139 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') | 140 @detail = JournalDetail.new( |
139 assert_match "01/31/2010", show_detail(@detail, true) | 141 :property => 'attr', |
142 :old_value => '2010-01-01', | |
143 :value => '2010-01-31', | |
144 :prop_key => 'due_date' | |
145 ) | |
146 with_settings :date_format => '%m/%d/%Y' do | |
147 assert_match "01/31/2010", show_detail(@detail, true) | |
148 end | |
140 end | 149 end |
141 | 150 |
142 should "format the old date" do | 151 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') | 152 @detail = JournalDetail.new( |
144 assert_match "01/01/2010", show_detail(@detail, true) | 153 :property => 'attr', |
145 end | 154 :old_value => '2010-01-01', |
146 end | 155 :value => '2010-01-31', |
147 | 156 :prop_key => 'due_date' |
148 context "with a project attribute" do | 157 ) |
149 should_show_the_old_and_new_values_for('project_id', Project) | 158 with_settings :date_format => '%m/%d/%Y' do |
150 end | 159 assert_match "01/01/2010", show_detail(@detail, true) |
151 | 160 end |
152 context "with a issue status attribute" do | 161 end |
153 should_show_the_old_and_new_values_for('status_id', IssueStatus) | 162 end |
154 end | 163 |
155 | 164 should "show old and new values with a project attribute" do |
156 context "with a tracker attribute" do | 165 detail = JournalDetail.new(:property => 'attr', :prop_key => 'project_id', :old_value => 1, :value => 2) |
157 should_show_the_old_and_new_values_for('tracker_id', Tracker) | 166 assert_match 'eCookbook', show_detail(detail, true) |
158 end | 167 assert_match 'OnlineStore', show_detail(detail, true) |
159 | 168 end |
160 context "with a assigned to attribute" do | 169 |
161 should_show_the_old_and_new_values_for('assigned_to_id', User) | 170 should "show old and new values with a issue status attribute" do |
162 end | 171 detail = JournalDetail.new(:property => 'attr', :prop_key => 'status_id', :old_value => 1, :value => 2) |
163 | 172 assert_match 'New', show_detail(detail, true) |
164 context "with a priority attribute" do | 173 assert_match 'Assigned', show_detail(detail, true) |
165 should_show_the_old_and_new_values_for('priority_id', IssuePriority) do | 174 end |
166 @old_value = IssuePriority.generate!(:type => 'IssuePriority') | 175 |
167 @new_value = IssuePriority.generate!(:type => 'IssuePriority') | 176 should "show old and new values with a tracker attribute" do |
168 end | 177 detail = JournalDetail.new(:property => 'attr', :prop_key => 'tracker_id', :old_value => 1, :value => 2) |
169 end | 178 assert_match 'Bug', show_detail(detail, true) |
170 | 179 assert_match 'Feature request', show_detail(detail, true) |
171 context "with a category attribute" do | 180 end |
172 should_show_the_old_and_new_values_for('category_id', IssueCategory) | 181 |
173 end | 182 should "show old and new values with a assigned to attribute" do |
174 | 183 detail = JournalDetail.new(:property => 'attr', :prop_key => 'assigned_to_id', :old_value => 1, :value => 2) |
175 context "with a fixed version attribute" do | 184 assert_match 'redMine Admin', show_detail(detail, true) |
176 should_show_the_old_and_new_values_for('fixed_version_id', Version) | 185 assert_match 'John Smith', show_detail(detail, true) |
177 end | 186 end |
178 | 187 |
179 context "with a estimated hours attribute" do | 188 should "show old and new values with a priority attribute" do |
180 should "format the time into two decimal places" | 189 detail = JournalDetail.new(:property => 'attr', :prop_key => 'priority_id', :old_value => 4, :value => 5) |
181 should "format the old time into two decimal places" | 190 assert_match 'Low', show_detail(detail, true) |
182 end | 191 assert_match 'Normal', show_detail(detail, true) |
183 | 192 end |
184 should "test custom fields" | 193 |
185 should "test attachments" | 194 should "show old and new values with a category attribute" do |
186 | 195 detail = JournalDetail.new(:property => 'attr', :prop_key => 'category_id', :old_value => 1, :value => 2) |
187 end | 196 assert_match 'Printing', show_detail(detail, true) |
188 | 197 assert_match 'Recipes', show_detail(detail, true) |
198 end | |
199 | |
200 should "show old and new values with a fixed version attribute" do | |
201 detail = JournalDetail.new(:property => 'attr', :prop_key => 'fixed_version_id', :old_value => 1, :value => 2) | |
202 assert_match '0.1', show_detail(detail, true) | |
203 assert_match '1.0', show_detail(detail, true) | |
204 end | |
205 | |
206 should "show old and new values with a estimated hours attribute" do | |
207 detail = JournalDetail.new(:property => 'attr', :prop_key => 'estimated_hours', :old_value => '5', :value => '6.3') | |
208 assert_match '5.00', show_detail(detail, true) | |
209 assert_match '6.30', show_detail(detail, true) | |
210 end | |
211 | |
212 should "show old and new values with a custom field" do | |
213 detail = JournalDetail.new(:property => 'cf', :prop_key => '1', :old_value => 'MySQL', :value => 'PostgreSQL') | |
214 assert_equal 'Database changed from MySQL to PostgreSQL', show_detail(detail, true) | |
215 end | |
216 | |
217 should "show added file" do | |
218 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', :old_value => nil, :value => 'error281.txt') | |
219 assert_match 'error281.txt', show_detail(detail, true) | |
220 end | |
221 | |
222 should "show removed file" do | |
223 detail = JournalDetail.new(:property => 'attachment', :prop_key => '1', :old_value => 'error281.txt', :value => nil) | |
224 assert_match 'error281.txt', show_detail(detail, true) | |
225 end | |
226 end | |
189 end | 227 end |