Search code examples
ruby-on-railsruby-on-rails-3httphttp-response-codes

RSpec testing in Rails and 304 HTTP status code


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?


Solution

  • 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.