Changeset 1163

Show
Ignore:
Timestamp:
01/03/08 22:42:47 (11 months ago)
Author:
has.s..@gmail.com
Message:

Refactor dispatch_to to allow access to the controller implicitly inside a block. You do not need to specify it as a block argument anymore. It still works.

eg.
dispatch_to(MyController?, :show){ |controller| controller.stub!(:stuff)}
or
dispatch_to(MyController?, :show){ controller.stub!(:stuff)}

now both work.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/merb/test/helper.rb

    r1142 r1163  
    120120      def dispatch_to(controller, action = :index, opts = {}) 
    121121        klass = controller.class == Class ? controller : controller.class 
    122         klass.stub!(:find_by_title).and_return(@page) 
    123         the_controller = klass.build(fake_request) 
    124         the_controller.stub!(:params).and_return(opts.merge!(:controller => "#{klass.name.downcase}", :action => action.to_s)) 
    125  
    126         yield the_controller if block_given? 
    127         @controller = the_controller 
    128         [the_controller, the_controller.dispatch(action.to_sym)] 
    129       end  
     122        @controller = klass.build(fake_request) 
     123        @controller.stub!(:params).and_return(opts.merge!(:controller => klass.name.downcase, :action => action.to_s)) 
     124        yield @controller if block_given? 
     125        [@controller, @controller.dispatch(action.to_sym)] 
     126      end 
    130127       
    131128      def path_with_options(path, opts)