Skip to content

Instantly share code, notes, and snippets.

@archfear
Created May 6, 2009 21:01
Show Gist options
  • Save archfear/107741 to your computer and use it in GitHub Desktop.
Save archfear/107741 to your computer and use it in GitHub Desktop.
class Test::Unit::TestCase
def self.should_have_before_filter(expected_method, options = {})
should_have_filter('before', expected_method, options)
end
def self.should_have_after_filter(expected_method, options = {})
should_have_filter('after', expected_method, options)
end
protected
def self.should_have_filter(filter_type, expected_method, options)
description = "have #{filter_type}_filter :#{expected_method}"
description << " with #{options.inspect}" unless options.empty?
should description do
klass = "action_controller/filters/#{filter_type}_filter".classify.constantize
expected = klass.new(:filter, expected_method.to_sym, options)
assert_equal 1, @controller.class.filter_chain.select { |filter|
filter.method == expected.method && filter.kind == expected.kind &&
filter.options == expected.options && filter.class == expected.class
}.size
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment