2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-04 18:27:41 -04:00
|
|
|
require "spec_helper"
|
|
|
|
require_dependency "on/update"
|
|
|
|
|
|
|
|
module On
|
|
|
|
RSpec.describe Update, type: :model, versioning: true do
|
|
|
|
describe "#versions" do
|
|
|
|
it "only creates one version record, for the update event" do
|
|
|
|
record = described_class.create(name: "Alice")
|
2018-12-04 16:10:35 -05:00
|
|
|
record.update(name: "blah")
|
2017-07-04 18:27:41 -04:00
|
|
|
record.destroy
|
|
|
|
expect(record.versions.length).to(eq(1))
|
|
|
|
expect(record.versions.last.event).to(eq("update"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-21 13:06:23 -04:00
|
|
|
describe "#paper_trail_event" do
|
2017-07-04 18:27:41 -04:00
|
|
|
it "rembembers the custom event name" do
|
|
|
|
record = described_class.create(name: "Alice")
|
|
|
|
record.paper_trail_event = "banana"
|
2018-12-04 16:10:35 -05:00
|
|
|
record.update(name: "blah")
|
2017-07-04 18:27:41 -04:00
|
|
|
record.destroy
|
|
|
|
expect(record.versions.length).to(eq(1))
|
|
|
|
expect(record.versions.last.event).to(eq("banana"))
|
|
|
|
end
|
|
|
|
end
|
2018-03-16 18:21:45 -04:00
|
|
|
|
|
|
|
describe "#touch" do
|
2018-03-16 18:42:36 -04:00
|
|
|
it "does not create a version" do
|
2018-03-16 18:21:45 -04:00
|
|
|
record = described_class.create(name: "Alice")
|
2018-03-16 18:42:36 -04:00
|
|
|
expect { record.touch }.not_to(
|
|
|
|
change { record.versions.count }
|
|
|
|
)
|
2018-03-16 18:21:45 -04:00
|
|
|
end
|
|
|
|
end
|
2017-07-04 18:27:41 -04:00
|
|
|
end
|
|
|
|
end
|