Sha256: 2ed3a4d384c1e9a7a408249d777d3cc975b4f5d923d194163fb5fbef85d370f8

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'

describe DownloadsController do
  describe '#show' do
    let(:user) { FactoryGirl.create(:user) }
    let(:another_user) { FactoryGirl.create(:user) }
    let(:image_file) { File.open(Rails.root.join('../fixtures/files/image.png')) }
    let(:generic_file) {
      FactoryGirl.create(:file_with_work, user: user, content: worthwhile_fixture_file_upload('files/image.png', 'image/png', false))
    }

    it "raise not_found if the object does not exist" do
      get :show, id: '8675309'
      expect(response).to be_not_found
    end

    context "when user doesn't have access" do
      before do
        generic_file
        sign_in another_user
      end
      it "redirects to root" do
        get :show, id: generic_file.to_param
        expect(response).to redirect_to root_path
        expect(flash["alert"]).to eq "You are not authorized to access this page."
      end
    end

    context "when user isn't logged in" do
      before { generic_file }
      it "redirects to sign in" do
        get :show, id: generic_file.to_param
        expect(response).to redirect_to new_user_session_path
        expect(flash["alert"]).to eq "You are not authorized to access this page."
      end
    end

    it 'sends the file if the user has access' do
      generic_file
      sign_in user
      get :show, id: generic_file.to_param
      expect(response.body).to eq generic_file.content.content
    end

    it 'sends requested datastream content' do
      generic_file.datastreams['thumbnail'].content = image_file
      generic_file.save!
      sign_in user
      get :show, id: generic_file.to_param, datastream_id: 'thumbnail'
      expect(response.body).to eq generic_file.thumbnail.content
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
worthwhile-0.1.2 spec/controllers/downloads_controller_spec.rb
worthwhile-0.1.1 spec/controllers/downloads_controller_spec.rb
worthwhile-0.1.0 spec/controllers/downloads_controller_spec.rb
worthwhile-0.0.3 spec/controllers/downloads_controller_spec.rb
worthwhile-0.0.2 spec/controllers/downloads_controller_spec.rb