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
include Versions # version/address_version.rb
LOCAL_TYPE_SHORT = 'loc'
INTERNATIONAL_TYPE_SHORT = 'int'
LOCAL_TYPE = 'LocalAddress'
@ -10,8 +12,6 @@ class Address < ActiveRecord::Base
belongs_to :contact
belongs_to :country
has_paper_trail class_name: 'AddressVersion'
class << self
# def validate_postal_info_types(parsed_frame)
# 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
extend ActiveSupport::Concern
included do
after_save :delayed_whois_update
end
# TODO: remove old
# included do
# after_save :delayed_whois_update
# end
private
# private
def delayed_whois_update
name = domain_name
return unless name
body = snapshot
delay.update_private_whois(name, body)
delay.update_public_whois(name, body)
end
# def delayed_whois_update
# name = domain_name
# return unless name
# body = snapshot
# delay.update_private_whois(name, body)
# delay.update_public_whois(name, body)
# end
def update_private_whois(domain_name, body)
wd = Whois::PublicDomain.find_or_initialize_by(name: domain_name)
wd.body = body
wd.save!
end
# def update_private_whois(domain_name, body)
# wd = Whois::PublicDomain.find_or_initialize_by(name: domain_name)
# wd.body = body
# wd.save!
# end
def update_public_whois(domain_name, body)
wd = Whois::PrivateDomain.find_or_initialize_by(name: domain_name)
wd.body = body
wd.save!
end
# def update_public_whois(domain_name, body)
# wd = Whois::PrivateDomain.find_or_initialize_by(name: domain_name)
# wd.body = body
# wd.save!
# end
def domain_name
name = reify.try(:name)
name = load_snapshot[:domain][:name] if event == 'create'
return name if name
end
# def domain_name
# name = reify.try(:name)
# name = load_snapshot[:domain][:name] if event == 'create'
# return name if name
# 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
extend ActiveSupport::Concern
module ClassMethods
def registrar_events(id)
registrar = Registrar.find(id)
return [] unless registrar
@events = []
registrar.users.each { |user| @events << user_events(user.id) }
registrar.api_users.each { |user| @events << epp_user_events(user.id) }
@events
end
# TODO: remove old
# module ClassMethods
# def registrar_events(id)
# registrar = Registrar.find(id)
# return [] unless registrar
# @events = []
# registrar.users.each { |user| @events << user_events(user.id) }
# registrar.epp_users.each { |user| @events << epp_user_events(user.id) }
# @events
# end
def user_events(id)
where(whodunnit: id.to_s)
end
# def user_events(id)
# where(whodunnit: id.to_s)
# end
def epp_user_events(id)
where(whodunnit: "#{id}-ApiUser")
end
end
# def epp_user_events(id)
# where(whodunnit: "#{id}-EppUser")
# 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
# TODO: Foreign contact will get email with activation link/username/temp password
include Versions # version/contact_version.rb
include EppErrors
has_one :address, dependent: :destroy
@ -34,17 +33,16 @@ class Contact < ActiveRecord::Base
delegate :zip, to: :address # , prefix: true
# callbacks
# TODO: remove old
# after_commit :domains_snapshot
after_update :domains_snapshot
after_destroy :domains_snapshot
# after_update :domains_snapshot
# after_destroy :domains_snapshot
before_create :generate_code
before_create :generate_auth_info
after_create :ensure_disclosure
# scopes
scope :current_registrars, ->(id) { where(registrar_id: id) }
# archiving
has_paper_trail class_name: 'ContactVersion'
IDENT_TYPE_ICO = 'ico'
IDENT_TYPES = [
@ -72,13 +70,14 @@ class Contact < ActiveRecord::Base
create_disclosure! unless disclosure
end
def domains_snapshot
(domains + domains_owned).uniq.each do |domain|
next unless domain.is_a?(Domain)
# next if domain.versions.last == domain.create_snapshot
domain.create_version # Method from paper_trail
end
end
# TODO: remove old
# def domains_snapshot
# (domains + domains_owned).uniq.each do |domain|
# next unless domain.is_a?(Domain)
# # next if domain.versions.last == domain.create_snapshot
# domain.create_version # Method from paper_trail
# end
# end
def juridical?
ident_type == IDENT_TYPE_ICO
@ -148,16 +147,17 @@ class Contact < ActiveRecord::Base
name
end
# TODO: remove old
# for archiving
def snapshot
{
name: name,
phone: phone,
code: code,
ident: ident,
email: email
}
end
# def snapshot
# {
# name: name,
# phone: phone,
# code: code,
# ident: ident,
# email: email
# }
# end
class << self
# non-EPP

View file

@ -1,4 +1,5 @@
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: most inputs should be trimmed before validatation, probably some global logic?
paginates_per 10 # just for showoff
@ -17,7 +18,9 @@ class Domain < ActiveRecord::Base
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
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,
reject_if: proc { |attrs| attrs[:hostname].blank? }
@ -102,9 +105,10 @@ class Domain < ActiveRecord::Base
attr_accessor :owner_contact_typeahead, :update_me
# TODO: remove old
# archiving
# 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
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 }
end
def new_version
return false if versions.try(:last).try(:snapshot) == create_snapshot
true
end
# TODO: remove old
# def new_version
# return false if versions.try(:last).try(:snapshot) == create_snapshot
# true
# end
def create_version
return true unless PaperTrail.enabled?
return true unless valid?
touch_with_version if new_version
end
# TODO: remove old
# def create_version
# return true unless PaperTrail.enabled?
# return true unless valid?
# touch_with_version if new_version
# end
def track_nameserver_add(_nameserver)
return true if versions.count == 0
return true unless valid? && new_version
# TODO: remove old
# def track_nameserver_add(_nameserver)
# return true if versions.count == 0
# return true unless valid? && new_version
touch_with_version
end
# touch_with_version
# end
def create_snapshot
oc = owner_contact.snapshot if owner_contact.is_a?(Contact)
{
owner_contact: oc,
tech_contacts: tech_contacts.map(&:snapshot),
admin_contacts: admin_contacts.map(&:snapshot),
nameservers: nameservers.map(&:snapshot),
domain: make_snapshot
}.to_yaml
end
# TODO: remove old
# def create_snapshot
# oc = owner_contact.snapshot if owner_contact.is_a?(Contact)
# {
# owner_contact: oc,
# tech_contacts: tech_contacts.map(&:snapshot),
# admin_contacts: admin_contacts.map(&:snapshot),
# nameservers: nameservers.map(&:snapshot),
# domain: make_snapshot
# }.to_yaml
# end
def make_snapshot
{
name: name,
status: status,
period: period,
period_unit: period_unit,
registrar_id: registrar.try(:id),
valid_to: valid_to,
valid_from: valid_from
}
end
# TODO: remove old
# def make_snapshot
# {
# name: name,
# status: status,
# period: period,
# period_unit: period_unit,
# registrar_id: registrar.try(:id),
# valid_to: valid_to,
# valid_from: valid_from
# }
# end
def name=(value)
value.strip!

View file

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

View file

@ -1,4 +1,5 @@
class DomainStatus < ActiveRecord::Base
include Versions # version/domain_status_version.rb
include EppErrors
belongs_to :domain
@ -50,9 +51,6 @@ class DomainStatus < ActiveRecord::Base
SERVER_ADMIN_CHANGE_PROHIBITED, SERVER_TECH_CHANGE_PROHIBITED
]
# archiving
has_paper_trail class_name: 'DomainStatusVersion'
def epp_code_map
{
'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
include Versions # version/nameserver_version.rb
include EppErrors
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 }
# rubocop: enable Metrics/LineLength
# archiving
has_paper_trail class_name: 'NameserverVersion'
after_destroy :domain_version
# TODO: remove old
# after_destroy :domain_version
before_validation :normalize_attributes
@ -34,13 +34,14 @@ class Nameserver < ActiveRecord::Base
}
end
def snapshot
{
hostname: hostname,
ipv4: ipv4,
ipv6: ipv6
}
end
# TODO: remove old
# def snapshot
# {
# hostname: hostname,
# ipv4: ipv4,
# ipv6: ipv6
# }
# end
def normalize_attributes
self.hostname = hostname.try(:strip).try(:downcase)
@ -48,9 +49,10 @@ class Nameserver < ActiveRecord::Base
self.ipv6 = ipv6.try(:strip).try(:upcase)
end
def domain_version
domain.create_version if domain
end
# TODO: remove old
# def domain_version
# domain.create_version if domain
# end
def to_s
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
include LogTable
include UserEvents
# self.table_name = :post_versions
# self.sequence_name = :post_version_id_seq
scope :deleted, -> { where(event: 'destroy') }
self.table_name = :contact_versions
self.sequence_name = :contact_version_id_seq
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

@ -29,6 +29,9 @@ module Registry
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
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
# `after_rollback`/`after_commit` callbacks and only printed them to the logs.

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
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|
t.integer "contact_id"
t.integer "country_id"
t.string "city", limit: 255
t.string "street", limit: 255
t.string "zip", limit: 255
t.string "city"
t.string "street"
t.string "zip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "street2", limit: 255
t.string "street3", limit: 255
t.string "street2"
t.string "street3"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "api_users", force: :cascade do |t|
@ -68,63 +59,60 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.boolean "name"
t.boolean "org_name"
t.boolean "address"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "contact_statuses", force: :cascade do |t|
t.string "value", limit: 255
t.string "description", limit: 255
t.string "value"
t.string "description"
t.integer "contact_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
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|
t.string "code", limit: 255
t.string "type", limit: 255
t.string "reg_no", limit: 255
t.string "phone", limit: 255
t.string "email", limit: 255
t.string "fax", limit: 255
t.string "code"
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", limit: 255
t.string "ident_type", limit: 255
t.string "ident"
t.string "ident_type"
t.integer "created_by_id"
t.integer "updated_by_id"
t.string "auth_info", limit: 255
t.string "name", limit: 255
t.string "org_name", limit: 255
t.string "auth_info"
t.string "name"
t.string "org_name"
t.integer "registrar_id"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "countries", force: :cascade do |t|
t.string "iso", limit: 255
t.string "name", limit: 255
t.string "iso"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false
t.text "handler", null: false
t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false
t.text "handler", null: false
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by", limit: 255
t.string "queue", limit: 255
t.string "locked_by"
t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
end
@ -133,10 +121,10 @@ ActiveRecord::Schema.define(version: 20150130085458) do
create_table "delegation_signers", force: :cascade do |t|
t.integer "domain_id"
t.string "key_tag", limit: 255
t.string "key_tag"
t.integer "alg"
t.integer "digest_type"
t.string "digest", limit: 255
t.string "digest"
end
create_table "dnskeys", force: :cascade do |t|
@ -146,41 +134,36 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.integer "alg"
t.text "public_key"
t.integer "delegation_signer_id"
t.string "ds_key_tag", limit: 255
t.string "ds_key_tag"
t.integer "ds_alg"
t.integer "ds_digest_type"
t.string "ds_digest", limit: 255
t.string "ds_digest"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "domain_contacts", force: :cascade do |t|
t.integer "contact_id"
t.integer "domain_id"
t.string "contact_type", limit: 255
t.string "contact_type"
t.datetime "created_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
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|
t.integer "domain_id"
t.string "description", limit: 255
t.string "value", limit: 255
t.string "description"
t.string "value"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "domain_transfers", force: :cascade do |t|
t.integer "domain_id"
t.string "status", limit: 255
t.string "status"
t.datetime "transfer_requested_at"
t.datetime "transferred_at"
t.integer "transfer_from_id"
@ -188,39 +171,31 @@ ActiveRecord::Schema.define(version: 20150130085458) do
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "wait_until"
t.integer "creator_id"
t.integer "updater_id"
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|
t.string "name", limit: 255
t.string "name"
t.integer "registrar_id"
t.datetime "registered_at"
t.string "status", limit: 255
t.string "status"
t.datetime "valid_from"
t.datetime "valid_to"
t.integer "owner_contact_id"
t.string "auth_info", limit: 255
t.string "auth_info"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name_dirty", limit: 255
t.string "name_puny", limit: 255
t.string "name_dirty"
t.string "name_puny"
t.integer "period"
t.string "period_unit", limit: 1
t.integer "creator_id"
t.integer "updater_id"
end
create_table "epp_sessions", force: :cascade do |t|
t.string "session_id", limit: 255
t.string "session_id"
t.text "data"
t.datetime "created_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", ["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|
t.integer "domain_id"
t.datetime "pa_date"
t.string "key_data_flags", limit: 255
t.string "key_data_protocol", limit: 255
t.string "key_data_alg", limit: 255
t.string "key_data_flags"
t.string "key_data_protocol"
t.string "key_data_alg"
t.text "key_data_public_key"
t.string "auth_info_pw", limit: 255
t.string "expiry_relative", limit: 255
t.string "auth_info_pw"
t.string "expiry_relative"
t.datetime "expiry_absolute"
t.integer "requester_id"
t.integer "accepter_id"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "legal_documents", force: :cascade do |t|
t.string "document_type", limit: 255
t.string "document_type"
t.text "body"
t.integer "documentable_id"
t.string "documentable_type", limit: 255
t.string "documentable_type"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
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|
t.integer "registrar_id"
t.string "body", limit: 255
t.string "attached_obj_type", limit: 255
t.string "attached_obj_id", limit: 255
t.string "body"
t.string "attached_obj_type"
t.string "attached_obj_id"
t.boolean "queued"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
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|
t.string "hostname", limit: 255
t.string "ipv4", limit: 255
t.string "hostname"
t.string "ipv4"
t.datetime "created_at"
t.datetime "updated_at"
t.string "ipv6", limit: 255
t.string "ipv6"
t.integer "domain_id"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "registrars", force: :cascade do |t|
t.string "name", limit: 255
t.string "reg_no", limit: 255
t.string "vat_no", limit: 255
t.string "address", limit: 255
t.string "name"
t.string "reg_no"
t.string "vat_no"
t.string "address"
t.integer "country_id"
t.string "billing_address", limit: 255
t.string "billing_address"
t.datetime "created_at"
t.datetime "updated_at"
<<<<<<< HEAD
t.string "phone"
t.string "email"
t.string "billing_email"
=======
t.integer "creator_id"
t.integer "updater_id"
>>>>>>> Added pure PaperTrail stack
end
create_table "reserved_domains", force: :cascade do |t|
t.string "name", limit: 255
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end
create_table "settings", force: :cascade do |t|
t.string "var", limit: 255, null: false
t.string "var", null: false
t.text "value"
t.integer "thing_id"
t.string "thing_type", limit: 30
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end
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|
t.string "username", limit: 255
t.string "password", limit: 255
t.string "username"
t.string "password"
t.datetime "created_at"
t.datetime "updated_at"
t.string "email", limit: 255
t.integer "sign_in_count", default: 0, null: false
t.string "email"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.string "identity_code", limit: 255
t.string "identity_code"
t.integer "country_id"
t.string "roles", array: true
t.string "roles", array: true
t.integer "creator_id"
t.integer "updater_id"
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|
t.string "origin", limit: 255
t.string "origin"
t.integer "ttl"
t.integer "refresh"
t.integer "retry"
t.integer "expire"
t.integer "minimum_ttl"
t.string "email", limit: 255
t.string "master_nameserver", limit: 255
t.string "email"
t.string "master_nameserver"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "creator_id"
t.integer "updater_id"
end
end

View file

@ -8,6 +8,16 @@ describe Contact do
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
before :all do
@contact = Contact.new
@ -41,6 +51,10 @@ describe Contact do
@contact.valid?
@contact.errors[:phone].should == ["Phone nr is invalid"]
end
it 'should not have any versions' do
@contact.versions.should == []
end
end
context 'with valid attributes' do
@ -57,6 +71,15 @@ describe Contact do
@contact.relations_with_domain?.should == false
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
# @contact.ident_type = 'ico'
# @contact.ident = '1234'

View file

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