Refactoring: Prefer Rails fixture_file_upload helper method instead of using Rack::Test::UploadedFile (directly).

This commit is contained in:
Thorsten Eckel 2019-03-14 02:37:35 +01:00
parent d5bf8a533c
commit e3d2192210
9 changed files with 9 additions and 18 deletions

View File

Can't render this file because it has a wrong number of fields in line 2.

View File

Can't render this file because it has a wrong number of fields in line 2.

View File

@ -518,8 +518,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
# invalid file
authenticated_as(admin_user)
csv_file_path = Rails.root.join('test', 'data', 'csv', 'organization_simple_col_not_existing.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/organization/simple_col_not_existing.csv', 'text/csv')
post '/api/v1/organizations/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(json_response).to be_a_kind_of(Hash)
@ -532,8 +531,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(json_response['errors'][1]).to eq("Line 2: Unable to create record - unknown attribute 'name2' for Organization.")
# valid file try
csv_file_path = Rails.root.join('test', 'data', 'csv', 'organization_simple.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/organization/simple.csv', 'text/csv')
post '/api/v1/organizations/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(json_response).to be_a_kind_of(Hash)
@ -546,8 +544,7 @@ RSpec.describe 'Organization', type: :request, searchindex: true do
expect(Organization.find_by(name: 'organization-member-import2')).to be_nil
# valid file
csv_file_path = Rails.root.join('test', 'data', 'csv', 'organization_simple.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/organization/simple.csv', 'text/csv')
post '/api/v1/organizations/import', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(json_response).to be_a_kind_of(Hash)

View File

@ -47,8 +47,7 @@ RSpec.describe 'Text Module', type: :request do
it 'does csv import - admin access' do
# invalid file
csv_file_path = Rails.root.join('test', 'data', 'csv', 'text_module_simple_col_not_existing.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/text_module/simple_col_not_existing.csv', 'text/csv')
authenticated_as(admin_user)
post '/api/v1/text_modules/import', params: { try: true, file: csv_file, col_sep: ';' }
@ -63,8 +62,7 @@ RSpec.describe 'Text Module', type: :request do
expect(json_response['errors'][1]).to eq("Line 2: Unable to create record - unknown attribute 'keywords2' for TextModule.")
# valid file try
csv_file_path = Rails.root.join('test', 'data', 'csv', 'text_module_simple.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/text_module/simple.csv', 'text/csv')
post '/api/v1/text_modules/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(json_response).to be_a_kind_of(Hash)
@ -77,8 +75,7 @@ RSpec.describe 'Text Module', type: :request do
expect(TextModule.find_by(name: 'some name2')).to be_nil
# valid file
csv_file_path = Rails.root.join('test', 'data', 'csv', 'text_module_simple.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/text_module/simple.csv', 'text/csv')
post '/api/v1/text_modules/import', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(json_response).to be_a_kind_of(Hash)

View File

@ -861,8 +861,7 @@ RSpec.describe 'User', type: :request, searchindex: true do
it 'does csv import - admin access (05.03)' do
# invalid file
csv_file_path = Rails.root.join('test', 'data', 'csv', 'user_simple_col_not_existing.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/user/simple_col_not_existing.csv', 'text/csv')
authenticated_as(admin_user)
post '/api/v1/users/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
@ -876,8 +875,7 @@ RSpec.describe 'User', type: :request, searchindex: true do
expect(json_response['errors'][1]).to eq("Line 2: Unable to create record - unknown attribute 'firstname2' for User.")
# valid file try
csv_file_path = Rails.root.join('test', 'data', 'csv', 'user_simple.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/user/simple.csv', 'text/csv')
post '/api/v1/users/import?try=true', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(json_response).to be_a_kind_of(Hash)
@ -890,8 +888,7 @@ RSpec.describe 'User', type: :request, searchindex: true do
expect(User.find_by(login: 'user-simple-import2')).to be_nil
# valid file
csv_file_path = Rails.root.join('test', 'data', 'csv', 'user_simple.csv')
csv_file = ::Rack::Test::UploadedFile.new(csv_file_path, 'text/csv')
csv_file = fixture_file_upload('csv_import/user/simple.csv', 'text/csv')
post '/api/v1/users/import', params: { file: csv_file, col_sep: ';' }
expect(response).to have_http_status(200)
expect(json_response).to be_a_kind_of(Hash)