Last active
May 1, 2017 01:05
-
-
Save brnrdog/4f1309f09abeda852ce05b555a9d9263 to your computer and use it in GitHub Desktop.
users_controller_spec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
def index | |
@users = User.all | |
render json: @users | |
end | |
def create | |
@user = User.create(user_params) | |
render json: @user, status: :created | |
end | |
def show | |
@user = User.find(params[:id]) | |
render json: @user | |
end | |
def update | |
@user = User.find(params[:id]) | |
render json: @user.update(user_params) | |
end | |
private | |
def user_params | |
params.require(:user) | |
.permit(:full_name, :cpf, :birthday_date, :gender, :password) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe UsersController, type: :controller do | |
let (:user) {FactoryGirl.build(:user)} | |
let (:attrs) {FactoryGirl.attributes_for(:user)} | |
describe 'GET #index' do | |
context 'a typical request has been made to the API' do | |
it 'has a http success status' do | |
get :index | |
expect(response).to have_http_status(:ok) | |
end | |
end | |
end | |
describe 'POST #create' do | |
context 'a typical request has been made to the API' do | |
it 'has a http success status' do | |
post :create, params: { id: user, user: attrs.to_h } | |
expect(response).to have_http_status(:created) | |
end | |
end | |
end | |
describe 'GET #show' do | |
context 'a typical request has been made to the API' do | |
it 'has a http success status' do | |
user.save | |
get :show, params: {id: user.id} | |
expect(response).to have_http_status(:ok) | |
end | |
end | |
end | |
describe 'PUT #update' do | |
context 'a typical request has been made to the API' do | |
it 'has a http success status' do | |
user.save | |
put :update, params: { id: user, user: attrs.to_h } | |
expect(response).to have_http_status(:ok) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment