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