Sha256: bf16e03f87dab2e397e809a0fa4eed16231bef52facc0df966351c76bc9c84cd

Contents?: true

Size: 2 KB

Versions: 2

Compression:

Stored size: 2 KB

Contents

require 'spec_helper'

describe CurationConcerns::SingleUseLinksController, type: :controller do
  routes { CurationConcerns::Engine.routes }
  let(:user) { FactoryGirl.find_or_create(:jill) }

  let(:file) do
    FileSet.create do |file|
      file.apply_depositor_metadata(user)
    end
  end

  describe "logged in user with edit permission" do
    let(:hash) { "some-dummy-sha2-hash" }

    before do
      sign_in user
      allow(DateTime).to receive(:now).and_return(DateTime.now)
      expect(Digest::SHA2).to receive(:new).and_return(hash)
    end

    describe "GET 'download'" do
      it "and_return http success" do
        get 'new_download', id: file
        expect(response).to be_success
        expect(assigns[:link]).to eq routes.url_helpers.download_single_use_link_path(hash)
      end
    end

    describe "GET 'show'" do
      it "and_return http success" do
        get 'new_show', id: file
        expect(response).to be_success
        expect(assigns[:link]).to eq routes.url_helpers.show_single_use_link_path(hash)
      end
    end
  end

  describe "logged in user without edit permission" do
    before do
      @other_user = FactoryGirl.find_or_create(:archivist)
      file.read_users << @other_user
      file.save
      sign_in @other_user
      file.read_users << @other_user
      file.save
    end

    describe "GET 'download'" do
      it "and_return http success" do
        get 'new_download', id: file
        expect(response).not_to be_success
      end
    end

    describe "GET 'show'" do
      it "and_return http success" do
        get 'new_show', id: file
        expect(response).not_to be_success
      end
    end
  end

  describe "unknown user" do
    describe "GET 'download'" do
      it "and_return http failure" do
        get 'new_download', id: file
        expect(response).not_to be_success
      end
    end

    describe "GET 'show'" do
      it "and_return http failure" do
        get 'new_show', id: file
        expect(response).not_to be_success
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
curation_concerns-0.3.0 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-0.2.0 spec/controllers/curation_concerns/single_use_links_controller_spec.rb