Sha256: e2e68ace9bed5dd24f7d2b2568d8155a52e17aea77fe55edc3c2e566b2779c4f

Contents?: true

Size: 1.99 KB

Versions: 1

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe Street do
  it { is_expected.to be_a_kind_of InscriptioCursualis::Street }

  it { is_expected.to belong_to(:city) }
  it { is_expected.to belong_to(:street_type) }

  it { is_expected.to have_and_belong_to_many(:neighborhoods) }

  it { is_expected.to validate_presence_of :city }
  it { is_expected.to validate_presence_of :name }
  it { is_expected.to validate_presence_of :neighborhoods }
  it { is_expected.to validate_presence_of :street_type }

  context '#neighborhoods' do
    let :city do
      double(:city, to_s: 'Belo Horizonte', marked_for_destruction?: false)
    end

    context 'with one neighborhood' do
      it 'must belongs to street city' do
        neighborhood = double(:neighborhood, city: double, to_s: 'Centenario', marked_for_destruction?: false)

        allow(subject).to receive(:city).and_return(city)
        allow(subject).to receive(:neighborhoods).and_return([neighborhood])

        subject.valid?

        expect(subject.errors[:base]).to include 'the neighborhood Centenario does not belongs to the Belo Horizonte city'
      end
    end

    context 'with more than one neighborhood' do
      it 'all of them must belong to street city' do
        first_neighborhood = double(:neighborhood, city: double, to_s: 'Centenario', marked_for_destruction?: false)
        second_neighborhood = double(:neighborhood, city: double, to_s: 'Vila Mariana', marked_for_destruction?: false)

        allow(subject).to receive(:city).and_return(city)
        allow(subject).to receive(:neighborhoods).and_return([first_neighborhood, second_neighborhood])

        subject.valid?

        expect(subject.errors[:base]).to include 'the neighborhoods Centenario, Vila Mariana do not belong to the Belo Horizonte city'
      end
    end
  end

  it 'cast to string using street type and name' do
    allow(subject).to receive(:street_type).and_return('Avenida')
    allow(subject).to receive(:name).and_return('Amazonas')

    expect(subject.to_s).to eq 'Avenida Amazonas'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unico-training-7.8.0 spec/models/street_spec.rb