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/skipper_spec.rb
Jared Beck 38fa23873c Merge rails_helper into spec_helper
The reason some projects have both is so that some spec files can be
run in isolation, without the rails stuff. In practice, I don't find
myself ever doing this. So, the complexity of two files is unnecessary.
2017-05-30 00:59:55 -04:00

42 lines
1.4 KiB
Ruby

require "spec_helper"
RSpec.describe Skipper, type: :model, versioning: true do
it { is_expected.to be_versioned }
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) }
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
end
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) }
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
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