diff --git a/app/helpers/epp/contacts_helper.rb b/app/helpers/epp/contacts_helper.rb index 5ebfdc037..31af049e1 100644 --- a/app/helpers/epp/contacts_helper.rb +++ b/app/helpers/epp/contacts_helper.rb @@ -1,5 +1,22 @@ module Epp::ContactsHelper def create_contact - cp = Hash.from_xml(parsed_frame.css("epp command create create").to_xml).with_indifferent_access + ph = get_params_hash('epp command create create')[:create] + + @contact = Contact.new( + code: ph[:id], + name: ph[:postalInfo][:name], + phone: ph[:voice], + email: ph[:email], + reg_no: ph[:ident] + ) + + @contact.addresses << Address.new( + country_id: Country.find_by(iso: ph[:postalInfo][:cc]), + street: ph[:postalInfo][:street], + zip: ph[:postalInfo][:pc] + ) + + @contact.save + render '/epp/contacts/create' end end diff --git a/app/views/epp/contacts/create.xml.builder b/app/views/epp/contacts/create.xml.builder index cd65bfbca..5377f0fa9 100644 --- a/app/views/epp/contacts/create.xml.builder +++ b/app/views/epp/contacts/create.xml.builder @@ -6,8 +6,8 @@ xml.epp_head do xml.resData do xml.tag!('contact:creData', 'xmlns:contact' => 'http://www.nic.cz/xml/epp/contact-1.6', 'xsi:schemaLocation' => 'http://www.nic.cz/xml/epp/contact-1.6 contact-1.6.xsd') do - xml.tag!('contact:id', @id) - xml.tag!('contact:crDate', @crDate) + xml.tag!('contact:id', @contact.code) + xml.tag!('contact:crDate', @contact.created_at) end end diff --git a/db/migrate/20140702144833_countries_table_rename.rb b/db/migrate/20140702144833_countries_table_rename.rb new file mode 100644 index 000000000..47e44b6ac --- /dev/null +++ b/db/migrate/20140702144833_countries_table_rename.rb @@ -0,0 +1,5 @@ +class CountriesTableRename < ActiveRecord::Migration + def change + rename_table :country_id, :countries + end +end diff --git a/db/migrate/20140702145448_address_column_rename.rb b/db/migrate/20140702145448_address_column_rename.rb new file mode 100644 index 000000000..55c947bd5 --- /dev/null +++ b/db/migrate/20140702145448_address_column_rename.rb @@ -0,0 +1,5 @@ +class AddressColumnRename < ActiveRecord::Migration + def change + rename_column :addresses, :address, :street + end +end diff --git a/db/schema.rb b/db/schema.rb index 8eae54fe0..8f922ada7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140701130945) do +ActiveRecord::Schema.define(version: 20140702145448) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,7 +20,7 @@ ActiveRecord::Schema.define(version: 20140701130945) do t.integer "contact_id" t.integer "country_id" t.string "city" - t.string "address" + t.string "street" t.string "zip" t.datetime "created_at" t.datetime "updated_at" @@ -38,7 +38,7 @@ ActiveRecord::Schema.define(version: 20140701130945) do t.datetime "updated_at" end - create_table "country_id", force: true do |t| + create_table "countries", force: true do |t| t.string "iso" t.string "name" t.datetime "created_at" diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e857..71458064c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,6 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +Country.where(name: 'Estonia', iso: 'EE').first_or_create +EppUser.where(username: 'gitlab', password: 'ghyt9e4fu', active: true).first_or_create diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 4208f8e1e..8576caff5 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -11,7 +11,9 @@ describe 'EPP Contact', epp: true do response = epp_request('contacts/create.xml') expect(response[:result_code]).to eq('1000') expect(response[:msg]).to eq('Command completed successfully') - expect(response[:clTRID]).to eq('ABC-12345') + expect(response[:clTRID]).to eq('neka005#10-02-08at13:51:37') + + expect(Contact.count).to eq(1) end end