Skip to content

Instantly share code, notes, and snippets.

@coldnebo
Created May 7, 2012 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coldnebo/2627378 to your computer and use it in GitHub Desktop.
Save coldnebo/2627378 to your computer and use it in GitHub Desktop.
trying to SimpleDelegator an AREL object
# based on http://tatey.com/2012/02/07/mocking-with-minitest-mock-and-simple-delegator/
class Order < ActiveRecord::Base
# …
end
class MyController < ApplicationController
def index
@orders = Order.find(:all)
end
end
# mocha version of a controller test involving AREL:
test "it should display an index page with all orders" do
::Order.expects(:find).with(:all).returns([])
get :index
assert_template :index
assert_response :success
end
# Simple Delegator version?
test "it should display an index page with blocks" do
mock_block = Class.new SimpleDelegator do
def find(...)
[]
end
end
# this is where I'm stuck. How can I rig the controller context so that it uses mock_block instead of the default Order.find
# controller.order = mock_order.new(Order.new)
get :index
assert_template :index
assert_response :success
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment