Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Use this template to report PaperTrail bugs.
# Please include only the minimum code necessary to reproduce your issue.
require "bundler/inline"
# STEP ONE: What versions are you using?
gemfile(true) do
ruby "2.3.3"
source "https://rubygems.org"
gem "activerecord", "4.2.7.1"
gem "minitest", "5.9.0"
gem "paper_trail", "4.1.0", require: false
gem "sqlite3"
end
require "active_record"
require "minitest/autorun"
require "logger"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.logger = nil
ActiveRecord::Schema.define do
# STEP TWO: Define your tables here.
create_table :bananas, force: true do |t|
t.integer :my_enum, null: false
t.timestamps null: false
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.integer :transaction_id
t.datetime :created_at
end
add_index :versions, [:item_type, :item_id]
add_index :versions, [:transaction_id]
create_table :version_associations do |t|
t.integer :version_id
t.string :foreign_key_name, null: false
t.integer :foreign_key_id
end
add_index :version_associations, [:version_id]
add_index :version_associations, [:foreign_key_name, :foreign_key_id],
name: "index_version_associations_on_foreign_key"
end
ActiveRecord::Base.logger = Logger.new(STDOUT)
require "paper_trail/config"
# STEP THREE: Configure PaperTrail as you would in your initializer
PaperTrail::Config.instance.track_associations = false
require "paper_trail"
# STEP FOUR: Define your AR models here.
class Banana < ActiveRecord::Base
enum my_enum: { foo: 4, bar: 5 }
has_paper_trail
end
# STEP FIVE: Please write a test that demonstrates your issue.
class BugTest < ActiveSupport::TestCase
def test_1
# Create the version
sample = Banana.create(my_enum: :foo)
sample.update!(my_enum: :bar)
# displaying human-readable changeset
changeset = Banana.last.versions.last.changeset
from = changeset['my_enum'][0]
to = changeset['my_enum'][1]
puts "Enum value changed from '#{from}' to '#{to}'."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment