2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-30 00:58:26 -04:00
|
|
|
require "spec_helper"
|
2017-02-06 12:54:07 -05:00
|
|
|
|
2017-07-04 18:27:41 -04:00
|
|
|
RSpec.describe Document, type: :model, versioning: true do
|
|
|
|
describe "have_a_version_with matcher" do
|
2017-02-06 12:54:07 -05:00
|
|
|
it "works with custom versions association" do
|
|
|
|
document = Document.create!(name: "Foo")
|
2018-12-04 16:10:35 -05:00
|
|
|
document.update!(name: "Bar")
|
2017-02-06 12:54:07 -05:00
|
|
|
expect(document).to have_a_version_with(name: "Foo")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-04 18:27:41 -04:00
|
|
|
describe "#paper_trail.next_version" do
|
|
|
|
it "returns the expected document" do
|
|
|
|
doc = Document.create
|
2018-12-04 16:10:35 -05:00
|
|
|
doc.update(name: "Doc 1")
|
2017-07-04 18:27:41 -04:00
|
|
|
reified = doc.paper_trail_versions.last.reify
|
|
|
|
expect(doc.name).to(eq(reified.paper_trail.next_version.name))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#paper_trail.previous_version" do
|
|
|
|
it "returns the expected document" do
|
|
|
|
doc = Document.create
|
2018-12-04 16:10:35 -05:00
|
|
|
doc.update(name: "Doc 1")
|
|
|
|
doc.update(name: "Doc 2")
|
2017-07-04 18:27:41 -04:00
|
|
|
expect(doc.paper_trail_versions.length).to(eq(3))
|
|
|
|
expect(doc.paper_trail.previous_version.name).to(eq("Doc 1"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#paper_trail_versions" do
|
|
|
|
it "returns the expected version records" do
|
|
|
|
doc = Document.create
|
2018-12-04 16:10:35 -05:00
|
|
|
doc.update(name: "Doc 1")
|
2017-07-04 18:27:41 -04:00
|
|
|
expect(doc.paper_trail_versions.length).to(eq(2))
|
|
|
|
expect(doc.paper_trail_versions.map(&:event)).to(
|
|
|
|
match_array(%w[create update])
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#versions" do
|
|
|
|
it "does not respond to versions method" do
|
|
|
|
doc = Document.create
|
2018-12-04 16:10:35 -05:00
|
|
|
doc.update(name: "Doc 1")
|
2017-07-04 18:27:41 -04:00
|
|
|
expect(doc).not_to respond_to(:versions)
|
|
|
|
end
|
|
|
|
end
|
2017-02-06 12:54:07 -05:00
|
|
|
end
|