Skip to content

Instantly share code, notes, and snippets.

@iiwo
Last active July 9, 2021 19:31
Show Gist options
  • Save iiwo/5031bcf9a4222b060170364329653e73 to your computer and use it in GitHub Desktop.
Save iiwo/5031bcf9a4222b060170364329653e73 to your computer and use it in GitHub Desktop.
sti_versions_duplicates.rb
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
gem "activerecord", "6.0.3.7"
gem "paper_trail", "~> 12", require: false
gem "sqlite3"
end
require "active_record"
require "minitest/autorun"
require "logger"
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :plans, force: true do |t|
t.integer :plan_type
end
create_table :versions do |t|
t.string :item_type, null: false
t.integer :item_id, null: false
t.string :event, null: false
t.string :whodunnit
t.text :object, limit: 1_073_741_823
t.text :object_changes, limit: 1_073_741_823
t.datetime :created_at
end
add_index :versions, %i[item_type item_id]
end
require "paper_trail"
class Plan < ActiveRecord::Base
self.inheritance_column = :plan_type
has_paper_trail
end
module Plans; end
class Plans::Custom < Plan
has_paper_trail
end
class STITest < Minitest::Test
def test_count_with_sti_class
plan = Plans::Custom.create!
assert_equal 1, plan.versions.count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment