Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding should_filter macro

  • Loading branch information...
commit 669a761959d2c8c0de81706a4bcb7aa8ffc0d842 1 parent 3b5f264
Dan Croak croaky authored
18 lib/shoulda/controller/macros.rb
@@ -100,6 +100,24 @@ def should_set_the_flash_to(val)
100 100 def should_not_set_the_flash
101 101 should_set_the_flash_to nil
102 102 end
  103 +
  104 + # Macro that creates a test asserting that b
  105 + # is set for the specified keys
  106 + #
  107 + # Example:
  108 + #
  109 + # should_filter :password, :ssn
  110 + def should_filter(*keys)
  111 + keys.each do |key|
  112 + should "filter #{key}" do
  113 + assert @controller.respond_to?(:filter_parameters),
  114 + "The key #{key} is not filtered"
  115 + filtered = @controller.send(:filter_parameters, {key.to_s => key.to_s})
  116 + assert_equal '[FILTERED]', filtered[key.to_s],
  117 + "The key #{key} is not filtered"
  118 + end
  119 + end
  120 + end
103 121
104 122 # Macro that creates a test asserting that the controller assigned to
105 123 # each of the named instance variable(s).
2  test/functional/users_controller_test.rb
@@ -13,6 +13,8 @@ def setup
13 13 @response = ActionController::TestResponse.new
14 14 @user = User.find(:first)
15 15 end
  16 +
  17 + should_filter :ssn
16 18
17 19 should_be_restful do |resource|
18 20 resource.identifier = :id
3  test/rails_root/app/controllers/users_controller.rb
... ... @@ -1,4 +1,7 @@
1 1 class UsersController < ApplicationController
  2 +
  3 + filter_parameter_logging :ssn
  4 +
2 5 # GET /users
3 6 # GET /users.xml
4 7 def index

0 comments on commit 669a761

Please sign in to comment.
Something went wrong with that request. Please try again.