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