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

Find the default country by ISO code #810

Merged
merged 10 commits into from Feb 17, 2016
Prev Previous commit
Next Next commit
Change behaviour of Spree::Address.build_default
Instead of the first country found, please raise an error if
the default country ISO code does not have an associated country.

The issue referenced in the spec, spree/spree#1142,
is people complaining about no states found for Nil, which only ever
happened because Spree::Country.default would silently fail before.
  • Loading branch information
mamhoff committed Feb 12, 2016
commit df57194f5bb5a0a65c2886c0182c053fe5a79f6e
12 changes: 7 additions & 5 deletions core/spec/models/spree/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,20 @@

context 'has a default country' do
before do
Spree::Config[:default_country_id] = default_country.id
Spree::Config[:default_country_iso] = default_country.iso
end

it "sets up a new record with Spree::Config[:default_country_id]" do
it "sets up a new record with Spree::Config[:default_country_iso]" do
expect(Spree::Address.build_default.country).to eq default_country
end
end

# Regression test for https://github.com/spree/spree/issues/1142
it "uses the first available country if :default_country_id is set to an invalid value" do
Spree::Config[:default_country_id] = "0"
expect(Spree::Address.build_default.country).to eq default_country
it "raises ActiveRecord::RecordNotFound if :default_country_iso is set to an invalid value" do
Spree::Config[:default_country_iso] = "00"
expect {
Spree::Address.build_default.country
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
end
Expand Down