Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Created June 8, 2017 05:45
Show Gist options
  • Save dineshsprabu/eb2d4b77a9eabe4a30f1db989e56ecde to your computer and use it in GitHub Desktop.
Save dineshsprabu/eb2d4b77a9eabe4a30f1db989e56ecde to your computer and use it in GitHub Desktop.
[Rails][Activerecord] Active Record Bug Test Helper
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'activerecord', '4.2.8'
gem 'mysql2', '0.4.5'
gem 'byebug'
GEMFILE
system 'bundle install'
end
require 'bundler'
Bundler.setup(:default)
require 'byebug'
require 'mysql2'
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
database: 'test',
min_messages: 'warning'
)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
message = "Running specs against #{ActiveRecord::Base.connection.adapter_name
}, Active Record #{ActiveRecord::VERSION::STRING} and Arel #{Arel::VERSION}..."
puts '=' * message.length, message, '=' * message.length
create_table :admins, force: true do |t|
t.timestamp :deleted_at
end
end
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
class << self
def default_scope
where('id = 1')
end
end
end
class Admin < ApplicationRecord
end
class BugTest < Minitest::Test
def test_association_stuff
Admin.all.load
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment