Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update paper trail gem #1094

Merged
merged 4 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ gem 'figaro', '1.1.1'
gem 'pg', '0.19.0'
gem 'ransack', '1.5.1' # for searching
gem 'validates_email_format_of', '1.6.3' # validates email against RFC 2822 and RFC 3696

# with polymorphic fix
gem 'paper_trail',
github: 'airblade/paper_trail',
ref: 'a453811226ec4ea59753ba6b827e390ced2fc140'
# NB! if this gets upgraded, ensure Setting.reload_settings! still works correctly
gem 'paper_trail', '~> 4.0'
gem 'rails-settings-cached', '0.4.1' # for settings

# html-xml
Expand Down
19 changes: 7 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
GIT
remote: https://github.com/airblade/paper_trail.git
revision: a453811226ec4ea59753ba6b827e390ced2fc140
ref: a453811226ec4ea59753ba6b827e390ced2fc140
specs:
paper_trail (4.0.0.beta3)
activerecord (>= 3.0, < 6.0)
activesupport (>= 3.0, < 6.0)
request_store (~> 1.1.0)

GIT
remote: https://github.com/internetee/company_register.git
revision: da7130542304fc543c90d54cd037d019a777c526
Expand Down Expand Up @@ -266,6 +256,10 @@ GEM
nori (2.6.0)
open4 (1.3.4)
orm_adapter (0.5.0)
paper_trail (4.2.0)
activerecord (>= 3.0, < 6.0)
activesupport (>= 3.0, < 6.0)
request_store (~> 1.1)
pdfkit (0.6.2)
pg (0.19.0)
polyamorous (1.3.1)
Expand Down Expand Up @@ -323,7 +317,8 @@ GEM
i18n
polyamorous (~> 1.1)
rdoc (4.3.0)
request_store (1.1.0)
request_store (1.4.1)
rack (>= 1.4)
responders (2.4.1)
actionpack (>= 4.2.0, < 6.0)
railties (>= 4.2.0, < 6.0)
Expand Down Expand Up @@ -476,7 +471,7 @@ DEPENDENCIES
mina (= 0.3.1)
money-rails
nokogiri
paper_trail!
paper_trail (~> 4.0)
pdfkit (= 0.6.2)
pg (= 0.19.0)
pry (= 0.10.1)
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20190302091059_restore_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class RestoreVersions < ActiveRecord::Migration
def change
drop_table :versions

create_table :versions do |t|
t.string :item_type, :null => false
t.integer :item_id, :null => false
t.string :event, :null => false
t.string :whodunnit
t.text :object
t.datetime :created_at
end
add_index :versions, [:item_type, :item_id]
end
end
5 changes: 5 additions & 0 deletions db/migrate/20190302111152_add_object_changes_to_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddObjectChangesToVersions < ActiveRecord::Migration
def change
add_column :versions, :object_changes, :jsonb
end
end
19 changes: 18 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,13 @@ ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;

CREATE TABLE public.versions (
id integer NOT NULL,
depricated_table_but_somehow_paper_trail_tests_fails_without_it text
item_type character varying NOT NULL,
item_id integer NOT NULL,
event character varying NOT NULL,
whodunnit character varying,
object text,
created_at timestamp without time zone,
object_changes jsonb
);


Expand Down Expand Up @@ -3980,6 +3986,13 @@ CREATE INDEX index_users_on_identity_code ON public.users USING btree (identity_
CREATE INDEX index_users_on_registrar_id ON public.users USING btree (registrar_id);


--
-- Name: index_versions_on_item_type_and_item_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--

CREATE INDEX index_versions_on_item_type_and_item_id ON public.versions USING btree (item_type, item_id);


--
-- Name: index_whois_records_on_domain_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
Expand Down Expand Up @@ -4927,6 +4940,10 @@ INSERT INTO schema_migrations (version) VALUES ('20190102144032');

INSERT INTO schema_migrations (version) VALUES ('20190209150026');

INSERT INTO schema_migrations (version) VALUES ('20190302091059');

INSERT INTO schema_migrations (version) VALUES ('20190302111152');

INSERT INTO schema_migrations (version) VALUES ('20190311111718');

INSERT INTO schema_migrations (version) VALUES ('20190312211614');
Expand Down
7 changes: 0 additions & 7 deletions lib/gem_ext/paper_trail.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# the following line is required for PaperTrail >= 4.0.0 with Rails
PaperTrail::Rails::Engine.eager_load!

PaperTrail::Version.module_eval do
self.abstract_class = true
end

# Store console and rake changes in versions
if defined?(::Rails::Console)
PaperTrail.whodunnit = "console-#{`whoami`.strip}"
Expand Down
8 changes: 0 additions & 8 deletions spec/models/account_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
require 'rails_helper'

RSpec.describe Account do
it 'has versions' do
with_versioning do
price = build(:account)
price.save!
expect(price.versions.size).to be(1)
end
end

describe 'registrar validation', db: false do
subject(:account) { described_class.new }

Expand Down
10 changes: 0 additions & 10 deletions spec/models/admin_user_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
require 'rails_helper'

RSpec.describe AdminUser do
context 'with invalid attribute' do
before do
@admin_user = described_class.new
end

it 'should not have any versions' do
@admin_user.versions.should == []
end
end

context 'with valid attributes' do
before do
@admin_user = create(:admin_user)
Expand Down
14 changes: 0 additions & 14 deletions spec/models/api_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
])
end

it 'should not have any versions' do
@api_user.versions.should == []
end

it 'should be active by default' do
@api_user.active.should == true
end
Expand All @@ -41,16 +37,6 @@
@api_user.valid?
@api_user.errors.full_messages.should match_array([])
end

it 'should have one version' do
with_versioning do
@api_user.versions.should == []
@api_user.username = 'newusername'
@api_user.save
@api_user.errors.full_messages.should match_array([])
@api_user.versions.size.should == 1
end
end
end

describe '::min_password_length', db: false do
Expand Down
24 changes: 0 additions & 24 deletions spec/models/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@
create(:zone, origin: 'ee')
end

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 :example do
@contact = Contact.new
Expand All @@ -28,10 +18,6 @@
@contact.updator.should == nil
end

it 'should not have any versions' do
@contact.versions.should == []
end

it 'should not accept long code' do
@contact.code = 'verylongcode' * 100
@contact.valid?
Expand Down Expand Up @@ -66,16 +52,6 @@
@contact = create(:contact)
end

it 'should have one version' do
with_versioning do
@contact.versions.reload.should == []
@contact.name = 'New name'
@contact.save
@contact.errors.full_messages.should match_array([])
@contact.versions.size.should == 1
end
end

it 'should not overwrite code' do
old_code = @contact.code
@contact.code = 'CID:REG1:should-not-overwrite-old-code-12345'
Expand Down
13 changes: 0 additions & 13 deletions spec/models/dnskey_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
@dnskey.errors.full_messages.should match_array([
])
end

it 'should not have any versions' do
@dnskey.versions.should == []
end
end

context 'with valid attributes' do
Expand Down Expand Up @@ -66,15 +62,6 @@
@dnskey.errors.full_messages.should match_array([])
end

# TODO: figure out why not working
# it 'should have one version' do
# with_versioning do
# @dnskey.versions.should == []
# @dnskey.touch_with_version
# @dnskey.versions.size.should == 1
# end
# end

it 'generates correct DS digest and DS key tag for ria.ee' do
d = create(:domain, name: 'ria.ee', dnskeys: [@dnskey])
dk = d.dnskeys.last
Expand Down
34 changes: 0 additions & 34 deletions spec/models/domain_contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@
it 'should have Tech name' do
@domain_contact.name.should == 'Tech'
end

it 'should have one version' do
@domain_contact = create(:domain_contact)

with_versioning do
@domain_contact.versions.reload.should == []
@domain_contact.contact = create(:contact)
@domain_contact.save!
@domain_contact.errors.full_messages.should match_array([])
@domain_contact.versions.size.should == 1
end
end
end

context 'with valid attributes with tech domain contact' do
Expand All @@ -82,18 +70,6 @@
it 'should have Tech name' do
@domain_contact.name.should == 'Tech'
end

it 'should have one version' do
@domain_contact = create(:domain_contact)

with_versioning do
@domain_contact.versions.reload.should == []
@domain_contact.contact = create(:contact)
@domain_contact.save!
@domain_contact.errors.full_messages.should match_array([])
@domain_contact.versions.size.should == 1
end
end
end

context 'with valid attributes with admin domain contact' do
Expand All @@ -115,15 +91,5 @@
it 'should have Tech name' do
@domain_contact.name.should == 'Admin'
end

it 'should have one version' do
with_versioning do
@domain_contact.versions.reload.should == []
@domain_contact.contact = create(:contact)
@domain_contact.save
@domain_contact.errors.full_messages.should match_array([])
@domain_contact.versions.size.should == 1
end
end
end
end
19 changes: 0 additions & 19 deletions spec/models/domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
@domain = Domain.new
end

it 'should not have any versions' do
@domain.versions.should == []
end

it 'should not have whois body' do
@domain.whois_record.should == nil
end
Expand Down Expand Up @@ -489,21 +485,6 @@
expect(d.statuses.count).to eq(1)
expect(d.statuses.first).to eq(DomainStatus::CLIENT_DELETE_PROHIBITED)
end

with_versioning do
context 'when saved' do
before(:each) do
domain = create(:domain, nameservers_attributes: [attributes_for(:nameserver),
attributes_for(:nameserver)])
end

it 'creates domain version' do
expect(DomainVersion.count).to eq(1)
expect(ContactVersion.count).to eq(3)
expect(NameserverVersion.count).to eq(2)
end
end
end
end

RSpec.describe Domain do
Expand Down
14 changes: 0 additions & 14 deletions spec/models/keyrelay_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
"Only one parameter allowed: relative or absolute"
])
end

it 'should not have any versions' do
@keyrelay.versions.should == []
end
end

context 'with valid attributes' do
Expand All @@ -63,16 +59,6 @@
@keyrelay.errors.full_messages.should match_array([])
end

it 'should have one version' do
with_versioning do
@keyrelay.versions.should == []
@keyrelay.auth_info_pw = 'newpw'
@keyrelay.save
@keyrelay.errors.full_messages.should match_array([])
@keyrelay.versions.size.should == 1
end
end

it 'is in pending status' do
@keyrelay.status.should == 'pending'
end
Expand Down
Loading