Advertisement
Guest User

spec

a guest
Nov 28th, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.94 KB | None | 0 0
  1. require 'rails_helper'
  2.  
  3. class AuthenticationController < ApplicationController
  4.   before_action :authenticate_auth_user!
  5.  
  6.   def index
  7.     render text: 'Super secret stuff!'
  8.   end
  9. end
  10.  
  11. RSpec.describe AuthenticationController, type: :controller do
  12.   describe 'GET #index' do
  13.  
  14.     context 'user logged in' do
  15.       it "responds with an HTTP 200 status code" do
  16.         user = User.create(email: "testmail@testserv.com", password: "qwerty123", password_confirmation: "qwerty123")
  17.         sign_in user
  18.         routes.draw { get "index" => "authentication#index" }
  19.         get :index, format: :json
  20.         expect(response).to have_http_status(200)
  21.       end
  22.     end
  23.  
  24.     context 'user doesn\'t logged in' do
  25.       it "responds with an HTTP 401 status code" do
  26.         routes.draw { get "index" => "authentication#index" }
  27.         get :index, format: :json
  28.         expect(response).to have_http_status(401)
  29.       end
  30.     end
  31.  
  32.   end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement