1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00
paper-trail-gem--paper_trail/test/unit/inheritance_column_test.rb
Jared Beck f963752703 Breaking change: Remove custom timestamp feature
A little over four years ago, a feature was added to allow users
to change the name of the `versions.created_at` column. No reason
was given at the time.

https://github.com/airblade/paper_trail/pull/129

There are three reasons why this should not be configurable:

1. The standard column name in rails is `created_at`.
2. The majority of the `versions` table is, and should be, an
   implementation detail of PT.
3. This configuration option added moderate complexity to the
   library, and severe complexity to the test suite.
2016-09-04 00:41:21 -04:00

41 lines
1.6 KiB
Ruby

require "test_helper"
class InheritanceColumnTest < ActiveSupport::TestCase
context "STI models" do
setup do
@animal = Animal.create name: "Animal"
@animal.update_attributes name: "Animal from the Muppets"
@animal.update_attributes name: "Animal Muppet"
@animal.destroy
@dog = Dog.create name: "Snoopy"
@dog.update_attributes name: "Scooby"
@dog.update_attributes name: "Scooby Doo"
@dog.destroy
@cat = Cat.create name: "Garfield"
@cat.update_attributes name: "Garfield (I hate Mondays)"
@cat.update_attributes name: "Garfield The Cat"
@cat.destroy
end
should "work with custom STI inheritance column" do
assert_equal 12, PaperTrail::Version.count
assert_equal 4, @animal.versions.count
assert_nil @animal.versions.first.reify
@animal.versions[1..-1].each { |v| assert_equal "Animal", v.reify.class.name }
# For some reason `@dog.versions` doesn't include the final `destroy` version.
# Neither do `@dog.versions.scoped` nor `@dog.versions(true)` nor `@dog.versions.reload`.
dog_versions = PaperTrail::Version.where(item_id: @dog.id).order(:created_at)
assert_equal 4, dog_versions.count
assert_nil dog_versions.first.reify
assert_equal %w(NilClass Dog Dog Dog), dog_versions.map { |v| v.reify.class.name }
cat_versions = PaperTrail::Version.where(item_id: @cat.id).order(:created_at)
assert_equal 4, cat_versions.count
assert_nil cat_versions.first.reify
assert_equal %w(NilClass Cat Cat Cat), cat_versions.map { |v| v.reify.class.name }
end
end
end