Sha256: 793cecc54d527b8f097c46eb0372b2a36e0d7ecad8d282b636d0fe3b4c14631e

Contents?: true

Size: 1.58 KB

Versions: 10

Compression:

Stored size: 1.58 KB

Contents

describe Hyrax::FeaturedWorksController, type: :controller do
  describe "#create" do
    before do
      sign_in create(:user)
      expect(controller).to receive(:authorize!).with(:create, FeaturedWork).and_return(true)
    end

    context "when there are no featured works" do
      it "creates one" do
        expect do
          post :create, params: { id: '1234abcd', format: :json }
        end.to change { FeaturedWork.count }.by(1)
        expect(response).to be_successful
      end
    end

    context "when there are 5 featured works" do
      before do
        5.times do |n|
          FeaturedWork.create(work_id: n.to_s)
        end
      end
      it "does not create another" do
        expect do
          post :create, params: { id: '1234abcd', format: :json }
        end.not_to change { FeaturedWork.count }
        expect(response.status).to eq 422
      end
    end
  end

  describe "#destroy" do
    before do
      sign_in create(:user)
      expect(controller).to receive(:authorize!).with(:destroy, FeaturedWork).and_return(true)
    end

    context "when the work exists" do
      before { create(:featured_work, work_id: '1234abcd') }

      it "removes it" do
        expect do
          delete :destroy, params: { id: '1234abcd', format: :json }
        end.to change { FeaturedWork.count }.by(-1)
        expect(response.status).to eq 204
      end
    end

    context "when it was already removed" do
      it "doesn't raise an error" do
        delete :destroy, params: { id: '1234abcd', format: :json }
        expect(response.status).to eq 204
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
hyrax-1.1.1 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.1.0 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.0.5 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.0.4 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.0.3 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.0.2 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.0.1 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.0.0.rc2 spec/controllers/hyrax/featured_works_controller_spec.rb
hyrax-1.0.0.rc1 spec/controllers/hyrax/featured_works_controller_spec.rb
test_hyrax-0.0.1.alpha spec/controllers/hyrax/featured_works_controller_spec.rb