Skip to content

Instantly share code, notes, and snippets.

@jaredbeck
Created January 8, 2016 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredbeck/91a7d4fc4528878bca06 to your computer and use it in GitHub Desktop.
Save jaredbeck/91a7d4fc4528878bca06 to your computer and use it in GitHub Desktop.
PaperTrail Issue 663 - Unable to reproduce
# https://github.com/airblade/paper_trail/issues/663
# Use this template to report PaperTrail bugs.
# It is based on the ActiveRecord template.
# https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
ruby '2.0.0'
source 'https://rubygems.org'
gem 'activerecord', '3.2.19'
gem 'factory_girl', '4.5.0'
gem 'paper_trail', '4.0.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 = Logger.new(STDOUT)
require 'paper_trail'
ActiveRecord::Schema.define do
create_table :bicycles, force: true do |t|
t.timestamps null: false
end
create_table :bicycles_tires, force: true do |t|
t.integer :bicycle_id, null: false
t.integer :tire_id, null: false
t.timestamps null: false
end
create_table :tires, force: true do |t|
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
t.text :item_title
t.text :other_data
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
class Bicycle < ActiveRecord::Base
has_and_belongs_to_many :tires,
after_add: :touch_with_version,
after_remove: :touch_with_version
has_paper_trail :meta => {
:item_title => Proc.new{ |item| item.data_changed },
:other_data => Proc.new{ |item|
{ :security_role_names => item.security_role_names }
}
}
def data_changed
true
end
def security_role_names
["foo"]
end
end
class Tire < ActiveRecord::Base
has_and_belongs_to_many :bicycles
end
FactoryGirl.define do
factory :bicycle do
end
end
class BugTest < ActiveSupport::TestCase
def test_1
FactoryGirl.create :bicycle
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment