Mercurial > hg > soundsoftware-site
comparison test/unit/journal_test.rb @ 1526:404aa68d4227
Merge from live branch
author | Chris Cannam |
---|---|
date | Thu, 11 Sep 2014 12:46:20 +0100 |
parents | e248c7af89ec |
children |
comparison
equal
deleted
inserted
replaced
1493:a5f2bdf3b486 | 1526:404aa68d4227 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2014 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. |
39 assert_equal 2, status.id | 39 assert_equal 2, status.id |
40 end | 40 end |
41 | 41 |
42 def test_create_should_send_email_notification | 42 def test_create_should_send_email_notification |
43 ActionMailer::Base.deliveries.clear | 43 ActionMailer::Base.deliveries.clear |
44 issue = Issue.find(:first) | 44 issue = Issue.first |
45 user = User.find(:first) | 45 user = User.first |
46 journal = issue.init_journal(user, issue) | 46 journal = issue.init_journal(user, issue) |
47 | 47 |
48 assert journal.save | 48 assert journal.save |
49 assert_equal 1, ActionMailer::Base.deliveries.size | 49 assert_equal 1, ActionMailer::Base.deliveries.size |
50 end | 50 end |
135 # Non member user should not see issues without permission | 135 # Non member user should not see issues without permission |
136 Role.non_member.remove_permission!(:view_issues) | 136 Role.non_member.remove_permission!(:view_issues) |
137 user.reload | 137 user.reload |
138 journals = Journal.visible(user).all | 138 journals = Journal.visible(user).all |
139 assert journals.empty? | 139 assert journals.empty? |
140 # User should see issues of projects for which he has view_issues permissions only | 140 # User should see issues of projects for which user has view_issues permissions only |
141 Member.create!(:principal => user, :project_id => 1, :role_ids => [1]) | 141 Member.create!(:principal => user, :project_id => 1, :role_ids => [1]) |
142 user.reload | 142 user.reload |
143 journals = Journal.visible(user).all | 143 journals = Journal.visible(user).all |
144 assert journals.any? | 144 assert journals.any? |
145 assert_nil journals.detect {|journal| journal.issue.project_id != 1} | 145 assert_nil journals.detect {|journal| journal.issue.project_id != 1} |
149 user = User.find(1) | 149 user = User.find(1) |
150 user.members.each(&:destroy) | 150 user.members.each(&:destroy) |
151 assert user.projects.empty? | 151 assert user.projects.empty? |
152 journals = Journal.visible(user).all | 152 journals = Journal.visible(user).all |
153 assert journals.any? | 153 assert journals.any? |
154 # Admin should see issues on private projects that he does not belong to | 154 # Admin should see issues on private projects that admin does not belong to |
155 assert journals.detect {|journal| !journal.issue.project.is_public?} | 155 assert journals.detect {|journal| !journal.issue.project.is_public?} |
156 end | 156 end |
157 | |
158 def test_preload_journals_details_custom_fields_should_set_custom_field_instance_variable | |
159 d = JournalDetail.new(:property => 'cf', :prop_key => '2') | |
160 journals = [Journal.new(:details => [d])] | |
161 | |
162 d.expects(:instance_variable_set).with("@custom_field", CustomField.find(2)).once | |
163 Journal.preload_journals_details_custom_fields(journals) | |
164 end | |
165 | |
166 def test_preload_journals_details_custom_fields_with_empty_set | |
167 assert_nothing_raised do | |
168 Journal.preload_journals_details_custom_fields([]) | |
169 end | |
170 end | |
171 | |
172 def test_details_should_normalize_dates | |
173 j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02')) | |
174 j.reload | |
175 assert_equal '2012-11-03', j.old_value | |
176 assert_equal '2013-01-02', j.value | |
177 end | |
178 | |
179 def test_details_should_normalize_true_values | |
180 j = JournalDetail.create!(:old_value => true, :value => true) | |
181 j.reload | |
182 assert_equal '1', j.old_value | |
183 assert_equal '1', j.value | |
184 end | |
185 | |
186 def test_details_should_normalize_false_values | |
187 j = JournalDetail.create!(:old_value => false, :value => false) | |
188 j.reload | |
189 assert_equal '0', j.old_value | |
190 assert_equal '0', j.value | |
191 end | |
192 | |
193 def test_custom_field_should_return_custom_field_for_cf_detail | |
194 d = JournalDetail.new(:property => 'cf', :prop_key => '2') | |
195 assert_equal CustomField.find(2), d.custom_field | |
196 end | |
197 | |
198 def test_custom_field_should_return_nil_for_non_cf_detail | |
199 d = JournalDetail.new(:property => 'subject') | |
200 assert_equal nil, d.custom_field | |
201 end | |
202 | |
203 def test_visible_details_should_include_relations_to_visible_issues_only | |
204 issue = Issue.generate! | |
205 visible_issue = Issue.generate! | |
206 IssueRelation.create!(:issue_from => issue, :issue_to => visible_issue, :relation_type => 'relates') | |
207 hidden_issue = Issue.generate!(:is_private => true) | |
208 IssueRelation.create!(:issue_from => issue, :issue_to => hidden_issue, :relation_type => 'relates') | |
209 issue.reload | |
210 assert_equal 1, issue.journals.size | |
211 journal = issue.journals.first | |
212 assert_equal 2, journal.details.size | |
213 | |
214 visible_details = journal.visible_details(User.anonymous) | |
215 assert_equal 1, visible_details.size | |
216 assert_equal visible_issue.id.to_s, visible_details.first.value | |
217 | |
218 visible_details = journal.visible_details(User.find(2)) | |
219 assert_equal 2, visible_details.size | |
220 end | |
157 end | 221 end |