Skip to content
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

Fix resume state transitions #721

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions app/controllers/web/account/resumes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def create
@resume = Web::Account::ResumeForm.new(params[:resume])
@resume.user = current_user

if @resume.save && change_visibility(@resume)
change_state(@resume)
if @resume.save
OpenAiJob.perform_later(@resume.id)
f(:success)
redirect_to account_resumes_path
Expand All @@ -33,13 +34,8 @@ def update
resume = current_user.resumes.find params[:id]
@resume = resume.becomes(Web::Account::ResumeForm)

if params[:publish]
@result = ResumeMutator.publish!(@resume, params[:resume])
elsif params[:hide]
@result = ResumeMutator.to_draft!(@resume, params[:resume])
end

if @result
change_state(@resume)
if @resume.update(params[:resume])
OpenAiJob.perform_later(@resume.id)
f(:success)
redirect_to account_resumes_path
Expand All @@ -53,9 +49,11 @@ def destroy; end

private

def change_visibility(resume)
return resume.publish! if params[:publish]

resume.hide! if params[:hide]
def change_state(resume)
if params[:publish]
resume.publish
else
resume.hide
end
end
end
15 changes: 0 additions & 15 deletions app/mutators/resume_mutator.rb

This file was deleted.

17 changes: 17 additions & 0 deletions test/controllers/web/account/resumes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ class Web::Account::ResumesControllerTest < ActionDispatch::IntegrationTest
assert { resume.not_evaluated? }
end

test '#create unfilled and fail to publish' do
attrs = {
name: 'Ruby developer'
}

params = {
publish: true,
resume: attrs
}

post(account_resumes_path, params:)
assert_response :unprocessable_entity

resume = Resume.find_by(name: attrs[:name])
assert { !resume }
end

test '#update evaluated_ai_state failed' do
resume = resumes(:one_evaluated_failed)
attrs = FactoryBot.attributes_for(:resume)
Expand Down
Loading