require File.dirname(__FILE__) + "/../spec_helper" describe Braintree::Customer do describe "inspect" do it "includes the id first" do output = Braintree::Customer._new({:first_name => 'Dan', :id => '1234'}).inspect output.should include("# "Company", :email => "e@mail.com", :fax => "483-438-5821", :first_name => "Patrick", :last_name => "Smith", :phone => "802-483-5932", :website => "patrick.smith.com", :created_at => Time.now, :updated_at => Time.now ) output = customer.inspect output.should include(%q(company: "Company")) output.should include(%q(email: "e@mail.com")) output.should include(%q(fax: "483-438-5821")) output.should include(%q(first_name: "Patrick")) output.should include(%q(last_name: "Smith")) output.should include(%q(phone: "802-483-5932")) output.should include(%q(website: "patrick.smith.com")) output.should include(%Q(created_at: #{customer.created_at.inspect})) output.should include(%Q(updated_at: #{customer.updated_at.inspect})) end end describe "self.create" do it "raises an exception if hash includes an invalid key" do expect do Braintree::Customer.create(:first_name => "Joe", :invalid_key => "foo") end.to raise_error(ArgumentError, "invalid keys: invalid_key") end end describe "self.update" do it "raises an exception if hash includes an invalid key" do expect do Braintree::Customer.update("customer_id", :first_name => "Joe", :invalid_key => "foo") end.to raise_error(ArgumentError, "invalid keys: invalid_key") end end describe "self.create_from_transparent_redirect" do it "raises an exception if the query string is forged" do expect do Braintree::Customer.create_from_transparent_redirect("forged=query_string") end.to raise_error(Braintree::ForgedQueryString) end end describe "==" do it "returns true when given a customer with the same id" do first = Braintree::Customer._new(:id => 123) second = Braintree::Customer._new(:id => 123) first.should == second second.should == first end it "returns false when given a customer with a different id" do first = Braintree::Customer._new(:id => 123) second = Braintree::Customer._new(:id => 124) first.should_not == second second.should_not == first end it "returns false when not given a customer" do customer = Braintree::Customer._new(:id => 123) customer.should_not == "not a customer" end end describe "initialize" do it "converts payment method hashes into payment method objects" do customer = Braintree::Customer._new( :credit_cards => [ {:token => "pm1"}, {:token => "pm2"} ] ) customer.credit_cards.size.should == 2 customer.credit_cards[0].token.should == "pm1" customer.credit_cards[1].token.should == "pm2" end end describe "new" do it "is protected" do expect do Braintree::Customer.new end.to raise_error(NoMethodError, /protected method .new/) end end end