Sha256: adf2a5ac512e197b852c0d64d7b2e740a7a9d2d8cbf559fc9a540e3a3da43e65

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true
require 'spec_helper'

RSpec.describe Addresses::CitiesController, type: :controller do
  routes { Addresses::Engine.routes }

  let!(:state) { create :state }
  let!(:state2) { create :state }
  let!(:city) { create :city, state: state, name: 'Natal' }
  let!(:city2) { create :city, state: state2, name: 'São Paulo' }

  describe "GET #index" do
    before { get :index, params: { state_id: state.id, format: :json } }

    it { expect(response).to have_http_status(:success) }
    it { expect(assigns(:cities)).to eq([city]) }
  end

  describe "GET #index without state id" do
    before { get :index, params: { format: :json } }

    it { expect(response).to have_http_status(:success) }
    it { expect(assigns(:cities)).to eq([city, city2]) }
  end

  describe "GET #index with search by name" do
    before { get :index, params: { name: 'natal', format: :json } }

    it { expect(response).to have_http_status(:success) }
    it { expect(assigns(:cities)).to eq([city]) }
  end

  describe "GET #show" do
    before { get :show, params: { id: city.id, format: :json } }

    it { expect(response).to have_http_status(:success) }
    it { expect(assigns(:city)).to eq(city) }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
addresses-1.0.9 spec/controllers/addresses/cities_controller_spec.rb
addresses-1.0.8 spec/controllers/addresses/cities_controller_spec.rb
addresses-1.0.7 spec/controllers/addresses/cities_controller_spec.rb