Skip to content

Commit

Permalink
Adding user controller test
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBrary committed May 8, 2017
1 parent 7ad1fa3 commit 5a56970
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'rails_helper'

RSpec.describe UsersController, type: :controller do

describe "GET #index as admin" do

before do
login_with create( :user, :admin )
end

after do
Warden.test_reset!
end

it "responds successfully with an HTTP 200 status code" do
get :index
expect(response).to be_success
expect(response).to have_http_status(200)
end

it "renders the index template" do
get :index
expect(response).to render_template("index")
end

it "loads all of the users into @users" do
User.where("id != ?", controller.current_user.id).destroy_all # clear users table
user1, user2 = create_pair(:user)
get :index
expect(assigns(:users)).to match_array([user1, user2, controller.current_user]) # used for login
end
end # of #index

end

0 comments on commit 5a56970

Please sign in to comment.