-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
187434149 flow to create user #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# app/models/user.rb | ||
class User < ApplicationRecord | ||
validates :email, presence: true, uniqueness: true | ||
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP, message: 'must be a valid email address' } | ||
|
||
# Relationship with LmsCredential | ||
# Associasions | ||
has_many :lms_credentials, dependent: :destroy | ||
has_many :user_to_courses | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a strange variable/class name, and isn't plural (which i'd expect for has_many). do you mean something like |
||
has_many :extensions | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,45 @@ | |
module Api | ||
module V1 | ||
describe UsersController do | ||
describe 'create' do | ||
it 'throws a 501 error' do | ||
post :create | ||
expect(response.status).to eq(501) | ||
describe 'POST #create' do | ||
context 'when creating a new user' do | ||
it 'creates the user successfully' do | ||
post :create, params: { email: '[email protected]' } | ||
|
||
expect(response).to have_http_status(:created) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is nitpicking but: technically you should proabbly put the |
||
expect(JSON.parse(response.body)['message']).to eq('User created successfully') | ||
expect(User.exists?(email: '[email protected]')).to be_truthy | ||
end | ||
end | ||
|
||
context 'when user with the same email already exists' do | ||
before do | ||
User.create(email: '[email protected]') | ||
end | ||
|
||
it 'returns an error message' do | ||
post :create, params: { email: '[email protected]' } | ||
|
||
expect(response).to have_http_status(:conflict) | ||
expect(JSON.parse(response.body)['message']).to eq('A user with this email already exists.') | ||
end | ||
end | ||
|
||
context 'when email is missing or invalid' do | ||
it 'returns an error when email is missing' do | ||
post :create, params: { email: '' } | ||
|
||
expect(response).to have_http_status(:unprocessable_entity) | ||
expect(JSON.parse(response.body)['message']).to eq('Failed to create user') | ||
end | ||
|
||
it 'returns an error when email is invalid' do | ||
# Assuming you add email format validation | ||
post :create, params: { email: 'invalid-email' } | ||
|
||
expect(response).to have_http_status(:unprocessable_entity) | ||
expect(JSON.parse(response.body)['message']).to eq('Failed to create user') | ||
end | ||
end | ||
end | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Associations