Sha256: 798caffabdcffeeb32305790601ee4a10648b5ab962ab15d7b345ada8e7b1344

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

require 'rails_helper'
require Rails.root.join('..', 'custom_json_serializer')

describe Boolit, :type => :model do
  it { is_expected.to be_versioned }

  it "has a default scope" do
    expect(subject.default_scopes).to_not be_empty
  end

  describe "Versioning", :versioning => true do
    subject { Boolit.create! }
    before { subject.update_attributes!(:name => Faker::Name.name) }

    it "should have versions" do
      expect(subject.versions.size).to eq(2)
    end

    it "should be able to be reified and persisted" do
      expect { subject.versions.last.reify.save! }.to_not raise_error
    end

    context "Instance falls out of default scope" do
      before { subject.update_attributes!(:scoped => false) }

      it "is NOT scoped" do
        expect(Boolit.first).to be_nil
      end

      it "should still be able to be reified and persisted" do
        expect { subject.previous_version.save! }.to_not raise_error
      end

      context "with `nil` attributes on the live instance" do
        before do
          PaperTrail.serializer = CustomJsonSerializer
          subject.update_attributes!(:name => nil)
          subject.update_attributes!(:name => Faker::Name.name)
        end
        after { PaperTrail.serializer = PaperTrail::Serializers::YAML }

        it "should not overwrite that attribute during the reification process" do
          expect(subject.previous_version.name).to be_nil
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
paper_trail-4.2.0 spec/models/boolit_spec.rb
paper_trail-4.1.0 spec/models/boolit_spec.rb
paper_trail-4.0.2 spec/models/boolit_spec.rb
paper_trail-4.0.1 spec/models/boolit_spec.rb
paper_trail-4.0.0 spec/models/boolit_spec.rb
paper_trail-4.0.0.rc2 spec/models/boolit_spec.rb
paper_trail-4.0.0.rc1 spec/models/boolit_spec.rb