require "rails_helper"

RSpec.describe Address, :type => :model do
  it "matches country name" do
    expect(Address.new(country: 'BR').country_name).to eq('Brazil')
    expect(Address.new(country: 'US').country_name).to eq('United States')
    expect(Address.new(country: 'PL').country_name).to eq('Poland')
    expect(Address.new(country: 'DE').country_name).to eq('Germany')
  end

  it "is valid" do
    address = FactoryGirl.build(:address)
    expect(address).to be_valid
  end

  it "is not valid" do
    address = FactoryGirl.build(:address)
    [ :title, :receiver, :street, :country, :state,
        :city, :postal_code ].each do |field|
      address_clone = address.clone
      address_clone.send("#{field}=", "")
      expect(address_clone).to_not be_valid
    end
    address.user = nil
    expect(address).to_not be_valid
  end
end

require "rails_helper"

RSpec.describe Address, :type => :model do
  context 'validations' do
    it { is_expected.to validate_presence_of(:title) }
    it { is_expected.to validate_presence_of(:receiver) }
    it { is_expected.to validate_presence_of(:street) }
    it { is_expected.to validate_presence_of(:country) }
    it { is_expected.to validate_presence_of(:state) }
    it { is_expected.to validate_presence_of(:city) }
    it { is_expected.to validate_presence_of(:postal_code) }
    it { is_expected.to validate_presence_of(:user) }
  end

  context 'country_name' do
    it "matches country name" do
      expect(Address.new(country: 'BR').country_name).to eq('Brazil')
      expect(Address.new(country: 'US').country_name).to eq('United States')
      expect(Address.new(country: 'PL').country_name).to eq('Poland')
      expect(Address.new(country: 'DE').country_name).to eq('Germany')
    end
  end
end

Refactor Address model spec with sholda-matchers
Refactor Address model spec with sholda-matchers
