Added some missing model specs + PaperTrail session fix

This commit is contained in:
Priit Tark 2015-02-02 18:09:01 +02:00
parent c248a957a6
commit a637eb5e01
39 changed files with 1447 additions and 845 deletions

View file

@ -22,8 +22,6 @@ class EppController < ApplicationController
end
def current_api_user
return @current_api_user if @current_api_user
@current_api_user ||= ApiUser.find_by_id(epp_session[:api_user_id])
# by default PaperTrail uses before filter and at that
# time current_api_user is not yet present
@ -205,7 +203,7 @@ class EppController < ApplicationController
request_successful: epp_errors.empty?,
request_object: params[:epp_object_type],
response: @response,
api_user_name: PaperTrail.whodunnit,
api_user_name: api_user_log_str(@api_user || current_api_user),
api_user_registrar: @api_user.try(:registrar).try(:to_s) || current_api_user.try(:registrar).try(:to_s),
ip: request.ip
})

View file

@ -1,5 +1,6 @@
class Address < ActiveRecord::Base
include Versions # version/address_version.rb
belongs_to :country_deprecated, foreign_key: :country_id
LOCAL_TYPE_SHORT = 'loc'
INTERNATIONAL_TYPE_SHORT = 'int'
@ -55,7 +56,7 @@ class Address < ActiveRecord::Base
def addr_hash_from_params(addr)
return {} if addr.nil?
return {} unless addr[:addr].is_a?(Hash)
{ country_code: Country.find_by(iso: addr[:addr][:cc]).try(:id),
{ country_code: Country.new(addr[:addr][:cc]).try(:alpha2),
city: addr[:addr][:city],
street: pretty_street(addr[:addr][:street]), # [0],
# street2: addr[:addr][:street][1],

View file

@ -4,10 +4,11 @@ class Dnskey < ActiveRecord::Base
belongs_to :domain
validates :alg, :protocol, :flags, :public_key, presence: true, if: :validate_key_data
validates :domain, :alg, :protocol, :flags, :public_key, presence: true, if: :validate_key_data
validate :validate_algorithm
validate :validate_protocol
validate :validate_flags
before_save -> { generate_digest if public_key_changed? && !ds_digest_changed? }

View file

@ -5,14 +5,15 @@ class Keyrelay < ActiveRecord::Base
belongs_to :domain
belongs_to :requester, class_name: 'Registrar'
belongs_to :accepter, class_name: 'Registrar'
belongs_to :accepter, class_name: 'Registrar'
has_many :legal_documents, as: :documentable
delegate :name, to: :domain, prefix: true
validates :domain, :key_data_public_key, :key_data_flags, :key_data_protocol,
:key_data_alg, :auth_info_pw, presence: true
validates :expiry_relative, duration_iso8601: true
validates :key_data_public_key, :key_data_flags, :key_data_protocol, :key_data_alg, :auth_info_pw, presence: true
validate :validate_expiry_relative_xor_expiry_absolute

View file

@ -5,6 +5,7 @@ class Registrar < ActiveRecord::Base
has_many :contacts, dependent: :restrict_with_error
has_many :api_users, dependent: :restrict_with_error
has_many :messages
belongs_to :country_deprecated, foreign_key: :country_id
validates :name, :reg_no, :address, :country, :email, presence: true
validates :name, :reg_no, uniqueness: true

View file

@ -7,12 +7,13 @@ class User < ActiveRecord::Base
# After activisation, system should require to change temp password.
# TODO: Estonian id validation
validates :username, :password, presence: true
validates :username, :password, :country_code, presence: true
validates :identity_code, uniqueness: true, allow_blank: true
validates :identity_code, presence: true, if: -> { country.alpha2 == 'EE' }
validates :email, presence: true, if: -> { country.alpha2 != 'EE' }
validates :identity_code, presence: true, if: -> { country_code == 'EE' }
validates :email, presence: true, if: -> { country_code != 'EE' }
validate :validate_identity_code
belongs_to :country_deprecated, foreign_key: :country_id
ROLES = %w(user customer_service admin)

View file

@ -6,6 +6,7 @@ class DurationIso8601Validator < ActiveModel::EachValidator
class << self
def validate(value)
return false if value.blank?
return true if value.empty?
begin