Skip to content

Instantly share code, notes, and snippets.

@blowmage
blowmage / History.txt
Created September 26, 2012 03:09
Stoopid example of MiniTest Shouldify
=== 1.0.0 / 2012-09-25
* 1 major enhancement
* Birthday!
@blowmage
blowmage / _readme.md
Created November 6, 2012 16:54
Presenters in Rails, using modules

Presenters in Rails

I have bemoaned the lack of a ViewModel in Rails many times, and I prefer using Presenters to simulate a ViewModel. But it turns out there is an object that does represent the state of the view in Rails apps. Its an instance of ActionView::Base that the controller calls view_context. We don't have much control of this object, but it seems like a logical place to put our view-specific behavior.

This code is an attempt at creating Presenters using modules. The module will be mixed into the view_context object. This is very similar to how a Decorator module will be mixed into a model object, only instead of being specific to the model is it specific to the view.

This means that testing your presenter is no different than testing any other module. So relying on dependencies such as other methods or instance variables can make testing difficult.

@blowmage
blowmage / tasks_controller_refactoring.rb
Created November 12, 2012 16:13 — forked from ryanb/tasks_controller_refactoring.rb
Variation of RubyTapas episode "021 Domain Model Events" without using callbacks or reimplementing dirty tracking.
class TasksController < ApplicationController
def update
if @task.update_attributes(params[:task])
TaskPusher.new(@task, socket_id).push_changes
TaskMailSender.new(@task, current_user).deliver_email
# success response
else
# failure respond
end
end
@blowmage
blowmage / tasks_controller_refactoring.rb
Created November 12, 2012 16:52 — forked from ryanb/tasks_controller_refactoring.rb
Variation of RubyTapas episode "021 Domain Model Events" without callbacks, using dirty, and keeping the tracker object.
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
@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
[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 / 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
@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 / 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

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: