Skip to content

Instantly share code, notes, and snippets.

View johnathanludwig's full-sized avatar
🖖
It’s chaos, be kind

Johnathan Ludwig johnathanludwig

🖖
It’s chaos, be kind
View GitHub Profile
@johnathanludwig
johnathanludwig / test.rb
Last active December 11, 2019 14:30
Test includes vs left_joins performance
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "activerecord", "~> 5.2.0"
gem "sqlite3"

Keybase proof

I hereby claim:

  • I am johnathanludwig on github.
  • I am bumontherun (https://keybase.io/bumontherun) on keybase.
  • I have a public key whose fingerprint is 4D70 2EB7 F31C 770F 0674 A482 97CE CB2A 0DBE CD6C

To claim this, I am signing this object:

@johnathanludwig
johnathanludwig / parallel_reporter.rb
Created April 29, 2015 15:43
This is a custom reporter used with minitest-reporters. Error messages may get cut off. Still trying to find the best way to print them without printing the stack trace twice.
require 'ansi/code'
module Minitest
module Reporters
# Features:
# Like the SpecReporter but with the pass/time on the left
# Collects the message before doing a puts so that lines dont get mixed up when running tests in threads
# Highlights lines in a stacktrace from this project
# Highlights slow tests
class ParallelReporter < BaseReporter
%h1 New Team
= form_for @team do |f|
= f.label :name
= f.text_field :name
-# fields_for accepts a second param of the object. Use @team.players incase its an edit, otherwise build a new player
= f.fields_for :players, (@team.players || @team.players.build) do |players|
= players.label :player_name
@johnathanludwig
johnathanludwig / testing.rake
Created June 19, 2014 18:57
Add custom test group to rake test
# Add test:workers rake task, and include it in the normal test run
namespace :test do
task run: ['test:workers']
['workers'].each do |name|
Rails::TestTask.new(name => 'test:prepare') do |t|
t.pattern = "test/#{name}/**/*_test.rb"
end
end
end
@johnathanludwig
johnathanludwig / date_range.rb
Last active September 8, 2015 21:26
A custom validator for date ranges. Read the comments for directions on how to use it. Place this file in your initializers directory. I prefer this structure: config/initializers/extensions/active_model/validations/date_range.rb
module ActiveModel
module Validations
class DateRangeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.blank?
pass = true
if comparison_date = options[:before]
if record.send(comparison_date).present?
pass = value < record.send(comparison_date)