From ec0fe87053d1bb791d9a344a3060e2ebd4ed76e7 Mon Sep 17 00:00:00 2001 From: Peter Mangiafico Date: Wed, 8 Jan 2020 11:48:16 -0800 Subject: [PATCH] rubocop fixes --- app/controllers/object_files_controller.rb | 2 +- spec/features/home_page_spec.rb | 2 +- spec/features/item_create_spec.rb | 2 +- spec/features/models/object_file_spec.rb | 5 ++-- spec/features/object_files_controller_spec.rb | 29 +++++++++---------- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/controllers/object_files_controller.rb b/app/controllers/object_files_controller.rb index 419e93fbb..f32bbf075 100644 --- a/app/controllers/object_files_controller.rb +++ b/app/controllers/object_files_controller.rb @@ -1,5 +1,5 @@ class ObjectFilesController < ApplicationController - before_filter :authenticate_user! + before_action :authenticate_user! def show @fobj = Hydrus::Item.find(params[:id]) diff --git a/spec/features/home_page_spec.rb b/spec/features/home_page_spec.rb index 09355ee50..e03713cb3 100644 --- a/spec/features/home_page_spec.rb +++ b/spec/features/home_page_spec.rb @@ -69,7 +69,7 @@ it 'breadcrumbs should not be displayed' do # Logged out - logout + sign_out visit root_path expect(page).not_to have_css(@breadcrumbs) end diff --git a/spec/features/item_create_spec.rb b/spec/features/item_create_spec.rb index 6760837c8..563598bca 100644 --- a/spec/features/item_create_spec.rb +++ b/spec/features/item_create_spec.rb @@ -125,7 +125,7 @@ f.file = Tempfile.new('mock_HydrusObjectFile_') f.save click_button(@buttons[:save]) - + save_and_open_page # confirm validation message is shown and publish button is not available expect(find(@div_alert)).to have_content(@notices[:save]) expect(find(@div_alert)).to have_content('Contributors must be entered') diff --git a/spec/features/models/object_file_spec.rb b/spec/features/models/object_file_spec.rb index 904869960..9efa4ae39 100644 --- a/spec/features/models/object_file_spec.rb +++ b/spec/features/models/object_file_spec.rb @@ -10,9 +10,9 @@ it 'finds four files associated with the first item and it grabs the url of a given file' do expect(files.size).to eq(4) f = files[0] - exp_url = '/uploads/bb/123/bb/1234/bb123bb1234/content/pinocchio.htm' + exp_url = '/file/druid:bb123bb1234/pinocchio.htm' expect(f.url).to eq(exp_url) - expect(f.current_path).to eq("#{Rails.root}/public#{exp_url}") + expect(f.current_path).to eq("#{Rails.root}/uploads/bb/123/bb/1234/bb123bb1234/content/pinocchio.htm") expect(files[1].filename).to eq(%q{pinocchio characters tc in file name.pdf}) expect(files[1].size).to be > 0 end @@ -24,7 +24,6 @@ files = @hi.files expect(files.size).to eq(4) file = files.first - file_url = file.url full_file_path = file.current_path expect(File.exists?(full_file_path)).to be_truthy diff --git a/spec/features/object_files_controller_spec.rb b/spec/features/object_files_controller_spec.rb index 7ab3269bb..eea21658f 100644 --- a/spec/features/object_files_controller_spec.rb +++ b/spec/features/object_files_controller_spec.rb @@ -1,32 +1,31 @@ require 'spec_helper' describe('Object Files Download', type: :request, integration: true) do - fixtures :users fixtures :object_files + let(:archivist1) { create :archivist1 } + let(:archivist99) { create :archivist99 } before :each do - @druid = 'druid:oo000oo0001' - @file = Hydrus::ObjectFile.find(2) # this PDF defined in the fixtures belongs to archivist1 + @druid = 'druid:bb123bb1234' + @file = Hydrus::ObjectFile.find(3) # this txt file defined in the fixtures belongs to archivist1 end - it 'should be redirected to the login page when accessing a file URL if not logged in' do - logout - visit @file.url - expect(current_path).to eq(new_user_session_path) - end - - it 'should allow the owner of the file to download it' do - login_as('archivist1') # owner of the item can download the file + it 'allows the owner of the file to download it' do + sign_in(archivist1) # owner of the item can download the file visit @file.url expect(page.status_code).to eq(200) - expect(page.response_headers['Content-Type']).to eq('application/pdf') + expect(page.response_headers['Content-Type']).to eq('text/plain') + logout(archivist1) end - it 'should redirect to home page and provide a not authorized message when accessing a file URL when logged in but do not have view access on the item' do - login_as('archivist99') # no view access on the item, no access + it 'redirects to home page with not authorized message when accessing a file URL when no access is allowed' do + sign_in(archivist99) # no view access on the item, no access visit @file.url - expect(page.response_headers['Content-Type']).not_to eq('application/pdf') + expect(page.response_headers['Content-Type']).not_to eq('text/plain') expect(current_path).to eq(root_path) expect(find('#flash-notices div.alert')).to have_content('You are not authorized to access this page.') + logout(archivist99) + visit @file.url + expect(current_path).to eq(root_path) # logged out, still can't get the file end end