Sha256: 02dd2270c4fb2a741952085d82479879d38d4f9d7204adc50d0f4142bf087c56

Contents?: true

Size: 1.89 KB

Versions: 9

Compression:

Stored size: 1.89 KB

Contents

describe Spotlight::Resources::UploadController, type: :controller do
  routes { Spotlight::Engine.routes }
  let(:exhibit) { FactoryBot.create(:exhibit) }

  describe 'when not logged in' do
    describe 'POST create' do
      it 'is not allowed' do
        post :create, params: { exhibit_id: exhibit }
        expect(response).to redirect_to main_app.new_user_session_path
      end
    end
  end

  describe 'when signed in as a curator' do
    let(:user) { FactoryBot.create(:exhibit_curator, exhibit: exhibit) }
    before { sign_in user }

    describe 'POST create' do
      let(:blacklight_solr) { double }

      before do
        allow_any_instance_of(Spotlight::Resource).to receive(:reindex).and_return(true)
        allow_any_instance_of(Spotlight::Resource).to receive(:blacklight_solr).and_return blacklight_solr
      end

      it 'create a Spotlight::Resources::Upload resource' do
        expect_any_instance_of(Spotlight::Resource).to receive(:reindex_later)
        post :create, params: { exhibit_id: exhibit, resources_upload: { url: 'url-data' } }
        expect(assigns[:resource]).to be_persisted
        expect(assigns[:resource]).to be_a(Spotlight::Resources::Upload)
      end
      it 'redirects to the item admin page' do
        post :create, params: { exhibit_id: exhibit, resources_upload: { url: 'url-data' } }
        expect(flash[:notice]).to eq 'Object uploaded successfully.'
        expect(response).to redirect_to admin_exhibit_catalog_path(exhibit, sort: :timestamp)
      end
      it 'redirects to the upload form when the add-and-continue parameter is present' do
        post :create, params: { exhibit_id: exhibit, 'add-and-continue' => 'true', resources_upload: { url: 'url-data' } }
        expect(flash[:notice]).to eq 'Object uploaded successfully.'
        expect(response).to redirect_to new_exhibit_resource_path(exhibit, anchor: 'new_resources_upload')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
blacklight-spotlight-2.4.1 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.4.0 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.3.3 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.3.2 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.3.1 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.3.0 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.2.1 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.2.0 spec/controllers/spotlight/resources/upload_controller_spec.rb
blacklight-spotlight-2.1.0 spec/controllers/spotlight/resources/upload_controller_spec.rb