Sha256: 50c644f742996e9f062af04cd75738ec8c6d039f27888e0df25070dcfa4b26cb

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

require 'rails_helper'

module Pwb
  RSpec.describe Api::V1::AgencyController, type: :controller do
    routes { Pwb::Engine.routes }

    context 'without signing in' do
      before(:each) do
        sign_in_stub nil
      end
      it "should not have a current_user" do
        expect(subject.current_user).to eq(nil)
      end
    end

    context 'with non_admin user' do
      login_non_admin_user

      it "should have a current_user" do
        expect(subject.current_user).to_not eq(nil)
      end

      describe 'GET #show' do
        it 'returns unauthorized status' do
          get :show, params: {}

          expect(response.status).to eq(422)
        end
      end
    end

    context 'with admin user' do
      login_admin_user

      it "should have a current_user" do
        expect(subject.current_user).to_not eq(nil)
      end

      describe 'GET #show' do
        let!(:agency) { FactoryGirl.create(:pwb_agency, company_name: 'my re') }

        it 'returns correct agency and default setup info' do
          get :show, params: {}
          # , format: :json

          expect(response.status).to eq(200)
          expect(response.content_type).to eq('application/json')

          result = JSON.parse(response.body)

          expect(result).to have_key('agency')
          expect(result['agency']['company_name']).to eq(agency.company_name)
          expect(result['setup']['name']).to eq('default')
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pwb-1.4.0 spec/controllers/pwb/api/v1/agency_controller_spec.rb
pwb-1.3.0 spec/controllers/pwb/api/v1/agency_controller_spec.rb
pwb-1.2.0 spec/controllers/pwb/api/v1/agency_controller_spec.rb
pwb-1.1.1 spec/controllers/pwb/api/v1/agency_controller_spec.rb
pwb-1.0.0 spec/controllers/pwb/api/v1/agency_controller_spec.rb
pwb-0.1.1 spec/controllers/pwb/api/v1/agency_controller_spec.rb
pwb-0.1.0 spec/controllers/pwb/api/v1/agency_controller_spec.rb
pwb-0.0.2 spec/controllers/pwb/api/v1/agency_controller_spec.rb