Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Jan 8, 2020
1 parent 209d44e commit ec0fe87
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/controllers/object_files_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ObjectFilesController < ApplicationController
before_filter :authenticate_user!
before_action :authenticate_user!

def show
@fobj = Hydrus::Item.find(params[:id])
Expand Down
2 changes: 1 addition & 1 deletion spec/features/home_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/features/item_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 2 additions & 3 deletions spec/features/models/object_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
29 changes: 14 additions & 15 deletions spec/features/object_files_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ec0fe87

Please sign in to comment.