##// END OF EJS Templates
add missing fixture to test/unit/journal_test.rb...
Toshi MARUYAMA -
r13547:84abe25b5748
parent child
Show More
@@ -1,223 +1,223
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class JournalTest < ActiveSupport::TestCase
21 21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details,
22 22 :issue_relations, :workflows,
23 23 :users, :members, :member_roles, :roles, :enabled_modules,
24 :groups_users,
24 :groups_users, :email_addresses,
25 25 :enumerations,
26 26 :projects_trackers, :trackers, :custom_fields
27 27
28 28 def setup
29 29 @journal = Journal.find 1
30 30 User.current = nil
31 31 end
32 32
33 33 def test_journalized_is_an_issue
34 34 issue = @journal.issue
35 35 assert_kind_of Issue, issue
36 36 assert_equal 1, issue.id
37 37 end
38 38
39 39 def test_new_status
40 40 status = @journal.new_status
41 41 assert_not_nil status
42 42 assert_kind_of IssueStatus, status
43 43 assert_equal 2, status.id
44 44 end
45 45
46 46 def test_create_should_send_email_notification
47 47 ActionMailer::Base.deliveries.clear
48 48 issue = Issue.first
49 49 user = User.first
50 50 journal = issue.init_journal(user, issue)
51 51
52 52 assert journal.save
53 53 assert_equal 1, ActionMailer::Base.deliveries.size
54 54 end
55 55
56 56 def test_should_not_save_journal_with_blank_notes_and_no_details
57 57 journal = Journal.new(:journalized => Issue.first, :user => User.first)
58 58
59 59 assert_no_difference 'Journal.count' do
60 60 assert_equal false, journal.save
61 61 end
62 62 end
63 63
64 64 def test_create_should_not_split_non_private_notes
65 65 assert_difference 'Journal.count' do
66 66 assert_no_difference 'JournalDetail.count' do
67 67 journal = Journal.generate!(:notes => 'Notes')
68 68 end
69 69 end
70 70
71 71 assert_difference 'Journal.count' do
72 72 assert_difference 'JournalDetail.count' do
73 73 journal = Journal.generate!(:notes => 'Notes', :details => [JournalDetail.new])
74 74 end
75 75 end
76 76
77 77 assert_difference 'Journal.count' do
78 78 assert_difference 'JournalDetail.count' do
79 79 journal = Journal.generate!(:notes => '', :details => [JournalDetail.new])
80 80 end
81 81 end
82 82 end
83 83
84 84 def test_create_should_split_private_notes
85 85 assert_difference 'Journal.count' do
86 86 assert_no_difference 'JournalDetail.count' do
87 87 journal = Journal.generate!(:notes => 'Notes', :private_notes => true)
88 88 journal.reload
89 89 assert_equal true, journal.private_notes
90 90 assert_equal 'Notes', journal.notes
91 91 end
92 92 end
93 93
94 94 assert_difference 'Journal.count', 2 do
95 95 assert_difference 'JournalDetail.count' do
96 96 journal = Journal.generate!(:notes => 'Notes', :private_notes => true, :details => [JournalDetail.new])
97 97 journal.reload
98 98 assert_equal true, journal.private_notes
99 99 assert_equal 'Notes', journal.notes
100 100 assert_equal 0, journal.details.size
101 101
102 102 journal_with_changes = Journal.order('id DESC').offset(1).first
103 103 assert_equal false, journal_with_changes.private_notes
104 104 assert_nil journal_with_changes.notes
105 105 assert_equal 1, journal_with_changes.details.size
106 106 assert_equal journal.created_on, journal_with_changes.created_on
107 107 end
108 108 end
109 109
110 110 assert_difference 'Journal.count' do
111 111 assert_difference 'JournalDetail.count' do
112 112 journal = Journal.generate!(:notes => '', :private_notes => true, :details => [JournalDetail.new])
113 113 journal.reload
114 114 assert_equal false, journal.private_notes
115 115 assert_equal '', journal.notes
116 116 assert_equal 1, journal.details.size
117 117 end
118 118 end
119 119 end
120 120
121 121 def test_visible_scope_for_anonymous
122 122 # Anonymous user should see issues of public projects only
123 123 journals = Journal.visible(User.anonymous).to_a
124 124 assert journals.any?
125 125 assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
126 126 # Anonymous user should not see issues without permission
127 127 Role.anonymous.remove_permission!(:view_issues)
128 128 journals = Journal.visible(User.anonymous).to_a
129 129 assert journals.empty?
130 130 end
131 131
132 132 def test_visible_scope_for_user
133 133 user = User.find(9)
134 134 assert user.projects.empty?
135 135 # Non member user should see issues of public projects only
136 136 journals = Journal.visible(user).to_a
137 137 assert journals.any?
138 138 assert_nil journals.detect {|journal| !journal.issue.project.is_public?}
139 139 # Non member user should not see issues without permission
140 140 Role.non_member.remove_permission!(:view_issues)
141 141 user.reload
142 142 journals = Journal.visible(user).to_a
143 143 assert journals.empty?
144 144 # User should see issues of projects for which user has view_issues permissions only
145 145 Member.create!(:principal => user, :project_id => 1, :role_ids => [1])
146 146 user.reload
147 147 journals = Journal.visible(user).to_a
148 148 assert journals.any?
149 149 assert_nil journals.detect {|journal| journal.issue.project_id != 1}
150 150 end
151 151
152 152 def test_visible_scope_for_admin
153 153 user = User.find(1)
154 154 user.members.each(&:destroy)
155 155 assert user.projects.empty?
156 156 journals = Journal.visible(user).to_a
157 157 assert journals.any?
158 158 # Admin should see issues on private projects that admin does not belong to
159 159 assert journals.detect {|journal| !journal.issue.project.is_public?}
160 160 end
161 161
162 162 def test_preload_journals_details_custom_fields_should_set_custom_field_instance_variable
163 163 d = JournalDetail.new(:property => 'cf', :prop_key => '2')
164 164 journals = [Journal.new(:details => [d])]
165 165
166 166 d.expects(:instance_variable_set).with("@custom_field", CustomField.find(2)).once
167 167 Journal.preload_journals_details_custom_fields(journals)
168 168 end
169 169
170 170 def test_preload_journals_details_custom_fields_with_empty_set
171 171 assert_nothing_raised do
172 172 Journal.preload_journals_details_custom_fields([])
173 173 end
174 174 end
175 175
176 176 def test_details_should_normalize_dates
177 177 j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02'))
178 178 j.reload
179 179 assert_equal '2012-11-03', j.old_value
180 180 assert_equal '2013-01-02', j.value
181 181 end
182 182
183 183 def test_details_should_normalize_true_values
184 184 j = JournalDetail.create!(:old_value => true, :value => true)
185 185 j.reload
186 186 assert_equal '1', j.old_value
187 187 assert_equal '1', j.value
188 188 end
189 189
190 190 def test_details_should_normalize_false_values
191 191 j = JournalDetail.create!(:old_value => false, :value => false)
192 192 j.reload
193 193 assert_equal '0', j.old_value
194 194 assert_equal '0', j.value
195 195 end
196 196
197 197 def test_custom_field_should_return_custom_field_for_cf_detail
198 198 d = JournalDetail.new(:property => 'cf', :prop_key => '2')
199 199 assert_equal CustomField.find(2), d.custom_field
200 200 end
201 201
202 202 def test_custom_field_should_return_nil_for_non_cf_detail
203 203 d = JournalDetail.new(:property => 'subject')
204 204 assert_equal nil, d.custom_field
205 205 end
206 206
207 207 def test_visible_details_should_include_relations_to_visible_issues_only
208 208 issue = Issue.generate!
209 209 visible_issue = Issue.generate!
210 210 hidden_issue = Issue.generate!(:is_private => true)
211 211
212 212 journal = Journal.new
213 213 journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'relates', :value => visible_issue.id)
214 214 journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'relates', :value => hidden_issue.id)
215 215
216 216 visible_details = journal.visible_details(User.anonymous)
217 217 assert_equal 1, visible_details.size
218 218 assert_equal visible_issue.id.to_s, visible_details.first.value.to_s
219 219
220 220 visible_details = journal.visible_details(User.find(2))
221 221 assert_equal 2, visible_details.size
222 222 end
223 223 end
General Comments 0
You need to be logged in to leave comments. Login now