2014-10-09 15:04:17 -04:00
|
|
|
require 'rails_helper'
|
2013-08-27 16:34:16 -04:00
|
|
|
|
|
|
|
describe "PaperTrail RSpec Helper" do
|
2013-10-29 12:07:54 -04:00
|
|
|
context 'default' do
|
|
|
|
it 'should have versioning off by default' do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2013-08-27 16:34:16 -04:00
|
|
|
end
|
2014-03-11 10:48:06 -04:00
|
|
|
it 'should turn versioning on in a `with_versioning` block' do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2013-10-29 12:07:54 -04:00
|
|
|
with_versioning do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-08-27 16:34:16 -04:00
|
|
|
end
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2013-10-29 12:07:54 -04:00
|
|
|
end
|
2014-03-12 10:09:59 -04:00
|
|
|
|
|
|
|
context "error within `with_versioning` block" do
|
|
|
|
it "should revert the value of `PaperTrail.enabled?` to it's previous state" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2014-03-12 10:09:59 -04:00
|
|
|
expect { with_versioning { raise } }.to raise_error
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2014-03-12 10:09:59 -04:00
|
|
|
end
|
|
|
|
end
|
2013-10-29 12:07:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context '`versioning: true`', :versioning => true do
|
|
|
|
it 'should have versioning on by default' do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-10-29 12:07:54 -04:00
|
|
|
end
|
|
|
|
it 'should keep versioning on after a with_versioning block' do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-10-29 12:07:54 -04:00
|
|
|
with_versioning do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-08-27 16:34:16 -04:00
|
|
|
end
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-08-27 16:34:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-11 10:48:06 -04:00
|
|
|
context '`with_versioning` block at class level' do
|
2014-10-09 15:04:17 -04:00
|
|
|
it { expect(PaperTrail).not_to be_enabled }
|
2014-03-11 10:48:06 -04:00
|
|
|
|
|
|
|
with_versioning do
|
|
|
|
it 'should have versioning on by default' do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).to be_enabled
|
2014-03-11 10:48:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
it 'should not leak the `enabled?` state into successive tests' do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2014-03-11 10:48:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-27 16:34:16 -04:00
|
|
|
describe :whodunnit do
|
2014-10-09 15:04:17 -04:00
|
|
|
before(:all) { PaperTrail.whodunnit = 'foobar' }
|
2013-08-27 16:34:16 -04:00
|
|
|
|
|
|
|
it "should get set to `nil` by default" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail.whodunnit).to be_nil
|
2013-08-27 16:34:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe :controller_info do
|
|
|
|
before(:all) { ::PaperTrail.controller_info = {:foo => 'bar'} }
|
|
|
|
|
|
|
|
it "should get set to an empty hash before each test" do
|
2014-10-09 15:04:17 -04:00
|
|
|
expect(PaperTrail.controller_info).to eq({})
|
2013-08-27 16:34:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|