##// END OF EJS Templates
Added unit tests for IssuesHelper#show_detail...
Eric Davis -
r3438:1a73f8fa0f46
parent child
Show More
@@ -0,0 +1,159
1 # Redmine - project management software
2 # Copyright (C) 2006-2010 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.dirname(__FILE__) + '/../../test_helper'
19
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 context "IssuesHelper#show_detail" do
48 context "with no_html" do
49 should 'show a changing attribute' do
50 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
51 assert_equal "% Done changed from 40 to 100", show_detail(@detail, true)
52 end
53
54 should 'show a new attribute' do
55 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
56 assert_equal "% Done set to 100", show_detail(@detail, true)
57 end
58
59 should 'show a deleted attribute' do
60 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
61 assert_equal "% Done deleted (50)", show_detail(@detail, true)
62 end
63 end
64
65 context "with html" do
66 should 'show a changing attribute with HTML highlights' do
67 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '40', :value => '100', :prop_key => 'done_ratio')
68 @response.body = show_detail(@detail, false)
69
70 assert_select 'strong', :text => '% Done'
71 assert_select 'i', :text => '40'
72 assert_select 'i', :text => '100'
73 end
74
75 should 'show a new attribute with HTML highlights' do
76 @detail = JournalDetail.generate!(:property => 'attr', :old_value => nil, :value => '100', :prop_key => 'done_ratio')
77 @response.body = show_detail(@detail, false)
78
79 assert_select 'strong', :text => '% Done'
80 assert_select 'i', :text => '100'
81 end
82
83 should 'show a deleted attribute with HTML highlights' do
84 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '50', :value => nil, :prop_key => 'done_ratio')
85 @response.body = show_detail(@detail, false)
86
87 assert_select 'strong', :text => '% Done'
88 assert_select 'strike' do
89 assert_select 'i', :text => '50'
90 end
91 end
92 end
93
94 context "with a start_date attribute" do
95 should "format the current date" do
96 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
97 assert_match "01/31/2010", show_detail(@detail, true)
98 end
99
100 should "format the old date" do
101 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'start_date')
102 assert_match "01/01/2010", show_detail(@detail, true)
103 end
104 end
105
106 context "with a due_date attribute" do
107 should "format the current date" do
108 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
109 assert_match "01/31/2010", show_detail(@detail, true)
110 end
111
112 should "format the old date" do
113 @detail = JournalDetail.generate!(:property => 'attr', :old_value => '2010-01-01', :value => '2010-01-31', :prop_key => 'due_date')
114 assert_match "01/01/2010", show_detail(@detail, true)
115 end
116 end
117
118 context "with a project attribute" do
119 should_show_the_old_and_new_values_for('project_id', Project)
120 end
121
122 context "with a issue status attribute" do
123 should_show_the_old_and_new_values_for('status_id', IssueStatus)
124 end
125
126 context "with a tracker attribute" do
127 should_show_the_old_and_new_values_for('tracker_id', Tracker)
128 end
129
130 context "with a assigned to attribute" do
131 should_show_the_old_and_new_values_for('assigned_to_id', User)
132 end
133
134 context "with a priority attribute" do
135 should_show_the_old_and_new_values_for('priority_id', IssuePriority) do
136 @old_value = IssuePriority.generate!(:type => 'IssuePriority')
137 @new_value = IssuePriority.generate!(:type => 'IssuePriority')
138 end
139 end
140
141 context "with a category attribute" do
142 should_show_the_old_and_new_values_for('category_id', IssueCategory)
143 end
144
145 context "with a fixed version attribute" do
146 should_show_the_old_and_new_values_for('fixed_version_id', Version)
147 end
148
149 context "with a estimated hours attribute" do
150 should "format the time into two decimal places"
151 should "format the old time into two decimal places"
152 end
153
154 should "test custom fields"
155 should "test attachments"
156
157 end
158
159 end
@@ -111,4 +111,35 class ActiveSupport::TestCase
111 111 }.size
112 112 end
113 113 end
114
115 def self.should_show_the_old_and_new_values_for(prop_key, model, &block)
116 context "" do
117 setup do
118 if block_given?
119 instance_eval &block
120 else
121 @old_value = model.generate!
122 @new_value = model.generate!
123 end
124 end
125
126 should "use the new value's name" do
127 @detail = JournalDetail.generate!(:property => 'attr',
128 :old_value => @old_value.id,
129 :value => @new_value.id,
130 :prop_key => prop_key)
131
132 assert_match @new_value.name, show_detail(@detail, true)
133 end
134
135 should "use the old value's name" do
136 @detail = JournalDetail.generate!(:property => 'attr',
137 :old_value => @old_value.id,
138 :value => @new_value.id,
139 :prop_key => prop_key)
140
141 assert_match @old_value.name, show_detail(@detail, true)
142 end
143 end
144 end
114 145 end
General Comments 0
You need to be logged in to leave comments. Login now