From 065814f2c10b376d98ce5af752442b1dee38b8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20J=C3=A4ggi?= Date: Tue, 25 Jun 2024 09:20:24 +0200 Subject: [PATCH 1/3] adjust some queries for pbs specs --- .github/workflows/tests.yml | 2 +- Rakefile | 2 -- app/controllers/youth/event/lists_controller.rb | 2 +- app/models/youth/event/course.rb | 4 ++-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bb4ccd65..172ecf0a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,7 +21,7 @@ on: default: 'master' jobs: wagon_tests: - uses: hitobito/hitobito/.github/workflows/wagon-tests.yml@master + uses: hitobito/hitobito/.github/workflows/wagon-tests.yml@psql-migration with: wagon_repository: ${{ github.event.repository.name }} core_ref: ${{ inputs.core_ref }} diff --git a/Rakefile b/Rakefile index 42898974..e3ab77b9 100644 --- a/Rakefile +++ b/Rakefile @@ -17,5 +17,3 @@ load 'rspec/rails/tasks/rspec.rake' require 'ci/reporter/rake/rspec' unless Rails.env.production? HitobitoYouth::Wagon.load_tasks - -task 'test:prepare' => 'db:test:prepare' diff --git a/app/controllers/youth/event/lists_controller.rb b/app/controllers/youth/event/lists_controller.rb index 0697bad6..4eb12f3c 100644 --- a/app/controllers/youth/event/lists_controller.rb +++ b/app/controllers/youth/event/lists_controller.rb @@ -54,7 +54,7 @@ def courses_for_bsv_export course_filters .to_scope .includes(participations: [:roles, person: :location]) - .order("event_dates.start_at") + .order("start_at") end def dates_from_to diff --git a/app/models/youth/event/course.rb b/app/models/youth/event/course.rb index 5e592c68..ebe6da28 100644 --- a/app/models/youth/event/course.rb +++ b/app/models/youth/event/course.rb @@ -77,8 +77,8 @@ def tentatives_count def organizers Person .includes(:roles) - .where(roles: {type: organizing_role_types, - group_id: groups.collect(&:id)}) + .where(roles: { type: organizing_role_types.map(&:to_s), + group_id: groups.collect(&:id) }) end def default_participation_state(participation, for_someone_else = false) From 7a986d72d926bd6f21ede5a27ce8e1a859cc750c Mon Sep 17 00:00:00 2001 From: megli2 Date: Wed, 14 Aug 2024 09:56:11 +0200 Subject: [PATCH 2/3] make rubocop happy --- app/models/youth/event/course.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/youth/event/course.rb b/app/models/youth/event/course.rb index ebe6da28..49e9d4ca 100644 --- a/app/models/youth/event/course.rb +++ b/app/models/youth/event/course.rb @@ -77,8 +77,12 @@ def tentatives_count def organizers Person .includes(:roles) - .where(roles: { type: organizing_role_types.map(&:to_s), - group_id: groups.collect(&:id) }) + .where( + roles: { + type: organizing_role_types.map(&:to_s), + group_id: groups.collect(&:id) + } + ) end def default_participation_state(participation, for_someone_else = false) From 6b1827ea2292ec88e49ec4dc2428ffcb119e518e Mon Sep 17 00:00:00 2001 From: megli2 Date: Wed, 21 Aug 2024 14:52:39 +0200 Subject: [PATCH 3/3] implement spec for person search --- app/indices/person_index.rb | 10 ------- app/models/youth/person.rb | 3 +++ .../search_strategies/person_search_spec.rb | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) delete mode 100644 app/indices/person_index.rb create mode 100644 spec/domain/search_strategies/person_search_spec.rb diff --git a/app/indices/person_index.rb b/app/indices/person_index.rb deleted file mode 100644 index 42c5ae0f..00000000 --- a/app/indices/person_index.rb +++ /dev/null @@ -1,10 +0,0 @@ -# Copyright (c) 2012-2015, Pfadibewegung Schweiz. This file is part of -# hitobito_pbs and licensed under the Affero General Public License version 3 -# or later. See the COPYING file at the top-level directory or at -# https://github.com/hitobito/hitobito_pbs. - -module PersonIndex; end - -ThinkingSphinx::Index.define_partial :person do - indexes j_s_number, ahv_number -end diff --git a/app/models/youth/person.rb b/app/models/youth/person.rb index 5422f424..bfe30856 100644 --- a/app/models/youth/person.rb +++ b/app/models/youth/person.rb @@ -14,6 +14,9 @@ module Youth::Person NATIONALITIES_J_S = %w[CH FL ANDERE].freeze included do + Person::SEARCHABLE_ATTRS << :ahv_number << :j_s_number + include PgSearchable + has_many :people_managers, foreign_key: :managed_id, dependent: :destroy has_many :people_manageds, class_name: "PeopleManager", diff --git a/spec/domain/search_strategies/person_search_spec.rb b/spec/domain/search_strategies/person_search_spec.rb new file mode 100644 index 00000000..a917b54d --- /dev/null +++ b/spec/domain/search_strategies/person_search_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" + +describe SearchStrategies::PersonSearch do + before do + people(:bottom_leader).update!(j_s_number: 12345, ahv_number: "756.9217.0769.85") + end + + describe "#search_fulltext" do + let(:user) { people(:top_leader) } + + it "finds accessible person by j_s number" do + result = search_class(people(:bottom_leader).j_s_number.to_s).search_fulltext + + expect(result).to include(people(:bottom_leader)) + end + + it "finds accessible person by ahv number" do + result = search_class(people(:bottom_leader).ahv_number.to_s).search_fulltext + + expect(result).to include(people(:bottom_leader)) + end + end + + def search_class(term = nil, page = nil) + described_class.new(user, term, page) + end +end \ No newline at end of file