From 9183d0cb6e8178e7509461469968274e21052c6b Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Mon, 22 Aug 2016 00:27:16 -0400 Subject: [PATCH] Move test/paper_trail_test.rb to rspec --- spec/models/widget_spec.rb | 26 +++++++++++++++++++++++++ spec/paper_trail_spec.rb | 11 +++++++++++ test/paper_trail_test.rb | 39 -------------------------------------- 3 files changed, 37 insertions(+), 39 deletions(-) delete mode 100644 test/paper_trail_test.rb diff --git a/spec/models/widget_spec.rb b/spec/models/widget_spec.rb index 1ed09918..9a858fc8 100644 --- a/spec/models/widget_spec.rb +++ b/spec/models/widget_spec.rb @@ -140,6 +140,23 @@ describe Widget, type: :model do describe "Methods" 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 "return value" do let(:orig_name) { FFaker::Name.name } @@ -269,6 +286,15 @@ describe Widget, type: :model do expect(widget.updated_at).to be > time_was 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 describe "Class" do diff --git a/spec/paper_trail_spec.rb b/spec/paper_trail_spec.rb index 9a6196ad..bab6a113 100644 --- a/spec/paper_trail_spec.rb +++ b/spec/paper_trail_spec.rb @@ -1,6 +1,17 @@ require "rails_helper" 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 it "should have versioning off by default" do expect(PaperTrail).not_to be_enabled diff --git a/test/paper_trail_test.rb b/test/paper_trail_test.rb deleted file mode 100644 index 3e7fab67..00000000 --- a/test/paper_trail_test.rb +++ /dev/null @@ -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