Skip to content

Commit

Permalink
Rename create_person method to create_or_find
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomTannenbaum committed Jul 30, 2024
1 parent 58a9824 commit a724c45
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def show
end

def new
@person = Ptime::PeopleEmployees.new.create_person(params[:ptime_employee_id])
@person = Ptime::PeopleEmployees.new.create_or_find(params[:ptime_employee_id])
# (%w[DE EN FR] - @person.language_skills.pluck(:language)).each do |language|
# @person.language_skills.push(LanguageSkill.new({ language: language, level: 'A1' }))
# end
Expand Down
2 changes: 1 addition & 1 deletion app/domain/ptime/people_employees.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Ptime
class PeopleEmployees
def create_person(ptime_employee_id)
def create_or_find(ptime_employee_id)
raise 'No ptime_employee_id provided' unless ptime_employee_id

person = Person.find_by(ptime_employee_id: ptime_employee_id)
Expand Down
4 changes: 2 additions & 2 deletions spec/domain/ptime/people_employees_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
end

it 'should raise error when no ptime_employee_id is passed to new action' do
expect{ Ptime::PeopleEmployees.new.create_person(nil) }.to raise_error(RuntimeError, 'No ptime_employee_id provided')
expect{ Ptime::PeopleEmployees.new.create_or_find(nil) }.to raise_error(RuntimeError, 'No ptime_employee_id provided')
end

it 'should return person if it has the given ptime_employee_id' do
person_wally = people(:wally)
person_wally.ptime_employee_id = 123
person_wally.save!

new_person = Ptime::PeopleEmployees.new.create_person(person_wally.ptime_employee_id)
new_person = Ptime::PeopleEmployees.new.create_or_find(person_wally.ptime_employee_id)
expect(person_wally.attributes.except(*%w[created_at updated_at])).to eql(new_person.attributes.except(*%w[created_at updated_at]))
end

Expand Down

0 comments on commit a724c45

Please sign in to comment.