From a724c4514db55e5906cffeda88190343e3170790 Mon Sep 17 00:00:00 2001 From: Jannik Pulfer Date: Mon, 29 Jul 2024 14:31:12 +0200 Subject: [PATCH] Rename create_person method to create_or_find --- app/controllers/people_controller.rb | 2 +- app/domain/ptime/people_employees.rb | 2 +- spec/domain/ptime/people_employees_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 493eba348..ea165865f 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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 diff --git a/app/domain/ptime/people_employees.rb b/app/domain/ptime/people_employees.rb index 1a6a7217d..103efb68c 100644 --- a/app/domain/ptime/people_employees.rb +++ b/app/domain/ptime/people_employees.rb @@ -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) diff --git a/spec/domain/ptime/people_employees_spec.rb b/spec/domain/ptime/people_employees_spec.rb index b30d2752a..b1cc07ab9 100644 --- a/spec/domain/ptime/people_employees_spec.rb +++ b/spec/domain/ptime/people_employees_spec.rb @@ -11,7 +11,7 @@ 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 @@ -19,7 +19,7 @@ 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