Sha256: 98b2d8e83648765ae5d13a3b75945760bbb4b90af2a88c3ad6d799cf579ef3ea

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

require 'rails_helper'

describe Skipper, :type => :model do
  with_versioning 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 "should not create a version" do
          skipper = Skipper.create!(:another_timestamp => t1)
          expect {
            skipper.update_attributes!(:another_timestamp => t2)
          }.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
            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 "should preserve 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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
paper_trail-4.2.0 spec/models/skipper_spec.rb
paper_trail-4.1.0 spec/models/skipper_spec.rb
paper_trail-4.0.2 spec/models/skipper_spec.rb
paper_trail-4.0.1 spec/models/skipper_spec.rb