Sha256: beda5f46e7e8af4bc49d8af9db65549d9c916cd70f6879510e7c378eae7f5f9d

Contents?: true

Size: 1.8 KB

Versions: 2

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'
require 'support/time_machine/structure'

describe ChronoModel::TimeMachine do
  include ChronoTest::TimeMachine::Helpers

  describe '#pred' do
    context 'on the first history entry' do
      subject { $t.foo.history.first.pred }
      it { is_expected.to be(nil) }
    end

    context 'on the second history entry' do
      subject { $t.foo.history.second.pred }
      it { is_expected.to eq $t.foo.history.first }
    end

    context 'on the last history entry' do
      subject { $t.foo.history.last.pred }
      it { is_expected.to eq $t.foo.history[$t.foo.history.size - 2] }
    end

    context 'on records having history' do
      subject { $t.bar.pred }
      it { expect(subject.name).to eq 'bar bar' }
    end

    context 'when there is enough history' do
      subject { $t.bar.pred.pred.pred.pred }
      it { expect(subject.name).to eq 'bar' }
    end

    context 'when no history is recorded' do
      let(:record) { Bar.create!(:name => 'quuuux') }

      subject { record.pred }

      it { is_expected.to be(nil) }

      after { record.destroy.history.delete_all }
    end
  end

  describe '#succ' do
    context 'on the first history entry' do
      subject { $t.foo.history.first.succ }

      it { is_expected.to eq $t.foo.history.second }
    end

    context 'on the second history entry' do
      subject { $t.foo.history.second.succ }

      it { is_expected.to eq $t.foo.history.third }
    end

    context 'on the last history entry' do
      subject { $t.foo.history.last.succ }

      it { is_expected.to be(nil) }
    end
  end

  describe '#first' do
    subject { $t.foo.history.sample.first }
    it { is_expected.to eq $t.foo.history.first }
  end

  describe '#last' do
    subject { $t.foo.history.sample.last }
    it { is_expected.to eq $t.foo.history.last }
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chrono_model-1.2.2 spec/chrono_model/time_machine/sequence_spec.rb
chrono_model-1.2.1 spec/chrono_model/time_machine/sequence_spec.rb