Created
May 7, 2012 11:49
-
-
Save coldnebo/2627378 to your computer and use it in GitHub Desktop.
trying to SimpleDelegator an AREL object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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