Sha256: 2006bbf99e45d8234874f2610e3dfe3afd3d956bbd137614ca58ff3ec4127f13

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

describe Spree::Api::V2::StatesController do
  routes { Spree::Core::Engine.routes }

  let!(:state) { create :state }

  describe '#index' do
    it 'can list all states' do
      get :index
      expect(JSON.parse(response.body)['data'].length).to eql 1
    end

    context 'by country id' do
      it 'will list selected states by country' do
        get :index, country_id: state.country.id
        expect(JSON.parse(response.body)['data'].length).to eql 1
      end

      it 'will not include states belonging to other countries' do
        new_state = create :state
        get :index, country_id: state.country.id
        state_ids = JSON.parse(response.body)['data'].map do |states|
          states['id']
        end
        expect(state_ids).to_not include new_state
      end
    end
  end

  describe '#show' do
    it 'will find selected state by id' do
      get :show, id: state.id
      state_id = parse_json(response.body)['data']['id']
      expect(state_id).to eql state.id.to_s
    end

    it 'can find a state by a country' do
      get :show, country_id: state.country.id, id: state.id
      state_id = parse_json(response.body)['data']['id']
      expect(state_id).to eql state.id.to_s
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
solidus_json_api-0.3.1 spec/controllers/spree/api/v2/states_controller_spec.rb
solidus_json_api-0.3.0 spec/controllers/spree/api/v2/states_controller_spec.rb
spree_api_v2-0.2.2 spec/controllers/spree/api/v2/states_controller_spec.rb
solidus_api_v2-0.2.2 spec/controllers/spree/api/v2/states_controller_spec.rb
solidus_api_v2-0.2.1 spec/controllers/spree/api/v2/states_controller_spec.rb
spree_api_v2-0.2.1 spec/controllers/spree/api/v2/states_controller_spec.rb
spree_api_v2-0.2.0 spec/controllers/spree/api/v2/states_controller_spec.rb
solidus_api_v2-0.2.0 spec/controllers/spree/api/v2/states_controller_spec.rb