Module: Woulda::LazyHttp::Macros

Defined in:
lib/woulda/lazy_http/macros.rb

Instance Method Summary collapse

Instance Method Details

#lazy_get(*actions) ⇒ Object

Automatically generates setup, should_respond_with, and should_render_template for one or more controller actions. This macro is intended for simple actions that respond to GET requests. If the action expects parameters, setup your object as a hash.

class PageControllerTest < ActionController::TestCase
  lazy_get :index, :about_us, :contact, {:search => {:query => 'foo'}}
end

Also compatible with Factory Girl:

class MemberControllerTest < ActionController::TestCase
  lazy_get :show => {:id => Factory(:member).id}
end


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/woulda/lazy_http/macros.rb', line 41

def lazy_get(*actions)
  actions.each do |action|
    params = nil
    context "on GET to #{action}" do
      if action.is_a? Hash
        b = action.keys.first
        params = action[b]
        action = b
      end
      setup { get action, params }
      should_respond_with :success
      should_render_template action
    end
  end
end