Created
May 25, 2014 14:29
-
-
Save ppdeassis/4ac82810632ba1d24d2c to your computer and use it in GitHub Desktop.
Ruby minimal script for bug reporting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
# source http://www.jonathanleighton.com/articles/2011/awesome-active-record-bug-reports/ | |
gem 'rails', '3.1.0' # change as required | |
require 'active_record' | |
# Print out what version we're running | |
puts "Active Record #{ActiveRecord::VERSION::STRING}" | |
# Connect to an in-memory sqlite3 database (more on this in a moment) | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'sqlite3', | |
:database => ':memory:' | |
) | |
# Create the minimal database schema necessary to reproduce the bug | |
ActiveRecord::Schema.define do | |
create_table :users, :force => true do |t| | |
end | |
create_table :user_folders, :force => true do |t| | |
t.integer :user_id | |
end | |
end | |
# Create the minimal set of models to reproduce the bug | |
class User < ActiveRecord::Base | |
end | |
class UserFolder < ActiveRecord::Base | |
belongs_to :user | |
end | |
# Create some test data | |
# | |
# If you're demonstrating an exception, then this is probably not necessary, | |
# but if your bug is to do with the wrong data being returned from the database, | |
# then you'll probably need some test data to show that. | |
user = User.create! | |
user_folder = UserFolder.create(:user => user) | |
# Reproduce the actual bug! | |
UserFolder.joins(:user).includes(:user) # => BOOM! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment