Sha256: c9c071d1f5f0d54f021930a6a17e08714e4bc744b97dd2ad03063afb89ea6235

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Spotlight::SolrController, type: :controller do
  routes { Spotlight::Engine.routes }
  let(:exhibit) { FactoryGirl.create(:exhibit) }

  describe 'when user does not have access' do
    before { sign_in FactoryGirl.create(:exhibit_visitor) }

    describe 'POST update' do
      it 'does not allow update' do
        post :update, exhibit_id: exhibit
        expect(response).to redirect_to main_app.root_path
      end
    end
  end

  describe 'when user is an admin' do
    let(:admin) { FactoryGirl.create(:site_admin) }
    let(:role) { admin.roles.first }
    let(:solr) { double }
    before { sign_in admin }
    before do
      expect(controller).to receive(:blacklight_solr).and_return(solr)
    end

    describe 'POST update' do
      it 'passes through the request data' do
        doc = {}
        expect(solr).to receive(:update) do |arr|
          doc = arr.first
        end

        post :update, { a: 1 }.to_json, content_type: :json, exhibit_id: exhibit

        expect(response).to be_successful
        expect(doc).to include 'a' => 1
      end

      it 'enriches the request with exhibit solr data' do
        doc = {}
        expect(solr).to receive(:update) do |arr|
          doc = arr.first
        end

        post :update, { a: 1 }.to_json, content_type: :json, exhibit_id: exhibit

        expect(response).to be_successful
        expect(doc).to include exhibit.solr_data
      end

      it 'enriches the request with sidecar data' do
        doc = {}
        expect(solr).to receive(:update) do |arr|
          doc = arr.first
        end

        allow_any_instance_of(SolrDocument).to receive(:to_solr).and_return(b: 1)

        post :update, { a: 1 }.to_json, content_type: :json, exhibit_id: exhibit

        expect(response).to be_successful
        expect(doc).to include b: 1
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacklight-spotlight-0.14.2 spec/controllers/spotlight/solr_controller_spec.rb
blacklight-spotlight-0.14.1 spec/controllers/spotlight/solr_controller_spec.rb
blacklight-spotlight-0.14.0 spec/controllers/spotlight/solr_controller_spec.rb
blacklight-spotlight-0.13.0 spec/controllers/spotlight/solr_controller_spec.rb