2014-10-09 19:04:17 +00:00
|
|
|
require 'rails_helper'
|
2013-08-27 20:34:16 +00:00
|
|
|
|
2015-12-19 23:47:13 +00:00
|
|
|
describe PaperTrail do
|
2013-10-29 16:07:54 +00:00
|
|
|
context 'default' do
|
|
|
|
it 'should have versioning off by default' do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2013-08-27 20:34:16 +00:00
|
|
|
end
|
2015-12-19 23:47:13 +00:00
|
|
|
|
2014-03-11 14:48:06 +00:00
|
|
|
it 'should turn versioning on in a `with_versioning` block' do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2013-10-29 16:07:54 +00:00
|
|
|
with_versioning do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-08-27 20:34:16 +00:00
|
|
|
end
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2013-10-29 16:07:54 +00:00
|
|
|
end
|
2014-03-12 14:09:59 +00: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 19:04:17 +00:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2015-12-19 23:47:13 +00:00
|
|
|
expect { with_versioning { raise } }.to raise_error(RuntimeError)
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2014-03-12 14:09:59 +00:00
|
|
|
end
|
|
|
|
end
|
2013-10-29 16:07:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context '`versioning: true`', :versioning => true do
|
|
|
|
it 'should have versioning on by default' do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-10-29 16:07:54 +00:00
|
|
|
end
|
2015-12-19 23:47:13 +00:00
|
|
|
|
2013-10-29 16:07:54 +00:00
|
|
|
it 'should keep versioning on after a with_versioning block' do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-10-29 16:07:54 +00:00
|
|
|
with_versioning do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-08-27 20:34:16 +00:00
|
|
|
end
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).to be_enabled
|
2013-08-27 20:34:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-11 14:48:06 +00:00
|
|
|
context '`with_versioning` block at class level' do
|
2014-10-09 19:04:17 +00:00
|
|
|
it { expect(PaperTrail).not_to be_enabled }
|
2014-03-11 14:48:06 +00:00
|
|
|
|
|
|
|
with_versioning do
|
|
|
|
it 'should have versioning on by default' do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).to be_enabled
|
2014-03-11 14:48:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
it 'should not leak the `enabled?` state into successive tests' do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail).not_to be_enabled
|
2014-03-11 14:48:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-27 20:34:16 +00:00
|
|
|
describe :whodunnit do
|
2014-10-09 19:04:17 +00:00
|
|
|
before(:all) { PaperTrail.whodunnit = 'foobar' }
|
2013-08-27 20:34:16 +00:00
|
|
|
|
|
|
|
it "should get set to `nil` by default" do
|
2014-10-09 19:04:17 +00:00
|
|
|
expect(PaperTrail.whodunnit).to be_nil
|
2013-08-27 20:34:16 +00: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 19:04:17 +00:00
|
|
|
expect(PaperTrail.controller_info).to eq({})
|
2013-08-27 20:34:16 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|