@@ -1,32 +1,36 | |||||
1 | <h2><%= l(:label_import_issues) %></h2> |
|
1 | <h2><%= l(:label_import_issues) %></h2> | |
2 |
|
2 | |||
3 | <% if @import.saved_items.count > 0 %> |
|
3 | <% if @import.saved_items.count > 0 %> | |
4 | <p><%= l(:notice_import_finished, :count => @import.saved_items.count) %></p> |
|
4 | <p><%= l(:notice_import_finished, :count => @import.saved_items.count) %></p> | |
5 |
|
5 | |||
6 | <ul> |
|
6 | <ul id="saved-items"> | |
7 | <% @import.saved_objects.each do |issue| %> |
|
7 | <% @import.saved_objects.each do |issue| %> | |
8 | <li><%= link_to_issue issue %></li> |
|
8 | <li><%= link_to_issue issue %></li> | |
9 | <% end %> |
|
9 | <% end %> | |
10 | </ul> |
|
10 | </ul> | |
11 | <% end %> |
|
11 | <% end %> | |
12 |
|
12 | |||
13 | <% if @import.unsaved_items.count > 0 %> |
|
13 | <% if @import.unsaved_items.count > 0 %> | |
14 | <p><%= l(:notice_import_finished_with_errors, :count => @import.unsaved_items.count, :total => @import.total_items) %></p> |
|
14 | <p><%= l(:notice_import_finished_with_errors, :count => @import.unsaved_items.count, :total => @import.total_items) %></p> | |
15 |
|
15 | |||
16 | <table id="unsaved-items" class="list"> |
|
16 | <table id="unsaved-items" class="list"> | |
|
17 | <thead> | |||
17 | <tr> |
|
18 | <tr> | |
18 | <th>Position</th> |
|
19 | <th>Position</th> | |
19 | <th>Message</th> |
|
20 | <th>Message</th> | |
20 | </tr> |
|
21 | </tr> | |
21 | <% @import.unsaved_items.each do |item| %> |
|
22 | </thead> | |
|
23 | <tbody> | |||
|
24 | <% @import.unsaved_items.each do |item| %> | |||
22 | <tr> |
|
25 | <tr> | |
23 | <td><%= item.position %></td> |
|
26 | <td><%= item.position %></td> | |
24 | <td><%= simple_format_without_paragraph item.message %></td> |
|
27 | <td><%= simple_format_without_paragraph item.message %></td> | |
25 | </tr> |
|
28 | </tr> | |
26 | <% end %> |
|
29 | <% end %> | |
|
30 | </tbody> | |||
27 | </table> |
|
31 | </table> | |
28 | <% end %> |
|
32 | <% end %> | |
29 |
|
33 | |||
30 | <% content_for :sidebar do %> |
|
34 | <% content_for :sidebar do %> | |
31 | <%= render :partial => 'issues/sidebar' %> |
|
35 | <%= render :partial => 'issues/sidebar' %> | |
32 | <% end %> |
|
36 | <% end %> |
@@ -1,201 +1,204 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2016 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 ImportsControllerTest < ActionController::TestCase |
|
20 | class ImportsControllerTest < ActionController::TestCase | |
21 | fixtures :projects, :enabled_modules, |
|
21 | fixtures :projects, :enabled_modules, | |
22 | :users, :email_addresses, |
|
22 | :users, :email_addresses, | |
23 | :roles, :members, :member_roles, |
|
23 | :roles, :members, :member_roles, | |
24 | :issues, :issue_statuses, |
|
24 | :issues, :issue_statuses, | |
25 | :trackers, :projects_trackers, |
|
25 | :trackers, :projects_trackers, | |
26 | :versions, |
|
26 | :versions, | |
27 | :issue_categories, |
|
27 | :issue_categories, | |
28 | :enumerations, |
|
28 | :enumerations, | |
29 | :workflows, |
|
29 | :workflows, | |
30 | :custom_fields, |
|
30 | :custom_fields, | |
31 | :custom_values, |
|
31 | :custom_values, | |
32 | :custom_fields_projects, |
|
32 | :custom_fields_projects, | |
33 | :custom_fields_trackers |
|
33 | :custom_fields_trackers | |
34 |
|
34 | |||
35 | def setup |
|
35 | def setup | |
36 | User.current = nil |
|
36 | User.current = nil | |
37 | @request.session[:user_id] = 2 |
|
37 | @request.session[:user_id] = 2 | |
38 | end |
|
38 | end | |
39 |
|
39 | |||
40 | def teardown |
|
40 | def teardown | |
41 | Import.destroy_all |
|
41 | Import.destroy_all | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_new_should_display_the_upload_form |
|
44 | def test_new_should_display_the_upload_form | |
45 | get :new |
|
45 | get :new | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'new' |
|
47 | assert_template 'new' | |
48 | assert_select 'input[name=?]', 'file' |
|
48 | assert_select 'input[name=?]', 'file' | |
49 | end |
|
49 | end | |
50 |
|
50 | |||
51 | def test_create_should_save_the_file |
|
51 | def test_create_should_save_the_file | |
52 | import = new_record(Import) do |
|
52 | import = new_record(Import) do | |
53 | post :create, :file => uploaded_test_file('import_issues.csv', 'text/csv') |
|
53 | post :create, :file => uploaded_test_file('import_issues.csv', 'text/csv') | |
54 | assert_response 302 |
|
54 | assert_response 302 | |
55 | end |
|
55 | end | |
56 | assert_equal 2, import.user_id |
|
56 | assert_equal 2, import.user_id | |
57 | assert_match /\A[0-9a-f]+\z/, import.filename |
|
57 | assert_match /\A[0-9a-f]+\z/, import.filename | |
58 | assert import.file_exists? |
|
58 | assert import.file_exists? | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_get_settings_should_display_settings_form |
|
61 | def test_get_settings_should_display_settings_form | |
62 | import = generate_import |
|
62 | import = generate_import | |
63 | get :settings, :id => import.to_param |
|
63 | get :settings, :id => import.to_param | |
64 | assert_response :success |
|
64 | assert_response :success | |
65 | assert_template 'settings' |
|
65 | assert_template 'settings' | |
66 | end |
|
66 | end | |
67 |
|
67 | |||
68 | def test_post_settings_should_update_settings |
|
68 | def test_post_settings_should_update_settings | |
69 | import = generate_import |
|
69 | import = generate_import | |
70 |
|
70 | |||
71 | post :settings, :id => import.to_param, |
|
71 | post :settings, :id => import.to_param, | |
72 | :import_settings => {:separator => ":", :wrapper => "|", :encoding => "UTF-8", :date_format => '%m/%d/%Y'} |
|
72 | :import_settings => {:separator => ":", :wrapper => "|", :encoding => "UTF-8", :date_format => '%m/%d/%Y'} | |
73 | assert_redirected_to "/imports/#{import.to_param}/mapping" |
|
73 | assert_redirected_to "/imports/#{import.to_param}/mapping" | |
74 |
|
74 | |||
75 | import.reload |
|
75 | import.reload | |
76 | assert_equal ":", import.settings['separator'] |
|
76 | assert_equal ":", import.settings['separator'] | |
77 | assert_equal "|", import.settings['wrapper'] |
|
77 | assert_equal "|", import.settings['wrapper'] | |
78 | assert_equal "UTF-8", import.settings['encoding'] |
|
78 | assert_equal "UTF-8", import.settings['encoding'] | |
79 | assert_equal '%m/%d/%Y', import.settings['date_format'] |
|
79 | assert_equal '%m/%d/%Y', import.settings['date_format'] | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def test_post_settings_should_update_total_items_count |
|
82 | def test_post_settings_should_update_total_items_count | |
83 | import = generate_import('import_iso8859-1.csv') |
|
83 | import = generate_import('import_iso8859-1.csv') | |
84 |
|
84 | |||
85 | post :settings, :id => import.to_param, |
|
85 | post :settings, :id => import.to_param, | |
86 | :import_settings => {:separator => ";", :wrapper => '"', :encoding => "ISO-8859-1"} |
|
86 | :import_settings => {:separator => ";", :wrapper => '"', :encoding => "ISO-8859-1"} | |
87 | assert_response 302 |
|
87 | assert_response 302 | |
88 | import.reload |
|
88 | import.reload | |
89 | assert_equal 2, import.total_items |
|
89 | assert_equal 2, import.total_items | |
90 | end |
|
90 | end | |
91 |
|
91 | |||
92 | def test_post_settings_with_wrong_encoding_should_display_error |
|
92 | def test_post_settings_with_wrong_encoding_should_display_error | |
93 | import = generate_import('import_iso8859-1.csv') |
|
93 | import = generate_import('import_iso8859-1.csv') | |
94 |
|
94 | |||
95 | post :settings, :id => import.to_param, |
|
95 | post :settings, :id => import.to_param, | |
96 | :import_settings => {:separator => ";", :wrapper => '"', :encoding => "UTF-8"} |
|
96 | :import_settings => {:separator => ";", :wrapper => '"', :encoding => "UTF-8"} | |
97 | assert_response 200 |
|
97 | assert_response 200 | |
98 | import.reload |
|
98 | import.reload | |
99 | assert_nil import.total_items |
|
99 | assert_nil import.total_items | |
100 | assert_select 'div#flash_error', /not a valid UTF-8 encoded file/ |
|
100 | assert_select 'div#flash_error', /not a valid UTF-8 encoded file/ | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def test_get_mapping_should_display_mapping_form |
|
103 | def test_get_mapping_should_display_mapping_form | |
104 | import = generate_import('import_iso8859-1.csv') |
|
104 | import = generate_import('import_iso8859-1.csv') | |
105 | import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"} |
|
105 | import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"} | |
106 | import.save! |
|
106 | import.save! | |
107 |
|
107 | |||
108 | get :mapping, :id => import.to_param |
|
108 | get :mapping, :id => import.to_param | |
109 | assert_response :success |
|
109 | assert_response :success | |
110 | assert_template 'mapping' |
|
110 | assert_template 'mapping' | |
111 |
|
111 | |||
112 | assert_select 'select[name=?]', 'import_settings[mapping][subject]' do |
|
112 | assert_select 'select[name=?]', 'import_settings[mapping][subject]' do | |
113 | assert_select 'option', 4 |
|
113 | assert_select 'option', 4 | |
114 | assert_select 'option[value="0"]', :text => 'column A' |
|
114 | assert_select 'option[value="0"]', :text => 'column A' | |
115 | end |
|
115 | end | |
116 |
|
116 | |||
117 | assert_select 'table.sample-data' do |
|
117 | assert_select 'table.sample-data' do | |
118 | assert_select 'tr', 3 |
|
118 | assert_select 'tr', 3 | |
119 | assert_select 'td', 9 |
|
119 | assert_select 'td', 9 | |
120 | end |
|
120 | end | |
121 | end |
|
121 | end | |
122 |
|
122 | |||
123 | def test_post_mapping_should_update_mapping |
|
123 | def test_post_mapping_should_update_mapping | |
124 | import = generate_import('import_iso8859-1.csv') |
|
124 | import = generate_import('import_iso8859-1.csv') | |
125 |
|
125 | |||
126 | post :mapping, :id => import.to_param, |
|
126 | post :mapping, :id => import.to_param, | |
127 | :import_settings => {:mapping => {:project_id => '1', :tracker_id => '2', :subject => '0'}} |
|
127 | :import_settings => {:mapping => {:project_id => '1', :tracker_id => '2', :subject => '0'}} | |
128 | assert_redirected_to "/imports/#{import.to_param}/run" |
|
128 | assert_redirected_to "/imports/#{import.to_param}/run" | |
129 | import.reload |
|
129 | import.reload | |
130 | mapping = import.settings['mapping'] |
|
130 | mapping = import.settings['mapping'] | |
131 | assert mapping |
|
131 | assert mapping | |
132 | assert_equal '1', mapping['project_id'] |
|
132 | assert_equal '1', mapping['project_id'] | |
133 | assert_equal '2', mapping['tracker_id'] |
|
133 | assert_equal '2', mapping['tracker_id'] | |
134 | assert_equal '0', mapping['subject'] |
|
134 | assert_equal '0', mapping['subject'] | |
135 | end |
|
135 | end | |
136 |
|
136 | |||
137 | def test_get_run |
|
137 | def test_get_run | |
138 | import = generate_import_with_mapping |
|
138 | import = generate_import_with_mapping | |
139 |
|
139 | |||
140 | get :run, :id => import |
|
140 | get :run, :id => import | |
141 | assert_response :success |
|
141 | assert_response :success | |
142 | assert_template 'run' |
|
142 | assert_template 'run' | |
143 | end |
|
143 | end | |
144 |
|
144 | |||
145 | def test_post_run_should_import_the_file |
|
145 | def test_post_run_should_import_the_file | |
146 | import = generate_import_with_mapping |
|
146 | import = generate_import_with_mapping | |
147 |
|
147 | |||
148 | assert_difference 'Issue.count', 3 do |
|
148 | assert_difference 'Issue.count', 3 do | |
149 | post :run, :id => import |
|
149 | post :run, :id => import | |
150 | assert_redirected_to "/imports/#{import.to_param}" |
|
150 | assert_redirected_to "/imports/#{import.to_param}" | |
151 | end |
|
151 | end | |
152 |
|
152 | |||
153 | import.reload |
|
153 | import.reload | |
154 | assert_equal true, import.finished |
|
154 | assert_equal true, import.finished | |
155 | assert_equal 3, import.items.count |
|
155 | assert_equal 3, import.items.count | |
156 |
|
156 | |||
157 | issues = Issue.order(:id => :desc).limit(3).to_a |
|
157 | issues = Issue.order(:id => :desc).limit(3).to_a | |
158 | assert_equal ["Child of existing issue", "Child 1", "First"], issues.map(&:subject) |
|
158 | assert_equal ["Child of existing issue", "Child 1", "First"], issues.map(&:subject) | |
159 | end |
|
159 | end | |
160 |
|
160 | |||
161 | def test_post_run_should_import_max_items_and_resume |
|
161 | def test_post_run_should_import_max_items_and_resume | |
162 | ImportsController.any_instance.stubs(:max_items_per_request).returns(2) |
|
162 | ImportsController.any_instance.stubs(:max_items_per_request).returns(2) | |
163 | import = generate_import_with_mapping |
|
163 | import = generate_import_with_mapping | |
164 |
|
164 | |||
165 | assert_difference 'Issue.count', 2 do |
|
165 | assert_difference 'Issue.count', 2 do | |
166 | post :run, :id => import |
|
166 | post :run, :id => import | |
167 | assert_redirected_to "/imports/#{import.to_param}/run" |
|
167 | assert_redirected_to "/imports/#{import.to_param}/run" | |
168 | end |
|
168 | end | |
169 |
|
169 | |||
170 | assert_difference 'Issue.count', 1 do |
|
170 | assert_difference 'Issue.count', 1 do | |
171 | post :run, :id => import |
|
171 | post :run, :id => import | |
172 | assert_redirected_to "/imports/#{import.to_param}" |
|
172 | assert_redirected_to "/imports/#{import.to_param}" | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | issues = Issue.order(:id => :desc).limit(3).to_a |
|
175 | issues = Issue.order(:id => :desc).limit(3).to_a | |
176 | assert_equal ["Child of existing issue", "Child 1", "First"], issues.map(&:subject) |
|
176 | assert_equal ["Child of existing issue", "Child 1", "First"], issues.map(&:subject) | |
177 | end |
|
177 | end | |
178 |
|
178 | |||
179 | def test_show_without_errors |
|
179 | def test_show_without_errors | |
180 | import = generate_import_with_mapping |
|
180 | import = generate_import_with_mapping | |
181 | import.run |
|
181 | import.run | |
182 | assert_equal 0, import.unsaved_items.count |
|
182 | assert_equal 0, import.unsaved_items.count | |
183 |
|
183 | |||
184 | get :show, :id => import.to_param |
|
184 | get :show, :id => import.to_param | |
185 | assert_response :success |
|
185 | assert_response :success | |
186 | assert_template 'show' |
|
186 | assert_template 'show' | |
|
187 | assert_select 'ul#saved-items' | |||
|
188 | assert_select 'ul#saved-items li', import.saved_items.count | |||
187 | assert_select 'table#unsaved-items', 0 |
|
189 | assert_select 'table#unsaved-items', 0 | |
188 | end |
|
190 | end | |
189 |
|
191 | |||
190 | def test_show_with_errors_should_show_unsaved_items |
|
192 | def test_show_with_errors_should_show_unsaved_items | |
191 | import = generate_import_with_mapping |
|
193 | import = generate_import_with_mapping | |
192 | import.mapping.merge! 'subject' => 20 |
|
194 | import.mapping.merge! 'subject' => 20 | |
193 | import.run |
|
195 | import.run | |
194 | assert_not_equal 0, import.unsaved_items.count |
|
196 | assert_not_equal 0, import.unsaved_items.count | |
195 |
|
197 | |||
196 | get :show, :id => import.to_param |
|
198 | get :show, :id => import.to_param | |
197 | assert_response :success |
|
199 | assert_response :success | |
198 | assert_template 'show' |
|
200 | assert_template 'show' | |
199 | assert_select 'table#unsaved-items' |
|
201 | assert_select 'table#unsaved-items' | |
|
202 | assert_select 'table#unsaved-items tbody tr', import.unsaved_items.count | |||
200 | end |
|
203 | end | |
201 | end |
|
204 | end |
General Comments 0
You need to be logged in to leave comments.
Login now