@@ -1,178 +1,178 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
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 |
|
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 JournalTest < ActiveSupport::TestCase |
|
20 | class JournalTest < ActiveSupport::TestCase | |
21 | fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, |
|
21 | fixtures :projects, :issues, :issue_statuses, :journals, :journal_details, | |
22 | :users, :members, :member_roles, :roles, :enabled_modules, |
|
22 | :users, :members, :member_roles, :roles, :enabled_modules, | |
23 | :projects_trackers, :trackers |
|
23 | :projects_trackers, :trackers | |
24 |
|
24 | |||
25 | def setup |
|
25 | def setup | |
26 | @journal = Journal.find 1 |
|
26 | @journal = Journal.find 1 | |
27 | end |
|
27 | end | |
28 |
|
28 | |||
29 | def test_journalized_is_an_issue |
|
29 | def test_journalized_is_an_issue | |
30 | issue = @journal.issue |
|
30 | issue = @journal.issue | |
31 | assert_kind_of Issue, issue |
|
31 | assert_kind_of Issue, issue | |
32 | assert_equal 1, issue.id |
|
32 | assert_equal 1, issue.id | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | def test_new_status |
|
35 | def test_new_status | |
36 | status = @journal.new_status |
|
36 | status = @journal.new_status | |
37 | assert_not_nil status |
|
37 | assert_not_nil status | |
38 | assert_kind_of IssueStatus, status |
|
38 | assert_kind_of IssueStatus, status | |
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.first |
|
44 | issue = Issue.first | |
45 | user = User.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 | |
51 |
|
51 | |||
52 | def test_should_not_save_journal_with_blank_notes_and_no_details |
|
52 | def test_should_not_save_journal_with_blank_notes_and_no_details | |
53 | journal = Journal.new(:journalized => Issue.first, :user => User.first) |
|
53 | journal = Journal.new(:journalized => Issue.first, :user => User.first) | |
54 |
|
54 | |||
55 | assert_no_difference 'Journal.count' do |
|
55 | assert_no_difference 'Journal.count' do | |
56 | assert_equal false, journal.save |
|
56 | assert_equal false, journal.save | |
57 | end |
|
57 | end | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def test_create_should_not_split_non_private_notes |
|
60 | def test_create_should_not_split_non_private_notes | |
61 | assert_difference 'Journal.count' do |
|
61 | assert_difference 'Journal.count' do | |
62 | assert_no_difference 'JournalDetail.count' do |
|
62 | assert_no_difference 'JournalDetail.count' do | |
63 | journal = Journal.generate!(:notes => 'Notes') |
|
63 | journal = Journal.generate!(:notes => 'Notes') | |
64 | end |
|
64 | end | |
65 | end |
|
65 | end | |
66 |
|
66 | |||
67 | assert_difference 'Journal.count' do |
|
67 | assert_difference 'Journal.count' do | |
68 | assert_difference 'JournalDetail.count' do |
|
68 | assert_difference 'JournalDetail.count' do | |
69 | journal = Journal.generate!(:notes => 'Notes', :details => [JournalDetail.new]) |
|
69 | journal = Journal.generate!(:notes => 'Notes', :details => [JournalDetail.new]) | |
70 | end |
|
70 | end | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | assert_difference 'Journal.count' do |
|
73 | assert_difference 'Journal.count' do | |
74 | assert_difference 'JournalDetail.count' do |
|
74 | assert_difference 'JournalDetail.count' do | |
75 | journal = Journal.generate!(:notes => '', :details => [JournalDetail.new]) |
|
75 | journal = Journal.generate!(:notes => '', :details => [JournalDetail.new]) | |
76 | end |
|
76 | end | |
77 | end |
|
77 | end | |
78 | end |
|
78 | end | |
79 |
|
79 | |||
80 | def test_create_should_split_private_notes |
|
80 | def test_create_should_split_private_notes | |
81 | assert_difference 'Journal.count' do |
|
81 | assert_difference 'Journal.count' do | |
82 | assert_no_difference 'JournalDetail.count' do |
|
82 | assert_no_difference 'JournalDetail.count' do | |
83 | journal = Journal.generate!(:notes => 'Notes', :private_notes => true) |
|
83 | journal = Journal.generate!(:notes => 'Notes', :private_notes => true) | |
84 | journal.reload |
|
84 | journal.reload | |
85 | assert_equal true, journal.private_notes |
|
85 | assert_equal true, journal.private_notes | |
86 | assert_equal 'Notes', journal.notes |
|
86 | assert_equal 'Notes', journal.notes | |
87 | end |
|
87 | end | |
88 | end |
|
88 | end | |
89 |
|
89 | |||
90 | assert_difference 'Journal.count', 2 do |
|
90 | assert_difference 'Journal.count', 2 do | |
91 | assert_difference 'JournalDetail.count' do |
|
91 | assert_difference 'JournalDetail.count' do | |
92 | journal = Journal.generate!(:notes => 'Notes', :private_notes => true, :details => [JournalDetail.new]) |
|
92 | journal = Journal.generate!(:notes => 'Notes', :private_notes => true, :details => [JournalDetail.new]) | |
93 | journal.reload |
|
93 | journal.reload | |
94 | assert_equal true, journal.private_notes |
|
94 | assert_equal true, journal.private_notes | |
95 | assert_equal 'Notes', journal.notes |
|
95 | assert_equal 'Notes', journal.notes | |
96 | assert_equal 0, journal.details.size |
|
96 | assert_equal 0, journal.details.size | |
97 |
|
97 | |||
98 | journal_with_changes = Journal.order('id DESC').offset(1).first |
|
98 | journal_with_changes = Journal.order('id DESC').offset(1).first | |
99 | assert_equal false, journal_with_changes.private_notes |
|
99 | assert_equal false, journal_with_changes.private_notes | |
100 | assert_nil journal_with_changes.notes |
|
100 | assert_nil journal_with_changes.notes | |
101 | assert_equal 1, journal_with_changes.details.size |
|
101 | assert_equal 1, journal_with_changes.details.size | |
102 | assert_equal journal.created_on, journal_with_changes.created_on |
|
102 | assert_equal journal.created_on, journal_with_changes.created_on | |
103 | end |
|
103 | end | |
104 | end |
|
104 | end | |
105 |
|
105 | |||
106 | assert_difference 'Journal.count' do |
|
106 | assert_difference 'Journal.count' do | |
107 | assert_difference 'JournalDetail.count' do |
|
107 | assert_difference 'JournalDetail.count' do | |
108 | journal = Journal.generate!(:notes => '', :private_notes => true, :details => [JournalDetail.new]) |
|
108 | journal = Journal.generate!(:notes => '', :private_notes => true, :details => [JournalDetail.new]) | |
109 | journal.reload |
|
109 | journal.reload | |
110 | assert_equal false, journal.private_notes |
|
110 | assert_equal false, journal.private_notes | |
111 | assert_equal '', journal.notes |
|
111 | assert_equal '', journal.notes | |
112 | assert_equal 1, journal.details.size |
|
112 | assert_equal 1, journal.details.size | |
113 | end |
|
113 | end | |
114 | end |
|
114 | end | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | def test_visible_scope_for_anonymous |
|
117 | def test_visible_scope_for_anonymous | |
118 | # Anonymous user should see issues of public projects only |
|
118 | # Anonymous user should see issues of public projects only | |
119 | journals = Journal.visible(User.anonymous).all |
|
119 | journals = Journal.visible(User.anonymous).all | |
120 | assert journals.any? |
|
120 | assert journals.any? | |
121 | assert_nil journals.detect {|journal| !journal.issue.project.is_public?} |
|
121 | assert_nil journals.detect {|journal| !journal.issue.project.is_public?} | |
122 | # Anonymous user should not see issues without permission |
|
122 | # Anonymous user should not see issues without permission | |
123 | Role.anonymous.remove_permission!(:view_issues) |
|
123 | Role.anonymous.remove_permission!(:view_issues) | |
124 | journals = Journal.visible(User.anonymous).all |
|
124 | journals = Journal.visible(User.anonymous).all | |
125 | assert journals.empty? |
|
125 | assert journals.empty? | |
126 | end |
|
126 | end | |
127 |
|
127 | |||
128 | def test_visible_scope_for_user |
|
128 | def test_visible_scope_for_user | |
129 | user = User.find(9) |
|
129 | user = User.find(9) | |
130 | assert user.projects.empty? |
|
130 | assert user.projects.empty? | |
131 | # Non member user should see issues of public projects only |
|
131 | # Non member user should see issues of public projects only | |
132 | journals = Journal.visible(user).all |
|
132 | journals = Journal.visible(user).all | |
133 | assert journals.any? |
|
133 | assert journals.any? | |
134 | assert_nil journals.detect {|journal| !journal.issue.project.is_public?} |
|
134 | assert_nil journals.detect {|journal| !journal.issue.project.is_public?} | |
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 |
|
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} | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def test_visible_scope_for_admin |
|
148 | def test_visible_scope_for_admin | |
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 |
|
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 |
|
157 | |||
158 | def test_details_should_normalize_dates |
|
158 | def test_details_should_normalize_dates | |
159 | j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02')) |
|
159 | j = JournalDetail.create!(:old_value => Date.parse('2012-11-03'), :value => Date.parse('2013-01-02')) | |
160 | j.reload |
|
160 | j.reload | |
161 | assert_equal '2012-11-03', j.old_value |
|
161 | assert_equal '2012-11-03', j.old_value | |
162 | assert_equal '2013-01-02', j.value |
|
162 | assert_equal '2013-01-02', j.value | |
163 | end |
|
163 | end | |
164 |
|
164 | |||
165 | def test_details_should_normalize_true_values |
|
165 | def test_details_should_normalize_true_values | |
166 | j = JournalDetail.create!(:old_value => true, :value => true) |
|
166 | j = JournalDetail.create!(:old_value => true, :value => true) | |
167 | j.reload |
|
167 | j.reload | |
168 | assert_equal '1', j.old_value |
|
168 | assert_equal '1', j.old_value | |
169 | assert_equal '1', j.value |
|
169 | assert_equal '1', j.value | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | def test_details_should_normalize_false_values |
|
172 | def test_details_should_normalize_false_values | |
173 | j = JournalDetail.create!(:old_value => false, :value => false) |
|
173 | j = JournalDetail.create!(:old_value => false, :value => false) | |
174 | j.reload |
|
174 | j.reload | |
175 | assert_equal '0', j.old_value |
|
175 | assert_equal '0', j.old_value | |
176 | assert_equal '0', j.value |
|
176 | assert_equal '0', j.value | |
177 | end |
|
177 | end | |
178 | end |
|
178 | end |
General Comments 0
You need to be logged in to leave comments.
Login now