Merge pull request #7432 from coopdevs/add-tests-to-customers

Add tests to customers
This commit is contained in:
Andy Brett
2021-04-17 11:28:24 -07:00
committed by GitHub
2 changed files with 68 additions and 1 deletions

View File

@@ -733,7 +733,8 @@ module Spree
end
def require_customer?
return true unless new_record? || state == 'cart'
return false if new_record? || state == 'cart'
true
end
def customer_is_valid?

View File

@@ -915,8 +915,74 @@ describe Spree::Order do
end
end
describe "#require_customer?" do
context "when the record is new" do
let(:order) { build(:order, state: state) }
context "and the state is not cart" do
let(:state) { "complete" }
it "returns true" do
expect(order.send(:require_customer?)).to eq(false)
end
end
context "and the state is cart" do
let(:state) { "cart" }
it "returns false" do
expect(order.send(:require_customer?)).to eq(false)
end
end
end
context "when the record is not new" do
let(:order) { create(:order, state: state) }
context "and the state is not cart" do
let(:state) { "complete" }
it "returns true" do
expect(order.send(:require_customer?)).to eq(true)
end
end
context "and the state is cart" do
let(:state) { "cart" }
it "returns false" do
expect(order.send(:require_customer?)).to eq(false)
end
end
end
end
describe "associating a customer" do
let(:distributor) { create(:distributor_enterprise) }
context "when creating an order" do
it "does not create a customer" do
order = create(:order, distributor: distributor)
expect(order.customer).to be_nil
end
end
context "when updating the order" do
let!(:order) { create(:order, distributor: distributor) }
before do
order.state = "complete"
order.save!
end
it "creates a customer" do
expect(order.customer).not_to be_nil
end
end
end
describe "#associate_customer" do
let(:distributor) { create(:distributor_enterprise) }
let!(:order) { create(:order, distributor: distributor) }
context "when an email address is available for the order" do