Sha256: 6aded594852f9decb1d255a2bc5feb42144aa0ace592f2876db234c8a881059f

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

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

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

  describe '#last_changes' do
    context 'on plain records' do
      context 'having history' do
        subject { $t.bar.last_changes }
        it { is_expected.to eq('name' => ['bar bar', 'new bar']) }
      end

      context 'without history' do
        let(:record) { Bar.create!(:name => 'foreveralone') }
        subject { record.last_changes }
        it { is_expected.to be_nil }
        after { record.destroy.history.delete_all } # UGLY
      end
    end

    context 'on history records' do
      context 'at the beginning of the timeline' do
        subject { $t.bar.history.first.last_changes }
        it { is_expected.to be_nil }
      end

      context 'in the middle of the timeline' do
        subject { $t.bar.history.second.last_changes }
        it { is_expected.to eq('name' => ['bar', 'foo bar']) }
      end
    end
  end

  describe '#changes_against' do
    context 'can compare records against history' do
      it { expect($t.bar.changes_against($t.bar.history.first)).to eq('name' => ['bar', 'new bar']) }
      it { expect($t.bar.changes_against($t.bar.history.second)).to eq('name' => ['foo bar', 'new bar']) }
      it { expect($t.bar.changes_against($t.bar.history.third)).to eq('name' => ['bar bar', 'new bar']) }
      it { expect($t.bar.changes_against($t.bar.history.last)).to eq({}) }
    end

    context 'can compare history against history' do
      it { expect($t.bar.history.first. changes_against($t.bar.history.third)).to eq('name' => ['bar bar', 'bar']) }
      it { expect($t.bar.history.second.changes_against($t.bar.history.third)).to eq('name' => ['bar bar', 'foo bar']) }
      it { expect($t.bar.history.third. changes_against($t.bar.history.third)).to eq({}) }
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

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