-
-
Save seerahulsingh/b7a8221bc90506b0489407a595ce749a to your computer and use it in GitHub Desktop.
Testing ApplicationController before_filter methods using RSpec's "anonymous" controller instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionControllerBase | |
| helper :do_something | |
| def do_something | |
| @from_do_something = params[:for_do_something] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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