Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

Commit

Permalink
Support email field on Location (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas McGoey-Smith authored Jul 21, 2017
1 parent 448a674 commit ac496c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/active_shipping/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Location
address3: [:address3],
phone: [:phone, :phone_number],
fax: [:fax, :fax_number],
email: [:email],
address_type: [:address_type],
company_name: [:company, :company_name],
}.freeze
Expand All @@ -28,6 +29,7 @@ class Location
:address3,
:phone,
:fax,
:email,
:address_type,
:company_name

Expand All @@ -54,6 +56,7 @@ def initialize(options = {})
@address3 = options[:address3]
@phone = options[:phone]
@fax = options[:fax]
@email = options[:email]
@company_name = options[:company_name] || options[:company]

self.address_type = options[:address_type]
Expand Down Expand Up @@ -122,6 +125,7 @@ def to_hash
address3: address3,
phone: phone,
fax: fax,
email: email,
address_type: address_type,
company_name: company_name
}
Expand All @@ -142,6 +146,7 @@ def inspect
string = prettyprint
string << "\nPhone: #{@phone}" unless @phone.blank?
string << "\nFax: #{@fax}" unless @fax.blank?
string << "\nEmail: #{@email}" unless @email.blank?
string
end

Expand Down
3 changes: 2 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def location_fixtures
:address1 => '110 Laurier Avenue West',
:postal_code => 'K1P 1J1',
:phone => '1-613-580-2400',
:fax => '1-613-580-2495'),
:fax => '1-613-580-2495',
:email => '[email protected]'),
:ottawa_with_name => Location.new( :country => 'CA',
:province => 'ON',
:city => 'Ottawa',
Expand Down
7 changes: 5 additions & 2 deletions test/unit/location_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class LocationTest < ActiveSupport::TestCase
address: '66 Gregory Ave.',
phone: '515-555-1212',
fax_number: 'none to speak of',
email: '[email protected]',
address_type: :commercial,
name: "Bob Bobsen",
}
Expand All @@ -35,6 +36,7 @@ class LocationTest < ActiveSupport::TestCase
assert_equal @attributes_hash[:address], location.address1
assert_equal @attributes_hash[:phone], location.phone
assert_equal @attributes_hash[:fax_number], location.fax
assert_equal @attributes_hash[:email], location.email
assert_equal @attributes_hash[:address_type].to_s, location.address_type
assert_equal @attributes_hash[:name], location.name
end
Expand Down Expand Up @@ -62,6 +64,7 @@ def respond_to?(method)
assert_equal @attributes_hash[:address], location.address1
assert_equal @attributes_hash[:phone], location.phone
assert_equal @attributes_hash[:fax_number], location.fax
assert_equal @attributes_hash[:email], location.email
assert_equal @attributes_hash[:address_type].to_s, location.address_type
assert_equal @attributes_hash[:name], location.name
end
Expand Down Expand Up @@ -116,7 +119,7 @@ def province_code
end

test "#inspect returns a readable string" do
expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada\nPhone: 1-613-580-2400\nFax: 1-613-580-2495"
expected = "110 Laurier Avenue West\nOttawa, ON, K1P 1J1\nCanada\nPhone: 1-613-580-2400\nFax: 1-613-580-2495\nEmail: [email protected]"
assert_equal expected, @location.inspect
end

Expand Down Expand Up @@ -165,7 +168,7 @@ def province_code
end

test "#to_hash has the expected attributes" do
expected = %w(address1 address2 address3 address_type city company_name country fax name phone postal_code province)
expected = %w(address1 address2 address3 address_type city company_name country email fax name phone postal_code province)

assert_equal expected, @location.to_hash.stringify_keys.keys.sort
end
Expand Down

0 comments on commit ac496c7

Please sign in to comment.