Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace create with build_stubbed in address model specs #6065

Merged
merged 1 commit into from
Sep 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions spec/models/spree/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
describe Spree::Address do
describe "clone" do
it "creates a copy of the address with the exception of the id, updated_at and created_at attributes" do
state = create(:state)
original = create(:address,
state = build_stubbed(:state)
original = build_stubbed(:address,
address1: 'address1',
address2: 'address2',
alternative_phone: 'alternative_phone',
Expand Down Expand Up @@ -62,9 +62,9 @@
end
end

let(:state) { create(:state, name: 'maryland', abbr: 'md') }
let(:state) { build_stubbed(:state, name: 'maryland', abbr: 'md') }
let(:country) { state.country }
let(:address) { create(:address, country: country, state: state) }
let(:address) { build_stubbed(:address, country: country, state: state) }

before do
country.states_required = true
Expand All @@ -77,23 +77,26 @@
end

it "full state name is in state_name and country does contain that state" do
allow(country.states).to receive_messages find_all_by_name_or_abbr: [create(:state, name: 'alabama', abbr: 'al')]
address.update state_name: 'alabama'
allow(country).to receive_message_chain(:states, :find_all_by_name_or_abbr) do
[build_stubbed(:state, name: 'alabama', abbr: 'al')]
end

address.state_name = 'alabama'
expect(address).to be_valid
expect(address.state.name).to eq 'alabama'
expect(address.state_name).to eq 'alabama'
end

it "state abbr is in state_name and country does contain that state" do
allow(country.states).to receive_messages find_all_by_name_or_abbr: [state]
allow(country).to receive_message_chain(:states, :find_all_by_name_or_abbr) { [state] }
address.state_name = state.abbr
expect(address).to be_valid
expect(address.state.abbr).to eq state.abbr
expect(address.state_name).to eq state.name
end

it "both state and state_name are entered and country does contain the state" do
allow(country.states).to receive_messages find_all_by_name_or_abbr: [state]
allow(country).to receive_message_chain(:states, :find_all_by_name_or_abbr) { [state] }
address.state = state
address.state_name = 'maryland'
expect(address).to be_valid
Expand Down