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

Only save user-assigned order addresses if they are not new records. #7

Merged
merged 10 commits into from
Sep 30, 2015
Merged
Prev Previous commit
Next Next commit
Added a test for checking out with blank addresses in the database.
  • Loading branch information
mike-bourgeous committed Sep 28, 2015
commit a94d184d5d599f55470272b2e5b02597a5ba95c9
38 changes: 37 additions & 1 deletion spec/features/checkout_address_selection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,42 @@
end.to change { user.addresses.count }.by(1)
end

context 'with invalid null addresses in the database' do
let(:nil_address) {
a = nil
5.times do
a = Spree::Address.new(user: user)
a.save(validate: false)
end
a
}

let(:address1) { build(:fake_address) }
let(:address2) { build(:fake_address) }

before(:each) do
expect(nil_address.id).to be > 0
end

scenario 'a user can still check out' do
restart_checkout
expect(current_path).to eq('/checkout/address')

within '#billing' do
choose I18n.t(:other_address, scope: :address_book)
fill_in_address(address1)
end

within '#shipping' do
choose I18n.t(:other_address, scope: :address_book)
fill_in_address(address2)
end

complete_checkout
expect(page).to have_content("processed successfully")
end
end

describe "when invalid address is entered" do
let(:address) do
Spree::Address.new(:firstname => nil, :state => state)
Expand Down Expand Up @@ -383,7 +419,7 @@
end.to_not change{ user.addresses.count }
end

it 'should assign the the user default addresses to the order' do
it 'should assign the user default addresses to the order' do
user.update_attributes!(
bill_address_id: user.addresses.first.id,
ship_address_id: create(:address, user: user).id
Expand Down