2016-03-05 17:07:32 -05:00
|
|
|
require "test_helper"
|
2011-02-08 12:16:35 -05:00
|
|
|
|
|
|
|
class PaperTrailTest < ActiveSupport::TestCase
|
2016-03-05 17:07:32 -05:00
|
|
|
test "Sanity test" do
|
2013-05-29 17:19:05 -04:00
|
|
|
assert_kind_of Module, PaperTrail::Version
|
2011-02-08 12:16:35 -05:00
|
|
|
end
|
2011-04-06 20:21:57 -04:00
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
test "Version Number" do
|
2013-12-02 10:05:19 -05:00
|
|
|
assert PaperTrail.const_defined?(:VERSION)
|
|
|
|
end
|
2016-03-03 18:16:47 -05:00
|
|
|
|
|
|
|
context "setting enabled" do
|
|
|
|
should "affect all threads" do
|
|
|
|
Thread.new { PaperTrail.enabled = false }.join
|
|
|
|
assert_equal false, PaperTrail.enabled?
|
|
|
|
end
|
|
|
|
teardown { PaperTrail.enabled = true }
|
2015-05-26 15:39:09 -04:00
|
|
|
end
|
2013-12-02 10:05:19 -05:00
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
test "create with plain model class" do
|
2011-04-06 20:21:57 -04:00
|
|
|
widget = Widget.create
|
|
|
|
assert_equal 1, widget.versions.length
|
|
|
|
end
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
test "update with plain model class" do
|
2011-04-06 20:21:57 -04:00
|
|
|
widget = Widget.create
|
|
|
|
assert_equal 1, widget.versions.length
|
2016-03-05 17:07:32 -05:00
|
|
|
widget.update_attributes(name: "Bugle")
|
2011-04-06 20:21:57 -04:00
|
|
|
assert_equal 2, widget.versions.length
|
|
|
|
end
|
|
|
|
|
2016-03-05 17:07:32 -05:00
|
|
|
test "destroy with plain model class" do
|
2011-04-06 20:21:57 -04:00
|
|
|
widget = Widget.create
|
|
|
|
assert_equal 1, widget.versions.length
|
|
|
|
widget.destroy
|
2016-03-05 17:07:32 -05:00
|
|
|
versions_for_widget = PaperTrail::Version.with_item_keys("Widget", widget.id)
|
2011-04-06 20:21:57 -04:00
|
|
|
assert_equal 2, versions_for_widget.length
|
|
|
|
end
|
2011-02-08 12:16:35 -05:00
|
|
|
end
|