Sha256: 1dfd12490b09054a4d6622ed41b1c13cd86e583fe878a316b07b54c21d5524f1

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Mongoid::History::Tracker do
  before :each do
    class Element
      include Mongoid::Document
      include Mongoid::Timestamps
      include Mongoid::History::Trackable

      track_history

      field :body

      # force preparation of options
      history_trackable_options
    end

    class Prompt < Element
      field :head
    end

    class User
      include Mongoid::Document
    end
  end

  after :each do
    Object.send(:remove_const, :Element)
    Object.send(:remove_const, :Prompt)
    Object.send(:remove_const, :User)
  end

  let(:user) { User.create! }

  it 'tracks subclass create and update' do
    prompt = Prompt.new(modifier: user)
    expect { prompt.save! }.to change(Tracker, :count).by(1)
    expect { prompt.update_attributes!(body: 'one', head: 'two') }.to change(Tracker, :count).by(1)
    prompt.undo! user
    expect(prompt.body).to be_blank
    expect(prompt.head).to be_blank
    prompt.redo! user, 2
    expect(prompt.body).to eq('one')
    expect(prompt.head).to eq('two')
    expect { prompt.destroy }.to change(Tracker, :count).by(1)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-history-0.8.3 spec/integration/subclasses_spec.rb