Refactor registrar address to smaller pieces

This commit is contained in:
Martin Lensment 2015-02-03 17:09:10 +02:00
parent 107767e241
commit 39ea06ab17
8 changed files with 57 additions and 22 deletions

View file

@ -56,7 +56,7 @@ class Admin::RegistrarsController < AdminController
def registrar_params
params.require(:registrar).permit(
:name, :reg_no, :vat_no, :address, :billing_address,
:name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address,
:country_code, :email, :phone, :billing_email
)
end

View file

@ -7,7 +7,7 @@ class Registrar < ActiveRecord::Base
has_many :messages
belongs_to :country_deprecated, foreign_key: :country_id
validates :name, :reg_no, :address, :country, :email, presence: true
validates :name, :reg_no, :country_code, :email, presence: true
validates :name, :reg_no, uniqueness: true
after_save :touch_domains_version
@ -22,6 +22,10 @@ class Registrar < ActiveRecord::Base
)
end
def address
[street, city, state, city].reject(&:empty?).compact.join(', ')
end
def to_s
name
end

View file

@ -24,22 +24,31 @@
.form-group
= f.label :phone
= f.text_field(:phone, class: 'form-control')
.col-md-6.text-left
.form-group
= f.label :country_code
= f.text_field :country_code, class: 'form-control'
.form-group
= f.label :address
= f.text_field(:address, class: 'form-control')
%p.help-block= t('address_help')
.form-group
= f.label :billing_address
= f.text_field(:billing_address, class: 'form-control')
%p.help-block= t('address_help')
.form-group
= f.label :billing_email
= f.text_field(:billing_email, class: 'form-control')
.col-md-6.text-left
.form-group
= f.label :street
= f.text_field(:street, class: 'form-control')
.form-group
= f.label :city
= f.text_field(:city, class: 'form-control')
.form-group
= f.label :state
= f.text_field(:state, class: 'form-control')
.form-group
= f.label :zip
= f.text_field(:zip, class: 'form-control')
.form-group
= f.label :country_code
= f.text_field :country_code, class: 'form-control'
/ EIS does not want Billing Address
/ .form-group
/ = f.label :billing_address
/ = f.text_field(:billing_address, class: 'form-control')
/ %p.help-block= t('address_help')
%hr
.row
.col-md-12.text-right

View file

@ -237,6 +237,7 @@ en:
billing_email: 'Billing e-mail'
phone: 'Contact phone'
email: 'Contact e-mail'
state: 'State / Province'
errors:
messages:

View file

@ -0,0 +1,10 @@
class AddNewAddressFieldsToRegistrar < ActiveRecord::Migration
def change
# get rid of old addresses, we will be migrating from the old db soon anyway
remove_column :registrars, :address, :string
add_column :registrars, :state, :string
add_column :registrars, :city, :string
add_column :registrars, :street, :string
add_column :registrars, :zip, :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: 20150203074508) do
ActiveRecord::Schema.define(version: 20150203135303) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -571,7 +571,6 @@ ActiveRecord::Schema.define(version: 20150203074508) do
t.string "name"
t.string "reg_no"
t.string "vat_no"
t.string "address"
t.integer "country_id"
t.string "billing_address"
t.datetime "created_at"
@ -582,6 +581,10 @@ ActiveRecord::Schema.define(version: 20150203074508) do
t.string "email"
t.string "billing_email"
t.string "country_code"
t.string "state"
t.string "city"
t.string "street"
t.string "zip"
end
create_table "reserved_domains", force: :cascade do |t|

View file

@ -1,7 +1,10 @@
Fabricator(:registrar) do
name { sequence(:name) { |i| "Registrar #{i}" } }
reg_no { sequence(:reg_no) { |i| "123#{i}" } }
address 'Street 999, Town, County, Postal'
street 'Street 999'
city 'Town'
state 'County'
zip 'Postal'
email 'info@registrar1.ee'
country_code 'EE'
end
@ -9,13 +12,19 @@ end
Fabricator(:registrar1, from: :registrar) do
name 'registrar1'
reg_no '111'
address 'Street 111, Town, County, Postal'
street 'Street 111'
city 'Town'
state 'County'
zip 'Postal'
email 'info@registrar1.ee'
end
Fabricator(:registrar2, from: :registrar) do
name 'registrar2'
reg_no '222'
address 'Street 222, Town, County, Postal'
street 'Street 222'
city 'Town'
state 'County'
zip 'Postal'
email 'info@registrar2.ee'
end

View file

@ -13,9 +13,8 @@ describe Registrar do
it 'is not valid' do
@registrar.valid?
@registrar.errors.full_messages.should match_array([
'Address is missing',
'Contact e-mail is missing',
'Country is missing',
'Country code is missing',
'Name is missing',
'Reg no is missing'
])