2

Using Devise for authentication. On a controller that has:

before_filter authenticate_user!, :except => [ :index, :show ]

I always get 304 Not Modified status code instead of 200 OK on the authenticated actions, even in the browser while signed in. The views render and work just fine.

It's stopping my tests from passing:

describe 'GET index' do
  it 'should be successful' do
    get 'index'
    response.should be_success  # Fails due to 304 status code
  end
end

I thought it was my controller's fault at first, but besides the before_filter and decent_exposure, the controller couldn't be any more common.

What could possibly be the root of this issue?

1
  • 304 can only be returned in a response to a conditional GET request. Commented Apr 17, 2011 at 7:20

2 Answers 2

2

304s are a good thing. In this case, it is what is expected (and desired) even though it may be giving some of your tests trouble. A 304 means that your webserver and client are communicating in a way to allow caching of the webserver's response.

I'm not entirely familiar with Rails, but I'd suspect there is a built in mechanism which is caching your responses. Here is a Rails article on caching:
http://guides.rubyonrails.org/caching_with_rails.html

And here is what looks like a way to disable caching on the Controller/Action level (ignore the parts about iframes... also this might not be the best way):
http://arjunghosh.wordpress.com/2008/04/29/how-to-force-the-browser-to-not-cache-in-rails/

Sign up to request clarification or add additional context in comments.

1 Comment

What's confusing is that caching is already disabled in the test environment. If I understood it right, any of my controller actions may return this status, correct? Then something else must be wrong...
1

The tests were failing because I was using Devise for authentication with the confirmable module and was not using confirmed users.

After setting the confirmed_at attribute in the factory, all tests passed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.