Rubocop autocorrect

This commit is contained in:
Martin Lensment 2014-08-25 14:14:25 +03:00
parent f8c48a7456
commit 6c5c0b38c8
59 changed files with 533 additions and 546 deletions

View file

@ -1,11 +1,20 @@
Style/LineLength:
AllCops:
RunRailsCops: true
Metrics/LineLength:
Max: 120
Documentation:
Enabled: false
Style/CyclomaticComplexity:
Severity: warning
Style/Semicolon:
AllowAsExpressionSeparator: true
Style/AndOr:
Enabled: false
Style/BracesAroundHashParameters:
Enabled: false
Style/IndentHash:
Enabled: false

View file

@ -61,7 +61,7 @@ module Epp::Common
end
def has_attribute(ph, path)
path.inject(ph) do |location, key|
path.reduce(ph) do |location, key|
location.respond_to?(:keys) ? location[key] : nil
end
end

View file

@ -1,7 +1,7 @@
module Shared::UserStamper
extend ActiveSupport::Concern
def stamp obj
def stamp(obj)
return false if obj.nil? || !obj.has_attribute?(:created_by_id && :updated_by_id)
if obj.new_record?
@ -10,6 +10,6 @@ module Shared::UserStamper
obj.updated_by_id = current_epp_user.id
end
return true
true
end
end

View file

@ -5,6 +5,7 @@ class Epp::CommandsController < ApplicationController
include Shared::UserStamper
private
def create
send("create_#{OBJECT_TYPES[params_hash['epp']['xmlns:ns2']]}")
end

View file

@ -2,6 +2,7 @@ class Epp::SessionsController < ApplicationController
include Epp::Common
private
def hello
render 'greeting'
end

View file

@ -16,6 +16,7 @@ class SettingGroupsController < ApplicationController
end
private
def set_setting_group
@setting_group = SettingGroup.find(params[:id])
end

View file

@ -41,16 +41,17 @@ module Epp::ContactsHelper
end
## HELPER METHODS
private
## CREATE
def validate_contact_create_request
@ph = params_hash['epp']['command']['create']['create']
xml_attrs_present?(@ph, [['id'],
['authInfo', 'pw'],
['postalInfo', 'name'],
['postalInfo', 'addr', 'city'],
['postalInfo', 'addr', 'cc']])
%w(authInfo pw),
%w(postalInfo name),
%w(postalInfo addr city),
%w(postalInfo addr cc)])
end
## UPDATE
@ -91,10 +92,10 @@ module Epp::ContactsHelper
pw = @ph.try(:[], :authInfo).try(:[], :pw) || @ph.try(:[], :chg).try(:[], :authInfo).try(:[], :pw) || []
id = @ph[:id]
return true if ( !find_contact.nil? && find_contact.auth_info_matches(pw) )
return true if !find_contact.nil? && find_contact.auth_info_matches(pw)
epp_errors << { code: '2201', msg: t('errors.messages.epp_authorization_error'), value: { obj: 'pw', val: pw } }
return false
false
end
def contact_and_address_attributes(type = :create)
@ -118,6 +119,6 @@ module Epp::ContactsHelper
return nil unless result
Contact::IDENT_TYPES.any? { |type| return type if result.include?(type) }
return nil
nil
end
end

View file

@ -48,6 +48,7 @@ module Epp::DomainsHelper
end
### HELPER METHODS ###
private
## CREATE

View file

@ -3,7 +3,7 @@ class Address < ActiveRecord::Base
belongs_to :country
class << self
def extract_attributes ah, type=:create
def extract_attributes(ah, _type = :create)
address_hash = {}
address_hash = ({
country_id: Country.find_by(iso: ah[:cc]).try(:id),
@ -14,7 +14,7 @@ class Address < ActiveRecord::Base
zip: ah[:pc]
}) if ah.is_a?(Hash)
address_hash.delete_if { |k, v| v.nil? }
address_hash.delete_if { |_k, v| v.nil? }
end
end
end

View file

@ -27,15 +27,15 @@ class Contact < ActiveRecord::Base
IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [
IDENT_TYPE_ICO, # Company registry code (or similar)
"op", #Estonian ID
"passport", #Passport number
"birthday" #Birthday date
'op', # Estonian ID
'passport', # Passport number
'birthday' # Birthday date
]
def ident_must_be_valid
# 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"
return true unless ident.present? && ident_type.present? && ident_type == 'op'
code = Isikukood.new(ident)
errors.add(:ident, 'bad format') unless code.valid?
end
@ -56,9 +56,9 @@ class Contact < ActiveRecord::Base
updated_by ? updated_by.username : nil
end
def auth_info_matches pw
def auth_info_matches(pw)
return true if auth_info == pw
return false
false
end
# Find a way to use self.domains with contact
@ -68,7 +68,7 @@ class Contact < ActiveRecord::Base
def relations_with_domain?
return true if domain_contacts.present? || domains_owned.present?
return false
false
end
# should use only in transaction
@ -100,10 +100,7 @@ class Contact < ActiveRecord::Base
end
class << self
def extract_attributes ph, type=:create
def extract_attributes(ph, type = :create)
contact_hash = {
phone: ph[:voice],
ident: ph[:ident],
@ -117,7 +114,7 @@ class Contact < ActiveRecord::Base
contact_hash[:code] = ph[:id] if type == :create
contact_hash.delete_if { |k, v| v.nil? }
contact_hash.delete_if { |_k, v| v.nil? }
end
def check_availability(codes)
@ -141,6 +138,4 @@ class Contact < ActiveRecord::Base
def clean_up_address
address.destroy if address
end
end

View file

@ -1,3 +1,2 @@
class Country < ActiveRecord::Base
end

View file

@ -15,13 +15,13 @@ class Domain < ActiveRecord::Base
has_many :domain_contacts
has_many :tech_contacts, -> {
has_many :tech_contacts, -> do
where(domain_contacts: { contact_type: DomainContact::TECH })
}, through: :domain_contacts, source: :contact
end, through: :domain_contacts, source: :contact
has_many :admin_contacts, -> {
has_many :admin_contacts, -> do
where(domain_contacts: { contact_type: DomainContact::ADMIN })
}, through: :domain_contacts, source: :contact
end, through: :domain_contacts, source: :contact
has_and_belongs_to_many :nameservers
@ -123,14 +123,14 @@ class Domain < ActiveRecord::Base
def attach_nameservers(ns_list)
ns_list.each do |ns_attrs|
self.nameservers.build(ns_attrs)
nameservers.build(ns_attrs)
end
end
def attach_statuses(status_list)
status_list.each do |x|
setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value])
self.domain_statuses.build(
domain_statuses.build(
setting: setting,
description: x[:description]
)
@ -139,7 +139,7 @@ class Domain < ActiveRecord::Base
def detach_contacts(contact_list)
to_delete = []
contact_list.each do |k, v|
contact_list.each do |_k, v|
v.each do |x|
contact = domain_contacts.joins(:contact).where(contacts: { code: x[:contact] })
if contact.blank?
@ -154,13 +154,13 @@ class Domain < ActiveRecord::Base
end
end
self.domain_contacts.delete(to_delete)
domain_contacts.delete(to_delete)
end
def detach_nameservers(ns_list)
to_delete = []
ns_list.each do |ns_attrs|
nameserver = self.nameservers.where(ns_attrs)
nameserver = nameservers.where(ns_attrs)
if nameserver.blank?
errors.add(:nameservers, {
obj: 'hostObj',
@ -172,7 +172,7 @@ class Domain < ActiveRecord::Base
end
end
self.nameservers.delete(to_delete)
nameservers.delete(to_delete)
end
def detach_statuses(status_list)
@ -190,7 +190,7 @@ class Domain < ActiveRecord::Base
end
end
self.domain_statuses.delete(to_delete)
domain_statuses.delete(to_delete)
end
### RENEW ###
@ -202,7 +202,7 @@ class Domain < ActiveRecord::Base
p = self.class.convert_period_to_time(period, unit)
self.valid_to = self.valid_to + p
self.valid_to = valid_to + p
self.period = period
self.period_unit = unit
save
@ -226,11 +226,11 @@ class Domain < ActiveRecord::Base
def validate_period
return unless period.present?
if period_unit == 'd'
valid_values = ['365', '366', '710', '712', '1065', '1068']
valid_values = %w(365 366 710 712 1065 1068)
elsif period_unit == 'm'
valid_values = ['12', '24', '36']
valid_values = %w(12 24 36)
else
valid_values = ['1', '2', '3']
valid_values = %w(1 2 3)
end
errors.add(:period, :out_of_range) unless valid_values.include?(period.to_s)
@ -351,12 +351,12 @@ class Domain < ActiveRecord::Base
res = []
domains.each do |x|
if !DomainNameValidator.validate_format(x)
unless DomainNameValidator.validate_format(x)
res << { name: x, avail: 0, reason: 'invalid format' }
next
end
if !DomainNameValidator.validate_reservation(x)
unless DomainNameValidator.validate_reservation(x)
res << { name: x, avail: 0, reason: I18n.t('errors.messages.epp_domain_reserved') }
next
end

View file

@ -1,3 +1,2 @@
class ReservedDomain < ActiveRecord::Base
end

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
load File.expand_path('../spring', __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
load File.expand_path('../spring', __FILE__)
rescue LoadError
end
require_relative '../config/boot'

View file

@ -7,7 +7,7 @@
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
Pathname.new(__FILE__).realpath)
require 'rubygems'

View file

@ -4,15 +4,15 @@
# It gets overwritten when you run the `spring binstub` command
unless defined?(Spring)
require "rubygems"
require "bundler"
require 'rubygems'
require 'bundler'
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
ENV["GEM_HOME"] = ""
ENV['GEM_PATH'] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
ENV['GEM_HOME'] = ''
Gem.paths = ENV
gem "spring", match[1]
require "spring/binstub"
gem 'spring', match[1]
require 'spring/binstub'
end
end

View file

@ -1,12 +1,12 @@
require File.expand_path('../boot', __FILE__)
# Pick the frameworks you want:
require "active_model/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
require 'active_model/railtie'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/railtie'
require 'sprockets/railtie'
# require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems

View file

@ -1 +1 @@
Dir[File.join(Rails.root, "lib", "ext", "*.rb")].each {|x| require x }
Dir[File.join(Rails.root, 'lib', 'ext', '*.rb')].each { |x| require x }

View file

@ -6,7 +6,7 @@ class CreateEppSessions < ActiveRecord::Migration
t.timestamps
end
add_index :epp_sessions, :session_id, :unique => true
add_index :epp_sessions, :session_id, unique: true
add_index :epp_sessions, :updated_at
end
end

View file

@ -4,7 +4,7 @@ class PopulateSettings < ActiveRecord::Migration
code: 'domain_validation',
settings: [
Setting.create(code: 'ns_min_count', value: 1),
Setting.create(code: 'ns_max_count', value: 13),
Setting.create(code: 'ns_max_count', value: 13)
]
)
end

View file

@ -11,181 +11,181 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140819103517) do
ActiveRecord::Schema.define(version: 20_140_819_103_517) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension 'plpgsql'
create_table "addresses", force: true do |t|
t.integer "contact_id"
t.integer "country_id"
t.string "city"
t.string "street"
t.string "zip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "street2"
t.string "street3"
create_table 'addresses', force: true do |t|
t.integer 'contact_id'
t.integer 'country_id'
t.string 'city'
t.string 'street'
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|
t.string "code"
t.string "name"
t.string "type"
t.string "reg_no"
t.string "phone"
t.string "email"
t.string "fax"
t.datetime "created_at"
t.datetime "updated_at"
t.string "ident"
t.string "ident_type"
t.string "org_name"
t.integer "created_by_id"
t.integer "updated_by_id"
t.string "auth_info"
create_table 'contacts', force: true do |t|
t.string 'code'
t.string 'name'
t.string 'type'
t.string 'reg_no'
t.string 'phone'
t.string 'email'
t.string 'fax'
t.datetime 'created_at'
t.datetime 'updated_at'
t.string 'ident'
t.string 'ident_type'
t.string 'org_name'
t.integer 'created_by_id'
t.integer 'updated_by_id'
t.string 'auth_info'
end
create_table "countries", force: true do |t|
t.string "iso"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'countries', force: true do |t|
t.string 'iso'
t.string 'name'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "domain_contacts", force: true do |t|
t.integer "contact_id"
t.integer "domain_id"
t.string "contact_type"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'domain_contacts', force: true do |t|
t.integer 'contact_id'
t.integer 'domain_id'
t.string 'contact_type'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "domain_statuses", force: true do |t|
t.integer "domain_id"
t.integer "setting_id"
t.string "description"
create_table 'domain_statuses', force: true do |t|
t.integer 'domain_id'
t.integer 'setting_id'
t.string 'description'
end
create_table "domains", force: true do |t|
t.string "name"
t.integer "registrar_id"
t.datetime "registered_at"
t.string "status"
t.datetime "valid_from"
t.datetime "valid_to"
t.integer "owner_contact_id"
t.integer "admin_contact_id"
t.integer "technical_contact_id"
t.integer "ns_set_id"
t.string "auth_info"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name_dirty"
t.string "name_puny"
t.integer "period"
t.string "period_unit", limit: 1
create_table 'domains', force: true do |t|
t.string 'name'
t.integer 'registrar_id'
t.datetime 'registered_at'
t.string 'status'
t.datetime 'valid_from'
t.datetime 'valid_to'
t.integer 'owner_contact_id'
t.integer 'admin_contact_id'
t.integer 'technical_contact_id'
t.integer 'ns_set_id'
t.string 'auth_info'
t.datetime 'created_at'
t.datetime 'updated_at'
t.string 'name_dirty'
t.string 'name_puny'
t.integer 'period'
t.string 'period_unit', limit: 1
end
create_table "domains_nameservers", force: true do |t|
t.integer "domain_id"
t.integer "nameserver_id"
create_table 'domains_nameservers', force: true do |t|
t.integer 'domain_id'
t.integer 'nameserver_id'
end
create_table "epp_sessions", force: true do |t|
t.string "session_id"
t.text "data"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'epp_sessions', force: true do |t|
t.string 'session_id'
t.text 'data'
t.datetime 'created_at'
t.datetime 'updated_at'
end
add_index "epp_sessions", ["session_id"], name: "index_epp_sessions_on_session_id", unique: true, using: :btree
add_index "epp_sessions", ["updated_at"], name: "index_epp_sessions_on_updated_at", using: :btree
add_index 'epp_sessions', ['session_id'], name: 'index_epp_sessions_on_session_id', unique: true, using: :btree
add_index 'epp_sessions', ['updated_at'], name: 'index_epp_sessions_on_updated_at', using: :btree
create_table "epp_users", force: true do |t|
t.integer "registrar_id"
t.string "username"
t.string "password"
t.boolean "active", default: false
t.text "csr"
t.text "crt"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'epp_users', force: true do |t|
t.integer 'registrar_id'
t.string 'username'
t.string 'password'
t.boolean 'active', default: false
t.text 'csr'
t.text 'crt'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "nameservers", force: true do |t|
t.string "hostname"
t.string "ipv4"
t.integer "ns_set_id"
t.datetime "created_at"
t.datetime "updated_at"
t.string "ipv6"
create_table 'nameservers', force: true do |t|
t.string 'hostname'
t.string 'ipv4'
t.integer 'ns_set_id'
t.datetime 'created_at'
t.datetime 'updated_at'
t.string 'ipv6'
end
create_table "nameservers_ns_sets", force: true do |t|
t.integer "nameserver_id"
t.integer "ns_set_id"
create_table 'nameservers_ns_sets', force: true do |t|
t.integer 'nameserver_id'
t.integer 'ns_set_id'
end
create_table "ns_sets", force: true do |t|
t.string "code"
t.integer "registrar_id"
t.string "auth_info"
t.string "report_level"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'ns_sets', force: true do |t|
t.string 'code'
t.integer 'registrar_id'
t.string 'auth_info'
t.string 'report_level'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "registrars", force: true do |t|
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"
t.datetime "updated_at"
create_table 'registrars', force: true do |t|
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'
t.datetime 'updated_at'
end
create_table "reserved_domains", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'reserved_domains', force: true do |t|
t.string 'name'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "rights", force: true do |t|
t.string "code"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'rights', force: true do |t|
t.string 'code'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "rights_roles", force: true do |t|
t.integer "right_id"
t.integer "role_id"
create_table 'rights_roles', force: true do |t|
t.integer 'right_id'
t.integer 'role_id'
end
create_table "roles", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'roles', force: true do |t|
t.string 'name'
t.datetime 'created_at'
t.datetime 'updated_at'
end
create_table "setting_groups", force: true do |t|
t.string "code"
create_table 'setting_groups', force: true do |t|
t.string 'code'
end
create_table "settings", force: true do |t|
t.integer "setting_group_id"
t.string "code"
t.string "value"
create_table 'settings', force: true do |t|
t.integer 'setting_group_id'
t.string 'code'
t.string 'value'
end
create_table "users", force: true do |t|
t.string "username"
t.string "password"
t.integer "role_id"
t.datetime "created_at"
t.datetime "updated_at"
create_table 'users', force: true do |t|
t.string 'username'
t.string 'password'
t.integer 'role_id'
t.datetime 'created_at'
t.datetime 'updated_at'
end
end

View file

@ -3,7 +3,7 @@ require 'builder'
class Builder::XmlMarkup
def epp_head
self.instruct!
self.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd') do
epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0', 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation' => 'urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd') do
yield
end
end

View file

@ -13,7 +13,7 @@ end
desc 'Run all but EPP specs'
RSpec::Core::RakeTask.new('test:other') do |t|
t.rspec_opts = "--tag ~epp"
t.rspec_opts = '--tag ~epp'
end
Rake::Task[:default].prerequisites.clear

View file

@ -4,13 +4,13 @@ describe 'EPP Contact', epp: true do
let(:server) { Epp::Server.new({ server: 'localhost', tag: 'gitlab', password: 'ghyt9e4fu', port: 701 }) }
context 'with valid user' do
before(:each) {
before(:each) do
Fabricate(:epp_user)
Fabricate(:domain_validation_setting_group)
}
end
context 'create command' do
it "fails if request is invalid" do
it 'fails if request is invalid' do
response = epp_request(contact_create_xml({ authInfo: [false], addr: { cc: false, city: false } }), :xml)
expect(response[:results][0][:result_code]).to eq('2003')
@ -69,9 +69,8 @@ describe 'EPP Contact', epp: true do
end
end
context 'update command' do
it "fails if request is invalid" do
it 'fails if request is invalid' do
response = epp_request('contacts/update_missing_attr.xml')
# response = epp_request(contact_update_xml( {id: false} ), :xml)
@ -80,7 +79,6 @@ describe 'EPP Contact', epp: true do
expect(response[:results].count).to eq 1
end
it 'fails with wrong authentication info' do
Fabricate(:contact, code: 'sh8013', auth_info: 'secure_password')
@ -126,7 +124,7 @@ describe 'EPP Contact', epp: true do
end
context 'delete command' do
it "fails if request is invalid" do
it 'fails if request is invalid' do
response = epp_request('contacts/delete_missing_attr.xml')
expect(response[:results][0][:result_code]).to eq('2003')
@ -135,7 +133,7 @@ describe 'EPP Contact', epp: true do
end
it 'deletes contact' do
Fabricate(:contact, code: "dwa1234")
Fabricate(:contact, code: 'dwa1234')
response = epp_request('contacts/delete.xml')
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
@ -163,9 +161,8 @@ describe 'EPP Contact', epp: true do
end
end
context 'check command' do
it "fails if request is invalid" do
it 'fails if request is invalid' do
response = epp_request(contact_check_xml(ids: [false]), :xml)
expect(response[:results][0][:result_code]).to eq('2003')
@ -191,7 +188,7 @@ describe 'EPP Contact', epp: true do
end
context 'info command' do
it "fails if request invalid" do
it 'fails if request invalid' do
response = epp_request('contacts/delete_missing_attr.xml')
expect(response[:results][0][:result_code]).to eq('2003')
@ -207,7 +204,7 @@ describe 'EPP Contact', epp: true do
end
it 'returns info about contact' do
Fabricate(:contact, name: "Johnny Awesome", created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR')
Fabricate(:contact, name: 'Johnny Awesome', created_by_id: '1', code: 'info-4444', auth_info: '2fooBAR')
Fabricate(:address)
response = epp_request('contacts/info.xml')
@ -220,7 +217,7 @@ describe 'EPP Contact', epp: true do
end
it 'doesn\'t display unassociated object' do
Fabricate(:contact, name:"Johnny Awesome", code: 'info-4444')
Fabricate(:contact, name: 'Johnny Awesome', code: 'info-4444')
response = epp_request('contacts/info.xml')
expect(response[:result_code]).to eq('2201')

View file

@ -30,11 +30,11 @@ describe 'EPP Domain', epp: true do
end
context 'with citizen as an owner' do
before(:each) {
before(:each) do
Fabricate(:contact, code: 'jd1234')
Fabricate(:contact, code: 'sh8013')
Fabricate(:contact, code: 'sh801333')
}
end
it 'creates a domain' do
response = epp_request(domain_create_xml, :xml)
@ -144,11 +144,11 @@ describe 'EPP Domain', epp: true do
end
context 'with juridical persion as an owner' do
before(:each) {
before(:each) do
Fabricate(:contact, code: 'jd1234', ident_type: 'ico')
Fabricate(:contact, code: 'sh8013')
Fabricate(:contact, code: 'sh801333')
}
end
it 'creates a domain with contacts' do
xml = domain_create_xml(contacts: [{ contact_value: 'sh8013', contact_type: 'admin' }])
@ -217,12 +217,12 @@ describe 'EPP Domain', epp: true do
expect(inf_data.css('name').text).to eq('example.ee')
expect(inf_data.css('registrant').text).to eq(d.owner_contact_code)
admin_contacts_from_request = inf_data.css('contact[type="admin"]').collect{|x| x.text }
admin_contacts_from_request = inf_data.css('contact[type="admin"]').map { |x| x.text }
admin_contacts_existing = d.admin_contacts.pluck(:code)
expect(admin_contacts_from_request).to eq(admin_contacts_existing)
hosts_from_request = inf_data.css('hostObj').collect{|x| x.text }
hosts_from_request = inf_data.css('hostObj').map { |x| x.text }
hosts_existing = d.nameservers.pluck(:hostname)
expect(hosts_from_request).to eq(hosts_existing)

View file

@ -124,7 +124,6 @@ describe 'EPP Helper', epp: true do
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_info_xml).to_s.squish
expect(generated).to eq(expected)
@ -145,7 +144,6 @@ describe 'EPP Helper', epp: true do
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_info_xml(name_value: 'one.ee', name_hosts: 'sub', pw: 'b3rafsla')).to_s.squish
expect(generated).to eq(expected)
end
@ -165,7 +163,6 @@ describe 'EPP Helper', epp: true do
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_check_xml).to_s.squish
expect(generated).to eq(expected)
@ -185,7 +182,6 @@ describe 'EPP Helper', epp: true do
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_check_xml(names: ['example.ee', 'example2.ee', 'example3.ee'])).to_s.squish
expect(generated).to eq(expected)
end
@ -207,7 +203,6 @@ describe 'EPP Helper', epp: true do
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_renew_xml).to_s.squish
expect(generated).to eq(expected)
@ -227,7 +222,6 @@ describe 'EPP Helper', epp: true do
</epp>
').to_s.squish
generated = Nokogiri::XML(domain_renew_xml(name: 'one.ee', curExpDate: '2009-11-15', period_value: '365', period_unit: 'd')).to_s.squish
expect(generated).to eq(expected)
end

View file

@ -1,23 +1,29 @@
Fabricator(:setting_group) do
code 'domain_validation'
settings { [
settings do
[
Fabricate(:setting, code: 'ns_min_count', value: 1),
Fabricate(:setting, code: 'ns_max_count', value: 13)
]}
]
end
end
Fabricator(:domain_validation_setting_group, from: :setting_group) do
code 'domain_validation'
settings { [
settings do
[
Fabricate(:setting, code: 'ns_min_count', value: 1),
Fabricate(:setting, code: 'ns_max_count', value: 13)
]}
]
end
end
Fabricator(:domain_statuses_setting_group, from: :setting_group) do
code 'domain_statuses'
settings { [
settings do
[
Fabricate(:setting, code: 'client_hold', value: 'clientHold'),
Fabricate(:setting, code: 'client_update_prohibited', value: 'clientUpdateProhibited')
]}
]
end
end

View file

@ -1,15 +1,14 @@
require "rails_helper"
require 'rails_helper'
describe Address do
it { should belong_to(:contact) }
it { should belong_to(:country) }
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' ] } } }
ph = { postalInfo: { name: 'fred', addr: { cc: 'EE', city: 'Village', street: %w(street1 street2) } } }
expect(Address.extract_attributes(ph[:postalInfo][:addr])).to eq({
city: 'Village',
country_id: 1,
@ -18,5 +17,3 @@ describe Address, '.extract_params' do
})
end
end

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe Contact do
it { should have_one(:address) }
@ -7,12 +7,12 @@ describe Contact do
before(:each) { @contact = Fabricate(:contact) }
it 'phone should return false' do
@contact.phone = "32341"
@contact.phone = '32341'
expect(@contact.valid?).to be false
end
it 'ident should return false' do
@contact.ident = "123abc"
@contact.ident = '123abc'
expect(@contact.valid?).to be false
end
@ -21,11 +21,11 @@ describe Contact do
expect(@contact.valid?).to eq false
expect(@contact.errors.messages).to match_array({
:code=>["Required parameter missing - code"],
:name=>["Required parameter missing - name"],
:phone=>["Required parameter missing - phone", "Phone nr is invalid"],
:email=>["Required parameter missing - email", "Email is invalid"],
:ident=>["Required parameter missing - ident"]
code: ['Required parameter missing - code'],
name: ['Required parameter missing - name'],
phone: ['Required parameter missing - phone', 'Phone nr is invalid'],
email: ['Required parameter missing - email', 'Email is invalid'],
ident: ['Required parameter missing - ident']
})
end
end
@ -60,7 +60,7 @@ describe Contact, '#relations_with_domain?' do
end
describe Contact, '#crID' do
before(:each) { Fabricate(:contact, code: "asd12", created_by: Fabricate(:epp_user)) }
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')
@ -71,9 +71,8 @@ describe Contact, '#crID' do
end
end
describe Contact, '#upID' do
before(:each) { Fabricate(:contact, code: "asd12", created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user)) }
before(:each) { Fabricate(:contact, code: 'asd12', created_by: Fabricate(:epp_user), updated_by: Fabricate(:epp_user)) }
it 'should return username of updater' do
expect(Contact.first.upID).to eq('gitlab')
@ -84,10 +83,9 @@ describe Contact, '#upID' do
end
end
describe Contact, '.extract_params' do
it 'returns params hash'do
ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: "fred", addr: { cc: 'EE' } } }
ph = { id: '123123', email: 'jdoe@example.com', postalInfo: { name: 'fred', addr: { cc: 'EE' } } }
expect(Contact.extract_attributes(ph)).to eq({
code: '123123',
email: 'jdoe@example.com',
@ -96,33 +94,31 @@ describe Contact, '.extract_params' do
end
end
describe Contact, '.check_availability' do
before(:each) {
Fabricate(:contact, code: "asd12")
Fabricate(:contact, code: "asd13")
}
before(:each) do
Fabricate(:contact, code: 'asd12')
Fabricate(:contact, code: 'asd13')
end
it 'should return array if argument is string' do
response = Contact.check_availability("asd12")
response = Contact.check_availability('asd12')
expect(response.class).to be Array
expect(response.length).to eq(1)
end
it 'should return in_use and available codes' do
response = Contact.check_availability(["asd12","asd13","asd14"])
response = Contact.check_availability(%w(asd12 asd13 asd14))
expect(response.class).to be Array
expect(response.length).to eq(3)
expect(response[0][:avail]).to eq(0)
expect(response[0][:code]).to eq("asd12")
expect(response[0][:code]).to eq('asd12')
expect(response[1][:avail]).to eq(0)
expect(response[1][:code]).to eq("asd13")
expect(response[1][:code]).to eq('asd13')
expect(response[2][:avail]).to eq(1)
expect(response[2][:code]).to eq("asd14")
expect(response[2][:code]).to eq('asd14')
end
end

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe Domain do
it { should belong_to(:registrar) }
@ -44,9 +44,9 @@ describe Domain do
expect(d.errors.messages).to match_array({
name: ['is missing'],
period: ['is not a number'],
owner_contact: ["Registrant is missing"],
admin_contacts: ["Admin contact is missing"],
nameservers: ["Nameservers count must be between 1-13"]
owner_contact: ['Registrant is missing'],
admin_contacts: ['Admin contact is missing'],
nameservers: ['Nameservers count must be between 1-13']
})
sg = SettingGroup.domain_validation

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe EppSession do
let(:epp_session) { Fabricate(:epp_session) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe EppUser do
it { should belong_to(:registrar) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe Nameserver do
it { should have_and_belong_to_many(:domains) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe NsSet do
it { should belong_to(:registrar) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe Registrar do
it { should belong_to(:country) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe Right do
it { should have_and_belong_to_many(:roles) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe Role do
it { should have_and_belong_to_many(:rights) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe SettingGroup do
it { should have_many(:settings) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe Setting do
it { should belong_to(:setting_group) }

View file

@ -1,4 +1,4 @@
require "rails_helper"
require 'rails_helper'
describe User do
it { should belong_to(:role) }

View file

@ -1,7 +1,7 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
ENV['RAILS_ENV'] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'shoulda/matchers'
require 'capybara/poltergeist'
@ -13,7 +13,7 @@ require 'capybara/poltergeist'
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.

View file

@ -14,65 +14,63 @@
# users commonly want.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
RSpec.configure do |_config|
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
# rspec-expectations config goes here. You can use an alternate
# assertion/expectation library such as wrong or the stdlib/minitest
# assertions if you prefer.
config.expect_with :rspec do |expectations|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
expectations.syntax = :expect
end
# rspec-mocks config goes here. You can use an alternate test double
# library (such as bogus or mocha) by changing the `mock_with` option here.
config.mock_with :rspec do |mocks|
# Enable only the newer, non-monkey-patching expect syntax.
# For more details, see:
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
mocks.syntax = :expect
# Prevents you from mocking or stubbing a method that does not exist on
# a real object. This is generally recommended.
mocks.verify_partial_doubles = true
end
=end
# # These two settings work together to allow you to limit a spec run
# # to individual examples or groups you care about by tagging them with
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
# # get run.
# config.filter_run :focus
# config.run_all_when_everything_filtered = true
#
# # Many RSpec users commonly either run the entire suite or an individual
# # file, and it's useful to allow more verbose output when running an
# # individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = 'doc'
# end
#
# # Print the 10 slowest examples and example groups at the
# # end of the spec run, to help surface which specs are running
# # particularly slow.
# config.profile_examples = 10
#
# # Run specs in random order to surface order dependencies. If you find an
# # order dependency and want to debug it, you can fix the order by providing
# # the seed, which is printed after each run.
# # --seed 1234
# config.order = :random
#
# # Seed global randomization in this process using the `--seed` CLI option.
# # Setting this allows you to use `--seed` to deterministically reproduce
# # test failures related to randomization by passing the same `--seed` value
# # as the one that triggered the failure.
# Kernel.srand config.seed
#
# # rspec-expectations config goes here. You can use an alternate
# # assertion/expectation library such as wrong or the stdlib/minitest
# # assertions if you prefer.
# config.expect_with :rspec do |expectations|
# # Enable only the newer, non-monkey-patching expect syntax.
# # For more details, see:
# # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
# expectations.syntax = :expect
# end
#
# # rspec-mocks config goes here. You can use an alternate test double
# # library (such as bogus or mocha) by changing the `mock_with` option here.
# config.mock_with :rspec do |mocks|
# # Enable only the newer, non-monkey-patching expect syntax.
# # For more details, see:
# # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# mocks.syntax = :expect
#
# # Prevents you from mocking or stubbing a method that does not exist on
# # a real object. This is generally recommended.
# mocks.verify_partial_doubles = true
# end
end

View file

@ -1,28 +1,24 @@
module Epp
def read_body filename
def read_body(filename)
File.read("spec/epp/requests/#{filename}")
end
# handles connection and login automatically
def epp_request(data, type = :filename)
begin
return parse_response(server.request(read_body(data))) if type == :filename
return parse_response(server.request(data))
rescue Exception => e
rescue => e
e
end
end
def epp_plain_request(data, type = :filename)
begin
return parse_response(server.send_request(read_body(data))) if type == :filename
return parse_response(server.send_request(data))
rescue Exception => e
rescue => e
e
end
end
def parse_response raw
def parse_response(raw)
res = Nokogiri::XML(raw)
obj = {
@ -61,7 +57,7 @@ module Epp
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no')
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.create do
@ -96,7 +92,7 @@ module Epp
def domain_renew_xml(xml_params = {})
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no')
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.renew do
@ -115,7 +111,7 @@ module Epp
xml_params[:names] = xml_params[:names] || ['example.ee']
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no')
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.check do
@ -137,7 +133,7 @@ module Epp
xml = Builder::XmlMarkup.new
xml.instruct!(:xml, :standalone => 'no')
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
xml.info do

View file

@ -1,7 +1,5 @@
module EppContactXmlBuilder
def contact_check_xml(xml_params = {})
xml_params[:ids] = xml_params[:ids] || [{ id: 'check-1234' }, { id: 'check-4321' }]
xml = Builder::XmlMarkup.new
@ -31,7 +29,6 @@ module EppContactXmlBuilder
city: 'Megaton', sp: 'F3 ', pc: '201-33', cc: 'EE' }
xml_params[:authInfo] = xml_params[:authInfo] || { pw: 'Aas34fq' }
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do
@ -81,11 +78,11 @@ module EppContactXmlBuilder
postalInfo = xml_params[:chg][:postalInfo] rescue nil
addr = postalInfo[:addr] rescue nil
if !addr
unless addr
addr = { street: 'Downtown', city: 'Stockholm', cc: 'SE' }
end
if !postalInfo
unless postalInfo
postalInfo = { name: 'Jane Doe', org: 'Fake Inc.', voice: '+321.12345', fax: '12312312', addr: addr }
end
@ -96,7 +93,6 @@ module EppContactXmlBuilder
xml_params[:chg][:authInfo] = xml_params[:chg][:authInfo] || { pw: 'ccds4324pok' }
xml.instruct!(:xml, standalone: 'no')
xml.epp('xmlns' => 'urn:ietf:params:xml:ns:epp-1.0') do
xml.command do