Added multiple streets to address

This commit is contained in:
Andres Keskküla 2014-08-13 13:35:25 +03:00
parent dc2ec5535f
commit e8ddf2272e
5 changed files with 20 additions and 14 deletions

View file

@ -120,7 +120,9 @@ module Epp::ContactsHelper
contact_hash = contact_hash.merge({
address_attributes: {
country_id: Country.find_by(iso: ph[:postalInfo][:addr][:cc]),
street: tidy_street,
street: ph[:postalInfo][:addr][:street][0],
street2: ph[:postalInfo][:addr][:street][1],
street3: ph[:postalInfo][:addr][:street][2],
zip: ph[:postalInfo][:addr][:pc]
}
}) if ph[:postalInfo].is_a?(Hash) && ph[:postalInfo][:addr].is_a?(Hash)
@ -135,16 +137,6 @@ module Epp::ContactsHelper
return false
end
def tidy_street
command = params[:command]
street = params_hash['epp']['command'][command][command][:postalInfo][:addr][:street]
return street if street.is_a? String
return street.join(',') if street.is_a? Array
return nil
rescue NoMethodError => e #refactor so wouldn't use rescue for flow control
return nil
end
def ident_type
result = params[:frame].slice(/(?<=\<ns2:ident type=)(.*)(?=<)/)

View file

@ -0,0 +1,6 @@
class AddStreetsToAddress < ActiveRecord::Migration
def change
add_column :addresses, :street2, :string
add_column :addresses, :street3, :string
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140808132327) do
ActiveRecord::Schema.define(version: 20140813102245) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -24,6 +24,8 @@ ActiveRecord::Schema.define(version: 20140808132327) do
t.string "zip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "street2"
t.string "street3"
end
create_table "contacts", force: true do |t|

View file

@ -61,6 +61,11 @@ describe 'EPP Contact', epp: true do
expect(Contact.count).to eq(1)
expect(Contact.first.org_name).to eq('Example Inc.')
expect(Contact.first.address.street).to eq('123 Example Dr.')
expect(Contact.first.address.street2).to eq('Suite 100')
expect(Contact.first.address.street3).to eq nil
end
it 'returns result data upon succesful contact creation' do
@ -89,12 +94,12 @@ describe 'EPP Contact', epp: true do
it 'stamps updated_by succesfully' do
Fabricate(:contact, code: 'sh8013')
expect(Contact.first.updated_by_id).to be nil
response = epp_request('contacts/update.xml')
expect(Contact.first.updated_by_id).to be 1
expect(Contact.first.updated_by_id).to eq 1
end
#TODO tests for missing/invalid/etc ident

View file

@ -1,5 +1,6 @@
Fabricator(:address) do
city Faker::Address.city
street Faker::Address.street_name
street Faker::Address.street_name
zip Faker::Address.zip
end