-
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
Changes from all commits
57f0e0b
aaa5010
2bb5274
4289dfa
8382be5
f939bd7
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 |
---|---|---|
|
@@ -9,6 +9,41 @@ | |
it { should validate_presence_of(:application_url) } | ||
it { should validate_presence_of(:contact_information) } | ||
it { should validate_presence_of(:company_id) } | ||
|
||
subject { | ||
user = User.create!( | ||
name: "Yolonda Aberdeer", | ||
email: "[email protected]", | ||
password: "nuggetbisket" | ||
) | ||
|
||
google = Company.create!( | ||
user_id: user.id, | ||
name: "Google", | ||
website: "google.com", | ||
street_address: "1600 Amphitheatre Parkway", | ||
city: "Mountain View", | ||
state: "CA", | ||
zip_code: "94043", | ||
notes: "Search engine" | ||
) | ||
|
||
JobApplication.create!( | ||
position_title: "Jr. CTO", | ||
date_applied: "2024-10-31", | ||
status: 1, | ||
notes: "Fingers crossed!", | ||
job_description: "Looking for Turing grad/jr dev to be CTO", | ||
application_url: "www.example.com", | ||
contact_information: "[email protected]", | ||
company_id: google.id, | ||
user_id: user.id | ||
) | ||
} | ||
|
||
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 | ||
Comment on lines
+44
to
+46
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. 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. |
||
end | ||
|
||
describe "associations" do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
expect(response.status).to eq(200) | ||
|
||
jobApp = JSON.parse(response.body, symbolize_names: true) | ||
|
||
expect(jobApp[:data][:type]).to eq("job_application") | ||
expect(jobApp[:data][:id]).to eq(JobApplication.last.id.to_s) | ||
expect(jobApp[:data][:attributes][:position_title]).to eq(job_application_params[:position_title]) | ||
|
@@ -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 commentThe 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. |
||
|
||
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) | ||
|
||
user_2 = User.create!(name: "Daniel Averdaniel", email: "[email protected]", password: "nuggetonnabiscut") | ||
|
||
post "/api/v1/users/#{user_2.id}/job_applications", | ||
params: { job_application: job_application_params } | ||
expect(response).to be_successful | ||
expect(response.status).to eq(200) | ||
end | ||
end | ||
|
||
context "sad path" do | ||
|
@@ -92,6 +106,23 @@ | |
expect(json[:message]).to eq("Company must exist and Position title can't be blank") | ||
expect(json[:status]).to eq(400) | ||
end | ||
|
||
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 | ||
Comment on lines
+110
to
+125
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. 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. |
||
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.
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.