Advertisement
Guest User

PostsController simple test

a guest
Aug 21st, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.71 KB | None | 0 0
  1. require 'test_helper'
  2.  
  3. class PostsControllerTest < ActionController::TestCase
  4.   test "get index is not authorized if not logged in" do
  5.     xhr :get, :index
  6.     assert_response :unauthorized
  7.   end
  8.  
  9.   test "get index is successful if logged in" do
  10.     @user = users(:dexter)
  11.     @user.skip_confirmation!
  12.     @user.save!
  13.  
  14.     @auth_headers = @user.create_new_auth_token
  15.     @token = @auth_headers['access-token']
  16.     @client_id = @auth_headers['client']
  17.     @expiry = @auth_headers['expiry']
  18.  
  19.     # ensure the request it not treated as batch request
  20.     age_token(@user,@client_id)
  21.  
  22.     request.headers.merge!(@auth_headers)
  23.  
  24.     xhr :get, :index, format: :json
  25.  
  26.     assert_response :ok
  27.   end
  28.  
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement