Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View bquorning's full-sized avatar

Benjamin Quorning bquorning

View GitHub Profile
@bquorning
bquorning / flatten.rb
Created February 19, 2018 20:53
Did Ruby 2.5 introduce a new bug, or fix an old bug? The implicit `flatten` -> `to_ary` -> `respond_to_missing` call has changed.
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
# 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 July 4, 2016 12:06
An instance of ActionController::Parameters stored in a column as YAML with Rails 4, cannot be read with Rails 5.
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 July 4, 2016 11:21
Models using `store` to serialize a `Hash` in the form of `ActionController::Parameters` in Rails 4 cannot read that same column in Rails 5.
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 April 20, 2016 15:17
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.
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'
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 March 20, 2016 10:45
Run with `rspec action_controller_gem.rb`. Fails as it is, but works with https://github.com/rspec/rspec-rails/pull/1568 applied.
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 March 7, 2016 13:53
Eager loaded belongs_to associations are always readonly
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'
@bquorning
bquorning / post-checkout hook
Last active December 17, 2015 21:39
Run bundler automatically when needed. Save file as .git/hooks/post-checkout in your project, and do a `chmod +x`. Heavily inspired by https://gist.github.com/whilefalse/1019087
#!/bin/bash
if [ ! `git diff --name-only HEAD@{1}..HEAD Gemfile Gemfile.lock | wc -l` -eq 0 ]
then
echo -e "\033[0;31m*** Gemfile change detected, running bundle check ***\033[0m"
(unset GIT_DIR ; bundle check || bundle install --local || bundle install)
fi
@bquorning
bquorning / gist:5325718
Created April 6, 2013 10:46
Here's the script I use to remove my merged branches, both remote and local. Disclaimer: Don’t blame me if you use this script to remove something you wanted do keep. Maybe add the `-n` flag to `git push` while you’re trying out how the script works. If in trouble, read [man git-reflog](http://git-scm.com/docs/git-reflog).
git checkout master
git pull
git remote prune origin
git branch -r --merged | grep bquorning | awk -F'/' '{ print ":" $2 "/" $3 }' | xargs git push origin
git branch --merged | grep -v "\* master" | xargs git branch -d
# That was actually a somewhat simplified version. Here's what I really use:
git checkout master && git pull && (git remote prune origin && git branch -r --merged | grep bquorning | awk -F'/' '{ print ":" $2 "/" $3 }' | xargs git push origin) & ; git branch --merged | grep -v "\* master" | xargs git branch -d