Skip to content

Instantly share code, notes, and snippets.

@blowmage
blowmage / lib-tasks-db_fixtures_dump.rake
Created December 6, 2022 11:45
Rails Rake task to dump the current environment's database into fixture files.
namespace :db do
namespace :fixtures do
desc "Dumps the current environment's database into fixtures (uses FIXTURES_PATH)"
task dump: :environment do
Rails.application.eager_load!
models = ApplicationRecord.descendants.reject { |model| model.primary_key.nil? }
fixture_files = ENV["FIXTURES"].to_s.split(",")
if fixture_files.any?
@blowmage
blowmage / ruby.svg
Created August 17, 2015 22:06
Ruby and RubyGems SVG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@blowmage
blowmage / docs.rake
Created November 15, 2014 01:56
A rake task to update the documentation in the gh-pages branch.
namespace :docs do
desc "Updates the documentation on the gh-pages branch"
task :update do
branch = `git symbolic-ref --short HEAD`.chomp
if "master" != branch
puts "You are on the #{branch} branch. You must be on the master branch to run this rake task."
exit
end
require_relative "../lib/my_gem/version.rb"
@blowmage
blowmage / diff.diff
Last active August 29, 2015 14:02
Updated Minitest::Spec doco
diff --git a/lib/minitest/spec.rb b/lib/minitest/spec.rb
index 40b5e6a..c5b334d 100644
--- a/lib/minitest/spec.rb
+++ b/lib/minitest/spec.rb
@@ -22,6 +22,25 @@ module Kernel # :nodoc:
##
# Describe a series of expectations for a given target +desc+.
#
+ # You can describe your test by passing the object under test:
+ #

Keybase proof

I hereby claim:

  • I am blowmage on github.
  • I am blowmage (https://keybase.io/blowmage) on keybase.
  • I have a public key whose fingerprint is 7FC4 001A B3B0 FFBA 60FD E278 861B B5BD 2A72 06AF

To claim this, I am signing this object:

@blowmage
blowmage / test_fakefs_thor.rb
Last active August 29, 2015 13:56
Test to reproduce the problems we were having with FakeFS in the minitest-rails tests. Use version 0.5.0 of FakeFS, and whatever the current version of Thor is.
require "minitest/autorun"
require "thor"
require "fakefs/safe"
class SampleGenerator < Thor::Group
include Thor::Actions
def start *args
template "foo.erb", "new/path/here/foo.rb"
end
end
@blowmage
blowmage / .profile
Last active August 29, 2015 13:55
chruby and ohmygems together at last
# my preferred prompt - ☣ [pairwithme:rails4] $
PS1='\[\e[1;31m\]☣ [\W$(if [ -n "$OMG_NAME" ]; then eval "echo :$OMG_NAME"; fi)] $\[\e[0m\] '
# chruby configuration
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
# set default ruby
chruby 2.1
@blowmage
blowmage / minitest-assertify.rb
Created October 21, 2013 14:18
minitest-assertify
module MiniTest
module Assertify
module Lifecycle # :nodoc:
# Hook into Minitest's Lifecycle to alias methods when tests are run.
def before_setup # :nodoc:
self.class.public_instance_methods.grep(/\Arefute_/).each do |method|
new_method = method.to_s.sub("refute_", "assert_not_").to_sym
class_eval do
alias_method new_method, method
end
[vagrant@precise32:/vagrant (master)]$ echo "using search_exec"
using search_exec
[vagrant@precise32:/vagrant (master)]$ rspec spec/models/user_search_spec.rb
/usr/local/rvm/gems/ruby-1.9.3-p374/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require': iconv will be deprecated in the future, use String#encode instead.
/vagrant/vendor/gems/message_bus/lib/message_bus.rb:130: warning: already initialized constant ENCODE_SITE_TOKEN
== Seed from /vagrant/db/fixtures/post_action_types.rb
- PostActionType {:id=>1, :name_key=>"bookmark", :is_flag=>false, :position=>1}
- PostActionType {:id=>2, :name_key=>"like", :is_flag=>false, :icon=>"heart", :position=>2}
- PostActionType {:id=>3, :name_key=>"off_topic", :is_flag=>true, :position=>3}
@blowmage
blowmage / tasks_controller_refactoring.rb
Created November 12, 2012 20:17 — forked from ryanb/tasks_controller_refactoring.rb
Variation of RubyTapas episode "021 Domain Model Events" without using callbacks
class TasksController < ApplicationController
def update
if @task.update_attributes(params[:task])
tracker = PostSaveTaskTracker.new(@task)
TaskPusher.new(tracker, socket_id).push_changes
TaskMailSender.new(tracker, current_user).deliver_email
# success response
else
# failure respond
end