From 967c0c15b5edec4c3c40b52ff5b6e454a585e7a1 Mon Sep 17 00:00:00 2001 From: Ben Atkins Date: Tue, 27 Aug 2013 11:17:20 -0400 Subject: [PATCH] Providing non-namespaced Version class that subclasses from the namespaced one with deprecation warnings. Relates to #165 --- lib/paper_trail/version.rb | 31 ++++++++++++++++++++++++------- test/unit/version_test.rb | 24 +++++++++++++++++++----- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/lib/paper_trail/version.rb b/lib/paper_trail/version.rb index d9d2f44c..d2bfd23f 100644 --- a/lib/paper_trail/version.rb +++ b/lib/paper_trail/version.rb @@ -199,10 +199,27 @@ module PaperTrail end end -# Legacy support for old applications using the original `Version` class -# class Version < PaperTrail::Version -# def initialize -# warn "DEPRECATED: Please use the namespaced `PaperTrail::Version` class instead." -# super -# end -# end +# Legacy support for old applications using the original non-namespaced `Version` class +class Version < PaperTrail::Version + def initialize(*args) + warn "DEPRECATED: Please use the namespaced `PaperTrail::Version` class instead. Support for the non-namespaced `Version` class will be removed in PaperTrail 3.1." + super + end + + class << self + def find(*args) + warn "DEPRECATED: Please use the namespaced `PaperTrail::Version` class instead. Support for the non-namespaced `Version` class will be removed in PaperTrail 3.1." + super + end + + def first(*args) + warn "DEPRECATED: Please use the namespaced `PaperTrail::Version` class instead. Support for the non-namespaced `Version` class will be removed in PaperTrail 3.1." + super + end + + def last(*args) + warn "DEPRECATED: Please use the namespaced `PaperTrail::Version` class instead. Support for the non-namespaced `Version` class will be removed in PaperTrail 3.1." + super + end + end +end diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index 527d00ba..f5e1829d 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -3,7 +3,7 @@ require 'test_helper' class PaperTrail::VersionTest < ActiveSupport::TestCase setup { change_schema - @article = Animal.create + @animal = Animal.create assert PaperTrail::Version.creates.present? } @@ -17,7 +17,7 @@ class PaperTrail::VersionTest < ActiveSupport::TestCase context "PaperTrail::Version.updates" do setup { - @article.update_attributes(:name => 'Animal') + @animal.update_attributes(:name => 'Animal') assert PaperTrail::Version.updates.present? } @@ -30,7 +30,7 @@ class PaperTrail::VersionTest < ActiveSupport::TestCase context "PaperTrail::Version.destroys" do setup { - @article.destroy + @animal.destroy assert PaperTrail::Version.destroys.present? } @@ -43,8 +43,8 @@ class PaperTrail::VersionTest < ActiveSupport::TestCase context "PaperTrail::Version.not_creates" do setup { - @article.update_attributes(:name => 'Animal') - @article.destroy + @animal.update_attributes(:name => 'Animal') + @animal.destroy assert PaperTrail::Version.not_creates.present? } @@ -55,3 +55,17 @@ class PaperTrail::VersionTest < ActiveSupport::TestCase end end end + +class VersionTest < ActiveSupport::TestCase + context "Version class" do + should "be a subclass of the `PaperTrail::Version` class" do + assert Version < PaperTrail::Version + end + + should "act like a `PaperTrail::Version` while warning the user" do + @animal = Animal.create! :name => Faker::Name.name + @animal.update_attributes! :name => Faker::Name.name + assert_equal Version.last.reify.name, @animal.versions.last.reify.name + end + end +end