1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Move test/paper_trail_test.rb to rspec

This commit is contained in:
Jared Beck 2016-08-22 00:27:16 -04:00
parent f3b3d16de7
commit 9183d0cb6e
3 changed files with 37 additions and 39 deletions

View file

@ -140,6 +140,23 @@ describe Widget, type: :model do
describe "Methods" do describe "Methods" do
describe "Instance", versioning: true do describe "Instance", versioning: true do
describe "#create" do
it "creates a version record" do
wordget = Widget.create
assert_equal 1, wordget.versions.length
end
end
describe "#destroy" do
it "creates a version record" do
widget = Widget.create
assert_equal 1, widget.versions.length
widget.destroy
versions_for_widget = PaperTrail::Version.with_item_keys("Widget", widget.id)
assert_equal 2, versions_for_widget.length
end
end
describe "#paper_trail.originator" do describe "#paper_trail.originator" do
describe "return value" do describe "return value" do
let(:orig_name) { FFaker::Name.name } let(:orig_name) { FFaker::Name.name }
@ -269,6 +286,15 @@ describe Widget, type: :model do
expect(widget.updated_at).to be > time_was expect(widget.updated_at).to be > time_was
end end
end end
describe "#update" do
it "creates a version record" do
widget = Widget.create
assert_equal 1, widget.versions.length
widget.update_attributes(name: "Bugle")
assert_equal 2, widget.versions.length
end
end
end end
describe "Class" do describe "Class" do

View file

@ -1,6 +1,17 @@
require "rails_helper" require "rails_helper"
describe PaperTrail do describe PaperTrail do
context "when enabled" do
it "affects all threads" do
Thread.new { PaperTrail.enabled = false }.join
assert_equal false, PaperTrail.enabled?
end
after do
PaperTrail.enabled = true
end
end
context "default" do context "default" do
it "should have versioning off by default" do it "should have versioning off by default" do
expect(PaperTrail).not_to be_enabled expect(PaperTrail).not_to be_enabled

View file

@ -1,39 +0,0 @@
require "test_helper"
class PaperTrailTest < ActiveSupport::TestCase
test "Sanity test" do
assert_kind_of Module, PaperTrail::Version
end
test "Version Number" do
assert PaperTrail.const_defined?(:VERSION)
end
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 }
end
test "create with plain model class" do
widget = Widget.create
assert_equal 1, widget.versions.length
end
test "update with plain model class" do
widget = Widget.create
assert_equal 1, widget.versions.length
widget.update_attributes(name: "Bugle")
assert_equal 2, widget.versions.length
end
test "destroy with plain model class" do
widget = Widget.create
assert_equal 1, widget.versions.length
widget.destroy
versions_for_widget = PaperTrail::Version.with_item_keys("Widget", widget.id)
assert_equal 2, versions_for_widget.length
end
end