paper-trail-gem--paper_trail/spec/models/skipper_spec.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

require "spec_helper"
2017-04-02 00:13:08 +00:00
RSpec.describe Skipper, type: :model, versioning: true do
it { is_expected.to be_versioned }
2017-04-02 00:13:08 +00:00
describe "#update_attributes!", versioning: true do
context "updating a skipped attribute" do
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
2017-04-02 00:13:08 +00:00
it "does not create a version" do
skipper = Skipper.create!(another_timestamp: t1)
expect {
skipper.update_attributes!(another_timestamp: t2)
}.not_to(change { skipper.versions.length })
end
end
2017-04-02 00:13:08 +00:00
end
2017-04-02 00:13:08 +00:00
describe "#reify" do
let(:t1) { Time.zone.local(2015, 7, 15, 20, 34, 0) }
let(:t2) { Time.zone.local(2015, 7, 15, 20, 34, 30) }
2017-04-02 00:13:08 +00:00
context "without preserve (default)" do
it "has no timestamp" do
skipper = Skipper.create!(another_timestamp: t1)
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
skipper = skipper.versions.last.reify
expect(skipper.another_timestamp).to be(nil)
end
end
2017-04-02 00:13:08 +00:00
context "with preserve" do
it "preserves its timestamp" do
skipper = Skipper.create!(another_timestamp: t1)
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
skipper = skipper.versions.last.reify(unversioned_attributes: :preserve)
expect(skipper.another_timestamp).to eq(t2)
end
end
end
end