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/post_spec.rb

36 lines
1,005 B
Ruby
Raw Normal View History

# frozen_string_literal: true
require "spec_helper"
# The `Post` model uses a custom version class, `PostVersion`
RSpec.describe Post, type: :model, versioning: true do
it "inserts records into the correct table, post_versions" do
post = Post.create
expect(PostVersion.count).to(eq(1))
post.update(content: "Some new content")
expect(PostVersion.count).to(eq(2))
expect(PaperTrail::Version.count).to(eq(0))
end
context "on the first version" do
it "have the correct index" do
post = Post.create
version = post.versions.first
expect(version.index).to(eq(0))
end
end
it "have versions of the custom class" do
post = Post.create
expect(post.versions.first.class.name).to(eq("PostVersion"))
end
describe "#changeset" do
it "returns nil because the object_changes column doesn't exist" do
post = Post.create
post.update(content: "Some new content")
expect(post.versions.last.changeset).to(be_nil)
end
end
end