Skip to content

Commit

Permalink
Add paper_trail to Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
aepyornis committed Mar 28, 2017
1 parent 6e8f3fa commit dd1f3bb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/models/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Entity < ActiveRecord::Base
# self.default_timezone = :local
# self.skip_time_zone_conversion_for_attributes = [:created_at, :updated_at]

has_paper_trail :ignore => [:link_count, :delta]

has_many :aliases, inverse_of: :entity, dependent: :destroy
has_many :images, inverse_of: :entity, dependent: :destroy
has_many :list_entities, inverse_of: :entity, dependent: :destroy
Expand Down
20 changes: 20 additions & 0 deletions spec/models/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,24 @@ def without_ids(array)
end
end
end # end Extension Attributes Functions

describe 'Using paper_trail for versision' do
with_versioning do
it 'creates version after updating name' do
human = create(:person)
expect(human.versions.size).to eq 1
expect { human.update(name: 'Emiliano Zapata') }.to change { human.versions.size }.by(1)
end

it 'does not create a version after changing updated_at' do
human = create(:person)
expect { human.touch }.not_to change { human.versions.size }
end

it 'does not create a version after changing link_count' do
human = create(:person)
expect { human.update(link_count: 10) }.not_to change { human.versions.size }
end
end
end
end
6 changes: 3 additions & 3 deletions spec/models/extension_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

describe ExtensionDefinition, type: :model do
it { should have_many(:extension_records) }
it { should have_many(:entities) }
it { should have_many(:entities) }

it 'should have ID constants' do
expect(ExtensionDefinition::PERSON_ID).to eql 1
expect(ExtensionDefinition::ORG_ID).to eql 2
end

describe 'person types & org types' do
it 'returns all person types' do
expect(ExtensionDefinition).to receive(:where).with(parent_id: 1).once.and_return(double(order: {name: :asc}))
Expand Down
6 changes: 6 additions & 0 deletions spec/models/extension_record_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rails_helper'

describe ExtensionRecord, type: :model do
it { should belong_to(:entity) }
it { should belong_to(:extension_definition) }
end

0 comments on commit dd1f3bb

Please sign in to comment.