Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Martin Lensment 2014-08-26 13:52:52 +03:00
commit 0a2ed60b9e
11 changed files with 50 additions and 46 deletions

View file

@ -3,6 +3,7 @@ AllCops:
Exclude:
- 'db/schema.rb'
- 'db/migrate/*'
Metrics/LineLength:
Max: 120
@ -21,3 +22,9 @@ Style/BracesAroundHashParameters:
Style/IndentHash:
Enabled: false
# No need to force reduce to use |a, e| as parameters.
# Configuration parameters: Methods.
Style/SingleLineBlockParams:
Enabled: false

View file

@ -11,5 +11,5 @@ module Shared::UserStamper
end
true
end
end
end

View file

@ -10,7 +10,8 @@ class Address < ActiveRecord::Base
belongs_to :contact
belongs_to :country
#validates_inclusion_of :type, in: TYPES
# TODO: validate inclusion of :type in LONG_TYPES or smth similar
# validates_inclusion_of :type, in: TYPES
class << self
def extract_attributes(ah)
@ -31,8 +32,7 @@ class Address < ActiveRecord::Base
def addr_hash_from_params(addr)
return {} unless addr[:addr].is_a?(Hash)
{
name: addr[:name],
{ name: addr[:name],
org_name: addr[:org],
country_id: Country.find_by(iso: addr[:addr][:cc]).try(:id),
city: addr[:addr][:city],
@ -40,7 +40,7 @@ class Address < ActiveRecord::Base
street2: addr[:addr][:street][1],
street3: addr[:addr][:street][2],
zip: addr[:addr][:pc]
}.delete_if { |k, v| v.nil? }
}.delete_if { |_k, v| v.nil? }
end
end
end

View file

@ -1,12 +1,12 @@
class Contact < ActiveRecord::Base
# TODO Foreign contact will get email with activation link/username/temp password
# TODO Phone number validation, in first phase very minimam in order to support current registries
# TODO: Foreign contact will get email with activation link/username/temp password
# TODO: Phone number validation, in first phase very minimam in order to support current registries
include EppErrors
EPP_ATTR_MAP = {}
has_one :local_address#, class_name: 'Address'#, foreign_key: 'local_address_id'
has_one :local_address
has_one :international_address
has_many :domain_contacts
@ -17,14 +17,18 @@ class Contact < ActiveRecord::Base
accepts_nested_attributes_for :local_address, :international_address
validates_presence_of :code, :phone, :email, :ident
# validates_presence_of :code, :phone, :email, :ident
validates :code, :phone, :email, :ident, presence: true
validate :ident_must_be_valid
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ # /\+\d{3}\.\d+/
validates :email, format: /@/
validates_uniqueness_of :code, message: :epp_id_taken
# validates_uniqueness_of :code, message: :epp_id_taken
validates :code, uniqueness: { message: :epp_id_taken }
delegate :name, to: :international_address
IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [
@ -38,18 +42,14 @@ class Contact < ActiveRecord::Base
CONTACT_TYPE_ADMIN = 'admin'
CONTACT_TYPES = [CONTACT_TYPE_TECH, CONTACT_TYPE_ADMIN]
#TEMP METHODS for transaction to STI
def name
international_address.name
end
# TEMP METHOD for transaction to STI
def address
international_address
end
##
def ident_must_be_valid
# TODO Ident can also be passport number or company registry code.
# TODO: Ident can also be passport number or company registry code.
# so have to make changes to validations (and doc/schema) accordingly
return true unless ident.present? && ident_type.present? && ident_type == 'op'
code = Isikukood.new(ident)
@ -64,11 +64,11 @@ class Contact < ActiveRecord::Base
ident_type != IDENT_TYPE_ICO
end
def crID
def cr_id
created_by ? created_by.username : nil
end
def upID
def up_id
updated_by ? updated_by.username : nil
end

View file

@ -1,3 +1,2 @@
class InternationalAddress < Address
end

View file

@ -1,3 +1,2 @@
class LocalAddress < Address
end

View file

@ -11,9 +11,9 @@ xml.epp_head do
xml.tag!('contact:fax', @contact.fax)
xml.tag!('contact:email', @contact.email)
xml.tag!('contact:clID', @current_epp_user.username) if @current_epp_user
xml.tag!('contact:crID', @contact.crID ) if @contact.crID
xml.tag!('contact:crID', @contact.cr_id ) if @contact.cr_id
xml.tag!('contact:crDate', @contact.created_at)
xml.tag!('contact:upID', @contact.upID) if @contact.upID
xml.tag!('contact:upID', @contact.up_id) if @contact.up_id
xml.tag!('contact:upDate', @contact.updated_at) unless @contact.updated_at == @contact.created_at
xml.tag!('contact:trDate', '123') if false
xml.tag!('contact:authInfo', '123') if false

View file

@ -34,7 +34,6 @@ describe 'EPP Contact', epp: true do
expect(Contact.count).to eq(1)
expect(Contact.first.international_address.org_name).to eq('Example Inc.')
expect(Contact.first.ident).to eq '37605030299'
expect(Contact.first.ident_type).to eq 'op'
@ -62,11 +61,11 @@ describe 'EPP Contact', epp: true do
expect(response[:msg]).to eq('Command completed successfully')
id = response[:parsed].css('resData creData id').first
crDate = response[:parsed].css('resData creData crDate').first
cr_date = response[:parsed].css('resData creData crDate').first
expect(id.text).to eq('sh8013')
# 5 seconds for what-ever weird lag reasons might happen
expect(crDate.text.to_time).to be_within(5).of(Time.now)
expect(cr_date.text.to_time).to be_within(5).of(Time.now)
end
@ -75,7 +74,6 @@ describe 'EPP Contact', epp: true do
response = epp_request(contact_create_xml, :xml)
expect(response[:result_code]).to eq('2302')
expect(response[:msg]).to eq('Contact id already exists')
@ -107,14 +105,13 @@ describe 'EPP Contact', epp: true do
expect(Contact.first.updated_by_id).to be nil
response = epp_request(contact_update_xml, :xml)
epp_request(contact_update_xml, :xml)
expect(Contact.first.updated_by_id).to eq 1
end
it 'is succesful' do
Fabricate(:contact, created_by_id: 1, email: 'not_updated@test.test', code: 'sh8013', auth_info: '2fooBAR')
# response = epp_request(contact_update_xml( { chg: { email: 'fred@bloggers.ee', postalInfo: { name: 'Fred Bloggers' } } } ), :xml)
response = epp_request('contacts/update.xml')
expect(response[:msg]).to eq('Command completed successfully')
@ -218,7 +215,7 @@ describe 'EPP Contact', epp: true do
end
it 'returns info about contact' do
Fabricate(:contact, created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR',
Fabricate(:contact, created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR',
international_address: Fabricate(:international_address, name: 'Johnny Awesome'))
response = epp_request('contacts/info.xml')

View file

@ -1,7 +1,7 @@
Fabricator(:international_address) do
name Faker::Name.name
city Faker::Address.city
street Faker::Address.street_name
name Faker::Name.name
city Faker::Address.city
street Faker::Address.street_name
street2 Faker::Address.street_name
zip Faker::Address.zip
end

View file

@ -7,16 +7,16 @@ end
describe Address, '.extract_params' do
it 'returns params hash'do
Fabricate(:country, iso:'EE')
ph = { postalInfo: { name: "fred", addr: { cc: 'EE', city: 'Village', street: [ 'street1', 'street2' ] } } }
expect(Address.extract_attributes(ph[:postalInfo])).to eq( {
Fabricate(:country, iso: 'EE')
ph = { postalInfo: { name: 'fred', addr: { cc: 'EE', city: 'Village', street: %w(street1 street2) } } }
expect(Address.extract_attributes(ph[:postalInfo])).to eq({
international_address_attributes: {
name: 'fred',
city: 'Village',
country_id: 1,
street: 'street1',
street2: 'street2',
}
street2: 'street2'
}
})
end
end

View file

@ -59,27 +59,29 @@ describe Contact, '#relations_with_domain?' do
end
end
describe Contact, '#crID' do
describe Contact, '#cr_id' do
before(:each) { Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user)) }
it 'should return username of creator' do
expect(Contact.first.crID).to eq('gitlab')
expect(Contact.first.cr_id).to eq('gitlab')
end
it 'should return nil when no creator' do
expect(Contact.new.crID).to be nil
expect(Contact.new.cr_id).to be nil
end
end
describe Contact, '#upID' do
before(:each) { Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user)) }
describe Contact, '#up_id' do
before(:each) do
Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user))
end
it 'should return username of updater' do
expect(Contact.first.upID).to eq('gitlab')
expect(Contact.first.up_id).to eq('gitlab')
end
it 'should return nil when no updater' do
expect(Contact.new.upID).to be nil
expect(Contact.new.up_id).to be nil
end
end
@ -89,7 +91,7 @@ describe Contact, '.extract_params' do
expect(Contact.extract_attributes(ph)).to eq({
code: '123123',
email: 'jdoe@example.com'
} )
})
end
end