Sha256: 12352d5b3fc457312de33fcfb19e378c60dfe7609fb7a46b200e9d9faa9158a9

Contents?: true

Size: 1.54 KB

Versions: 28

Compression:

Stored size: 1.54 KB

Contents

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, Version.count
      assert_equal 4, @animal.versions.count
      assert @animal.versions.first.reify.nil?
      @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 = Version.where(:item_id => @dog.id)
      assert_equal 4, dog_versions.count
      assert dog_versions.first.reify.nil?
      dog_versions[1..-1].each { |v| assert_equal 'Dog', v.reify.class.name }

      cat_versions = Version.where(:item_id => @cat.id)
      assert_equal 4, cat_versions.count
      assert cat_versions.first.reify.nil?
      cat_versions[1..-1].each { |v| assert_equal 'Cat', v.reify.class.name }
    end
  end

end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
paper_trail-2.7.2 test/unit/inheritance_column_test.rb
paper_trail-2.7.1 test/unit/inheritance_column_test.rb
paper_trail-2.7.0 test/unit/inheritance_column_test.rb
paper_trail-2.6.4 test/unit/inheritance_column_test.rb
paper_trail-2.6.3 test/unit/inheritance_column_test.rb
paper_trail-2.6.2 test/unit/inheritance_column_test.rb
paper_trail-2.6.1 test/unit/inheritance_column_test.rb
paper_trail-2.6.0 test/unit/inheritance_column_test.rb
paper_trail-2.5.2 test/unit/inheritance_column_test.rb
paper_trail-2.5.0 test/unit/inheritance_column_test.rb
paper_trail-2.4.1 test/unit/inheritance_column_test.rb
paper_trail-2.4.0 test/unit/inheritance_column_test.rb
bkwld-paper_trail-2.3.3 test/unit/inheritance_column_test.rb
paper_trail-2.3.3 test/unit/inheritance_column_test.rb
bkwld-paper_trail-2.3.2 test/unit/inheritance_column_test.rb
paper_trail-2.3.2 test/unit/inheritance_column_test.rb
paper_trail-2.3.1 test/unit/inheritance_column_test.rb
paper_trail-2.3.0 test/unit/inheritance_column_test.rb
paper_trail-2.2.9 test/unit/inheritance_column_test.rb
paper_trail-2.2.8 test/unit/inheritance_column_test.rb