Sha256: 807b0d712d4fd4f52c88f61eee14f54827b3917f8b488db3587d334114268743

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

require 'spec_helper'

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

      field :body

      track_history on: [:body]
    end

    class Prompt < Element
    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') }.to change(Tracker, :count).by(1)
    prompt.undo! user
    expect(prompt.body).to be_blank
    prompt.redo! user, 2
    expect(prompt.body).to eq('one')
    expect { prompt.destroy }.to change(Tracker, :count).by(1)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-history-0.8.2 spec/integration/subclasses_spec.rb
mongoid-history-0.8.1 spec/integration/subclasses_spec.rb