-
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
Refactor/job application application url uniqueness #34
Refactor/job application application url uniqueness #34
Conversation
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.
Code looks good, thank you for picking up this validation and testing. Updated documentation looks good as well.
@@ -44,6 +44,20 @@ | |||
expect(jobApp[:data][:attributes][:contact_information]).to eq(job_application_params[:contact_information]) | |||
expect(jobApp[:data][:attributes][:company_id]).to eq(job_application_params[:company_id]) | |||
end | |||
it "Allows 2 unique users to create job applications with the same URL" do |
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.
This is an excellent test to include, not only does it test the flexibility of the validation, but this functionality is necessary for the foundation of this application.
spec/requests/api/v1/job_applications/job_application_create_spec.rb
Outdated
Show resolved
Hide resolved
it "returns a error message if a user tries to create multiple job applications with the same URL" do | ||
post "/api/v1/users/#{@user.id}/job_applications", | ||
params: { job_application: job_application_params } | ||
expect(response).to be_successful | ||
expect(response.status).to eq(200) | ||
|
||
post "/api/v1/users/#{@user.id}/job_applications", | ||
params: { job_application: job_application_params } | ||
expect(response).to_not be_successful | ||
expect(response.status).to eq(400) | ||
|
||
json = JSON.parse(response.body, symbolize_names: true) | ||
|
||
expect(json[:message]).to eq("Application url already exists for the user, try making a new application with a new URL.") | ||
expect(json[:status]).to eq(400) | ||
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.
I like that you added and tested this functionality, verifying that a user cannot make multiple entries of the same job application. This is a excellent enhancement for maintaining clean and accurate data being stored in the database. From a user perspective, I would appreciate this functionality, as I could be creating a new job application online, yet have the wrong URL in my clipboard, and this error message would prove very helpful in understanding.
it "validates uniqueness of job application for a given user" do | ||
expect(subject).to validate_uniqueness_of(:application_url).scoped_to(:user_id).with_message("already exists for the user, try making a new application with a new URL.") | ||
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.
A lot goes into testing the validity scoped to a user. I appreciate the clean, one-line test, and a very user-friendly error message. Excellent work.
@@ -6,7 +6,7 @@ class JobApplication < ApplicationRecord | |||
validates :date_applied, presence: true | |||
validates :status, presence: true | |||
validates :job_description, presence: true | |||
validates :application_url, presence: true | |||
validates :application_url, presence: true, uniqueness: { scope: :user_id, message: "already exists for the user, try making a new application with a new URL." } |
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.
Great work adding this particular validation. Now we can ensure that every application record is unique per user while allowing other users to have the same url. This will help maintain data integrity and avoid duplicate entries for the same job application.
Type of Change
Description
application_url
field in job application modelMotivation and Context
Related Tickets
Added Test?
job_application_spec.rb
job_application_create_spec.rb
Checklist: