2016-03-05 17:07:32 -05:00
|
|
|
require "rails_helper"
|
2015-07-15 21:28:07 -04:00
|
|
|
|
2016-02-15 22:32:40 -05:00
|
|
|
describe Skipper, type: :model do
|
2015-08-03 05:01:16 -04:00
|
|
|
with_versioning do
|
|
|
|
it { is_expected.to be_versioned }
|
2015-07-15 21:28:07 -04:00
|
|
|
|
2016-02-15 22:32:40 -05:00
|
|
|
describe "#update_attributes!", versioning: true do
|
2015-08-03 05:01:16 -04:00
|
|
|
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 "should not create a version" do
|
2016-02-15 22:32:40 -05:00
|
|
|
skipper = Skipper.create!(another_timestamp: t1)
|
2015-08-03 05:01:16 -04:00
|
|
|
expect {
|
2016-02-15 22:32:40 -05:00
|
|
|
skipper.update_attributes!(another_timestamp: t2)
|
2015-08-03 05:01:16 -04:00
|
|
|
}.to_not change { skipper.versions.length }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "reify" do
|
|
|
|
context "reifying a with 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) }
|
|
|
|
|
|
|
|
context "without preserve (default)" do
|
|
|
|
it "should have no timestamp" do
|
2016-02-15 22:32:40 -05:00
|
|
|
skipper = Skipper.create!(another_timestamp: t1)
|
|
|
|
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
|
2015-08-03 05:01:16 -04:00
|
|
|
skipper = skipper.versions.last.reify
|
|
|
|
expect(skipper.another_timestamp).to be(nil)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with preserve" do
|
|
|
|
it "should preserve its timestamp" do
|
2016-02-15 22:32:40 -05:00
|
|
|
skipper = Skipper.create!(another_timestamp: t1)
|
|
|
|
skipper.update_attributes!(another_timestamp: t2, name: "Foobar")
|
|
|
|
skipper = skipper.versions.last.reify(unversioned_attributes: :preserve)
|
2015-08-03 05:01:16 -04:00
|
|
|
expect(skipper.another_timestamp).to eq(t2)
|
|
|
|
end
|
|
|
|
end
|
2015-07-15 21:28:07 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|