Skip to content

Instantly share code, notes, and snippets.

@skorfmann
Created March 5, 2015 21:29
Show Gist options
  • Save skorfmann/690a173fe15309962de2 to your computer and use it in GitHub Desktop.
Save skorfmann/690a173fe15309962de2 to your computer and use it in GitHub Desktop.
shared_examples 'included before filter' do |expected_filter, actions|
controller do
skip_filter *_process_action_callbacks.map(&:filter).reject {|filter| filter == expected_filter }
actions.each do |action|
define_method(action) do
render nothing: true
end
end
end
before do
controller_route = described_class.name.underscore.gsub('_controller', '')
routes.draw do
actions.each do |action|
get action.to_s => "#{controller_route}##{action}"
end
end
end
actions.each do |action|
it "action #{action} has '#{expected_filter}' as before filter" do
expect(controller).to receive(expected_filter)
get action
end
end
end
it_should_behave_like "included before filter", :render_pretty?, [:show, :index]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment