Given the following Rails 4.2 controller:
class Api::UsersController < ApplicationController def index respond_to do |format| format.html do flash[:error] = 'Access denied' redirect_to root_url end format.json do render json: {}, status: :unauthorised end end end end
When with RSpec 3, I try to call this index action and expect that status 401 will always have status 200.
The only time I got 401 was to replace the contents of index action of head 401 , but I would like to respond with error 401, and also create a "nice" body, for example { error: 401, message: 'Unauthorised' } .
Why is status: :unauthorised ignored?
ruby ruby-on-rails ruby-on-rails-4
Zedtux
source share