Skip to content

Instantly share code, notes, and snippets.

@batter
Created October 21, 2014 17:39
Show Gist options
  • Save batter/dbc05f6a47f414f185c2 to your computer and use it in GitHub Desktop.
Save batter/dbc05f6a47f414f185c2 to your computer and use it in GitHub Desktop.
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.10'
gem 'sqlite3', '1.3.9'
gem 'paper_trail', '3.0.6'
gem 'friendly_id', '5.0.4'
require 'active_record'
require 'minitest/autorun'
require 'logger'
require 'paper_trail'
require 'friendly_id'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# 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 :posts do |t|
t.string :name
t.text :body
t.string :slug, :unique => true
t.timestamps
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
t.datetime :created_at
end
add_index :versions, [:item_type, :item_id]
create_table :friendly_id_slugs do |t|
t.string :slug, :null => false
t.integer :sluggable_id, :null => false
t.string :sluggable_type, :limit => 50
t.string :scope
t.datetime :created_at
end
add_index :friendly_id_slugs, :sluggable_id
add_index :friendly_id_slugs, [:slug, :sluggable_type]
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], :unique => true
add_index :friendly_id_slugs, :sluggable_type
end
class Post < ActiveRecord::Base
extend FriendlyId
friendly_id :name, use: :slugged
has_paper_trail only: [:slug, :name]
end
class BugTest < Minitest::Test
def test_versioning
post = Post.create!(name: 'post name')
post.update_attribute(:name, 'name changed')
assert_equal 2, post.versions.count
post.update_attribute(:body, 'here is some body text')
assert_equal 2, post.versions.count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment