35137.patch

Yuichi HARADA, 2021-04-21 07:06

Download (2.95 KB)

View differences:

app/controllers/imports_controller.rb
50 50

  
51 51
  def settings
52 52
    if request.post? && @import.parse_file
53
      redirect_to import_mapping_path(@import)
53
      if @import.total_items == 0
54
        flash.now[:error] = l(:error_no_data_import_file)
55
      else
56
        redirect_to import_mapping_path(@import)
57
      end
54 58
    end
55 59

  
56 60
  rescue CSV::MalformedCSVError, EncodingError => e
config/locales/en.yml
223 223
  error_invalid_file_encoding: "The file is not a valid %{encoding} encoded file"
224 224
  error_invalid_csv_file_or_settings: "The file is not a CSV file or does not match the settings below (%{value})"
225 225
  error_can_not_read_import_file: "An error occurred while reading the file to import"
226
  error_no_data_import_file: "There is no data to import into the file"
226 227
  error_attachment_extension_not_allowed: "Attachment extension %{extension} is not allowed"
227 228
  error_ldap_bind_credentials: "Invalid LDAP Account/Password"
228 229
  error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue"
test/fixtures/files/import_issues_only_header_row.csv
1
priority;Subject;start_date;parent;private;progress;custom;"target version";category;user;estimated_hours;tracker;status;database;cf_6;
test/functional/imports_controller_test.rb
180 180
    assert_select 'div#flash_error', /The file is not a CSV file or does not match the settings below \([[:print:]]+\)/
181 181
  end
182 182

  
183
  def test_post_settings_with_only_header_row_should_display_error
184
    import = generate_import('import_issues_only_header_row.csv')
185

  
186
    post(
187
      :settings,
188
      :params => {
189
        :id => import.to_param,
190
        :import_settings => {
191
          :separator => ';',
192
          :wrapper => '"',
193
          :encoding => 'ISO-8859-1'
194
        }
195
      }
196
    )
197
    assert_response 200
198
    import.reload
199
    assert_equal 0, import.total_items
200

  
201
    assert_select 'div#flash_error', /There is no data to import into the file/
202
  end
203

  
183 204
  def test_get_mapping_should_display_mapping_form
184 205
    import = generate_import('import_iso8859-1.csv')
185 206
    import.settings = {'separator' => ";", 'wrapper' => '"', 'encoding' => "ISO-8859-1"}