@@ -1,178 +1,178 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 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 | :users, :members, :member_roles, :roles, :enabled_modules, |
|
23 | 23 | :projects_trackers, :trackers |
|
24 | 24 | |
|
25 | 25 | def setup |
|
26 | 26 | @journal = Journal.find 1 |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def test_journalized_is_an_issue |
|
30 | 30 | issue = @journal.issue |
|
31 | 31 | assert_kind_of Issue, issue |
|
32 | 32 | assert_equal 1, issue.id |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def test_new_status |
|
36 | 36 | status = @journal.new_status |
|
37 | 37 | assert_not_nil status |
|
38 | 38 | assert_kind_of IssueStatus, status |
|
39 | 39 | assert_equal 2, status.id |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def test_create_should_send_email_notification |
|
43 | 43 | ActionMailer::Base.deliveries.clear |
|
44 | 44 | issue = Issue.first |
|
45 | 45 | user = User.first |
|
46 | 46 | journal = issue.init_journal(user, issue) |
|
47 | 47 | |
|
48 | 48 | assert journal.save |
|
49 | 49 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def test_should_not_save_journal_with_blank_notes_and_no_details |
|
53 | 53 | journal = Journal.new(:journalized => Issue.first, :user => User.first) |
|
54 | 54 | |
|
55 | 55 | assert_no_difference 'Journal.count' do |
|
56 | 56 | assert_equal false, journal.save |
|
57 | 57 | end |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def test_create_should_not_split_non_private_notes |
|
61 | 61 | assert_difference 'Journal.count' do |
|
62 | 62 | assert_no_difference 'JournalDetail.count' do |
|
63 | 63 | journal = Journal.generate!(:notes => 'Notes') |
|
64 | 64 | end |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | assert_difference 'Journal.count' do |
|
68 | 68 | assert_difference 'JournalDetail.count' do |
|
69 | 69 | journal = Journal.generate!(:notes => 'Notes', :details => [JournalDetail.new]) |
|
70 | 70 | end |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | assert_difference 'Journal.count' do |
|
74 | 74 | assert_difference 'JournalDetail.count' do |
|
75 | 75 | journal = Journal.generate!(:notes => '', :details => [JournalDetail.new]) |
|
76 | 76 | end |
|
77 | 77 | end |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def test_create_should_split_private_notes |
|
81 | 81 | assert_difference 'Journal.count' do |
|
82 | 82 | assert_no_difference 'JournalDetail.count' do |
|
83 | 83 | journal = Journal.generate!(:notes => 'Notes', :private_notes => true) |
|
84 | 84 | journal.reload |
|
85 | 85 | assert_equal true, journal.private_notes |
|
86 | 86 | assert_equal 'Notes', journal.notes |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | assert_difference 'Journal.count', 2 do |
|
91 | 91 | assert_difference 'JournalDetail.count' do |
|
92 | 92 | journal = Journal.generate!(:notes => 'Notes', :private_notes => true, :details => [JournalDetail.new]) |
|
93 | 93 | journal.reload |
|
94 | 94 | assert_equal true, journal.private_notes |
|
95 | 95 | assert_equal 'Notes', journal.notes |
|
96 | 96 | assert_equal 0, journal.details.size |
|
97 | 97 | |
|
98 | 98 | journal_with_changes = Journal.order('id DESC').offset(1).first |
|
99 | 99 | assert_equal false, journal_with_changes.private_notes |
|
100 | 100 | assert_nil journal_with_changes.notes |
|
101 | 101 | assert_equal 1, journal_with_changes.details.size |
|
102 | 102 | assert_equal journal.created_on, journal_with_changes.created_on |
|
103 | 103 | end |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | assert_difference 'Journal.count' do |
|
107 | 107 | assert_difference 'JournalDetail.count' do |
|
108 | 108 | journal = Journal.generate!(:notes => '', :private_notes => true, :details => [JournalDetail.new]) |
|
109 | 109 | journal.reload |
|
110 | 110 | assert_equal false, journal.private_notes |
|
111 | 111 | assert_equal '', journal.notes |
|
112 | 112 | assert_equal 1, journal.details.size |
|
113 | 113 | end |
|
114 | 114 | end |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def test_visible_scope_for_anonymous |
|
118 | 118 | # Anonymous user should see issues of public projects only |
|
119 | 119 | journals = Journal.visible(User.anonymous).all |
|
120 | 120 | assert journals.any? |
|
121 | 121 | assert_nil journals.detect {|journal| !journal.issue.project.is_public?} |
|
122 | 122 | # Anonymous user should not see issues without permission |
|
123 | 123 | Role.anonymous.remove_permission!(:view_issues) |
|
124 | 124 | journals = Journal.visible(User.anonymous).all |
|
125 | 125 | assert journals.empty? |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def test_visible_scope_for_user |
|
129 | 129 | user = User.find(9) |
|
130 | 130 | assert user.projects.empty? |
|
131 | 131 | # Non member user should see issues of public projects only |
|
132 | 132 | journals = Journal.visible(user).all |
|
133 | 133 | assert journals.any? |
|
134 | 134 | assert_nil journals.detect {|journal| !journal.issue.project.is_public?} |
|
135 | 135 | # Non member user should not see issues without permission |
|
136 | 136 | Role.non_member.remove_permission!(:view_issues) |
|
137 | 137 | user.reload |
|
138 | 138 | journals = Journal.visible(user).all |
|
139 | 139 | assert journals.empty? |
|
140 |
# User should see issues of projects for which |
|
|
140 | # User should see issues of projects for which user has view_issues permissions only | |
|
141 | 141 | Member.create!(:principal => user, :project_id => 1, :role_ids => [1]) |
|
142 | 142 | user.reload |
|
143 | 143 | journals = Journal.visible(user).all |
|
144 | 144 | assert journals.any? |
|
145 | 145 | assert_nil journals.detect {|journal| journal.issue.project_id != 1} |
|
146 | 146 | end |
|
147 | 147 | |
|
148 | 148 | def test_visible_scope_for_admin |
|
149 | 149 | user = User.find(1) |
|
150 | 150 | user.members.each(&:destroy) |
|
151 | 151 | assert user.projects.empty? |
|
152 | 152 | journals = Journal.visible(user).all |
|
153 | 153 | assert journals.any? |
|
154 |
# Admin should see issues on private projects that |
|
|
154 | # Admin should see issues on private projects that admin does not belong to | |
|
155 | 155 | assert journals.detect {|journal| !journal.issue.project.is_public?} |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | 158 | def test_details_should_normalize_dates |
|
159 | 159 | j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02')) |
|
160 | 160 | j.reload |
|
161 | 161 | assert_equal '2012-11-03', j.old_value |
|
162 | 162 | assert_equal '2013-01-02', j.value |
|
163 | 163 | end |
|
164 | 164 | |
|
165 | 165 | def test_details_should_normalize_true_values |
|
166 | 166 | j = JournalDetail.create!(:old_value => true, :value => true) |
|
167 | 167 | j.reload |
|
168 | 168 | assert_equal '1', j.old_value |
|
169 | 169 | assert_equal '1', j.value |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | def test_details_should_normalize_false_values |
|
173 | 173 | j = JournalDetail.create!(:old_value => false, :value => false) |
|
174 | 174 | j.reload |
|
175 | 175 | assert_equal '0', j.old_value |
|
176 | 176 | assert_equal '0', j.value |
|
177 | 177 | end |
|
178 | 178 | end |
General Comments 0
You need to be logged in to leave comments.
Login now