require 'test_helper' module RubyPsigate class AddressTest < Test::Unit::TestCase def setup @address = Address.new end should "instantiate the address with hash" do @valid_attributes = { :firstname => "Bob", :lastname => "Parsons", :line1 => "1234 West 3rd Street", :line2 => "Apt 123", :city => "Toronto", :state => "Ontario", :country => "Canada", :zipcode => "N3N3N3", :telephone => "4161234567", :fax => "4169999999", :company => "Bob Parsons Company" } @address = Address.new(@valid_attributes) %w( firstname lastname line1 line2 city state province country zipcode postalcode telephone fax company ).each do |field| assert_not_nil @address.send(field.to_sym) end end %w( firstname lastname line1 line2 city state province country zipcode postalcode telephone fax company ).each do |field| should "respond to #{field}" do assert @address.respond_to?(field.downcase.to_sym) setter = field.downcase + "=" assert @address.respond_to?(setter.to_sym) end end should "when setting :state, also sets :province" do @address.state = "Some value" assert_equal @address.province, @address.state end should "when setting :province, also sets :state" do @address.province = "Some value" assert_equal @address.state, @address.province end should "when setting :zipcode, also sets :postalcode" do @address.zipcode = "Some value" assert_equal @address.postalcode, @address.zipcode end should "when setting :postalcode, also sets :zipcode" do @address.postalcode = "Some value" assert_equal @address.zipcode, @address.postalcode end should "have a method #name that combines firstname and lastname" do @address.firstname = "Bob" @address.lastname = "Parsons" assert_equal "Bob Parsons", @address.name end should "return firstname only" do @address.firstname = "Bob" assert_equal "Bob", @address.name end should "return lastname only" do @address.lastname = "Parsons" assert_equal "Parsons", @address.name end should "have an alias address1 to line1" do @address.line1 = "Some address" assert_equal "Some address", @address.address1 end should "have an alias address2 to line2" do @address.line2 = "Some address" assert_equal "Some address", @address.address2 end should "return a hash of billing address attributes" do @address = valid_address @expectation = { :Bname => "Bob Parsons", :Bcompany => "Bob Parson's Co.", :Baddress1 => "1234 West Street", :Baddress2 => "Apt 100", :Bcity => "Toronto", :Bprovince => "Ontario", :Bcountry => "CA", :Bpostalcode => "L3N9J2", :Phone => "416-333-3333", :Fax => "416-322-2222" } assert_equal @expectation, @address.to_hash(:billing) end should "return a hash of shipping address attributes" do @address = valid_address @expectation = { :Sname => "Bob Parsons", :Scompany => "Bob Parson's Co.", :Saddress1 => "1234 West Street", :Saddress2 => "Apt 100", :Scity => "Toronto", :Sprovince => "Ontario", :Scountry => "CA", :Spostalcode => "L3N9J2" } assert_equal @expectation, @address.to_hash(:shipping) end should "return a hash of account address attributes (for recurring xml transactions)" do @address = valid_address @expectation = { :Name => "Bob Parsons", :Company => "Bob Parson's Co.", :Address1 => "1234 West Street", :Address2 => "Apt 100", :City => "Toronto", :Province => "Ontario", :PostalCode => "L3N9J2", :Country => "CA", :Phone => "416-333-3333", :Fax => "416-322-2222" } assert_equal @expectation, @address.to_hash(:account) end end end