Sha256: 0b5e52ab3d7f8bb4779cedc4fe4c30f715437cf4f0deb17c09257b41d27986a0

Contents?: true

Size: 1.4 KB

Versions: 28

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

module Spree
  describe Spree::Api::PromotionsController, :type => :controller do
    render_views

    shared_examples "a JSON response" do
      it 'should be ok' do
        expect(subject).to be_ok
      end

      it 'should return JSON' do
        payload = HashWithIndifferentAccess.new(JSON.parse(subject.body))
        expect(payload).to_not be_nil
        Spree::Api::ApiHelpers.promotion_attributes.each do |attribute|
          expect(payload).to be_has_key(attribute)
        end
      end
    end

    before do
      stub_authentication!
    end

    let(:promotion) { create :promotion, code: '10off' }

    describe 'GET #show' do
      subject { api_get :show, id: id }

      context 'when admin' do
        sign_in_as_admin!

        context 'when finding by id' do
          let(:id) { promotion.id }

          it_behaves_like "a JSON response"
        end

        context 'when finding by code' do
          let(:id) { promotion.codes.first }

          it_behaves_like "a JSON response"
        end

        context 'when id does not exist' do
          let(:id) { 'argh' }

          it 'should be 404' do
            expect(subject.status).to eq(404)
          end
        end
      end

      context 'when non admin' do
        let(:id) { promotion.id }

        it 'should be unauthorized' do
          subject
          assert_unauthorized!
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
solidus_api-1.2.3 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.4 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.0.7 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.0.6 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.2.2 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.2.1 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.3 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.0.5 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.2.0 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.2.0.rc2 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.0.4 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.2 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.2.0.rc1 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.2.0.beta1 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.0.3 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.1 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.0 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.0.pre2 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.0.pre1 spec/controllers/spree/api/promotions_controller_spec.rb
solidus_api-1.1.0.beta1 spec/controllers/spree/api/promotions_controller_spec.rb