Skip to content
Permalink
Browse files

Refactoring: Prefer Rails fixture_file_upload helper method instead o…

…f using Rack::Test::UploadedFile (directly).
  • Loading branch information...
thorsteneckel committed Mar 14, 2019
1 parent d5bf8a5 commit e3d219221050efd899a9f1d2fcbb6b7b8dc1d0ae
@@ -518,8 +518,7 @@

# 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 @@
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 @@
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)
@@ -47,8 +47,7 @@
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 @@
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 @@
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)
@@ -861,8 +861,7 @@
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 @@
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 @@
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)

0 comments on commit e3d2192

Please sign in to comment.
You can’t perform that action at this time.