Sha256: d373a9bd1ef2dfc58dfd370347bd582564e0c1720eff4e936be0c30ec1743c92

Contents?: true

Size: 1.94 KB

Versions: 23

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

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

  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
        post 'create_download', id: file
        expect(response).to be_success
        expect(response.body).to eq download_single_use_link_url(hash)
      end
    end

    describe "GET 'show'" do
      it "and_return http success" do
        post 'create_show', id: file
        expect(response).to be_success
        expect(response.body).to eq show_single_use_link_url(hash)
      end
    end
  end

  describe "logged in user without edit permission" do
    before do
      @other_user = create(:user)
      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
        post 'create_download', id: file
        expect(response).not_to be_success
      end
    end

    describe "GET 'show'" do
      it "and_return http success" do
        post 'create_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
        post 'create_download', id: file
        expect(response).not_to be_success
      end
    end

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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
curation_concerns-1.1.2 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.1.1 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.1.0 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta10 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta9 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta8 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta7 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta6 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta5 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta4 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta3 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta2 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-1.0.0.beta1 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-0.14.0 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-0.14.0.pre4 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-0.14.0.pre3 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-0.14.0.pre2 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-0.14.0.pre1 spec/controllers/curation_concerns/single_use_links_controller_spec.rb
curation_concerns-0.13.1 spec/controllers/curation_concerns/single_use_links_controller_spec.rb