Skip to content

Commit

Permalink
account_id isn't always required. It may be blank for :subscribe calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Sep 4, 2012
1 parent 89461c0 commit 9c5a370
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/zuora/objects/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/zuora/objects/payment_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 18 additions & 4 deletions spec/zuora/objects/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,31 @@
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

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
Expand Down

0 comments on commit 9c5a370

Please sign in to comment.