Added pure PaperTrail stack

This commit is contained in:
Priit Tark 2015-01-28 17:26:26 +02:00
parent ea6bdc19f9
commit 09a816d5a8
27 changed files with 846 additions and 492 deletions

View file

@ -1,4 +1,6 @@
class Address < ActiveRecord::Base class Address < ActiveRecord::Base
include Versions # version/address_version.rb
LOCAL_TYPE_SHORT = 'loc' LOCAL_TYPE_SHORT = 'loc'
INTERNATIONAL_TYPE_SHORT = 'int' INTERNATIONAL_TYPE_SHORT = 'int'
LOCAL_TYPE = 'LocalAddress' LOCAL_TYPE = 'LocalAddress'
@ -10,8 +12,6 @@ class Address < ActiveRecord::Base
belongs_to :contact belongs_to :contact
belongs_to :country belongs_to :country
has_paper_trail class_name: 'AddressVersion'
class << self class << self
# def validate_postal_info_types(parsed_frame) # def validate_postal_info_types(parsed_frame)
# errors, used = [], [] # errors, used = [], []

View file

@ -1,4 +0,0 @@
class AddressVersion < PaperTrail::Version
self.table_name = :address_versions
self.sequence_name = :address_version_id_seq
end

View file

@ -1,35 +1,36 @@
module DomainVersionObserver module DomainVersionObserver
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do # TODO: remove old
after_save :delayed_whois_update # included do
end # after_save :delayed_whois_update
# end
private # private
def delayed_whois_update # def delayed_whois_update
name = domain_name # name = domain_name
return unless name # return unless name
body = snapshot # body = snapshot
delay.update_private_whois(name, body) # delay.update_private_whois(name, body)
delay.update_public_whois(name, body) # delay.update_public_whois(name, body)
end # end
def update_private_whois(domain_name, body) # def update_private_whois(domain_name, body)
wd = Whois::PublicDomain.find_or_initialize_by(name: domain_name) # wd = Whois::PublicDomain.find_or_initialize_by(name: domain_name)
wd.body = body # wd.body = body
wd.save! # wd.save!
end # end
def update_public_whois(domain_name, body) # def update_public_whois(domain_name, body)
wd = Whois::PrivateDomain.find_or_initialize_by(name: domain_name) # wd = Whois::PrivateDomain.find_or_initialize_by(name: domain_name)
wd.body = body # wd.body = body
wd.save! # wd.save!
end # end
def domain_name # def domain_name
name = reify.try(:name) # name = reify.try(:name)
name = load_snapshot[:domain][:name] if event == 'create' # name = load_snapshot[:domain][:name] if event == 'create'
return name if name # return name if name
end # end
end end

View file

@ -0,0 +1,10 @@
module LogTable
extend ActiveSupport::Concern
included do
# one plase to define log tables
log_table_name = "log_#{table_name.sub('_versions', '').tableize}"
self.table_name = log_table_name
self.sequence_name = log_table_name
end
end

View file

@ -1,22 +1,23 @@
module UserEvents module UserEvents
extend ActiveSupport::Concern extend ActiveSupport::Concern
module ClassMethods # TODO: remove old
def registrar_events(id) # module ClassMethods
registrar = Registrar.find(id) # def registrar_events(id)
return [] unless registrar # registrar = Registrar.find(id)
@events = [] # return [] unless registrar
registrar.users.each { |user| @events << user_events(user.id) } # @events = []
registrar.api_users.each { |user| @events << epp_user_events(user.id) } # registrar.users.each { |user| @events << user_events(user.id) }
@events # registrar.epp_users.each { |user| @events << epp_user_events(user.id) }
end # @events
# end
def user_events(id) # def user_events(id)
where(whodunnit: id.to_s) # where(whodunnit: id.to_s)
end # end
def epp_user_events(id) # def epp_user_events(id)
where(whodunnit: "#{id}-ApiUser") # where(whodunnit: "#{id}-EppUser")
end # end
end # end
end end

View file

@ -0,0 +1,10 @@
module Versions
extend ActiveSupport::Concern
included do
has_paper_trail class_name: "#{model_name}Version"
end
class_methods do
end
end

View file

@ -1,6 +1,5 @@
class Contact < ActiveRecord::Base class Contact < ActiveRecord::Base
# TODO: Foreign contact will get email with activation link/username/temp password include Versions # version/contact_version.rb
include EppErrors include EppErrors
has_one :address, dependent: :destroy has_one :address, dependent: :destroy
@ -34,17 +33,16 @@ class Contact < ActiveRecord::Base
delegate :zip, to: :address # , prefix: true delegate :zip, to: :address # , prefix: true
# callbacks # callbacks
# TODO: remove old
# after_commit :domains_snapshot # after_commit :domains_snapshot
after_update :domains_snapshot # after_update :domains_snapshot
after_destroy :domains_snapshot # after_destroy :domains_snapshot
before_create :generate_code before_create :generate_code
before_create :generate_auth_info before_create :generate_auth_info
after_create :ensure_disclosure after_create :ensure_disclosure
# scopes # scopes
scope :current_registrars, ->(id) { where(registrar_id: id) } scope :current_registrars, ->(id) { where(registrar_id: id) }
# archiving
has_paper_trail class_name: 'ContactVersion'
IDENT_TYPE_ICO = 'ico' IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [ IDENT_TYPES = [
@ -72,13 +70,14 @@ class Contact < ActiveRecord::Base
create_disclosure! unless disclosure create_disclosure! unless disclosure
end end
def domains_snapshot # TODO: remove old
(domains + domains_owned).uniq.each do |domain| # def domains_snapshot
next unless domain.is_a?(Domain) # (domains + domains_owned).uniq.each do |domain|
# next if domain.versions.last == domain.create_snapshot # next unless domain.is_a?(Domain)
domain.create_version # Method from paper_trail # # next if domain.versions.last == domain.create_snapshot
end # domain.create_version # Method from paper_trail
end # end
# end
def juridical? def juridical?
ident_type == IDENT_TYPE_ICO ident_type == IDENT_TYPE_ICO
@ -148,16 +147,17 @@ class Contact < ActiveRecord::Base
name name
end end
# TODO: remove old
# for archiving # for archiving
def snapshot # def snapshot
{ # {
name: name, # name: name,
phone: phone, # phone: phone,
code: code, # code: code,
ident: ident, # ident: ident,
email: email # email: email
} # }
end # end
class << self class << self
# non-EPP # non-EPP

View file

@ -1,4 +1,5 @@
class Domain < ActiveRecord::Base class Domain < ActiveRecord::Base
include Versions # version/domain_version.rb
# TODO: whois requests ip whitelist for full info for own domains and partial info for other domains # TODO: whois requests ip whitelist for full info for own domains and partial info for other domains
# TODO: most inputs should be trimmed before validatation, probably some global logic? # TODO: most inputs should be trimmed before validatation, probably some global logic?
paginates_per 10 # just for showoff paginates_per 10 # just for showoff
@ -17,7 +18,9 @@ class Domain < ActiveRecord::Base
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) }, -> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
through: :domain_contacts, source: :contact through: :domain_contacts, source: :contact
has_many :nameservers, dependent: :delete_all, after_add: :track_nameserver_add # TODO: remove old
# has_many :nameservers, dependent: :delete_all, after_add: :track_nameserver_add
has_many :nameservers, dependent: :delete_all
accepts_nested_attributes_for :nameservers, allow_destroy: true, accepts_nested_attributes_for :nameservers, allow_destroy: true,
reject_if: proc { |attrs| attrs[:hostname].blank? } reject_if: proc { |attrs| attrs[:hostname].blank? }
@ -102,9 +105,10 @@ class Domain < ActiveRecord::Base
attr_accessor :owner_contact_typeahead, :update_me attr_accessor :owner_contact_typeahead, :update_me
# TODO: remove old
# archiving # archiving
# if proc works only on changes on domain sadly # if proc works only on changes on domain sadly
has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }, if: proc(&:new_version) # has_paper_trail class_name: 'DomainVersion', meta: { snapshot: :create_snapshot }, if: proc(&:new_version)
def tech_domain_contacts def tech_domain_contacts
domain_contacts.select { |x| x.contact_type == DomainContact::TECH } domain_contacts.select { |x| x.contact_type == DomainContact::TECH }
@ -114,46 +118,51 @@ class Domain < ActiveRecord::Base
domain_contacts.select { |x| x.contact_type == DomainContact::ADMIN } domain_contacts.select { |x| x.contact_type == DomainContact::ADMIN }
end end
def new_version # TODO: remove old
return false if versions.try(:last).try(:snapshot) == create_snapshot # def new_version
true # return false if versions.try(:last).try(:snapshot) == create_snapshot
end # true
# end
def create_version # TODO: remove old
return true unless PaperTrail.enabled? # def create_version
return true unless valid? # return true unless PaperTrail.enabled?
touch_with_version if new_version # return true unless valid?
end # touch_with_version if new_version
# end
def track_nameserver_add(_nameserver) # TODO: remove old
return true if versions.count == 0 # def track_nameserver_add(_nameserver)
return true unless valid? && new_version # return true if versions.count == 0
# return true unless valid? && new_version
touch_with_version # touch_with_version
end # end
def create_snapshot # TODO: remove old
oc = owner_contact.snapshot if owner_contact.is_a?(Contact) # def create_snapshot
{ # oc = owner_contact.snapshot if owner_contact.is_a?(Contact)
owner_contact: oc, # {
tech_contacts: tech_contacts.map(&:snapshot), # owner_contact: oc,
admin_contacts: admin_contacts.map(&:snapshot), # tech_contacts: tech_contacts.map(&:snapshot),
nameservers: nameservers.map(&:snapshot), # admin_contacts: admin_contacts.map(&:snapshot),
domain: make_snapshot # nameservers: nameservers.map(&:snapshot),
}.to_yaml # domain: make_snapshot
end # }.to_yaml
# end
def make_snapshot # TODO: remove old
{ # def make_snapshot
name: name, # {
status: status, # name: name,
period: period, # status: status,
period_unit: period_unit, # period: period,
registrar_id: registrar.try(:id), # period_unit: period_unit,
valid_to: valid_to, # registrar_id: registrar.try(:id),
valid_from: valid_from # valid_to: valid_to,
} # valid_from: valid_from
end # }
# end
def name=(value) def name=(value)
value.strip! value.strip!

View file

@ -3,8 +3,9 @@ class DomainContact < ActiveRecord::Base
belongs_to :contact belongs_to :contact
belongs_to :domain belongs_to :domain
after_create :domain_snapshot # TODO: remove old
after_destroy :domain_snapshot # after_create :domain_snapshot
# after_destroy :domain_snapshot
# after_save :domain_snapshot # after_save :domain_snapshot
attr_accessor :value_typeahead attr_accessor :value_typeahead
@ -38,10 +39,11 @@ class DomainContact < ActiveRecord::Base
@value_typeahead || contact.try(:name) || nil @value_typeahead || contact.try(:name) || nil
end end
def domain_snapshot # TODO: remove old
return true if domain.nil? # def domain_snapshot
return true if domain.versions.count == 0 # avoid snapshot on creation # return true if domain.nil?
domain.create_version # return true if domain.versions.count == 0 # avoid snapshot on creation
true # domain.create_version
end # true
# end
end end

View file

@ -1,4 +1,5 @@
class DomainStatus < ActiveRecord::Base class DomainStatus < ActiveRecord::Base
include Versions # version/domain_status_version.rb
include EppErrors include EppErrors
belongs_to :domain belongs_to :domain
@ -50,9 +51,6 @@ class DomainStatus < ActiveRecord::Base
SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED
] ]
# archiving
has_paper_trail class_name: 'DomainStatusVersion'
def epp_code_map def epp_code_map
{ {
'2302' => [ # Object exists '2302' => [ # Object exists

View file

@ -1,4 +0,0 @@
class DomainStatusVersion < PaperTrail::Version
self.table_name = :domain_status_versions
self.sequence_name = :domain_status_version_id_seq
end

View file

@ -1,36 +0,0 @@
class DomainVersion < PaperTrail::Version
include UserEvents
include DomainVersionObserver if Setting.whois_enabled # unless Setting.whois_enabled
scope :deleted, -> { where(event: 'destroy') }
self.table_name = :domain_versions
self.sequence_name = :domain_version_id_seq
def load_snapshot
snapshot ? YAML.load(snapshot) : {}
end
def previous?
return true if previous
false
end
def name
name = reify.try(:name)
name = load_snapshot[:domain].try(:[], :name) unless name
name
end
def changed_elements
return [] unless previous?
@changes = []
@previous_snap = previous.load_snapshot
@snap = load_snapshot
[:owner_contact, :tech_contacts, :admin_contacts, :nameservers, :domain].each do |key|
@changes << key unless @snap[key] == @previous_snap[key]
end
@changes
end
end

View file

@ -1,4 +1,5 @@
class Nameserver < ActiveRecord::Base class Nameserver < ActiveRecord::Base
include Versions # version/nameserver_version.rb
include EppErrors include EppErrors
belongs_to :registrar belongs_to :registrar
@ -10,9 +11,8 @@ class Nameserver < ActiveRecord::Base
validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true } validates :ipv6, format: { with: /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/, allow_blank: true }
# rubocop: enable Metrics/LineLength # rubocop: enable Metrics/LineLength
# archiving # TODO: remove old
has_paper_trail class_name: 'NameserverVersion' # after_destroy :domain_version
after_destroy :domain_version
before_validation :normalize_attributes before_validation :normalize_attributes
@ -34,13 +34,14 @@ class Nameserver < ActiveRecord::Base
} }
end end
def snapshot # TODO: remove old
{ # def snapshot
hostname: hostname, # {
ipv4: ipv4, # hostname: hostname,
ipv6: ipv6 # ipv4: ipv4,
} # ipv6: ipv6
end # }
# end
def normalize_attributes def normalize_attributes
self.hostname = hostname.try(:strip).try(:downcase) self.hostname = hostname.try(:strip).try(:downcase)
@ -48,9 +49,10 @@ class Nameserver < ActiveRecord::Base
self.ipv6 = ipv6.try(:strip).try(:upcase) self.ipv6 = ipv6.try(:strip).try(:upcase)
end end
def domain_version # TODO: remove old
domain.create_version if domain # def domain_version
end # domain.create_version if domain
# end
def to_s def to_s
hostname hostname

View file

@ -1,4 +0,0 @@
class NameserverVersion < PaperTrail::Version
self.table_name = :nameserver_versions
self.sequence_name = :nameserver_version_id_seq
end

View file

@ -0,0 +1,3 @@
class AddressVersion < PaperTrail::Version
include LogTable
end

View file

@ -1,8 +1,8 @@
class ContactVersion < PaperTrail::Version class ContactVersion < PaperTrail::Version
include LogTable
include UserEvents include UserEvents
# self.table_name = :post_versions
# self.sequence_name = :post_version_id_seq
scope :deleted, -> { where(event: 'destroy') } scope :deleted, -> { where(event: 'destroy') }
self.table_name = :contact_versions
self.sequence_name = :contact_version_id_seq
end end

View file

@ -0,0 +1,3 @@
class DomainStatusVersion < PaperTrail::Version
include LogTable
end

View file

@ -0,0 +1,39 @@
class DomainVersion < PaperTrail::Version
include LogTable
include UserEvents
# TODO: remove old
# include DomainVersionObserver if Setting.whois_enabled # unless Setting.whois_enabled
scope :deleted, -> { where(event: 'destroy') }
# TODO: remove old
# def load_snapshot
# snapshot ? YAML.load(snapshot) : {}
# end
# TODO: remove old
# def previous?
# return true if previous
# false
# end
# TODO: remove old
# def name
# name = reify.try(:name)
# name = load_snapshot[:domain].try(:[], :name) unless name
# name
# end
# TODO: remove old
# def changed_elements
# return [] unless previous?
# @changes = []
# @previous_snap = previous.load_snapshot
# @snap = load_snapshot
# [:owner_contact, :tech_contacts, :admin_contacts, :nameservers, :domain].each do |key|
# @changes << key unless @snap[key] == @previous_snap[key]
# end
# @changes
# end
end

View file

@ -0,0 +1,3 @@
class NameserverVersion < PaperTrail::Version
include LogTable
end

View file

@ -30,6 +30,9 @@ module Registry
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb') config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')] config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
# Load all model subdirs
config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
# Active Record used to suppresses errors raised within # Active Record used to suppresses errors raised within
# `after_rollback`/`after_commit` callbacks and only printed them to the logs. # `after_rollback`/`after_commit` callbacks and only printed them to the logs.
# In the next version, these errors will no longer be suppressed. # In the next version, these errors will no longer be suppressed.

View file

@ -0,0 +1,13 @@
# the following line is required for PaperTrail >= 4.0.0 with Rails
PaperTrail::Rails::Engine.eager_load!
# Store console and rake changes in versions
if defined?(::Rails::Console)
PaperTrail.whodunnit = "#{`whoami`.strip}: console"
elsif File.basename($PROGRAM_NAME) == "rake"
PaperTrail.whodunnit = "#{`whoami`.strip}: rake #{ARGV.join ' '}"
end
PaperTrail::Version.module_eval do
self.abstract_class = true
end

View file

@ -0,0 +1,28 @@
class AddJsonBasedVersions < ActiveRecord::Migration
def change
%w(address contact_disclosure contact contact_status country dnskey
domain_contact domain domain_status domain_transfer epp_user keyrelay
legal_document message nameserver registrar
reserved_domain setting user zonefile_setting
).each do |name|
table_name = "log_#{name.tableize}"
create_table table_name do |t|
t.string :item_type, null: false
t.integer :item_id, null: false
t.string :event, null: false
t.string :whodunnit
t.json :object
t.json :object_changes
t.datetime :created_at
end
add_index table_name, [:item_type, :item_id]
add_index table_name, :whodunnit
add_column name.tableize, :creator_id_tmp, :integer
add_column name.tableize, :updater_id_tmp, :integer
rename_column name.tableize, :creator_id_tmp, :creator_id
rename_column name.tableize, :updater_id_tmp, :updater_id
end
end
end

View file

@ -0,0 +1,14 @@
class DropAllVersionsDisabledByDefault < ActiveRecord::Migration
def change
# All versions are depricated by log_* tables
# comment to remove unneeded old versions tables
# drop_table "version_associations"
# drop_table "versions"
# drop_table "address_versions"
# drop_table "contact_versions"
# drop_table "domain_status_versions"
# drop_table "domain_versions"
# drop_table "nameserver_versions"
end
end

View file

@ -16,27 +16,18 @@ ActiveRecord::Schema.define(version: 20150130085458) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
create_table "address_versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object"
t.datetime "created_at"
end
add_index "address_versions", ["item_type", "item_id"], name: "index_address_versions_on_item_type_and_item_id", using: :btree
create_table "addresses", force: :cascade do |t| create_table "addresses", force: :cascade do |t|
t.integer "contact_id" t.integer "contact_id"
t.integer "country_id" t.integer "country_id"
t.string "city", limit: 255 t.string "city"
t.string "street", limit: 255 t.string "street"
t.string "zip", limit: 255 t.string "zip"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "street2", limit: 255 t.string "street2"
t.string "street3", limit: 255 t.string "street3"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "api_users", force: :cascade do |t| create_table "api_users", force: :cascade do |t|
@ -68,63 +59,60 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.boolean "name" t.boolean "name"
t.boolean "org_name" t.boolean "org_name"
t.boolean "address" t.boolean "address"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "contact_statuses", force: :cascade do |t| create_table "contact_statuses", force: :cascade do |t|
t.string "value", limit: 255 t.string "value"
t.string "description", limit: 255 t.string "description"
t.integer "contact_id" t.integer "contact_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "contact_versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object"
t.datetime "created_at"
end
add_index "contact_versions", ["item_type", "item_id"], name: "index_contact_versions_on_item_type_and_item_id", using: :btree
create_table "contacts", force: :cascade do |t| create_table "contacts", force: :cascade do |t|
t.string "code", limit: 255 t.string "code"
t.string "type", limit: 255 t.string "type"
t.string "reg_no", limit: 255 t.string "reg_no"
t.string "phone", limit: 255 t.string "phone"
t.string "email", limit: 255 t.string "email"
t.string "fax", limit: 255 t.string "fax"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "ident", limit: 255 t.string "ident"
t.string "ident_type", limit: 255 t.string "ident_type"
t.integer "created_by_id" t.integer "created_by_id"
t.integer "updated_by_id" t.integer "updated_by_id"
t.string "auth_info", limit: 255 t.string "auth_info"
t.string "name", limit: 255 t.string "name"
t.string "org_name", limit: 255 t.string "org_name"
t.integer "registrar_id" t.integer "registrar_id"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "countries", force: :cascade do |t| create_table "countries", force: :cascade do |t|
t.string "iso", limit: 255 t.string "iso"
t.string "name", limit: 255 t.string "name"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "delayed_jobs", force: :cascade do |t| create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false t.integer "attempts", default: 0, null: false
t.text "handler", null: false t.text "handler", null: false
t.text "last_error" t.text "last_error"
t.datetime "run_at" t.datetime "run_at"
t.datetime "locked_at" t.datetime "locked_at"
t.datetime "failed_at" t.datetime "failed_at"
t.string "locked_by", limit: 255 t.string "locked_by"
t.string "queue", limit: 255 t.string "queue"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
end end
@ -133,10 +121,10 @@ ActiveRecord::Schema.define(version: 20150130085458) do
create_table "delegation_signers", force: :cascade do |t| create_table "delegation_signers", force: :cascade do |t|
t.integer "domain_id" t.integer "domain_id"
t.string "key_tag", limit: 255 t.string "key_tag"
t.integer "alg" t.integer "alg"
t.integer "digest_type" t.integer "digest_type"
t.string "digest", limit: 255 t.string "digest"
end end
create_table "dnskeys", force: :cascade do |t| create_table "dnskeys", force: :cascade do |t|
@ -146,41 +134,36 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.integer "alg" t.integer "alg"
t.text "public_key" t.text "public_key"
t.integer "delegation_signer_id" t.integer "delegation_signer_id"
t.string "ds_key_tag", limit: 255 t.string "ds_key_tag"
t.integer "ds_alg" t.integer "ds_alg"
t.integer "ds_digest_type" t.integer "ds_digest_type"
t.string "ds_digest", limit: 255 t.string "ds_digest"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "domain_contacts", force: :cascade do |t| create_table "domain_contacts", force: :cascade do |t|
t.integer "contact_id" t.integer "contact_id"
t.integer "domain_id" t.integer "domain_id"
t.string "contact_type", limit: 255 t.string "contact_type"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "contact_code_cache", limit: 255 t.string "contact_code_cache"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "domain_status_versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object"
t.datetime "created_at"
end
add_index "domain_status_versions", ["item_type", "item_id"], name: "index_domain_status_versions_on_item_type_and_item_id", using: :btree
create_table "domain_statuses", force: :cascade do |t| create_table "domain_statuses", force: :cascade do |t|
t.integer "domain_id" t.integer "domain_id"
t.string "description", limit: 255 t.string "description"
t.string "value", limit: 255 t.string "value"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "domain_transfers", force: :cascade do |t| create_table "domain_transfers", force: :cascade do |t|
t.integer "domain_id" t.integer "domain_id"
t.string "status", limit: 255 t.string "status"
t.datetime "transfer_requested_at" t.datetime "transfer_requested_at"
t.datetime "transferred_at" t.datetime "transferred_at"
t.integer "transfer_from_id" t.integer "transfer_from_id"
@ -188,39 +171,31 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.datetime "wait_until" t.datetime "wait_until"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "domain_versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object"
t.datetime "created_at"
t.text "snapshot"
end
add_index "domain_versions", ["item_type", "item_id"], name: "index_domain_versions_on_item_type_and_item_id", using: :btree
create_table "domains", force: :cascade do |t| create_table "domains", force: :cascade do |t|
t.string "name", limit: 255 t.string "name"
t.integer "registrar_id" t.integer "registrar_id"
t.datetime "registered_at" t.datetime "registered_at"
t.string "status", limit: 255 t.string "status"
t.datetime "valid_from" t.datetime "valid_from"
t.datetime "valid_to" t.datetime "valid_to"
t.integer "owner_contact_id" t.integer "owner_contact_id"
t.string "auth_info", limit: 255 t.string "auth_info"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "name_dirty", limit: 255 t.string "name_dirty"
t.string "name_puny", limit: 255 t.string "name_puny"
t.integer "period" t.integer "period"
t.string "period_unit", limit: 1 t.string "period_unit", limit: 1
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "epp_sessions", force: :cascade do |t| create_table "epp_sessions", force: :cascade do |t|
t.string "session_id", limit: 255 t.string "session_id"
t.text "data" t.text "data"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
@ -229,141 +204,402 @@ ActiveRecord::Schema.define(version: 20150130085458) do
add_index "epp_sessions", ["session_id"], name: "index_epp_sessions_on_session_id", unique: true, 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 add_index "epp_sessions", ["updated_at"], name: "index_epp_sessions_on_updated_at", using: :btree
create_table "epp_users", force: :cascade 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"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "keyrelays", force: :cascade do |t| create_table "keyrelays", force: :cascade do |t|
t.integer "domain_id" t.integer "domain_id"
t.datetime "pa_date" t.datetime "pa_date"
t.string "key_data_flags", limit: 255 t.string "key_data_flags"
t.string "key_data_protocol", limit: 255 t.string "key_data_protocol"
t.string "key_data_alg", limit: 255 t.string "key_data_alg"
t.text "key_data_public_key" t.text "key_data_public_key"
t.string "auth_info_pw", limit: 255 t.string "auth_info_pw"
t.string "expiry_relative", limit: 255 t.string "expiry_relative"
t.datetime "expiry_absolute" t.datetime "expiry_absolute"
t.integer "requester_id" t.integer "requester_id"
t.integer "accepter_id" t.integer "accepter_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "legal_documents", force: :cascade do |t| create_table "legal_documents", force: :cascade do |t|
t.string "document_type", limit: 255 t.string "document_type"
t.text "body" t.text "body"
t.integer "documentable_id" t.integer "documentable_id"
t.string "documentable_type", limit: 255 t.string "documentable_type"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "log_addresses", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_addresses", ["item_type", "item_id"], name: "index_log_addresses_on_item_type_and_item_id", using: :btree
add_index "log_addresses", ["whodunnit"], name: "index_log_addresses_on_whodunnit", using: :btree
create_table "log_contact_disclosures", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_contact_disclosures", ["item_type", "item_id"], name: "index_log_contact_disclosures_on_item_type_and_item_id", using: :btree
add_index "log_contact_disclosures", ["whodunnit"], name: "index_log_contact_disclosures_on_whodunnit", using: :btree
create_table "log_contact_statuses", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_contact_statuses", ["item_type", "item_id"], name: "index_log_contact_statuses_on_item_type_and_item_id", using: :btree
add_index "log_contact_statuses", ["whodunnit"], name: "index_log_contact_statuses_on_whodunnit", using: :btree
create_table "log_contacts", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_contacts", ["item_type", "item_id"], name: "index_log_contacts_on_item_type_and_item_id", using: :btree
add_index "log_contacts", ["whodunnit"], name: "index_log_contacts_on_whodunnit", using: :btree
create_table "log_countries", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_countries", ["item_type", "item_id"], name: "index_log_countries_on_item_type_and_item_id", using: :btree
add_index "log_countries", ["whodunnit"], name: "index_log_countries_on_whodunnit", using: :btree
create_table "log_dnskeys", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_dnskeys", ["item_type", "item_id"], name: "index_log_dnskeys_on_item_type_and_item_id", using: :btree
add_index "log_dnskeys", ["whodunnit"], name: "index_log_dnskeys_on_whodunnit", using: :btree
create_table "log_domain_contacts", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_domain_contacts", ["item_type", "item_id"], name: "index_log_domain_contacts_on_item_type_and_item_id", using: :btree
add_index "log_domain_contacts", ["whodunnit"], name: "index_log_domain_contacts_on_whodunnit", using: :btree
create_table "log_domain_statuses", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_domain_statuses", ["item_type", "item_id"], name: "index_log_domain_statuses_on_item_type_and_item_id", using: :btree
add_index "log_domain_statuses", ["whodunnit"], name: "index_log_domain_statuses_on_whodunnit", using: :btree
create_table "log_domain_transfers", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_domain_transfers", ["item_type", "item_id"], name: "index_log_domain_transfers_on_item_type_and_item_id", using: :btree
add_index "log_domain_transfers", ["whodunnit"], name: "index_log_domain_transfers_on_whodunnit", using: :btree
create_table "log_domains", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_domains", ["item_type", "item_id"], name: "index_log_domains_on_item_type_and_item_id", using: :btree
add_index "log_domains", ["whodunnit"], name: "index_log_domains_on_whodunnit", using: :btree
create_table "log_epp_users", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_epp_users", ["item_type", "item_id"], name: "index_log_epp_users_on_item_type_and_item_id", using: :btree
add_index "log_epp_users", ["whodunnit"], name: "index_log_epp_users_on_whodunnit", using: :btree
create_table "log_keyrelays", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_keyrelays", ["item_type", "item_id"], name: "index_log_keyrelays_on_item_type_and_item_id", using: :btree
add_index "log_keyrelays", ["whodunnit"], name: "index_log_keyrelays_on_whodunnit", using: :btree
create_table "log_legal_documents", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_legal_documents", ["item_type", "item_id"], name: "index_log_legal_documents_on_item_type_and_item_id", using: :btree
add_index "log_legal_documents", ["whodunnit"], name: "index_log_legal_documents_on_whodunnit", using: :btree
create_table "log_messages", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_messages", ["item_type", "item_id"], name: "index_log_messages_on_item_type_and_item_id", using: :btree
add_index "log_messages", ["whodunnit"], name: "index_log_messages_on_whodunnit", using: :btree
create_table "log_nameservers", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_nameservers", ["item_type", "item_id"], name: "index_log_nameservers_on_item_type_and_item_id", using: :btree
add_index "log_nameservers", ["whodunnit"], name: "index_log_nameservers_on_whodunnit", using: :btree
create_table "log_registrars", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_registrars", ["item_type", "item_id"], name: "index_log_registrars_on_item_type_and_item_id", using: :btree
add_index "log_registrars", ["whodunnit"], name: "index_log_registrars_on_whodunnit", using: :btree
create_table "log_reserved_domains", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_reserved_domains", ["item_type", "item_id"], name: "index_log_reserved_domains_on_item_type_and_item_id", using: :btree
add_index "log_reserved_domains", ["whodunnit"], name: "index_log_reserved_domains_on_whodunnit", using: :btree
create_table "log_settings", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_settings", ["item_type", "item_id"], name: "index_log_settings_on_item_type_and_item_id", using: :btree
add_index "log_settings", ["whodunnit"], name: "index_log_settings_on_whodunnit", using: :btree
create_table "log_users", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_users", ["item_type", "item_id"], name: "index_log_users_on_item_type_and_item_id", using: :btree
add_index "log_users", ["whodunnit"], name: "index_log_users_on_whodunnit", using: :btree
create_table "log_zonefile_settings", force: :cascade do |t|
t.string "item_type", null: false
t.integer "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.json "object"
t.json "object_changes"
t.datetime "created_at"
end
add_index "log_zonefile_settings", ["item_type", "item_id"], name: "index_log_zonefile_settings_on_item_type_and_item_id", using: :btree
add_index "log_zonefile_settings", ["whodunnit"], name: "index_log_zonefile_settings_on_whodunnit", using: :btree
create_table "messages", force: :cascade do |t| create_table "messages", force: :cascade do |t|
t.integer "registrar_id" t.integer "registrar_id"
t.string "body", limit: 255 t.string "body"
t.string "attached_obj_type", limit: 255 t.string "attached_obj_type"
t.string "attached_obj_id", limit: 255 t.string "attached_obj_id"
t.boolean "queued" t.boolean "queued"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "nameserver_versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object"
t.datetime "created_at"
end
add_index "nameserver_versions", ["item_type", "item_id"], name: "index_nameserver_versions_on_item_type_and_item_id", using: :btree
create_table "nameservers", force: :cascade do |t| create_table "nameservers", force: :cascade do |t|
t.string "hostname", limit: 255 t.string "hostname"
t.string "ipv4", limit: 255 t.string "ipv4"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "ipv6", limit: 255 t.string "ipv6"
t.integer "domain_id" t.integer "domain_id"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "registrars", force: :cascade do |t| create_table "registrars", force: :cascade do |t|
t.string "name", limit: 255 t.string "name"
t.string "reg_no", limit: 255 t.string "reg_no"
t.string "vat_no", limit: 255 t.string "vat_no"
t.string "address", limit: 255 t.string "address"
t.integer "country_id" t.integer "country_id"
t.string "billing_address", limit: 255 t.string "billing_address"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
<<<<<<< HEAD
t.string "phone" t.string "phone"
t.string "email" t.string "email"
t.string "billing_email" t.string "billing_email"
=======
t.integer "creator_id"
t.integer "updater_id"
>>>>>>> Added pure PaperTrail stack
end end
create_table "reserved_domains", force: :cascade do |t| create_table "reserved_domains", force: :cascade do |t|
t.string "name", limit: 255 t.string "name"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "settings", force: :cascade do |t| create_table "settings", force: :cascade do |t|
t.string "var", limit: 255, null: false t.string "var", null: false
t.text "value" t.text "value"
t.integer "thing_id" t.integer "thing_id"
t.string "thing_type", limit: 30 t.string "thing_type", limit: 30
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree
create_table "users", force: :cascade do |t| create_table "users", force: :cascade do |t|
t.string "username", limit: 255 t.string "username"
t.string "password", limit: 255 t.string "password"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.string "email", limit: 255 t.string "email"
t.integer "sign_in_count", default: 0, null: false t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at" t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at" t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip" t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip" t.inet "last_sign_in_ip"
t.string "identity_code", limit: 255 t.string "identity_code"
t.integer "country_id" t.integer "country_id"
t.string "roles", array: true t.string "roles", array: true
t.integer "creator_id"
t.integer "updater_id"
end end
create_table "version_associations", force: :cascade do |t|
t.integer "version_id"
t.string "foreign_key_name", null: false
t.integer "foreign_key_id"
end
add_index "version_associations", ["foreign_key_name", "foreign_key_id"], name: "index_version_associations_on_foreign_key", using: :btree
add_index "version_associations", ["version_id"], name: "index_version_associations_on_version_id", using: :btree
create_table "versions", force: :cascade do |t|
t.string "item_type", limit: 255, null: false
t.integer "item_id", null: false
t.string "event", limit: 255, null: false
t.string "whodunnit", limit: 255
t.text "object"
t.datetime "created_at"
t.integer "transaction_id"
end
add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree
add_index "versions", ["transaction_id"], name: "index_versions_on_transaction_id", using: :btree
create_table "zonefile_settings", force: :cascade do |t| create_table "zonefile_settings", force: :cascade do |t|
t.string "origin", limit: 255 t.string "origin"
t.integer "ttl" t.integer "ttl"
t.integer "refresh" t.integer "refresh"
t.integer "retry" t.integer "retry"
t.integer "expire" t.integer "expire"
t.integer "minimum_ttl" t.integer "minimum_ttl"
t.string "email", limit: 255 t.string "email"
t.string "master_nameserver", limit: 255 t.string "master_nameserver"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end end
end end

View file

@ -8,6 +8,16 @@ describe Contact do
it { should have_one(:address) } it { should have_one(:address) }
context 'about class' do
it 'should have versioning enabled?' do
Contact.paper_trail_enabled_for_model?.should == true
end
it 'should have custom log prexied table name for versions table' do
ContactVersion.table_name.should == 'log_contacts'
end
end
context 'with invalid attribute' do context 'with invalid attribute' do
before :all do before :all do
@contact = Contact.new @contact = Contact.new
@ -41,6 +51,10 @@ describe Contact do
@contact.valid? @contact.valid?
@contact.errors[:phone].should == ["Phone nr is invalid"] @contact.errors[:phone].should == ["Phone nr is invalid"]
end end
it 'should not have any versions' do
@contact.versions.should == []
end
end end
context 'with valid attributes' do context 'with valid attributes' do
@ -57,6 +71,15 @@ describe Contact do
@contact.relations_with_domain?.should == false @contact.relations_with_domain?.should == false
end end
it 'should not have one version' do
with_versioning do
@contact.versions.should == []
@contact.name = 'New name'
@contact.save
@contact.versions.size.should == 1
end
end
# it 'ico should be valid' do # it 'ico should be valid' do
# @contact.ident_type = 'ico' # @contact.ident_type = 'ico'
# @contact.ident = '1234' # @contact.ident = '1234'

View file

@ -1,192 +1,193 @@
require 'rails_helper' require 'rails_helper'
describe DomainVersion do describe DomainVersion do
with_versioning do # TODO: update to new stac
before(:each) do # with_versioning do
Setting.ns_min_count = 1 # before(:each) do
Fabricate(:domain, name: 'version.ee', dnskeys: [], domain_contacts: []) do # Setting.ns_min_count = 1
owner_contact { Fabricate(:contact, name: 'owner_contact', code: 'asd', email: 'owner1@v.ee') } # Fabricate(:domain, name: 'version.ee', dnskeys: [], domain_contacts: []) do
nameservers(count: 1) { Fabricate(:nameserver, hostname: 'ns.test.ee', ipv4: nil) } # owner_contact { Fabricate(:contact, name: 'owner_contact', code: 'asd', email: 'owner1@v.ee') }
admin_contacts(count: 1) { Fabricate(:contact, name: 'admin_contact 1', code: 'qwe', email: 'admin1@v.ee') } # nameservers(count: 1) { Fabricate(:nameserver, hostname: 'ns.test.ee', ipv4: nil) }
tech_contacts(count: 1) { Fabricate(:contact, name: 'tech_contact 1', code: 'zxc', email: 'tech1@v.ee') } # admin_contacts(count: 1) { Fabricate(:contact, name: 'admin_contact 1', code: 'qwe', email: 'admin1@v.ee') }
end # tech_contacts(count: 1) { Fabricate(:contact, name: 'tech_contact 1', code: 'zxc', email: 'tech1@v.ee') }
end # end
# end
context 'when domain is created' do # context 'when domain is created' do
it('creates a domain version') { expect(DomainVersion.count).to eq(1) } # it('creates a domain version') { expect(DomainVersion.count).to eq(1) }
it('has a snapshot') { expect(DomainVersion.first.snapshot).not_to be_empty } # it('has a snapshot') { expect(DomainVersion.first.snapshot).not_to be_empty }
it('has a snapshot with admin_contacts') do # it('has a snapshot with admin_contacts') do
expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include( # expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include(
name: 'admin_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee' # name: 'admin_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee'
) # )
end # end
it('has a snapshot with domain') do # it('has a snapshot with domain') do
expect(DomainVersion.last.load_snapshot[:domain]).to include( # expect(DomainVersion.last.load_snapshot[:domain]).to include(
name: 'version.ee', status: nil # name: 'version.ee', status: nil
) # )
end # end
it('has a snapshot with nameservers') do # it('has a snapshot with nameservers') do
expect(DomainVersion.last.load_snapshot[:nameservers]).to include( # expect(DomainVersion.last.load_snapshot[:nameservers]).to include(
hostname: 'ns.test.ee', ipv4: nil, ipv6: nil # hostname: 'ns.test.ee', ipv4: nil, ipv6: nil
) # )
end # end
it('has a snapshot with owner contact') do # it('has a snapshot with owner contact') do
expect(DomainVersion.last.load_snapshot[:owner_contact]).to include( # expect(DomainVersion.last.load_snapshot[:owner_contact]).to include(
name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' # name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee'
) # )
end # end
it('has a snapshot with tech contacts') do # it('has a snapshot with tech contacts') do
expect(DomainVersion.last.load_snapshot[:tech_contacts].first).to include( # expect(DomainVersion.last.load_snapshot[:tech_contacts].first).to include(
name: 'tech_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'tech1@v.ee' # name: 'tech_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'tech1@v.ee'
) # )
end # end
end # end
context 'when domain is deleted' do # context 'when domain is deleted' do
it 'creates a version' do # it 'creates a version' do
expect(DomainVersion.count).to eq(1) # expect(DomainVersion.count).to eq(1)
Domain.first.destroy # Domain.first.destroy
expect(DomainVersion.count).to eq(2) # expect(DomainVersion.count).to eq(2)
expect(DomainVersion.last.load_snapshot).to include({ # expect(DomainVersion.last.load_snapshot).to include({
admin_contacts: [], # admin_contacts: [],
# domain: { name: 'version.ee', status: nil }, # # domain: { name: 'version.ee', status: nil },
nameservers: [], # nameservers: [],
tech_contacts: [] # tech_contacts: []
}) # })
expect(DomainVersion.last.load_snapshot[:owner_contact]).to include( # expect(DomainVersion.last.load_snapshot[:owner_contact]).to include(
{ name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' } # { name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' }
) # )
end # end
end # end
context 'when adding child' do # context 'when adding child' do
it 'contact creates a version' do # it 'contact creates a version' do
expect(DomainVersion.count).to eq(1) # expect(DomainVersion.count).to eq(1)
expect(Domain.last.tech_contacts.count).to eq(1) # expect(Domain.last.tech_contacts.count).to eq(1)
Domain.last.tech_contacts << Fabricate(:contact, name: 'tech contact 2', phone: '+371.12345678', # Domain.last.tech_contacts << Fabricate(:contact, name: 'tech contact 2', phone: '+371.12345678',
code: '123', email: 'tech2@v.ee') # code: '123', email: 'tech2@v.ee')
expect(Domain.last.tech_contacts.count).to eq(2) # expect(Domain.last.tech_contacts.count).to eq(2)
expect(DomainVersion.count).to eq(2) # expect(DomainVersion.count).to eq(2)
end # end
it 'nameserver creates a version' do # it 'nameserver creates a version' do
expect(DomainVersion.count).to eq(1) # expect(DomainVersion.count).to eq(1)
expect(Domain.last.nameservers.count).to eq(1) # expect(Domain.last.nameservers.count).to eq(1)
Domain.last.nameservers << Fabricate(:nameserver, hostname: 'ns.server.ee', created_at: Time.now - 20) # Domain.last.nameservers << Fabricate(:nameserver, hostname: 'ns.server.ee', created_at: Time.now - 20)
expect(DomainVersion.count).to eq(2) # expect(DomainVersion.count).to eq(2)
end # end
end # end
context 'when removing child' do # context 'when removing child' do
it('has one domain version before events') { expect(DomainVersion.count).to eq(1) } # it('has one domain version before events') { expect(DomainVersion.count).to eq(1) }
it 'contact creates a version' do # it 'contact creates a version' do
expect(DomainVersion.count).to eq(1) # expect(DomainVersion.count).to eq(1)
DomainContact.last.destroy # DomainContact.last.destroy
expect(Domain.last.valid?).to be(true) # expect(Domain.last.valid?).to be(true)
expect(DomainVersion.count).to eq(2) # expect(DomainVersion.count).to eq(2)
end # end
end # end
context 'when deleting child' do # context 'when deleting child' do
it 'contact creates a version' do # it 'contact creates a version' do
expect(DomainVersion.count).to eq(1) # expect(DomainVersion.count).to eq(1)
Contact.find_by(name: 'tech_contact 1').destroy # Contact.find_by(name: 'tech_contact 1').destroy
expect(DomainVersion.count).to eq(2) # expect(DomainVersion.count).to eq(2)
expect(DomainVersion.last.load_snapshot[:admin_contacts].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:admin_contacts].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include( # expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include(
name: 'admin_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee' # name: 'admin_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee'
) # )
expect(DomainVersion.last.load_snapshot[:domain][:name]).to eq('version.ee') # expect(DomainVersion.last.load_snapshot[:domain][:name]).to eq('version.ee')
expect(DomainVersion.last.load_snapshot[:domain][:status]).to eq(nil) # expect(DomainVersion.last.load_snapshot[:domain][:status]).to eq(nil)
expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1) # expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1)
expect(DomainVersion.last.load_snapshot[:domain][:period_unit]).to eq('y') # expect(DomainVersion.last.load_snapshot[:domain][:period_unit]).to eq('y')
expect(DomainVersion.last.load_snapshot[:domain][:valid_from]).to eq(Time.now.utc.beginning_of_day) # expect(DomainVersion.last.load_snapshot[:domain][:valid_from]).to eq(Time.now.utc.beginning_of_day)
expect(DomainVersion.last.load_snapshot[:domain][:valid_to]).to eq(Time.now.utc.beginning_of_day + 1.year) # expect(DomainVersion.last.load_snapshot[:domain][:valid_to]).to eq(Time.now.utc.beginning_of_day + 1.year)
expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1) # expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1)
expect(DomainVersion.last.load_snapshot[:nameservers].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:nameservers].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:nameservers].first).to include( # expect(DomainVersion.last.load_snapshot[:nameservers].first).to include(
hostname: 'ns.test.ee', ipv4: nil, ipv6: nil # hostname: 'ns.test.ee', ipv4: nil, ipv6: nil
) # )
expect(DomainVersion.last.load_snapshot[:owner_contact]).to include( # expect(DomainVersion.last.load_snapshot[:owner_contact]).to include(
{ name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' } # { name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' }
) # )
expect(DomainVersion.last.load_snapshot[:tech_contacts]).to eq([]) # expect(DomainVersion.last.load_snapshot[:tech_contacts]).to eq([])
end # end
it 'nameserver creates a version' do # it 'nameserver creates a version' do
Domain.last.nameservers << Fabricate(:nameserver, created_at: Time.now - 30) # Domain.last.nameservers << Fabricate(:nameserver, created_at: Time.now - 30)
Domain.last.nameservers.last.destroy # Domain.last.nameservers.last.destroy
expect(DomainVersion.count).to eq(3) # expect(DomainVersion.count).to eq(3)
expect(Domain.last.nameservers.count).to eq(1) # expect(Domain.last.nameservers.count).to eq(1)
expect(DomainVersion.last.load_snapshot[:admin_contacts].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:admin_contacts].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include( # expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include(
name: 'admin_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee' # name: 'admin_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee'
) # )
expect(DomainVersion.last.load_snapshot[:domain][:name]).to eq('version.ee') # expect(DomainVersion.last.load_snapshot[:domain][:name]).to eq('version.ee')
expect(DomainVersion.last.load_snapshot[:domain][:status]).to eq(nil) # expect(DomainVersion.last.load_snapshot[:domain][:status]).to eq(nil)
expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1) # expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1)
expect(DomainVersion.last.load_snapshot[:domain][:period_unit]).to eq('y') # expect(DomainVersion.last.load_snapshot[:domain][:period_unit]).to eq('y')
expect(DomainVersion.last.load_snapshot[:nameservers].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:nameservers].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:nameservers].first).to include( # expect(DomainVersion.last.load_snapshot[:nameservers].first).to include(
hostname: 'ns.test.ee', ipv4: nil, ipv6: nil # hostname: 'ns.test.ee', ipv4: nil, ipv6: nil
) # )
expect(DomainVersion.last.load_snapshot[:owner_contact]).to include( # expect(DomainVersion.last.load_snapshot[:owner_contact]).to include(
{ name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' } # { name: 'owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' }
) # )
expect(DomainVersion.last.load_snapshot[:tech_contacts].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:tech_contacts].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:tech_contacts].first).to include( # expect(DomainVersion.last.load_snapshot[:tech_contacts].first).to include(
name: 'tech_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'tech1@v.ee' # name: 'tech_contact 1', phone: '+372.12345678', ident: '37605030299', email: 'tech1@v.ee'
) # )
end # end
end # end
context 'when editing children' do # context 'when editing children' do
it 'creates a version' do # it 'creates a version' do
expect(DomainVersion.count).to eq(1) # expect(DomainVersion.count).to eq(1)
Contact.find_by(name: 'owner_contact').update_attributes!(name: 'edited owner_contact') # Contact.find_by(name: 'owner_contact').update_attributes!(name: 'edited owner_contact')
expect(DomainVersion.count).to eq(2) # expect(DomainVersion.count).to eq(2)
end # end
it 'creates 3 versions' do # it 'creates 3 versions' do
expect(DomainVersion.count).to eq(1) # expect(DomainVersion.count).to eq(1)
Contact.find_by(name: 'owner_contact').update_attributes!(name: 'edited owner_contact') # Contact.find_by(name: 'owner_contact').update_attributes!(name: 'edited owner_contact')
expect(DomainVersion.count).to eq(2) # expect(DomainVersion.count).to eq(2)
Contact.find_by(name: 'tech_contact 1').update_attributes!(name: 'edited tech_contact') # Contact.find_by(name: 'tech_contact 1').update_attributes!(name: 'edited tech_contact')
expect(DomainVersion.count).to eq(3) # expect(DomainVersion.count).to eq(3)
Contact.find_by(name: 'admin_contact 1').update_attributes!(name: 'edited admin_contact') # Contact.find_by(name: 'admin_contact 1').update_attributes!(name: 'edited admin_contact')
expect(DomainVersion.count).to eq(4) # expect(DomainVersion.count).to eq(4)
expect(DomainVersion.last.load_snapshot[:admin_contacts].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:admin_contacts].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include( # expect(DomainVersion.last.load_snapshot[:admin_contacts].first).to include(
name: 'edited admin_contact', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee' # name: 'edited admin_contact', phone: '+372.12345678', ident: '37605030299', email: 'admin1@v.ee'
) # )
expect(DomainVersion.last.load_snapshot[:domain][:name]).to eq('version.ee') # expect(DomainVersion.last.load_snapshot[:domain][:name]).to eq('version.ee')
expect(DomainVersion.last.load_snapshot[:domain][:status]).to eq(nil) # expect(DomainVersion.last.load_snapshot[:domain][:status]).to eq(nil)
expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1) # expect(DomainVersion.last.load_snapshot[:domain][:period]).to eq(1)
expect(DomainVersion.last.load_snapshot[:domain][:period_unit]).to eq('y') # expect(DomainVersion.last.load_snapshot[:domain][:period_unit]).to eq('y')
expect(DomainVersion.last.load_snapshot[:nameservers].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:nameservers].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:nameservers].first).to include( # expect(DomainVersion.last.load_snapshot[:nameservers].first).to include(
hostname: 'ns.test.ee', ipv4: nil, ipv6: nil # hostname: 'ns.test.ee', ipv4: nil, ipv6: nil
) # )
expect(DomainVersion.last.load_snapshot[:owner_contact]).to include( # expect(DomainVersion.last.load_snapshot[:owner_contact]).to include(
{ name: 'edited owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' } # { name: 'edited owner_contact', phone: '+372.12345678', ident: '37605030299', email: 'owner1@v.ee' }
) # )
expect(DomainVersion.last.load_snapshot[:tech_contacts].size).to eq(1) # expect(DomainVersion.last.load_snapshot[:tech_contacts].size).to eq(1)
expect(DomainVersion.last.load_snapshot[:tech_contacts].first).to include( # expect(DomainVersion.last.load_snapshot[:tech_contacts].first).to include(
name: 'edited tech_contact', phone: '+372.12345678', ident: '37605030299', email: 'tech1@v.ee' # name: 'edited tech_contact', phone: '+372.12345678', ident: '37605030299', email: 'tech1@v.ee'
) # )
end # end
end # end
end # end
end end

View file

@ -26,6 +26,9 @@ Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
ActiveRecord::Migration.maintain_test_schema! ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config| RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
# If you're not using ActiveRecord, or you'd prefer not to run each of your # If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false # examples within a transaction, remove the following line or assign false
# instead of true. # instead of true.