mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Test and simplify #require_customer?
This commit is contained in:
@@ -733,7 +733,8 @@ module Spree
|
||||
end
|
||||
|
||||
def require_customer?
|
||||
return true unless new_record? || state == 'cart'
|
||||
return if new_record? || state == 'cart'
|
||||
true
|
||||
end
|
||||
|
||||
def customer_is_valid?
|
||||
|
||||
@@ -915,6 +915,48 @@ 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(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "and the state is cart" do
|
||||
let(:state) { "cart" }
|
||||
|
||||
it "returns false" do
|
||||
expect(order.send(:require_customer?)).to eq(nil)
|
||||
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(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "associating a customer" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:order) { create(:order, distributor: distributor) }
|
||||
|
||||
Reference in New Issue
Block a user