2017-12-10 23:05:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-30 00:58:26 -04:00
|
|
|
require "spec_helper"
|
2017-05-30 00:52:03 -04:00
|
|
|
require "support/custom_json_serializer"
|
2015-05-08 12:27:32 -04:00
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
RSpec.describe Boolit, type: :model, versioning: true do
|
2017-10-27 12:07:47 -04:00
|
|
|
let(:boolit) { Boolit.create! }
|
2015-05-08 12:27:32 -04:00
|
|
|
|
2018-12-04 16:10:35 -05:00
|
|
|
before { boolit.update!(name: FFaker::Name.name) }
|
2017-04-01 20:13:08 -04:00
|
|
|
|
|
|
|
it "has two versions" do
|
2017-10-27 12:07:47 -04:00
|
|
|
expect(boolit.versions.size).to eq(2)
|
2015-05-08 12:27:32 -04:00
|
|
|
end
|
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
it "can be reified and persisted" do
|
2017-10-27 12:07:47 -04:00
|
|
|
expect { boolit.versions.last.reify.save! }.not_to raise_error
|
2017-04-01 20:13:08 -04:00
|
|
|
end
|
2017-03-31 21:42:14 -04:00
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
context "Instance falls out of default scope" do
|
2018-12-04 16:10:35 -05:00
|
|
|
before { boolit.update!(scoped: false) }
|
2015-05-08 12:27:32 -04:00
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
it "is NOT scoped" do
|
|
|
|
expect(Boolit.first).to be_nil
|
2015-05-08 12:27:32 -04:00
|
|
|
end
|
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
it "still can be reified and persisted" do
|
2017-10-27 12:07:47 -04:00
|
|
|
expect { boolit.paper_trail.previous_version.save! }.not_to raise_error
|
2015-05-08 12:27:32 -04:00
|
|
|
end
|
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
context "with `nil` attributes on the live instance" do
|
|
|
|
before do
|
|
|
|
PaperTrail.serializer = CustomJsonSerializer
|
2018-12-04 16:10:35 -05:00
|
|
|
boolit.update!(name: nil)
|
|
|
|
boolit.update!(name: FFaker::Name.name)
|
2015-05-08 12:27:32 -04:00
|
|
|
end
|
2018-08-14 01:29:08 -04:00
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
after { PaperTrail.serializer = PaperTrail::Serializers::YAML }
|
2015-05-08 12:27:32 -04:00
|
|
|
|
2017-04-01 20:13:08 -04:00
|
|
|
it "does not overwrite that attribute during the reification process" do
|
2017-10-27 12:07:47 -04:00
|
|
|
expect(boolit.paper_trail.previous_version.name).to be_nil
|
2015-05-08 12:27:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|