##// END OF EJS Templates
Don't use auth_sources fixtures when not needed....
Jean-Philippe Lang -
r8795:a9161a3fdeff
parent child
Show More
@@ -1,144 +1,143
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2
3 3 class ActivitiesControllerTest < ActionController::TestCase
4 4 fixtures :projects, :trackers, :issue_statuses, :issues,
5 5 :enumerations, :users, :issue_categories,
6 6 :projects_trackers,
7 7 :roles,
8 8 :member_roles,
9 9 :members,
10 10 :groups_users,
11 11 :enabled_modules,
12 12 :workflows,
13 :auth_sources,
14 13 :journals, :journal_details
15 14
16 15
17 16 def test_project_index
18 17 get :index, :id => 1, :with_subprojects => 0
19 18 assert_response :success
20 19 assert_template 'index'
21 20 assert_not_nil assigns(:events_by_day)
22 21
23 22 assert_tag :tag => "h3",
24 23 :content => /#{2.days.ago.to_date.day}/,
25 24 :sibling => { :tag => "dl",
26 25 :child => { :tag => "dt",
27 26 :attributes => { :class => /issue-edit/ },
28 27 :child => { :tag => "a",
29 28 :content => /(#{IssueStatus.find(2).name})/,
30 29 }
31 30 }
32 31 }
33 32 end
34 33
35 34 def test_project_index_with_invalid_project_id_should_respond_404
36 35 get :index, :id => 299
37 36 assert_response 404
38 37 end
39 38
40 39 def test_previous_project_index
41 40 get :index, :id => 1, :from => 3.days.ago.to_date
42 41 assert_response :success
43 42 assert_template 'index'
44 43 assert_not_nil assigns(:events_by_day)
45 44
46 45 assert_tag :tag => "h3",
47 46 :content => /#{3.day.ago.to_date.day}/,
48 47 :sibling => { :tag => "dl",
49 48 :child => { :tag => "dt",
50 49 :attributes => { :class => /issue/ },
51 50 :child => { :tag => "a",
52 51 :content => /#{Issue.find(1).subject}/,
53 52 }
54 53 }
55 54 }
56 55 end
57 56
58 57 def test_global_index
59 58 get :index
60 59 assert_response :success
61 60 assert_template 'index'
62 61 assert_not_nil assigns(:events_by_day)
63 62
64 63 assert_tag :tag => "h3",
65 64 :content => /#{5.day.ago.to_date.day}/,
66 65 :sibling => { :tag => "dl",
67 66 :child => { :tag => "dt",
68 67 :attributes => { :class => /issue/ },
69 68 :child => { :tag => "a",
70 69 :content => /#{Issue.find(5).subject}/,
71 70 }
72 71 }
73 72 }
74 73 end
75 74
76 75 def test_user_index
77 76 get :index, :user_id => 2
78 77 assert_response :success
79 78 assert_template 'index'
80 79 assert_not_nil assigns(:events_by_day)
81 80
82 81 assert_tag :tag => "h3",
83 82 :content => /#{3.day.ago.to_date.day}/,
84 83 :sibling => { :tag => "dl",
85 84 :child => { :tag => "dt",
86 85 :attributes => { :class => /issue/ },
87 86 :child => { :tag => "a",
88 87 :content => /#{Issue.find(1).subject}/,
89 88 }
90 89 }
91 90 }
92 91 end
93 92
94 93 def test_user_index_with_invalid_user_id_should_respond_404
95 94 get :index, :user_id => 299
96 95 assert_response 404
97 96 end
98 97
99 98 def test_index_atom_feed
100 99 get :index, :format => 'atom', :with_subprojects => 0
101 100 assert_response :success
102 101 assert_template 'common/feed.atom'
103 102
104 103 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
105 104 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?with_subprojects=0'}
106 105 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
107 106 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?with_subprojects=0'}
108 107
109 108 assert_tag :tag => 'entry', :child => {
110 109 :tag => 'link',
111 110 :attributes => {:href => 'http://test.host/issues/11'}}
112 111 end
113 112
114 113 def test_index_atom_feed_with_explicit_selection
115 114 get :index, :format => 'atom', :with_subprojects => 0,
116 115 :show_changesets => 1,
117 116 :show_documents => 1,
118 117 :show_files => 1,
119 118 :show_issues => 1,
120 119 :show_messages => 1,
121 120 :show_news => 1,
122 121 :show_time_entries => 1,
123 122 :show_wiki_edits => 1
124 123
125 124 assert_response :success
126 125 assert_template 'common/feed.atom'
127 126
128 127 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
129 128 :attributes => {:rel => 'self', :href => 'http://test.host/activity.atom?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
130 129 assert_tag :tag => 'link', :parent => {:tag => 'feed', :parent => nil },
131 130 :attributes => {:rel => 'alternate', :href => 'http://test.host/activity?show_changesets=1&amp;show_documents=1&amp;show_files=1&amp;show_issues=1&amp;show_messages=1&amp;show_news=1&amp;show_time_entries=1&amp;show_wiki_edits=1&amp;with_subprojects=0'}
132 131
133 132 assert_tag :tag => 'entry', :child => {
134 133 :tag => 'link',
135 134 :attributes => {:href => 'http://test.host/issues/11'}}
136 135 end
137 136
138 137 def test_index_atom_feed_with_one_item_type
139 138 get :index, :format => 'atom', :show_issues => '1'
140 139 assert_response :success
141 140 assert_template 'common/feed.atom'
142 141 assert_tag :tag => 'title', :content => /Issues/
143 142 end
144 143 end
@@ -1,44 +1,43
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2
3 3 class AutoCompletesControllerTest < ActionController::TestCase
4 4 fixtures :projects, :issues, :issue_statuses,
5 5 :enumerations, :users, :issue_categories,
6 6 :trackers,
7 7 :projects_trackers,
8 8 :roles,
9 9 :member_roles,
10 10 :members,
11 :auth_sources,
12 11 :enabled_modules,
13 12 :workflows,
14 13 :journals, :journal_details
15 14
16 15 def test_issues_should_not_be_case_sensitive
17 16 get :issues, :project_id => 'ecookbook', :q => 'ReCiPe'
18 17 assert_response :success
19 18 assert_not_nil assigns(:issues)
20 19 assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
21 20 end
22 21
23 22 def test_issues_should_return_issue_with_given_id
24 23 get :issues, :project_id => 'subproject1', :q => '13'
25 24 assert_response :success
26 25 assert_not_nil assigns(:issues)
27 26 assert assigns(:issues).include?(Issue.find(13))
28 27 end
29 28
30 29 def test_auto_complete_with_scope_all_and_cross_project_relations
31 30 Setting.cross_project_issue_relations = '1'
32 31 get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
33 32 assert_response :success
34 33 assert_not_nil assigns(:issues)
35 34 assert assigns(:issues).include?(Issue.find(13))
36 35 end
37 36
38 37 def test_auto_complete_with_scope_all_without_cross_project_relations
39 38 Setting.cross_project_issue_relations = '0'
40 39 get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all'
41 40 assert_response :success
42 41 assert_equal [], assigns(:issues)
43 42 end
44 43 end
@@ -1,81 +1,80
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2
3 3 class CalendarsControllerTest < ActionController::TestCase
4 4 fixtures :projects,
5 5 :trackers,
6 6 :projects_trackers,
7 7 :roles,
8 8 :member_roles,
9 9 :members,
10 :auth_sources,
11 10 :enabled_modules
12 11
13 12 def test_calendar
14 13 get :show, :project_id => 1
15 14 assert_response :success
16 15 assert_template 'calendar'
17 16 assert_not_nil assigns(:calendar)
18 17 end
19 18
20 19 def test_cross_project_calendar
21 20 get :show
22 21 assert_response :success
23 22 assert_template 'calendar'
24 23 assert_not_nil assigns(:calendar)
25 24 end
26 25
27 26 context "GET :show" do
28 27 should "run custom queries" do
29 28 @query = Query.generate_default!(:is_public => true)
30 29
31 30 get :show, :query_id => @query.id
32 31 assert_response :success
33 32 end
34 33
35 34 end
36 35
37 36 def test_week_number_calculation
38 37 Setting.start_of_week = 7
39 38
40 39 get :show, :month => '1', :year => '2010'
41 40 assert_response :success
42 41
43 42 assert_tag :tag => 'tr',
44 43 :descendant => {:tag => 'td',
45 44 :attributes => {:class => 'week-number'}, :content => '53'},
46 45 :descendant => {:tag => 'td',
47 46 :attributes => {:class => 'odd'}, :content => '27'},
48 47 :descendant => {:tag => 'td',
49 48 :attributes => {:class => 'even'}, :content => '2'}
50 49
51 50 assert_tag :tag => 'tr',
52 51 :descendant => {:tag => 'td',
53 52 :attributes => {:class => 'week-number'}, :content => '1'},
54 53 :descendant => {:tag => 'td',
55 54 :attributes => {:class => 'odd'}, :content => '3'},
56 55 :descendant => {:tag => 'td',
57 56 :attributes => {:class => 'even'}, :content => '9'}
58 57
59 58
60 59 Setting.start_of_week = 1
61 60 get :show, :month => '1', :year => '2010'
62 61 assert_response :success
63 62
64 63 assert_tag :tag => 'tr',
65 64 :descendant => {:tag => 'td',
66 65 :attributes => {:class => 'week-number'}, :content => '53'},
67 66 :descendant => {:tag => 'td',
68 67 :attributes => {:class => 'even'}, :content => '28'},
69 68 :descendant => {:tag => 'td',
70 69 :attributes => {:class => 'even'}, :content => '3'}
71 70
72 71 assert_tag :tag => 'tr',
73 72 :descendant => {:tag => 'td',
74 73 :attributes => {:class => 'week-number'}, :content => '1'},
75 74 :descendant => {:tag => 'td',
76 75 :attributes => {:class => 'even'}, :content => '4'},
77 76 :descendant => {:tag => 'td',
78 77 :attributes => {:class => 'even'}, :content => '10'}
79 78
80 79 end
81 80 end
@@ -1,252 +1,251
1 1 require File.expand_path('../../test_helper', __FILE__)
2 2
3 3 class ContextMenusControllerTest < ActionController::TestCase
4 4 fixtures :projects,
5 5 :trackers,
6 6 :projects_trackers,
7 7 :roles,
8 8 :member_roles,
9 9 :members,
10 :auth_sources,
11 10 :enabled_modules,
12 11 :workflows,
13 12 :journals, :journal_details,
14 13 :versions,
15 14 :issues, :issue_statuses, :issue_categories,
16 15 :users,
17 16 :enumerations,
18 17 :time_entries
19 18
20 19 def test_context_menu_one_issue
21 20 @request.session[:user_id] = 2
22 21 get :issues, :ids => [1]
23 22 assert_response :success
24 23 assert_template 'context_menu'
25 24 assert_tag :tag => 'a', :content => 'Edit',
26 25 :attributes => { :href => '/issues/1/edit',
27 26 :class => 'icon-edit' }
28 27 assert_tag :tag => 'a', :content => 'Closed',
29 28 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bstatus_id%5D=5',
30 29 :class => '' }
31 30 assert_tag :tag => 'a', :content => 'Immediate',
32 31 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8',
33 32 :class => '' }
34 33 assert_no_tag :tag => 'a', :content => 'Inactive Priority'
35 34 # Versions
36 35 assert_tag :tag => 'a', :content => '2.0',
37 36 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3',
38 37 :class => '' }
39 38 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
40 39 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
41 40 :class => '' }
42 41
43 42 assert_tag :tag => 'a', :content => 'Dave Lopper',
44 43 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
45 44 :class => '' }
46 45 assert_tag :tag => 'a', :content => 'Copy',
47 46 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
48 47 :class => 'icon-copy' }
49 48 assert_no_tag :tag => 'a', :content => 'Move'
50 49 assert_tag :tag => 'a', :content => 'Delete',
51 50 :attributes => { :href => '/issues?ids%5B%5D=1',
52 51 :class => 'icon-del' }
53 52 end
54 53
55 54 def test_context_menu_one_issue_by_anonymous
56 55 get :issues, :ids => [1]
57 56 assert_response :success
58 57 assert_template 'context_menu'
59 58 assert_tag :tag => 'a', :content => 'Delete',
60 59 :attributes => { :href => '#',
61 60 :class => 'icon-del disabled' }
62 61 end
63 62
64 63 def test_context_menu_multiple_issues_of_same_project
65 64 @request.session[:user_id] = 2
66 65 get :issues, :ids => [1, 2]
67 66 assert_response :success
68 67 assert_template 'context_menu'
69 68 assert_not_nil assigns(:issues)
70 69 assert_equal [1, 2], assigns(:issues).map(&:id).sort
71 70
72 71 ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
73 72 assert_tag :tag => 'a', :content => 'Edit',
74 73 :attributes => { :href => "/issues/bulk_edit?#{ids}",
75 74 :class => 'icon-edit' }
76 75 assert_tag :tag => 'a', :content => 'Closed',
77 76 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
78 77 :class => '' }
79 78 assert_tag :tag => 'a', :content => 'Immediate',
80 79 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
81 80 :class => '' }
82 81 assert_tag :tag => 'a', :content => 'Dave Lopper',
83 82 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=3",
84 83 :class => '' }
85 84 assert_tag :tag => 'a', :content => 'Copy',
86 85 :attributes => { :href => "/issues/bulk_edit?copy=1&amp;#{ids}",
87 86 :class => 'icon-copy' }
88 87 assert_no_tag :tag => 'a', :content => 'Move'
89 88 assert_tag :tag => 'a', :content => 'Delete',
90 89 :attributes => { :href => "/issues?#{ids}",
91 90 :class => 'icon-del' }
92 91 end
93 92
94 93 def test_context_menu_multiple_issues_of_different_projects
95 94 @request.session[:user_id] = 2
96 95 get :issues, :ids => [1, 2, 6]
97 96 assert_response :success
98 97 assert_template 'context_menu'
99 98 assert_not_nil assigns(:issues)
100 99 assert_equal [1, 2, 6], assigns(:issues).map(&:id).sort
101 100
102 101 ids = assigns(:issues).map(&:id).map {|i| "ids%5B%5D=#{i}"}.join('&amp;')
103 102 assert_tag :tag => 'a', :content => 'Edit',
104 103 :attributes => { :href => "/issues/bulk_edit?#{ids}",
105 104 :class => 'icon-edit' }
106 105 assert_tag :tag => 'a', :content => 'Closed',
107 106 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bstatus_id%5D=5",
108 107 :class => '' }
109 108 assert_tag :tag => 'a', :content => 'Immediate',
110 109 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bpriority_id%5D=8",
111 110 :class => '' }
112 111 assert_tag :tag => 'a', :content => 'John Smith',
113 112 :attributes => { :href => "/issues/bulk_update?#{ids}&amp;issue%5Bassigned_to_id%5D=2",
114 113 :class => '' }
115 114 assert_tag :tag => 'a', :content => 'Delete',
116 115 :attributes => { :href => "/issues?#{ids}",
117 116 :class => 'icon-del' }
118 117 end
119 118
120 119 def test_context_menu_should_include_list_custom_fields
121 120 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
122 121 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
123 122 @request.session[:user_id] = 2
124 123 get :issues, :ids => [1]
125 124
126 125 assert_tag 'a',
127 126 :content => 'List',
128 127 :attributes => {:href => '#'},
129 128 :sibling => {:tag => 'ul', :children => {:count => 3}}
130 129
131 130 assert_tag 'a',
132 131 :content => 'Foo',
133 132 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=Foo"}
134 133 assert_tag 'a',
135 134 :content => 'none',
136 135 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D="}
137 136 end
138 137
139 138 def test_context_menu_should_not_include_null_value_for_required_custom_fields
140 139 field = IssueCustomField.create!(:name => 'List', :is_required => true, :field_format => 'list',
141 140 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
142 141 @request.session[:user_id] = 2
143 142 get :issues, :ids => [1, 2]
144 143
145 144 assert_tag 'a',
146 145 :content => 'List',
147 146 :attributes => {:href => '#'},
148 147 :sibling => {:tag => 'ul', :children => {:count => 2}}
149 148 end
150 149
151 150 def test_context_menu_on_single_issue_should_select_current_custom_field_value
152 151 field = IssueCustomField.create!(:name => 'List', :field_format => 'list',
153 152 :possible_values => ['Foo', 'Bar'], :is_for_all => true, :tracker_ids => [1, 2, 3])
154 153 issue = Issue.find(1)
155 154 issue.custom_field_values = {field.id => 'Bar'}
156 155 issue.save!
157 156 @request.session[:user_id] = 2
158 157 get :issues, :ids => [1]
159 158
160 159 assert_tag 'a',
161 160 :content => 'List',
162 161 :attributes => {:href => '#'},
163 162 :sibling => {:tag => 'ul', :children => {:count => 3}}
164 163 assert_tag 'a',
165 164 :content => 'Bar',
166 165 :attributes => {:class => /icon-checked/}
167 166 end
168 167
169 168 def test_context_menu_should_include_bool_custom_fields
170 169 field = IssueCustomField.create!(:name => 'Bool', :field_format => 'bool',
171 170 :is_for_all => true, :tracker_ids => [1, 2, 3])
172 171 @request.session[:user_id] = 2
173 172 get :issues, :ids => [1]
174 173
175 174 assert_tag 'a',
176 175 :content => 'Bool',
177 176 :attributes => {:href => '#'},
178 177 :sibling => {:tag => 'ul', :children => {:count => 3}}
179 178
180 179 assert_tag 'a',
181 180 :content => 'Yes',
182 181 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=1"}
183 182 end
184 183
185 184 def test_context_menu_should_include_user_custom_fields
186 185 field = IssueCustomField.create!(:name => 'User', :field_format => 'user',
187 186 :is_for_all => true, :tracker_ids => [1, 2, 3])
188 187 @request.session[:user_id] = 2
189 188 get :issues, :ids => [1]
190 189
191 190 assert_tag 'a',
192 191 :content => 'User',
193 192 :attributes => {:href => '#'},
194 193 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).members.count + 1}}
195 194
196 195 assert_tag 'a',
197 196 :content => 'John Smith',
198 197 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=2"}
199 198 end
200 199
201 200 def test_context_menu_should_include_version_custom_fields
202 201 field = IssueCustomField.create!(:name => 'Version', :field_format => 'version', :is_for_all => true, :tracker_ids => [1, 2, 3])
203 202 @request.session[:user_id] = 2
204 203 get :issues, :ids => [1]
205 204
206 205 assert_tag 'a',
207 206 :content => 'Version',
208 207 :attributes => {:href => '#'},
209 208 :sibling => {:tag => 'ul', :children => {:count => Project.find(1).shared_versions.count + 1}}
210 209
211 210 assert_tag 'a',
212 211 :content => '2.0',
213 212 :attributes => {:href => "/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bcustom_field_values%5D%5B#{field.id}%5D=3"}
214 213 end
215 214
216 215 def test_context_menu_by_assignable_user_should_include_assigned_to_me_link
217 216 @request.session[:user_id] = 2
218 217 get :issues, :ids => [1]
219 218 assert_response :success
220 219 assert_template 'context_menu'
221 220
222 221 assert_tag :tag => 'a', :content => / me /,
223 222 :attributes => { :href => '/issues/bulk_update?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=2',
224 223 :class => '' }
225 224 end
226 225
227 226 def test_context_menu_issue_visibility
228 227 get :issues, :ids => [1, 4]
229 228 assert_response :success
230 229 assert_template 'context_menu'
231 230 assert_equal [1], assigns(:issues).collect(&:id)
232 231 end
233 232
234 233 def test_time_entries_context_menu
235 234 @request.session[:user_id] = 2
236 235 get :time_entries, :ids => [1, 2]
237 236 assert_response :success
238 237 assert_template 'time_entries'
239 238 assert_tag 'a', :content => 'Edit'
240 239 assert_no_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
241 240 end
242 241
243 242 def test_time_entries_context_menu_without_edit_permission
244 243 @request.session[:user_id] = 2
245 244 Role.find_by_name('Manager').remove_permission! :edit_time_entries
246 245
247 246 get :time_entries, :ids => [1, 2]
248 247 assert_response :success
249 248 assert_template 'time_entries'
250 249 assert_tag 'a', :content => 'Edit', :attributes => {:class => /disabled/}
251 250 end
252 251 end
@@ -1,334 +1,334
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 require 'users_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class UsersController; def rescue_action(e) raise e end; end
23 23
24 24 class UsersControllerTest < ActionController::TestCase
25 25 include Redmine::I18n
26 26
27 fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values, :groups_users
27 fixtures :users, :projects, :members, :member_roles, :roles, :custom_fields, :custom_values, :groups_users
28 28
29 29 def setup
30 30 @controller = UsersController.new
31 31 @request = ActionController::TestRequest.new
32 32 @response = ActionController::TestResponse.new
33 33 User.current = nil
34 34 @request.session[:user_id] = 1 # admin
35 35 end
36 36
37 37 def test_index
38 38 get :index
39 39 assert_response :success
40 40 assert_template 'index'
41 41 end
42 42
43 43 def test_index
44 44 get :index
45 45 assert_response :success
46 46 assert_template 'index'
47 47 assert_not_nil assigns(:users)
48 48 # active users only
49 49 assert_nil assigns(:users).detect {|u| !u.active?}
50 50 end
51 51
52 52 def test_index_with_status_filter
53 53 get :index, :status => 3
54 54 assert_response :success
55 55 assert_template 'index'
56 56 assert_not_nil assigns(:users)
57 57 assert_equal [3], assigns(:users).map(&:status).uniq
58 58 end
59 59
60 60 def test_index_with_name_filter
61 61 get :index, :name => 'john'
62 62 assert_response :success
63 63 assert_template 'index'
64 64 users = assigns(:users)
65 65 assert_not_nil users
66 66 assert_equal 1, users.size
67 67 assert_equal 'John', users.first.firstname
68 68 end
69 69
70 70 def test_index_with_group_filter
71 71 get :index, :group_id => '10'
72 72 assert_response :success
73 73 assert_template 'index'
74 74 users = assigns(:users)
75 75 assert users.any?
76 76 assert_equal([], (users - Group.find(10).users))
77 77 end
78 78
79 79 def test_show
80 80 @request.session[:user_id] = nil
81 81 get :show, :id => 2
82 82 assert_response :success
83 83 assert_template 'show'
84 84 assert_not_nil assigns(:user)
85 85
86 86 assert_tag 'li', :content => /Phone number/
87 87 end
88 88
89 89 def test_show_should_not_display_hidden_custom_fields
90 90 @request.session[:user_id] = nil
91 91 UserCustomField.find_by_name('Phone number').update_attribute :visible, false
92 92 get :show, :id => 2
93 93 assert_response :success
94 94 assert_template 'show'
95 95 assert_not_nil assigns(:user)
96 96
97 97 assert_no_tag 'li', :content => /Phone number/
98 98 end
99 99
100 100 def test_show_should_not_fail_when_custom_values_are_nil
101 101 user = User.find(2)
102 102
103 103 # Create a custom field to illustrate the issue
104 104 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
105 105 custom_value = user.custom_values.build(:custom_field => custom_field).save!
106 106
107 107 get :show, :id => 2
108 108 assert_response :success
109 109 end
110 110
111 111 def test_show_inactive
112 112 @request.session[:user_id] = nil
113 113 get :show, :id => 5
114 114 assert_response 404
115 115 end
116 116
117 117 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
118 118 @request.session[:user_id] = nil
119 119 get :show, :id => 9
120 120 assert_response 404
121 121 end
122 122
123 123 def test_show_inactive_by_admin
124 124 @request.session[:user_id] = 1
125 125 get :show, :id => 5
126 126 assert_response 200
127 127 assert_not_nil assigns(:user)
128 128 end
129 129
130 130 def test_show_displays_memberships_based_on_project_visibility
131 131 @request.session[:user_id] = 1
132 132 get :show, :id => 2
133 133 assert_response :success
134 134 memberships = assigns(:memberships)
135 135 assert_not_nil memberships
136 136 project_ids = memberships.map(&:project_id)
137 137 assert project_ids.include?(2) #private project admin can see
138 138 end
139 139
140 140 def test_show_current_should_require_authentication
141 141 @request.session[:user_id] = nil
142 142 get :show, :id => 'current'
143 143 assert_response 302
144 144 end
145 145
146 146 def test_show_current
147 147 @request.session[:user_id] = 2
148 148 get :show, :id => 'current'
149 149 assert_response :success
150 150 assert_template 'show'
151 151 assert_equal User.find(2), assigns(:user)
152 152 end
153 153
154 154 def test_new
155 155 get :new
156 156
157 157 assert_response :success
158 158 assert_template :new
159 159 assert assigns(:user)
160 160 end
161 161
162 162 def test_create
163 163 Setting.bcc_recipients = '1'
164 164
165 165 assert_difference 'User.count' do
166 166 assert_difference 'ActionMailer::Base.deliveries.size' do
167 167 post :create,
168 168 :user => {
169 169 :firstname => 'John',
170 170 :lastname => 'Doe',
171 171 :login => 'jdoe',
172 172 :password => 'secret',
173 173 :password_confirmation => 'secret',
174 174 :mail => 'jdoe@gmail.com',
175 175 :mail_notification => 'none'
176 176 },
177 177 :send_information => '1'
178 178 end
179 179 end
180 180
181 181 user = User.first(:order => 'id DESC')
182 182 assert_redirected_to :controller => 'users', :action => 'edit', :id => user.id
183 183
184 184 assert_equal 'John', user.firstname
185 185 assert_equal 'Doe', user.lastname
186 186 assert_equal 'jdoe', user.login
187 187 assert_equal 'jdoe@gmail.com', user.mail
188 188 assert_equal 'none', user.mail_notification
189 189 assert user.check_password?('secret')
190 190
191 191 mail = ActionMailer::Base.deliveries.last
192 192 assert_not_nil mail
193 193 assert_equal [user.mail], mail.bcc
194 194 assert mail.body.include?('secret')
195 195 end
196 196
197 197 def test_create_with_failure
198 198 assert_no_difference 'User.count' do
199 199 post :create, :user => {}
200 200 end
201 201
202 202 assert_response :success
203 203 assert_template 'new'
204 204 end
205 205
206 206 def test_edit
207 207 get :edit, :id => 2
208 208
209 209 assert_response :success
210 210 assert_template 'edit'
211 211 assert_equal User.find(2), assigns(:user)
212 212 end
213 213
214 214 def test_update
215 215 ActionMailer::Base.deliveries.clear
216 216 put :update, :id => 2, :user => {:firstname => 'Changed', :mail_notification => 'only_assigned'}, :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
217 217
218 218 user = User.find(2)
219 219 assert_equal 'Changed', user.firstname
220 220 assert_equal 'only_assigned', user.mail_notification
221 221 assert_equal true, user.pref[:hide_mail]
222 222 assert_equal 'desc', user.pref[:comments_sorting]
223 223 assert ActionMailer::Base.deliveries.empty?
224 224 end
225 225
226 226 def test_update_with_failure
227 227 assert_no_difference 'User.count' do
228 228 put :update, :id => 2, :user => {:firstname => ''}
229 229 end
230 230
231 231 assert_response :success
232 232 assert_template 'edit'
233 233 end
234 234
235 235 def test_update_with_group_ids_should_assign_groups
236 236 put :update, :id => 2, :user => {:group_ids => ['10']}
237 237
238 238 user = User.find(2)
239 239 assert_equal [10], user.group_ids
240 240 end
241 241
242 242 def test_update_with_activation_should_send_a_notification
243 243 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
244 244 u.login = 'foo'
245 245 u.status = User::STATUS_REGISTERED
246 246 u.save!
247 247 ActionMailer::Base.deliveries.clear
248 248 Setting.bcc_recipients = '1'
249 249
250 250 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
251 251 assert u.reload.active?
252 252 mail = ActionMailer::Base.deliveries.last
253 253 assert_not_nil mail
254 254 assert_equal ['foo.bar@somenet.foo'], mail.bcc
255 255 assert mail.body.include?(ll('fr', :notice_account_activated))
256 256 end
257 257
258 258 def test_update_with_password_change_should_send_a_notification
259 259 ActionMailer::Base.deliveries.clear
260 260 Setting.bcc_recipients = '1'
261 261
262 262 put :update, :id => 2, :user => {:password => 'newpass', :password_confirmation => 'newpass'}, :send_information => '1'
263 263 u = User.find(2)
264 264 assert u.check_password?('newpass')
265 265
266 266 mail = ActionMailer::Base.deliveries.last
267 267 assert_not_nil mail
268 268 assert_equal [u.mail], mail.bcc
269 269 assert mail.body.include?('newpass')
270 270 end
271 271
272 272 test "put :update with a password change to an AuthSource user switching to Internal authentication" do
273 273 # Configure as auth source
274 274 u = User.find(2)
275 275 u.auth_source = AuthSource.find(1)
276 276 u.save!
277 277
278 278 put :update, :id => u.id, :user => {:auth_source_id => '', :password => 'newpass'}, :password_confirmation => 'newpass'
279 279
280 280 assert_equal nil, u.reload.auth_source
281 281 assert u.check_password?('newpass')
282 282 end
283 283
284 284 def test_destroy
285 285 assert_difference 'User.count', -1 do
286 286 delete :destroy, :id => 2
287 287 end
288 288 assert_redirected_to '/users'
289 289 assert_nil User.find_by_id(2)
290 290 end
291 291
292 292 def test_destroy_should_not_accept_get_requests
293 293 assert_no_difference 'User.count' do
294 294 get :destroy, :id => 2
295 295 end
296 296 assert_response 405
297 297 end
298 298
299 299 def test_destroy_should_be_denied_for_non_admin_users
300 300 @request.session[:user_id] = 3
301 301
302 302 assert_no_difference 'User.count' do
303 303 get :destroy, :id => 2
304 304 end
305 305 assert_response 403
306 306 end
307 307
308 308 def test_create_membership
309 309 assert_difference 'Member.count' do
310 310 post :edit_membership, :id => 7, :membership => { :project_id => 3, :role_ids => [2]}
311 311 end
312 312 assert_redirected_to :action => 'edit', :id => '7', :tab => 'memberships'
313 313 member = Member.first(:order => 'id DESC')
314 314 assert_equal User.find(7), member.principal
315 315 assert_equal [2], member.role_ids
316 316 assert_equal 3, member.project_id
317 317 end
318 318
319 319 def test_update_membership
320 320 assert_no_difference 'Member.count' do
321 321 put :edit_membership, :id => 2, :membership_id => 1, :membership => { :role_ids => [2]}
322 322 end
323 323 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
324 324 assert_equal [2], Member.find(1).role_ids
325 325 end
326 326
327 327 def test_destroy_membership
328 328 assert_difference 'Member.count', -1 do
329 329 delete :destroy_membership, :id => 2, :membership_id => 1
330 330 end
331 331 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
332 332 assert_nil Member.find_by_id(1)
333 333 end
334 334 end
@@ -1,128 +1,128
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 TimeEntryTest < ActiveSupport::TestCase
21 21 fixtures :issues, :projects, :users, :time_entries,
22 :members, :roles, :member_roles, :auth_sources,
22 :members, :roles, :member_roles,
23 23 :trackers, :issue_statuses,
24 24 :projects_trackers,
25 25 :journals, :journal_details,
26 26 :issue_categories, :enumerations,
27 27 :groups_users,
28 28 :enabled_modules,
29 29 :workflows
30 30
31 31 def test_hours_format
32 32 assertions = { "2" => 2.0,
33 33 "21.1" => 21.1,
34 34 "2,1" => 2.1,
35 35 "1,5h" => 1.5,
36 36 "7:12" => 7.2,
37 37 "10h" => 10.0,
38 38 "10 h" => 10.0,
39 39 "45m" => 0.75,
40 40 "45 m" => 0.75,
41 41 "3h15" => 3.25,
42 42 "3h 15" => 3.25,
43 43 "3 h 15" => 3.25,
44 44 "3 h 15m" => 3.25,
45 45 "3 h 15 m" => 3.25,
46 46 "3 hours" => 3.0,
47 47 "12min" => 0.2,
48 48 }
49 49
50 50 assertions.each do |k, v|
51 51 t = TimeEntry.new(:hours => k)
52 52 assert_equal v, t.hours, "Converting #{k} failed:"
53 53 end
54 54 end
55 55
56 56 def test_hours_should_default_to_nil
57 57 assert_nil TimeEntry.new.hours
58 58 end
59 59
60 60 def test_spent_on_with_blank
61 61 c = TimeEntry.new
62 62 c.spent_on = ''
63 63 assert_nil c.spent_on
64 64 end
65 65
66 66 def test_spent_on_with_nil
67 67 c = TimeEntry.new
68 68 c.spent_on = nil
69 69 assert_nil c.spent_on
70 70 end
71 71
72 72 def test_spent_on_with_string
73 73 c = TimeEntry.new
74 74 c.spent_on = "2011-01-14"
75 75 assert_equal Date.parse("2011-01-14"), c.spent_on
76 76 end
77 77
78 78 def test_spent_on_with_invalid_string
79 79 c = TimeEntry.new
80 80 c.spent_on = "foo"
81 81 assert_nil c.spent_on
82 82 end
83 83
84 84 def test_spent_on_with_date
85 85 c = TimeEntry.new
86 86 c.spent_on = Date.today
87 87 assert_equal Date.today, c.spent_on
88 88 end
89 89
90 90 def test_spent_on_with_time
91 91 c = TimeEntry.new
92 92 c.spent_on = Time.now
93 93 assert_equal Date.today, c.spent_on
94 94 end
95 95
96 96 def test_validate_time_entry
97 97 anon = User.anonymous
98 98 project = Project.find(1)
99 99 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
100 100 :priority => IssuePriority.all.first, :subject => 'test_create',
101 101 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
102 102 assert issue.save
103 103 activity = TimeEntryActivity.find_by_name('Design')
104 104 te = TimeEntry.create(:spent_on => '2010-01-01',
105 105 :hours => 100000,
106 106 :issue => issue,
107 107 :project => project,
108 108 :user => anon,
109 109 :activity => activity)
110 110 assert_equal 1, te.errors.count
111 111 end
112 112
113 113 def test_set_project_if_nil
114 114 anon = User.anonymous
115 115 project = Project.find(1)
116 116 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => anon.id, :status_id => 1,
117 117 :priority => IssuePriority.all.first, :subject => 'test_create',
118 118 :description => 'IssueTest#test_create', :estimated_hours => '1:30')
119 119 assert issue.save
120 120 activity = TimeEntryActivity.find_by_name('Design')
121 121 te = TimeEntry.create(:spent_on => '2010-01-01',
122 122 :hours => 10,
123 123 :issue => issue,
124 124 :user => anon,
125 125 :activity => activity)
126 126 assert_equal project.id, te.project.id
127 127 end
128 128 end
General Comments 0
You need to be logged in to leave comments. Login now