Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hmm, I'm not clear on what you want to test, exactly. It sounds like you're testing for the existence of</p> <pre><code>before_filter :authenticate_user! </code></pre> <p>but this is only helpful if you also know that <code>:authenticate_user!</code> behaves as you intend. So I would recommend a two-pronged testing attack - </p> <ol> <li>Test that #authenticate_user! behaves according to your specifications</li> <li>Write specs to ensure the method you are protecting with the before_filter has correct behavior when the user is logged in and logged out. </li> </ol> <p>Idiomatically, <code>before_filter</code> methods are declared <em>private</em>, so your specs could look something like:</p> <pre><code>describe ApplicationController do describe 'GET /my_account' do # a method to which the before_filter applies subject { get :my_account } context 'with a logged-out session' do it 'redirects to the homepage' do response.should redirect_to root_url end end context 'with a logged-in session' do # if you use FactoryGirl and have a spec helper method log_in() to set up the session before { log_in(FactoryGirl.create :user) } it { should render_template('my_account') } # etc... end end describe 'private #authenticate_user!' do subject { ApplicationController.send(:authenticate_user!) } it 'calls the authentication logic' do Authentication.expects(:attempt_login) # or whatever to verify the internals subject end end end </code></pre> <p>By testing both separately, you can verify that the desired behavior is maintained regardless of the implementation of <code>:authenticate_user!</code> or other login internals. And, you get to do it without doing too much reliance on Rails internals!</p> <p>Let me know if this makes any sense whatsoever. I'm relatively new to StackOverflow, so feedback is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload