From cbdc90fd5f21fad38aa927d8ce87371fa9e2da69 Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 2 Aug 2024 10:10:57 +0200 Subject: [PATCH] Fix controller specs --- db/schema.rb | 3 +-- .../people/picture_controller_spec.rb | 4 +-- spec/features/cv_search_spec.rb | 2 +- spec/features/routing_spec.rb | 3 ++- spec/rails_helper.rb | 4 ++- spec/support/default_params.rb | 25 +++++++++++++++++++ 6 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 spec/support/default_params.rb diff --git a/db/schema.rb b/db/schema.rb index 038f495fa..14cf33abf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_06_24_122411) do +ActiveRecord::Schema[7.0].define(version: 2024_06_03_085509) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -148,7 +148,6 @@ t.string "email" t.integer "department_id" t.string "shortname" - t.integer "ptime_employee_id" t.index ["company_id"], name: "index_people_on_company_id" end diff --git a/spec/controllers/people/picture_controller_spec.rb b/spec/controllers/people/picture_controller_spec.rb index 345a98a80..e3619e16e 100644 --- a/spec/controllers/people/picture_controller_spec.rb +++ b/spec/controllers/people/picture_controller_spec.rb @@ -15,7 +15,7 @@ end it 'should update picture' do - process :update, method: :put, params: { id: bob.id, picture: fixture_file_upload('picture.png', 'image/png') } + put :update, params: { id: bob.id, picture: fixture_file_upload('picture.png', 'image/png') } path = json['data']['picture_path'] @@ -25,7 +25,7 @@ expect(bob['picture']).to eq('picture.png') expect(path).to eq(picture_person_path(bob)) - process :show, method: :get , params: { id: bob.id } + get :show, params: { id: bob.id } new_picture_md5 = 'c903aeff2bec840bd7c028631bd56596' diff --git a/spec/features/cv_search_spec.rb b/spec/features/cv_search_spec.rb index 13abcdd66..5e3e2dc45 100644 --- a/spec/features/cv_search_spec.rb +++ b/spec/features/cv_search_spec.rb @@ -43,7 +43,7 @@ fill_in 'cv_search_field', with: education_location check_search_results(Person.human_attribute_name(:educations)) click_link(Person.human_attribute_name(:educations)) - expect(current_url).to eq(person_path(person, q: education_location)) + expect(current_url).to end_with(person_path(person, q: education_location)) end it 'should only display results when length of search-text is > 3' do diff --git a/spec/features/routing_spec.rb b/spec/features/routing_spec.rb index c21057c81..42fb29141 100644 --- a/spec/features/routing_spec.rb +++ b/spec/features/routing_spec.rb @@ -5,7 +5,8 @@ "/": "/de/people", "/de/": "/de/people", "/people": "/de/people", - "/people_skills": "/de/people_skills" + "/people_skills": "/de/people_skills", + "/en": "/en/people", } before(:each) do sign_in auth_users(:user), scope: :auth_user diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 8e8861be4..d8d10d318 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -66,6 +66,8 @@ config.include(JsonMacros, type: :controller) config.include(JsonAssertion, type: :controller) config.include(ControllerHelpers, type: :controller) + config.include DefaultParams, type: :controller + # Feature helper @@ -85,6 +87,6 @@ config.filter_rails_from_backtrace! config.before(:each, type: :feature) do - default_url_options[:locale] = I18n.default_locale + default_url_options[:locale] = I18n.locale end end diff --git a/spec/support/default_params.rb b/spec/support/default_params.rb new file mode 100644 index 000000000..074c35211 --- /dev/null +++ b/spec/support/default_params.rb @@ -0,0 +1,25 @@ +require 'active_support/concern' + +module DefaultParams + extend ActiveSupport::Concern + + included do + let(:default_params) {{locale: I18n.locale}} + prepend RequestHelpersCustomized + end + + module RequestHelpersCustomized + l = lambda do |path, **kwargs| + if default_params + kwargs[:params] ||= {} + default_params.each do |key, value| + kwargs[:params][key] ||= value + end + end + super(path, params: kwargs[:params]) + end + %w(get post patch put delete).each do |method| + define_method(method, l) + end + end +end