##// END OF EJS Templates
Rails4: replace deprecated Relation#first with finder options at integration IssuesTest...
Toshi MARUYAMA -
r12324:d02bcbcee5d2
parent child
Show More
@@ -1,220 +1,220
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 IssuesTest < ActionController::IntegrationTest
20 class IssuesTest < ActionController::IntegrationTest
21 fixtures :projects,
21 fixtures :projects,
22 :users,
22 :users,
23 :roles,
23 :roles,
24 :members,
24 :members,
25 :member_roles,
25 :member_roles,
26 :trackers,
26 :trackers,
27 :projects_trackers,
27 :projects_trackers,
28 :enabled_modules,
28 :enabled_modules,
29 :issue_statuses,
29 :issue_statuses,
30 :issues,
30 :issues,
31 :enumerations,
31 :enumerations,
32 :custom_fields,
32 :custom_fields,
33 :custom_values,
33 :custom_values,
34 :custom_fields_trackers
34 :custom_fields_trackers
35
35
36 # create an issue
36 # create an issue
37 def test_add_issue
37 def test_add_issue
38 log_user('jsmith', 'jsmith')
38 log_user('jsmith', 'jsmith')
39 get 'projects/1/issues/new', :tracker_id => '1'
39 get 'projects/1/issues/new', :tracker_id => '1'
40 assert_response :success
40 assert_response :success
41 assert_template 'issues/new'
41 assert_template 'issues/new'
42
42
43 post 'projects/1/issues', :tracker_id => "1",
43 post 'projects/1/issues', :tracker_id => "1",
44 :issue => { :start_date => "2006-12-26",
44 :issue => { :start_date => "2006-12-26",
45 :priority_id => "4",
45 :priority_id => "4",
46 :subject => "new test issue",
46 :subject => "new test issue",
47 :category_id => "",
47 :category_id => "",
48 :description => "new issue",
48 :description => "new issue",
49 :done_ratio => "0",
49 :done_ratio => "0",
50 :due_date => "",
50 :due_date => "",
51 :assigned_to_id => "" },
51 :assigned_to_id => "" },
52 :custom_fields => {'2' => 'Value for field 2'}
52 :custom_fields => {'2' => 'Value for field 2'}
53 # find created issue
53 # find created issue
54 issue = Issue.find_by_subject("new test issue")
54 issue = Issue.find_by_subject("new test issue")
55 assert_kind_of Issue, issue
55 assert_kind_of Issue, issue
56
56
57 # check redirection
57 # check redirection
58 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
58 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
59 follow_redirect!
59 follow_redirect!
60 assert_equal issue, assigns(:issue)
60 assert_equal issue, assigns(:issue)
61
61
62 # check issue attributes
62 # check issue attributes
63 assert_equal 'jsmith', issue.author.login
63 assert_equal 'jsmith', issue.author.login
64 assert_equal 1, issue.project.id
64 assert_equal 1, issue.project.id
65 assert_equal 1, issue.status.id
65 assert_equal 1, issue.status.id
66 end
66 end
67
67
68 # add then remove 2 attachments to an issue
68 # add then remove 2 attachments to an issue
69 def test_issue_attachments
69 def test_issue_attachments
70 log_user('jsmith', 'jsmith')
70 log_user('jsmith', 'jsmith')
71 set_tmp_attachments_directory
71 set_tmp_attachments_directory
72
72
73 put 'issues/1',
73 put 'issues/1',
74 :notes => 'Some notes',
74 :notes => 'Some notes',
75 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
75 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
76 assert_redirected_to "/issues/1"
76 assert_redirected_to "/issues/1"
77
77
78 # make sure attachment was saved
78 # make sure attachment was saved
79 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
79 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
80 assert_kind_of Attachment, attachment
80 assert_kind_of Attachment, attachment
81 assert_equal Issue.find(1), attachment.container
81 assert_equal Issue.find(1), attachment.container
82 assert_equal 'This is an attachment', attachment.description
82 assert_equal 'This is an attachment', attachment.description
83 # verify the size of the attachment stored in db
83 # verify the size of the attachment stored in db
84 #assert_equal file_data_1.length, attachment.filesize
84 #assert_equal file_data_1.length, attachment.filesize
85 # verify that the attachment was written to disk
85 # verify that the attachment was written to disk
86 assert File.exist?(attachment.diskfile)
86 assert File.exist?(attachment.diskfile)
87
87
88 # remove the attachments
88 # remove the attachments
89 Issue.find(1).attachments.each(&:destroy)
89 Issue.find(1).attachments.each(&:destroy)
90 assert_equal 0, Issue.find(1).attachments.length
90 assert_equal 0, Issue.find(1).attachments.length
91 end
91 end
92
92
93 def test_other_formats_links_on_index
93 def test_other_formats_links_on_index
94 get '/projects/ecookbook/issues'
94 get '/projects/ecookbook/issues'
95
95
96 %w(Atom PDF CSV).each do |format|
96 %w(Atom PDF CSV).each do |format|
97 assert_tag :a, :content => format,
97 assert_tag :a, :content => format,
98 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
98 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
99 :rel => 'nofollow' }
99 :rel => 'nofollow' }
100 end
100 end
101 end
101 end
102
102
103 def test_other_formats_links_on_index_without_project_id_in_url
103 def test_other_formats_links_on_index_without_project_id_in_url
104 get '/issues', :project_id => 'ecookbook'
104 get '/issues', :project_id => 'ecookbook'
105
105
106 %w(Atom PDF CSV).each do |format|
106 %w(Atom PDF CSV).each do |format|
107 assert_tag :a, :content => format,
107 assert_tag :a, :content => format,
108 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
108 :attributes => { :href => "/projects/ecookbook/issues.#{format.downcase}",
109 :rel => 'nofollow' }
109 :rel => 'nofollow' }
110 end
110 end
111 end
111 end
112
112
113 def test_pagination_links_on_index
113 def test_pagination_links_on_index
114 Setting.per_page_options = '2'
114 Setting.per_page_options = '2'
115 get '/projects/ecookbook/issues'
115 get '/projects/ecookbook/issues'
116
116
117 assert_tag :a, :content => '2',
117 assert_tag :a, :content => '2',
118 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
118 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
119
119
120 end
120 end
121
121
122 def test_pagination_links_on_index_without_project_id_in_url
122 def test_pagination_links_on_index_without_project_id_in_url
123 Setting.per_page_options = '2'
123 Setting.per_page_options = '2'
124 get '/issues', :project_id => 'ecookbook'
124 get '/issues', :project_id => 'ecookbook'
125
125
126 assert_tag :a, :content => '2',
126 assert_tag :a, :content => '2',
127 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
127 :attributes => { :href => '/projects/ecookbook/issues?page=2' }
128
128
129 end
129 end
130
130
131 def test_issue_with_user_custom_field
131 def test_issue_with_user_custom_field
132 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
132 @field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true, :trackers => Tracker.all)
133 Role.anonymous.add_permission! :add_issues, :edit_issues
133 Role.anonymous.add_permission! :add_issues, :edit_issues
134 users = Project.find(1).users
134 users = Project.find(1).users
135 tester = users.first
135 tester = users.first
136
136
137 # Issue form
137 # Issue form
138 get '/projects/ecookbook/issues/new'
138 get '/projects/ecookbook/issues/new'
139 assert_response :success
139 assert_response :success
140 assert_tag :select,
140 assert_tag :select,
141 :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
141 :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
142 :children => {:count => (users.size + 1)}, # +1 for blank value
142 :children => {:count => (users.size + 1)}, # +1 for blank value
143 :child => {
143 :child => {
144 :tag => 'option',
144 :tag => 'option',
145 :attributes => {:value => tester.id.to_s},
145 :attributes => {:value => tester.id.to_s},
146 :content => tester.name
146 :content => tester.name
147 }
147 }
148
148
149 # Create issue
149 # Create issue
150 assert_difference 'Issue.count' do
150 assert_difference 'Issue.count' do
151 post '/projects/ecookbook/issues',
151 post '/projects/ecookbook/issues',
152 :issue => {
152 :issue => {
153 :tracker_id => '1',
153 :tracker_id => '1',
154 :priority_id => '4',
154 :priority_id => '4',
155 :subject => 'Issue with user custom field',
155 :subject => 'Issue with user custom field',
156 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
156 :custom_field_values => {@field.id.to_s => users.first.id.to_s}
157 }
157 }
158 end
158 end
159 issue = Issue.first(:order => 'id DESC')
159 issue = Issue.order('id DESC').first
160 assert_response 302
160 assert_response 302
161
161
162 # Issue view
162 # Issue view
163 follow_redirect!
163 follow_redirect!
164 assert_tag :th,
164 assert_tag :th,
165 :content => /Tester/,
165 :content => /Tester/,
166 :sibling => {
166 :sibling => {
167 :tag => 'td',
167 :tag => 'td',
168 :content => tester.name
168 :content => tester.name
169 }
169 }
170 assert_tag :select,
170 assert_tag :select,
171 :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
171 :attributes => {:name => "issue[custom_field_values][#{@field.id}]"},
172 :children => {:count => (users.size + 1)}, # +1 for blank value
172 :children => {:count => (users.size + 1)}, # +1 for blank value
173 :child => {
173 :child => {
174 :tag => 'option',
174 :tag => 'option',
175 :attributes => {:value => tester.id.to_s, :selected => 'selected'},
175 :attributes => {:value => tester.id.to_s, :selected => 'selected'},
176 :content => tester.name
176 :content => tester.name
177 }
177 }
178
178
179 # Update issue
179 # Update issue
180 new_tester = users[1]
180 new_tester = users[1]
181 assert_difference 'Journal.count' do
181 assert_difference 'Journal.count' do
182 put "/issues/#{issue.id}",
182 put "/issues/#{issue.id}",
183 :notes => 'Updating custom field',
183 :notes => 'Updating custom field',
184 :issue => {
184 :issue => {
185 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
185 :custom_field_values => {@field.id.to_s => new_tester.id.to_s}
186 }
186 }
187 end
187 end
188 assert_response 302
188 assert_response 302
189
189
190 # Issue view
190 # Issue view
191 follow_redirect!
191 follow_redirect!
192 assert_tag :content => 'Tester',
192 assert_tag :content => 'Tester',
193 :ancestor => {:tag => 'ul', :attributes => {:class => /details/}},
193 :ancestor => {:tag => 'ul', :attributes => {:class => /details/}},
194 :sibling => {
194 :sibling => {
195 :content => tester.name,
195 :content => tester.name,
196 :sibling => {
196 :sibling => {
197 :content => new_tester.name
197 :content => new_tester.name
198 }
198 }
199 }
199 }
200 end
200 end
201
201
202 def test_update_using_invalid_http_verbs
202 def test_update_using_invalid_http_verbs
203 subject = 'Updated by an invalid http verb'
203 subject = 'Updated by an invalid http verb'
204
204
205 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
205 get '/issues/update/1', {:issue => {:subject => subject}}, credentials('jsmith')
206 assert_response 404
206 assert_response 404
207 assert_not_equal subject, Issue.find(1).subject
207 assert_not_equal subject, Issue.find(1).subject
208
208
209 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
209 post '/issues/1', {:issue => {:subject => subject}}, credentials('jsmith')
210 assert_response 404
210 assert_response 404
211 assert_not_equal subject, Issue.find(1).subject
211 assert_not_equal subject, Issue.find(1).subject
212 end
212 end
213
213
214 def test_get_watch_should_be_invalid
214 def test_get_watch_should_be_invalid
215 assert_no_difference 'Watcher.count' do
215 assert_no_difference 'Watcher.count' do
216 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
216 get '/watchers/watch?object_type=issue&object_id=1', {}, credentials('jsmith')
217 assert_response 404
217 assert_response 404
218 end
218 end
219 end
219 end
220 end
220 end
General Comments 0
You need to be logged in to leave comments. Login now