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

Commit

Permalink
add tests for new mediated download links
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Aug 8, 2017
1 parent d4bf776 commit 78f18f2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 0 additions & 5 deletions spec/controllers/object_files_controller_spec.rb

This file was deleted.

34 changes: 34 additions & 0 deletions spec/features/object_files_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'

describe("Object Files Download", :type => :request, :integration => true) do

fixtures :users
fixtures :object_files

before :each do
@druid = 'druid:oo000oo0001'
@file = Hydrus::ObjectFile.find(2) # this PDF 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
visit @file.url
expect(page.status_code).to eq(200)
expect(page.response_headers['Content-Type']).to eq("application/pdf")
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
visit @file.url
expect(page.response_headers['Content-Type']).not_to eq("application/pdf")
expect(current_path).to eq(root_path)
expect(find("#flash-notices div.alert")).to have_content("You are not authorized to access this page.")
end

end

0 comments on commit 78f18f2

Please sign in to comment.