Sha256: 90a41c2446a270062fa681164c42fde00161c0987a720869b7eb4ac49d3ceccf

Contents?: true

Size: 1.67 KB

Versions: 7

Compression:

Stored size: 1.67 KB

Contents

require 'rails_helper'

RSpec.describe 'Index action for people' do
  let(:parsed_body) { request && response && JSON.parse(response.body) }

  context 'with no people' do
    let(:request) { get '/people' }

    it 'is successful' do
      request
      expect(response).to be_successful
    end

    it 'is has a blank body' do
      expect(parsed_body).to be_blank
    end
  end

  context 'with a person' do
    let!(:person) { Person.create(first_name: 'Anthony', last_name: 'Guy') }

    shared_examples 'a request with the person' do
      it 'is successful' do
        request
        expect(response).to be_successful
      end

      it 'has people' do
        expect(parsed_body).not_to be_blank
      end

      it 'has the right person' do
        expect(parsed_body).to include(include('id' => person.id.to_s))
      end
    end

    context 'with a good first-name search' do
      let(:request) { get '/people', params: { filters: { first_name: 'A' } } }

      it_behaves_like 'a request with the person'
    end

    context 'with a good last-name search' do
      let(:request) { get '/people', params: { filters: { last_name: 'G' } } }

      it_behaves_like 'a request with the person'
    end

    context 'with a valid view' do
      let(:request) { get '/people', params: { view: 'detail' } }

      it_behaves_like 'a request with the person'
    end

    context 'with an invalid view' do
      let(:request) { get '/people', params: { view: 'not-a-thing-lol' } }

      it 'is not successful' do
        request
        expect(response).not_to be_successful
      end

      it 'is a bad request' do
        request
        expect(response).to be_bad_request
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sober_swag-0.25.2 example/spec/requests/people/index_spec.rb
sober_swag-0.25.1 example/spec/requests/people/index_spec.rb
sober_swag-0.25.0 example/spec/requests/people/index_spec.rb
sober_swag-0.24.1 example/spec/requests/people/index_spec.rb
sober_swag-0.24.0 example/spec/requests/people/index_spec.rb
sober_swag-0.23.0 example/spec/requests/people/index_spec.rb
sober_swag-0.22.0 example/spec/requests/people/index_spec.rb