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/boolit_spec.rb

45 lines
1.2 KiB
Ruby
Raw Normal View History

2017-12-10 23:05:11 -05:00
# frozen_string_literal: true
require "spec_helper"
require "support/custom_json_serializer"
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! }
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)
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
before { boolit.update!(scoped: false) }
2017-04-01 20:13:08 -04:00
it "is NOT scoped" do
expect(Boolit.first).to be_nil
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
end
2017-04-01 20:13:08 -04:00
context "with `nil` attributes on the live instance" do
before do
PaperTrail.serializer = CustomJsonSerializer
boolit.update!(name: nil)
boolit.update!(name: FFaker::Name.name)
end
2017-04-01 20:13:08 -04:00
after { PaperTrail.serializer = PaperTrail::Serializers::YAML }
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
end
end
end
end