Skip to content

Instantly share code, notes, and snippets.

Benjamin Quorning bquorning

View GitHub Profile
@bquorning
bquorning / flatten.rb
Created Feb 19, 2018
Did Ruby 2.5 introduce a new bug, or fix an old bug? The implicit `flatten` -> `to_ary` -> `respond_to_missing` call has changed.
View flatten.rb
class A
def respond_to?(method, include_all = false)
::Kernel.puts "respond_to?(#{method.inspect}, #{include_all.inspect})"
end
end
class B
def respond_to_missing?(method, include_all = false)
::Kernel.puts "respond_to_missing?(#{method.inspect}, #{include_all.inspect})"
end
View rspec-rails-json-controller-params.rb
# Run this script with `ruby rspec-rails-json-controller-params.rb`
# It will spawn two processes: one using Minitest, one using RSpec.
if ARGV.empty?
puts `ruby #{__FILE__} test`
puts `ruby #{__FILE__} spec`
exit
end
require "bundler/inline"
@bquorning
bquorning / store-issue-rails-4.rb
Last active Jul 4, 2016
An instance of ActionController::Parameters stored in a column as YAML with Rails 4, cannot be read with Rails 5.
View store-issue-rails-4.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
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@bquorning
bquorning / hash-with-ivars.rb
Last active Jul 4, 2016
Models using `store` to serialize a `Hash` in the form of `ActionController::Parameters` in Rails 4 cannot read that same column in Rails 5.
View hash-with-ivars.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
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@bquorning
bquorning / gist.rb
Last active Apr 20, 2016
ActiveRecord trying to save readonly records on has_many_through assignment. It looks like the bug was introduced by https://github.com/rails/rails/commit/d849f42b4ecf687ed5350f5a2402fb795aa33aac, and it should probably check `if !record.readonly?` and not just remove the condition.
View gist.rb
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'activerecord', '5.0.0.beta3'
gem 'sqlite3'
end
require 'active_record'
require 'minitest/autorun'
View rails-issue-24392.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
source 'https://rubygems.org'
# Activate the gem you are reporting the issue against.
@bquorning
bquorning / action_controller_gem.rb
Last active Mar 20, 2016
Run with `rspec action_controller_gem.rb`. Fails as it is, but works with https://github.com/rspec/rspec-rails/pull/1568 applied.
View action_controller_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
source 'https://rubygems.org'
gem 'rails', '5.0.0.beta3'
@bquorning
bquorning / active_record_master.rb
Last active Mar 7, 2016
Eager loaded belongs_to associations are always readonly
View active_record_master.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
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
View My project's git pre-commit hook runs Rubocop on changed files
#!/bin/sh
STAGED=$(git diff --cached --name-only --diff-filter=ACM | grep -e '\.rb$' -e '\.rake$' -e '\.ru$' -e Capfile -e 'Gemfile$')
if [ "$STAGED" ]; then
./bin/rubocop -- $STAGED
fi
@bquorning
bquorning / gist:460ad070893cbe498df5
Last active Aug 29, 2015
Uniqueness validation bug in Rails 4.1.10.rc1
View gist:460ad070893cbe498df5
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.1.10.rc1'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
You can’t perform that action at this time.