diff --git a/lib/zuora/objects/contact.rb b/lib/zuora/objects/contact.rb index 51df6ff..7c2a070 100644 --- a/lib/zuora/objects/contact.rb +++ b/lib/zuora/objects/contact.rb @@ -2,7 +2,8 @@ module Zuora::Objects class Contact < Base belongs_to :account - validates_presence_of :account_id, :first_name, :last_name + validates_presence_of :first_name, :last_name + validates_presence_of :account_id, :unless => Proc.new { |contact| contact.new_record? } validates_length_of :first_name, :maximum => 100 validates_length_of :last_name, :maximum => 100 validates_length_of :nick_name, :maximum => 100, :allow_nil => true diff --git a/lib/zuora/objects/payment_method.rb b/lib/zuora/objects/payment_method.rb index 73e89c1..c1394db 100644 --- a/lib/zuora/objects/payment_method.rb +++ b/lib/zuora/objects/payment_method.rb @@ -2,7 +2,7 @@ module Zuora::Objects class PaymentMethod < Base belongs_to :account - validates_presence_of :account_id + validates_presence_of :account_id, :unless => Proc.new { |contact| contact.new_record? } # Generic Validations validates_inclusion_of :type, :in => %w(ACH Cash Check CreditCard CreditCardReferenceTransaction DebitCard Other PayPal WireTransfer) diff --git a/spec/zuora/objects/contact_spec.rb b/spec/zuora/objects/contact_spec.rb index da990e4..0843fde 100644 --- a/spec/zuora/objects/contact_spec.rb +++ b/spec/zuora/objects/contact_spec.rb @@ -20,10 +20,6 @@ subject.should_not be_valid end - it "requires account_id" do - subject.errors[:account_id].should include("can't be blank") - end - it "requires first_name" do subject.errors[:first_name].should include("can't be blank") end @@ -31,6 +27,24 @@ it "requires last_name" do subject.errors[:last_name].should include("can't be blank") end + + context "when new record" do + it "should not require account_id" do + subject.errors[:account_id].should_not include("can't be blank") + end + end + + context "when persisted record" do + before :each do + subject.stub(:new_record? => false) + + subject.should_not be_valid + end + + it "requires account_id" do + subject.errors[:account_id].should include("can't be blank") + end + end end describe "read only attributes" do