Created
March 14, 2020 18:22
-
-
Save donrestarone/e464a1033d9801387ba83de866dec1bd to your computer and use it in GitHub Desktop.
a simple controller test that asserts if a user is created
This file contains 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 Api::Core::V1::UsersController, type: :controller do | |
it 'must be able to create a user when first_name, last_name, email and password are specified' do | |
post :create, params: {first_name: 'Cletus', last_name: 'Mccletus', email: 'cletus@mccletus.com', password: 'cletus12345', password_confirmation: 'cletus12345'} | |
response_body = JSON.parse(response.body) | |
expect(response_body.keys).to eql ["status", "code"] | |
expect(response_body["code"]).to eql 200 | |
end | |
it 'must fail gracefully when first_name, last_name, email or password are not specified when trying to create a user' do | |
post :create, params: {last_name: 'Mccletus', email: 'cletus@mccletus.com', password: 'cletus12345', password_confirmation: 'cletus12345'} | |
response_body = JSON.parse(response.body) | |
expect(response_body["code"]).to eql 422 | |
post :create, params: {first_name: 'Cletus', email: 'cletus@mccletus.com', password: 'cletus12345', password_confirmation: 'cletus12345'} | |
response_body = JSON.parse(response.body) | |
expect(response_body["code"]).to eql 422 | |
post :create, params: { email: 'cletus@mccletus.com', password: 'cletus12345', password_confirmation: 'cletus12345'} | |
response_body = JSON.parse(response.body) | |
expect(response_body["code"]).to eql 422 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment