From e3d219221050efd899a9f1d2fcbb6b7b8dc1d0ae Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 14 Mar 2019 02:37:35 +0100 Subject: [PATCH] Refactoring: Prefer Rails fixture_file_upload helper method instead of using Rack::Test::UploadedFile (directly). --- .../fixtures/csv_import/organization/simple.csv | 0 .../csv_import/organization/simple_col_not_existing.csv | 0 .../fixtures/csv_import/text_module/simple.csv | 0 .../csv_import/text_module/simple_col_not_existing.csv | 0 .../fixtures/csv_import/user/simple.csv | 0 .../fixtures/csv_import/user/simple_col_not_existing.csv | 0 spec/requests/organization_spec.rb | 9 +++------ spec/requests/text_module_spec.rb | 9 +++------ spec/requests/user_spec.rb | 9 +++------ 9 files changed, 9 insertions(+), 18 deletions(-) rename test/data/csv/organization_simple.csv => spec/fixtures/csv_import/organization/simple.csv (100%) rename test/data/csv/organization_simple_col_not_existing.csv => spec/fixtures/csv_import/organization/simple_col_not_existing.csv (100%) rename test/data/csv/text_module_simple.csv => spec/fixtures/csv_import/text_module/simple.csv (100%) rename test/data/csv/text_module_simple_col_not_existing.csv => spec/fixtures/csv_import/text_module/simple_col_not_existing.csv (100%) rename test/data/csv/user_simple.csv => spec/fixtures/csv_import/user/simple.csv (100%) rename test/data/csv/user_simple_col_not_existing.csv => spec/fixtures/csv_import/user/simple_col_not_existing.csv (100%) diff --git a/test/data/csv/organization_simple.csv b/spec/fixtures/csv_import/organization/simple.csv similarity index 100% rename from test/data/csv/organization_simple.csv rename to spec/fixtures/csv_import/organization/simple.csv diff --git a/test/data/csv/organization_simple_col_not_existing.csv b/spec/fixtures/csv_import/organization/simple_col_not_existing.csv similarity index 100% rename from test/data/csv/organization_simple_col_not_existing.csv rename to spec/fixtures/csv_import/organization/simple_col_not_existing.csv diff --git a/test/data/csv/text_module_simple.csv b/spec/fixtures/csv_import/text_module/simple.csv similarity index 100% rename from test/data/csv/text_module_simple.csv rename to spec/fixtures/csv_import/text_module/simple.csv diff --git a/test/data/csv/text_module_simple_col_not_existing.csv b/spec/fixtures/csv_import/text_module/simple_col_not_existing.csv similarity index 100% rename from test/data/csv/text_module_simple_col_not_existing.csv rename to spec/fixtures/csv_import/text_module/simple_col_not_existing.csv diff --git a/test/data/csv/user_simple.csv b/spec/fixtures/csv_import/user/simple.csv similarity index 100% rename from test/data/csv/user_simple.csv rename to spec/fixtures/csv_import/user/simple.csv diff --git a/test/data/csv/user_simple_col_not_existing.csv b/spec/fixtures/csv_import/user/simple_col_not_existing.csv similarity index 100% rename from test/data/csv/user_simple_col_not_existing.csv rename to spec/fixtures/csv_import/user/simple_col_not_existing.csv diff --git a/spec/requests/organization_spec.rb b/spec/requests/organization_spec.rb index 973d4675d..245fb923c 100644 --- a/spec/requests/organization_spec.rb +++ b/spec/requests/organization_spec.rb @@ -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) diff --git a/spec/requests/text_module_spec.rb b/spec/requests/text_module_spec.rb index 4d78b1399..1ef654a0f 100644 --- a/spec/requests/text_module_spec.rb +++ b/spec/requests/text_module_spec.rb @@ -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) diff --git a/spec/requests/user_spec.rb b/spec/requests/user_spec.rb index fdf77611a..ea632ce80 100644 --- a/spec/requests/user_spec.rb +++ b/spec/requests/user_spec.rb @@ -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)