2016-03-05 17:07:32 -05:00
|
|
|
require "rails_helper"
|
2013-08-27 16:34:16 -04:00
|
|
|
|
2015-12-19 18:47:13 -05:00
|
|
|
describe PaperTrail do
|
2016-03-05 17:07:32 -05: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
|
2015-12-19 18:47:13 -05:00
|
|
|
|
2016-03-05 17:07:32 -05: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
|
2015-12-19 18:47:13 -05:00
|
|
|
expect { with_versioning { raise } }.to raise_error(RuntimeError)
|
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
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
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
|
2015-12-19 18:47:13 -05:00
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
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
|
|
|
|
|
2016-03-05 17:07:32 -05: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
|
2016-03-05 17:07:32 -05:00
|
|
|
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
|
2016-03-05 17:07:32 -05:00
|
|
|
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
|
2016-03-05 17:07:32 -05: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
|
2016-03-05 17:11:08 -05:00
|
|
|
before(:all) { ::PaperTrail.controller_info = { foo: "bar" } }
|
2013-08-27 16:34:16 -04:00
|
|
|
|
|
|
|
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
|