Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save seerahulsingh/b7a8221bc90506b0489407a595ce749a to your computer and use it in GitHub Desktop.

Select an option

Save seerahulsingh/b7a8221bc90506b0489407a595ce749a to your computer and use it in GitHub Desktop.
Testing ApplicationController before_filter methods using RSpec's "anonymous" controller instance
class ApplicationController < ActionControllerBase
helper :do_something
def do_something
@from_do_something = params[:for_do_something]
end
end
require 'rails_helper'
describe ApplicationController do
controller do
before_filter :do_something
def action_requiring_filter
render nothing: true
end
end
before(:each) do
routes.draw do
get 'action_requiring_filter' => 'anonymous#action_requiring_filter'
end
end
context "when an action requires a before filter" do
it "runs the filter" do
get :action_requiring_filter, for_do_something: 'some value'
expect(assigns[:from_do_something]).to eq('some value')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment