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

Bendyworks/deduplicate starting salary #267

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
#206 get salary start date from tenure rather than from a hidden field
  • Loading branch information
Roger Roelofs committed Mar 25, 2021
commit 8ee9daa31ebb184912391f507d1456979cbeb423
31 changes: 19 additions & 12 deletions app/controllers/employees_controller.rb
Original file line number Diff line number Diff line change
@@ -44,17 +44,24 @@ def set_employee
end

def employee_params
params.require(:employee).permit(:first_name,
:last_name,
:starting_salary,
:direct_experience,
:indirect_experience,
:billable,
:notes,
:planning_raise_date,
:planning_raise_salary,
:planning_notes,
tenures_attributes: [:id, :start_date, :end_date, :_destroy],
salaries_attributes: [:id, :start_date, :annual_amount])
emp_params = params.require(:employee)
.permit(:first_name,
:last_name,
:starting_salary,
:direct_experience,
:indirect_experience,
:billable,
:notes,
:planning_raise_date,
:planning_raise_salary,
:planning_notes,
tenures_attributes: [:id, :start_date, :end_date, :_destroy],
salaries_attributes: [:id, :annual_amount])
salary = emp_params.dig(:salaries_attributes, "0")
tenure = emp_params.dig(:tenures_attributes, "0")
if salary && tenure
emp_params[:salaries_attributes]["0"][:start_date] = tenure[:start_date]
end
emp_params
end
end
3 changes: 1 addition & 2 deletions app/views/employees/_form.html.haml
Original file line number Diff line number Diff line change
@@ -50,8 +50,7 @@
= f.label :indirect_experience, 'Indirect experience (months)', class: 'control-label'
= f.number_field :indirect_experience, class: 'form-control'
= f.fields_for :salaries, (employee.salaries.first || employee.salaries.build) do |salary_f|
= salary_f.hidden_field :id unless employee.salaries.count == 0
= salary_f.hidden_field :start_date unless employee.salaries.count == 0
= salary_f.hidden_field :id
.form-group.col-lg-12
= salary_f.label :annual_amount, 'Starting salary annual amount', class: 'control-label'
.input-group
6 changes: 3 additions & 3 deletions spec/controllers/employees_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@

describe 'POST create' do
describe 'with valid params' do
let(:valid_attributes) {{ employee: attributes_for(:employee).merge(tenures_attributes: [{ start_date: Time.zone.today }]) }}
let(:valid_attributes) {{ employee: attributes_for(:employee).merge(tenures_attributes: {"0" => { start_date: Time.zone.today }}) }}
it 'creates a new Employee' do
expect do
post :create, params: valid_attributes
@@ -59,7 +59,7 @@

it 'creates a new Employee with the expected start date' do
post :create, params: valid_attributes
expect(assigns(:employee).start_date).to eq(valid_attributes[:employee][:tenures_attributes][0][:start_date])
expect(assigns(:employee).start_date).to eq(valid_attributes[:employee][:tenures_attributes]["0"][:start_date])
end

it 'assigns a newly created employee as @employee' do
@@ -70,7 +70,7 @@
end

describe 'with invalid params' do
let(:invalid_attributes) {{ employee: attributes_for(:employee).merge(first_name: nil).merge(tenures_attributes: [{ start_date: Time.zone.today }]) }}
let(:invalid_attributes) {{ employee: attributes_for(:employee).merge(first_name: nil).merge(tenures_attributes: {"0" => { start_date: Time.zone.today }}) }}

it 'assigns a newly created but unsaved employee as @employee' do
post :create, params: invalid_attributes