Skip to content

Commit

Permalink
Feature/604 readd educations (#659)
Browse files Browse the repository at this point in the history
* readd base functionallity

* fix styling of educations

* add translations

* add test

* fix advanced trainings tests after changing translations

* resolve bug for not refreshing after create

* resolve error for error displaying

* fix error in features/educations_spec

* use helper instead of implement logic in view

---------

Co-authored-by: Yanick Minder <[email protected]>
  • Loading branch information
kcinay055679 and kcinay055679 authored Apr 16, 2024
1 parent eb2c213 commit c37f048
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 7 deletions.
1 change: 0 additions & 1 deletion app/controllers/advanced_trainings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

class AdvancedTrainingsController < People::PersonRelationsController
self.permitted_attrs = %i[description year_to month_to year_from month_from person_id]
self.nesting = Person
end
5 changes: 5 additions & 0 deletions app/controllers/educations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class EducationsController < People::PersonRelationsController
self.permitted_attrs = %i[location title month_to year_to month_from year_from person_id]
end
11 changes: 8 additions & 3 deletions app/controllers/people/person_relations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class People::PersonRelationsController < CrudController
self.nesting = Person

def index
redirect_to person_path(entry.person)
Expand All @@ -12,9 +13,13 @@ def show

def create
super do |format, success|
if success && params.key?(:render_new_after_save)
remove_instance_variable(model_ivar_name)
format.turbo_stream { render('save_and_new') }
if success
if params.key?(:render_new_after_save)
remove_instance_variable(model_ivar_name)
format.turbo_stream { render('save_and_new') }
else
format.turbo_stream { render('refresh_after_new') }
end
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/views/educations/_education.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%div.border-top
%turbo-frame{id: dom_id(education)}
= link_to edit_person_education_path(@person, education), data:{turbo_prefetch: :false}, class: "text-decoration-none text-dark bg-hover-gray d-block" do
%div.d-flex.row.pt-3.pb-5
%span.col-3.ps-5
= date_range_label education
%span.col.d-flex.flex-column
%span.fw-bolder
= education.title
= education.location
7 changes: 7 additions & 0 deletions app/views/educations/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= form_with model: ([entry.person, entry]) do |f|
= render('people/person_relations/form', form: f) do
- content_for :input do
= t "activerecord.attributes.education.title"
= f.text_area :title, placeholder: "Description", class: "form-control w-100"
= t "activerecord.attributes.education.location"
= f.text_area :location, placeholder: "Ein Ausbildungsort", class: "form-control w-100"
3 changes: 2 additions & 1 deletion app/views/people/_cv.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
= render('profile')
= render('core_competences')
= render('people/person_relations/index', list: @person.advanced_trainings)
= render('people/person_relations/index', list: @person.advanced_trainings.list)
= render('people/person_relations/index', list: @person.educations.list)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
= turbo_stream.remove dom_id(entry.class.new)

= turbo_stream.update name_of_obj(entry) do
= render entries
10 changes: 10 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ de:
cancel: Abbrechen
delete: Löschen
save-and-new: Speichern & Neu

attributes:
year_from: Jahr von
year_to: Jahr bis
month_from: Monat von
month_to: Monat bis
activerecord:
models:
advanced_training: Weiterbildung
education: Ausbildung
attributes:
advanced_training:
description: Beschreibung
education:
title: Ausbildung
location: Ausbildungsort
skills:
table:
skill: Skill
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

resources :people do
resources :advanced_trainings
resources :educations
member do
get 'export-cv', to: 'people/export_cv#show'
put 'picture', to: 'people/picture#update'
Expand Down
5 changes: 3 additions & 2 deletions spec/features/advanced_trainings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
click_link(href: new_person_advanced_training_path(person))
within('turbo-frame#new_advanced_training') do
fill_in 'advanced_training_description', with: description
select '2020', from: 'advanced_training_year_from'
click_default_submit
end
expect(page).to have_content(description)
Expand Down Expand Up @@ -99,7 +100,7 @@

click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Year from muss ausgefüllt werden")
expect(page).to have_css(".alert.alert-danger", text: "Jahr von muss ausgefüllt werden")
end

it 'Update entry and clear description' do
Expand All @@ -121,7 +122,7 @@
select '2010', from: 'advanced_training_year_to'
click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Year from muss vor \"Datum bis\" sein")
expect(page).to have_css(".alert.alert-danger", text: "Jahr von muss vor \"Datum bis\" sein")
end
end

Expand Down
95 changes: 95 additions & 0 deletions spec/features/educations_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
require 'rails_helper'

describe 'Educations', type: :feature, js:true do
let(:person) { people(:bob) }

before(:each) do
sign_in auth_users(:admin)
visit person_path(person)
end

describe 'Crud actions' do
it 'shows all' do
within('turbo-frame#education') do
person.educations.each do |education|
expect(page).to have_content(education.title)
expect(page).to have_content(education.location)
end
end
end

it 'creates and saves new education' do
title = 'Döner-Verkäufer'
new_location = 'Dönerbude'

click_link(href: new_person_education_path(person))

within('turbo-frame#new_education') do
select '2024', from: 'education_year_from'
fill_in 'education_title', with: title
fill_in 'education_location', with: new_location
click_default_submit
end

expect(page).to have_content(title)
expect(page).to have_content(new_location)
end

it 'updates education' do
updated_location = 'Dönerbude des Vertrauens'

education = person.educations.first
within("turbo-frame#education_#{education.id}") do
find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click
fill_in 'education_location', with: updated_location
click_default_submit
end
expect(page).to have_content(updated_location)
end

it 'cancels without saving' do
education = person.educations.first
old_location = education.location
updated_location = 'Dönerbude des Vertrauens'

within("turbo-frame#education_#{education.id}") do
find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click
fill_in 'education_location', with: updated_location
find('a', text: 'Abbrechen').click
end
expect(person.educations.first.location).to eq(old_location)
end
end

describe 'Error handling' do
it 'create new education without title and location' do
click_link(href: new_person_education_path(person))

within('turbo-frame#new_education') do
click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Ausbildung muss ausgefüllt werden")
expect(page).to have_css(".alert.alert-danger", text: "Ausbildungsort muss ausgefüllt werden")
end

it 'Update entry and clear title & description' do
education = person.educations.first
within("turbo-frame#education_#{education.id}") do
find("[href=\"#{edit_person_education_path(person, education)}\"]").all("*").first.click
fill_in 'education_title', with: ""
fill_in 'education_location', with: ""
click_default_submit
end
expect(page).to have_css(".alert.alert-danger", text: "Ausbildung muss ausgefüllt werden")
expect(page).to have_css(".alert.alert-danger", text: "Ausbildungsort muss ausgefüllt werden")
end
end

def click_default_submit
find("button[type='submit'][name='save']").click
end

def click_save_and_new_submit
find("button[type='submit'][name='render_new_after_save']").click
end
end

0 comments on commit c37f048

Please sign in to comment.