Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Modify customer address validation to allow no address on Windows flavor #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/quickeebooks/windows/model/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def email_address_is_valid
end

def require_an_address
if addresses.nil? || (addresses.is_a?(Array) && addresses.empty?)
errors.add(:addresses, "Must provide at least one address for this Customer.")
if (addresses.is_a?(Array) && addresses.empty?)
errors.add(:addresses, "Cannot send an empty address.")
end
end

Expand Down
12 changes: 11 additions & 1 deletion spec/quickeebooks/windows/services/customer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@
customer.errors.keys.include?(:name).should == true
end

it "cannot create a customer with no address" do
it "cannot create a customer with an empty address" do
customer = Quickeebooks::Windows::Model::Customer.new
service = Quickeebooks::Windows::Service::Customer.new
service.access_token = @oauth
service.realm_id = @realm_id
customer.name = "Bobs Plumbing"
customer.addresses = []
lambda do
service.create(customer)
end.should raise_error(InvalidModelException)
Expand All @@ -104,6 +105,15 @@
customer.errors.keys.include?(:addresses).should == true
end

it "can create a customer with no address" do
customer = Quickeebooks::Windows::Model::Customer.new
service = Quickeebooks::Windows::Service::Customer.new
service.access_token = @oauth
service.realm_id = @realm_id
customer.name = "Bobs Plumbing"
customer.valid?.should == true
end

it "cannot create a customer with an invalid email" do
customer = Quickeebooks::Windows::Model::Customer.new
service = Quickeebooks::Windows::Service::Customer.new
Expand Down