Skip to content

Commit

Permalink
Merge pull request solidusio#1468 from mamhoff/allow-sending-empty-st…
Browse files Browse the repository at this point in the history
…ring-as-country-iso

Convert blank country_iso on prices to nil
  • Loading branch information
jhawthorn committed Sep 28, 2016
2 parents 1967742 + cef2abc commit ac2d68f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/app/models/spree/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def display_country
end
end

def country_iso=(country_iso)
self[:country_iso] = country_iso.presence
end

private

def sum_of_vat_amounts
Expand Down
15 changes: 15 additions & 0 deletions core/spec/models/spree/price_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
it { is_expected.to be_valid }
end

context 'when country iso is an empty string' do
let(:country_iso) { "" }

it { is_expected.to be_valid }
end

context 'when country iso is a country code' do
let!(:country) { create(:country, iso: "DE") }
let(:country_iso) { "DE" }
Expand All @@ -69,6 +75,15 @@
end
end

describe "country_iso=" do
let(:price) { Spree::Price.new(country_iso: "de") }

it "assigns nil if passed nil" do
price.country_iso = nil
expect(price.country_iso).to be_nil
end
end

describe '#country' do
let!(:country) { create(:country, iso: "DE") }
let(:price) { create(:price, country_iso: "DE") }
Expand Down

0 comments on commit ac2d68f

Please sign in to comment.