mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 03:30:33 +02:00
Added creator and updator
This commit is contained in:
parent
52d662a8cb
commit
50673f6dda
5 changed files with 106 additions and 48 deletions
|
@ -1,10 +1,22 @@
|
||||||
|
# Papertrail concerns is mainly tested at country spec
|
||||||
module Versions
|
module Versions
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
has_paper_trail class_name: "#{model_name}Version"
|
has_paper_trail class_name: "#{model_name}Version"
|
||||||
end
|
|
||||||
|
|
||||||
class_methods do
|
before_create :add_creator
|
||||||
|
before_create :add_updator
|
||||||
|
before_update :add_updator
|
||||||
|
|
||||||
|
def add_creator
|
||||||
|
self.creator_str = ::PaperTrail.whodunnit
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_updator
|
||||||
|
self.updator_str = ::PaperTrail.whodunnit
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
15
db/migrate/20150129144652_add_creator_and_updater.rb
Normal file
15
db/migrate/20150129144652_add_creator_and_updater.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class AddCreatorAndUpdater < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
%w(address contact_disclosure contact contact_status country dnskey
|
||||||
|
domain_contact domain domain_status domain_transfer api_user keyrelay
|
||||||
|
legal_document message nameserver registrar
|
||||||
|
reserved_domain setting user zonefile_setting
|
||||||
|
).each do |name|
|
||||||
|
table_name = name.tableize
|
||||||
|
remove_column table_name, :creator_id, :string
|
||||||
|
remove_column table_name, :updater_id, :string
|
||||||
|
add_column table_name, :creator_str, :string
|
||||||
|
add_column table_name, :updator_str, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
85
db/schema.rb
85
db/schema.rb
|
@ -11,7 +11,8 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150129134601) do
|
ActiveRecord::Schema.define(version: 20150129144652) 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"
|
||||||
|
|
||||||
|
@ -25,8 +26,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "street2"
|
t.string "street2"
|
||||||
t.string "street3"
|
t.string "street3"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "api_users", force: :cascade do |t|
|
create_table "api_users", force: :cascade do |t|
|
||||||
|
@ -38,8 +39,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.text "crt"
|
t.text "crt"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "cached_nameservers", id: false, force: :cascade do |t|
|
create_table "cached_nameservers", id: false, force: :cascade do |t|
|
||||||
|
@ -60,8 +61,8 @@ ActiveRecord::Schema.define(version: 20150129134601) 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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contact_statuses", force: :cascade do |t|
|
create_table "contact_statuses", force: :cascade do |t|
|
||||||
|
@ -70,8 +71,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contacts", force: :cascade do |t|
|
create_table "contacts", force: :cascade do |t|
|
||||||
|
@ -91,8 +92,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "org_name"
|
t.string "org_name"
|
||||||
t.integer "registrar_id"
|
t.integer "registrar_id"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "countries", force: :cascade do |t|
|
create_table "countries", force: :cascade do |t|
|
||||||
|
@ -100,8 +101,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "delayed_jobs", force: :cascade do |t|
|
create_table "delayed_jobs", force: :cascade do |t|
|
||||||
|
@ -143,8 +144,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.integer "ds_alg"
|
t.integer "ds_alg"
|
||||||
t.integer "ds_digest_type"
|
t.integer "ds_digest_type"
|
||||||
t.string "ds_digest"
|
t.string "ds_digest"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domain_contacts", force: :cascade do |t|
|
create_table "domain_contacts", force: :cascade do |t|
|
||||||
|
@ -154,16 +155,16 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "contact_code_cache"
|
t.string "contact_code_cache"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
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"
|
t.string "description"
|
||||||
t.string "value"
|
t.string "value"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domain_transfers", force: :cascade do |t|
|
create_table "domain_transfers", force: :cascade do |t|
|
||||||
|
@ -176,8 +177,8 @@ ActiveRecord::Schema.define(version: 20150129134601) 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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "domains", force: :cascade do |t|
|
create_table "domains", force: :cascade do |t|
|
||||||
|
@ -195,8 +196,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.string "name_puny"
|
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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "epp_sessions", force: :cascade do |t|
|
create_table "epp_sessions", force: :cascade do |t|
|
||||||
|
@ -236,8 +237,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "legal_documents", force: :cascade do |t|
|
create_table "legal_documents", force: :cascade do |t|
|
||||||
|
@ -247,8 +248,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.string "documentable_type"
|
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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "log_addresses", force: :cascade do |t|
|
create_table "log_addresses", force: :cascade do |t|
|
||||||
|
@ -519,8 +520,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "nameservers", force: :cascade do |t|
|
create_table "nameservers", force: :cascade do |t|
|
||||||
|
@ -530,8 +531,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "ipv6"
|
t.string "ipv6"
|
||||||
t.integer "domain_id"
|
t.integer "domain_id"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "registrars", force: :cascade do |t|
|
create_table "registrars", force: :cascade do |t|
|
||||||
|
@ -548,25 +549,27 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.string "billing_email"
|
t.string "billing_email"
|
||||||
t.integer "creator_id"
|
t.integer "creator_id"
|
||||||
t.integer "updater_id"
|
t.integer "updater_id"
|
||||||
|
t.string "creator_str"
|
||||||
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "reserved_domains", force: :cascade do |t|
|
create_table "reserved_domains", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.integer "creator_id"
|
t.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "settings", force: :cascade do |t|
|
create_table "settings", force: :cascade do |t|
|
||||||
t.string "var", 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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
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
|
||||||
|
@ -585,8 +588,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.string "identity_code"
|
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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "versions", force: :cascade do |t|
|
create_table "versions", force: :cascade do |t|
|
||||||
|
@ -604,8 +607,8 @@ ActiveRecord::Schema.define(version: 20150129134601) do
|
||||||
t.string "master_nameserver"
|
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.string "creator_str"
|
||||||
t.integer "updater_id"
|
t.string "updator_str"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Country do
|
describe Country do
|
||||||
before :all do
|
|
||||||
@epp_user = Fabricate(:country)
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'about class' do
|
context 'about class' do
|
||||||
it 'should have versioning enabled?' do
|
it 'should have versioning enabled?' do
|
||||||
Country.paper_trail_enabled_for_model?.should == true
|
Country.paper_trail_enabled_for_model?.should == true
|
||||||
|
@ -30,6 +26,14 @@ describe Country do
|
||||||
it 'should not have any versions' do
|
it 'should not have any versions' do
|
||||||
@country.versions.should == []
|
@country.versions.should == []
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not have any creator' do
|
||||||
|
@country.creator_str.should == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not have any updater' do
|
||||||
|
@country.updator_str.should == nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with valid attributes' do
|
context 'with valid attributes' do
|
||||||
|
@ -42,7 +46,7 @@ describe Country do
|
||||||
@country.errors.full_messages.should match_array([])
|
@country.errors.full_messages.should match_array([])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not have one version' do
|
it 'should not have a version' do
|
||||||
with_versioning do
|
with_versioning do
|
||||||
@country.versions.should == []
|
@country.versions.should == []
|
||||||
@country.name = 'New name'
|
@country.name = 'New name'
|
||||||
|
@ -50,5 +54,28 @@ describe Country do
|
||||||
@country.versions.size.should == 1
|
@country.versions.size.should == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should have creator' do
|
||||||
|
PaperTrail.whodunnit = 'test-user'
|
||||||
|
|
||||||
|
with_versioning do
|
||||||
|
@country = Fabricate(:country)
|
||||||
|
@country.name = 'Updated name'
|
||||||
|
@country.save
|
||||||
|
@country.creator_str.should == 'test-user'
|
||||||
|
@country.updator_str.should == 'test-user'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should have creator' do
|
||||||
|
PaperTrail.whodunnit = 'test-user-2'
|
||||||
|
|
||||||
|
with_versioning do
|
||||||
|
@country.name = 'Updated name'
|
||||||
|
@country.save
|
||||||
|
@country.updator_str.should == 'test-user-2'
|
||||||
|
@country.creator_str.should == nil # Factory does not have it
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ require 'rspec/rails'
|
||||||
require 'shoulda/matchers'
|
require 'shoulda/matchers'
|
||||||
require 'capybara/poltergeist'
|
require 'capybara/poltergeist'
|
||||||
require 'paper_trail/frameworks/rspec'
|
require 'paper_trail/frameworks/rspec'
|
||||||
|
PaperTrail.whodunnit = 'autotest'
|
||||||
|
|
||||||
if ENV['ROBOT']
|
if ENV['ROBOT']
|
||||||
require 'simplecov'
|
require 'simplecov'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue