forked from saasbook/flextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 187434370-seed-database
- Loading branch information
Showing
11 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
class Course < ApplicationRecord | ||
|
||
#Relationship with User (and UserToCourse) | ||
has_many :user_to_courses | ||
has_many :users, :through => :user_to_courses | ||
# Associations | ||
has_many :course_to_lmss | ||
has_many :lmss, through: :course_to_lmss | ||
has_many :user_to_courses | ||
has_many :users, through: :user_to_courses | ||
|
||
# Validations | ||
validates :course_name, presence: true | ||
|
||
#Relationship with Lms (and CourseToLms) | ||
has_many :course_to_lmss | ||
has_many :lmss, :through => :course_to_lmss | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
class CourseToLms < ApplicationRecord | ||
belongs_to :lms | ||
belongs_to :course | ||
|
||
# Associations | ||
belongs_to :course | ||
belongs_to :lms | ||
|
||
# Validations | ||
validates :course_id, presence: true | ||
validates :lms_id, presence: true | ||
|
||
end |
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
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
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
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) | ||
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 | ||
|
||
|
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