1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/spec/models/animal_spec.rb
2016-03-05 17:07:32 -05:00

36 lines
1 KiB
Ruby

require "rails_helper"
describe Animal, type: :model do
it { is_expected.to be_versioned }
describe "STI", versioning: true do
it { expect(Animal.inheritance_column).to eq("species") }
describe "updates to the `inheritance_column`" do
subject { Cat.create!(name: "Leo") }
it "should be allowed" do
subject.update_attributes(name: "Spike", species: "Dog")
dog = Animal.find(subject.id)
expect(dog).to be_instance_of(Dog)
end
end
context "with callback-methods" do
context "when only has_paper_trail set in super class" do
let(:callback_cat) { Cat.create(name: "Markus") }
it "trails all events" do
callback_cat.update_attributes(name: "Billie")
callback_cat.destroy
expect(callback_cat.versions.collect(&:event)).to eq %w(create update destroy)
end
it "does not break reify" do
callback_cat.destroy
expect { callback_cat.versions.last.reify }.not_to raise_error
end
end
end
end
end