Module: Shoulda::Matchers::ActionController

Defined in:
lib/shoulda/matchers/action_controller.rb,
lib/shoulda/matchers/action_controller/route_params.rb,
lib/shoulda/matchers/action_controller/route_matcher.rb,
lib/shoulda/matchers/action_controller/callback_matcher.rb,
lib/shoulda/matchers/action_controller/redirect_to_matcher.rb,
lib/shoulda/matchers/action_controller/set_session_matcher.rb,
lib/shoulda/matchers/action_controller/rescue_from_matcher.rb,
lib/shoulda/matchers/action_controller/respond_with_matcher.rb,
lib/shoulda/matchers/action_controller/filter_param_matcher.rb,
lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb,
lib/shoulda/matchers/action_controller/render_template_matcher.rb,
lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb,
lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb

Overview

:nodoc:

Defined Under Namespace

Classes: CallbackMatcher, FilterParamMatcher, RedirectToMatcher, RenderTemplateMatcher, RenderWithLayoutMatcher, RescueFromMatcher, RespondWithMatcher, RouteMatcher, RouteParams, SetSessionMatcher, SetTheFlashMatcher, StrongParametersMatcher

Instance Method Summary (collapse)

Instance Method Details

- (Object) filter_param(key)

Ensures that filter_parameter_logging is set for the specified key.

Example:

it { should filter_param(:password) }


9
10
11
# File 'lib/shoulda/matchers/action_controller/filter_param_matcher.rb', line 9

def filter_param(key)
  FilterParamMatcher.new(key)
end

- (Object) permit(*attributes)



13
14
15
# File 'lib/shoulda/matchers/action_controller/strong_parameters_matcher.rb', line 13

def permit(*attributes)
  StrongParametersMatcher.new(self, attributes)
end

- (Object) redirect_to(url_or_description, &block)

Ensures a controller redirected to the given url.

Example:

it { should redirect_to('http://somewhere.com')  }
it { should redirect_to(users_path)  }


10
11
12
# File 'lib/shoulda/matchers/action_controller/redirect_to_matcher.rb', line 10

def redirect_to(url_or_description, &block)
  RedirectToMatcher.new(url_or_description, self, &block)
end

- (Object) render_template(options = {}, message = nil)

Ensures a controller rendered the given template.

Example:

it { should render_template(:show)  }

assert that the "_customer" partial was rendered
it { should render_template(partial: '_customer')  }

assert that the "_customer" partial was rendered twice
it { should render_template(partial: '_customer', count: 2)  }

assert that no partials were rendered
it { should render_template(partial: false)  }


18
19
20
# File 'lib/shoulda/matchers/action_controller/render_template_matcher.rb', line 18

def render_template(options = {}, message = nil)
  RenderTemplateMatcher.new(options, message, self)
end

- (Object) render_with_layout(expected_layout = nil)

Ensures that the controller rendered with the given layout.

Example:

it { should render_with_layout }
it { should render_with_layout(:special) }
it { should_not render_with_layout }


12
13
14
# File 'lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb', line 12

def render_with_layout(expected_layout = nil)
  RenderWithLayoutMatcher.new(expected_layout).in_context(self)
end

- (Object) rescue_from(exception)



4
5
6
# File 'lib/shoulda/matchers/action_controller/rescue_from_matcher.rb', line 4

def rescue_from(exception)
  RescueFromMatcher.new exception
end

- (Object) respond_with(status)

Ensures a controller responded with expected 'response' status code.

You can pass an explicit status number like 200, 301, 404, 500 or its symbolic equivalent :success, :redirect, :missing, :error. See ActionController::StatusCodes for a full list.

Example:

it { should respond_with(:success)  }
it { should respond_with(:redirect) }
it { should respond_with(:missing)  }
it { should respond_with(:error)    }
it { should respond_with(501)       }


18
19
20
# File 'lib/shoulda/matchers/action_controller/respond_with_matcher.rb', line 18

def respond_with(status)
  RespondWithMatcher.new(status)
end

- (Object) route(method, path)

Ensures that requesting path using method routes to options.

If you don't specify a controller, it will use the controller from the example group.

to_param is called on the options given.

Examples:

it { should route(:get, '/posts').
              to(controller: :posts, action: :index) }
it { should route(:get, '/posts').to('posts#index') }
it { should route(:get, '/posts/new').to(action: :new) }
it { should route(:post, '/posts').to(action: :create) }
it { should route(:get, '/posts/1').to(action: :show, id: 1) }
it { should route(:get, '/posts/1').to('posts#show', id: 1) }
it { should route(:get, '/posts/1/edit').to(action: :edit, id: 1) }
it { should route(:put, '/posts/1').to(action: :update, id: 1) }
it { should route(:delete, '/posts/1').
              to(action: :destroy, id: 1) }
it { should route(:get, '/users/1/posts/1').
              to(action: :show, id: 1, user_id: 1) }
it { should route(:get, '/users/1/posts/1').
              to('posts#show', id: 1, user_id: 1) }


29
30
31
# File 'lib/shoulda/matchers/action_controller/route_matcher.rb', line 29

def route(method, path)
  RouteMatcher.new(method, path, self)
end

- (Object) set_session(key)

Ensures that a session key was set to the expected value.

Example:

it { should set_session(:message) }
it { should set_session(:user_id).to(@user.id) }
it { should_not set_session(:user_id) }


12
13
14
# File 'lib/shoulda/matchers/action_controller/set_session_matcher.rb', line 12

def set_session(key)
  SetSessionMatcher.new(key)
end

- (Object) set_the_flash

Ensures that the flash contains the given value. Can be a String, a Regexp, or nil (indicating that the flash should not be set).

Example:

it { should set_the_flash }
it { should set_the_flash.to('Thank you for placing this order.') }
it { should set_the_flash.to(/created/i) }
it { should set_the_flash[:alert].to('Password does not match') }
it { should set_the_flash.to(/logged in/i).now }
it { should_not set_the_flash }


16
17
18
# File 'lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb', line 16

def set_the_flash
  SetTheFlashMatcher.new
end

- (Object) use_after_action(callback)

Ensure a controller uses a given after_action

Example:

it { should use_after_action(:log_activity) }
it { should_not use_after_action(:destroy_user) }


40
41
42
# File 'lib/shoulda/matchers/action_controller/callback_matcher.rb', line 40

def use_after_action(callback)
  CallbackMatcher.new(callback, :after, :action)
end

- (Object) use_after_filter(callback)

Ensure a controller uses a given before_filter

Example:

it { should use_after_filter(:log_activity) }
it { should_not use_after_filter(:destroy_user) }


20
21
22
# File 'lib/shoulda/matchers/action_controller/callback_matcher.rb', line 20

def use_after_filter(callback)
  CallbackMatcher.new(callback, :after, :filter)
end

- (Object) use_around_action(callback)

Ensure a controller uses a given around_action

Example:

it { should use_around_action(:log_activity) }
it { should_not use_around_action(:destroy_user) }


60
61
62
# File 'lib/shoulda/matchers/action_controller/callback_matcher.rb', line 60

def use_around_action(callback)
  CallbackMatcher.new(callback, :around, :action)
end

- (Object) use_around_filter(callback)

Ensure a controller uses a given around_filter

Example:

it { should use_around_filter(:log_activity) }
it { should_not use_around_filter(:destroy_user) }


50
51
52
# File 'lib/shoulda/matchers/action_controller/callback_matcher.rb', line 50

def use_around_filter(callback)
  CallbackMatcher.new(callback, :around, :filter)
end

- (Object) use_before_action(callback)

Ensure a controller uses a given before_action

Example:

it { should use_before_action(:authenticate_user!) }
it { should_not use_before_action(:prevent_ssl) }


30
31
32
# File 'lib/shoulda/matchers/action_controller/callback_matcher.rb', line 30

def use_before_action(callback)
  CallbackMatcher.new(callback, :before, :action)
end

- (Object) use_before_filter(callback)

Ensure a controller uses a given before_filter

Example:

it { should use_before_filter(:authenticate_user!) }
it { should_not use_before_filter(:prevent_ssl) }


10
11
12
# File 'lib/shoulda/matchers/action_controller/callback_matcher.rb', line 10

def use_before_filter(callback)
  CallbackMatcher.new(callback, :before, :filter)
end