File: update_spec.rb

package info (click to toggle)
ruby-paper-trail 12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,200 kB
  • sloc: ruby: 6,743; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 1,103 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

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")
        record.update(name: "blah")
        record.destroy
        expect(record.versions.length).to(eq(1))
        expect(record.versions.last.event).to(eq("update"))
      end
    end

    describe "#paper_trail_event" do
      it "rembembers the custom event name" do
        record = described_class.create(name: "Alice")
        record.paper_trail_event = "banana"
        record.update(name: "blah")
        record.destroy
        expect(record.versions.length).to(eq(1))
        expect(record.versions.last.event).to(eq("banana"))
      end
    end

    describe "#touch" do
      it "does not create a version" do
        record = described_class.create(name: "Alice")
        expect { record.touch }.not_to(
          change { record.versions.count }
        )
      end
    end
  end
end