Providing non-namespaced Version class that subclasses from the namespaced one with deprecation warnings. Relates to #165

This commit is contained in:
Ben Atkins 2013-08-27 11:17:20 -04:00
parent b4e53f861a
commit 967c0c15b5
2 changed files with 43 additions and 12 deletions

View File

@ -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

View File

@ -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