From 4c9b8f87141cd5c8a42ae355879132ec329f56f9 Mon Sep 17 00:00:00 2001 From: hirokiej <123009866+hirokiej@users.noreply.github.com> Date: Wed, 23 Jul 2025 01:43:54 +0900 Subject: [PATCH 1/4] =?UTF-8?q?ColleagueTraineesRecentReportsQuery?= =?UTF-8?q?=E3=81=AB=E5=90=8C=E5=83=9A=E7=A0=94=E4=BF=AE=E7=94=9F=E3=81=AE?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=97=A5=E5=A0=B1=E3=82=92=E9=99=8D=E9=A0=86?= =?UTF-8?q?=E3=81=A7=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B=E3=83=AD=E3=82=B8?= =?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...colleague_trainees_recent_reports_query.rb | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/queries/colleague_trainees_recent_reports_query.rb diff --git a/app/queries/colleague_trainees_recent_reports_query.rb b/app/queries/colleague_trainees_recent_reports_query.rb new file mode 100644 index 00000000000..93f0e7ddee7 --- /dev/null +++ b/app/queries/colleague_trainees_recent_reports_query.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class ColleagueTraineesRecentReportsQuery < Patterns::Query + queries Report + + private + + def query + relation + .joins(:user) + .where(users: { id: colleague_trainee_ids }) + .not_wip + .default_order + .with_avatar + end + + def initialize(relation = Report.all, current_user:) + super(relation) + @current_user = current_user + end + + def colleague_trainee_ids + @current_user.colleague_trainees.pluck(:id) + end +end From 0c9ca0784fa09a34c9b7b1cf105b9bd51eafe0e9 Mon Sep 17 00:00:00 2001 From: hirokiej <123009866+hirokiej@users.noreply.github.com> Date: Wed, 23 Jul 2025 01:44:46 +0900 Subject: [PATCH 2/4] =?UTF-8?q?ColleagueTraineesRecentReportsQuery?= =?UTF-8?q?=E3=82=92=E4=BD=BF=E3=81=A3=E3=81=A6home=5Fcontroller=E3=81=AE?= =?UTF-8?q?=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92=E3=83=AA=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/home_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 50ebce4e8d8..9be9a0d364d 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -46,8 +46,7 @@ def display_dashboard @inactive_students = User.with_attached_avatar.inactive_students_and_trainees.order(last_activity_at: :desc) @job_seeking_users = User.with_attached_avatar.job_seeking.includes(:reports, :products, :works, :course, :company) @colleague_trainees = current_user.colleague_trainees.with_attached_avatar.includes(:reports, :products, :comments) - colleague_trainees_reports = Report.with_avatar.where(wip: false).where(user: current_user.colleague_trainees.with_attached_avatar) - @colleague_trainees_recent_reports = colleague_trainees_reports.order(reported_on: :desc).limit(10) + @colleague_trainees_recent_reports = ColleagueTraineesRecentReportsQuery.new(current_user:).call.limit(10) @recent_reports = Report.with_avatar.where(wip: false).order(reported_on: :desc, created_at: :desc).limit(10) @product_deadline_day = Product::PRODUCT_DEADLINE @colleagues = current_user.colleagues_other_than_self From cf48ed4e043c1865da62e1fa3bc8ecfada72269e Mon Sep 17 00:00:00 2001 From: hirokiej <123009866+hirokiej@users.noreply.github.com> Date: Thu, 24 Jul 2025 02:38:19 +0900 Subject: [PATCH 3/4] =?UTF-8?q?ColleagueTraineesRecentReportsQuery?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/reports.yml | 8 +++++ ...ague_trainees_recent_reports_query_test.rb | 34 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/queries/colleague_trainees_recent_reports_query_test.rb diff --git a/test/fixtures/reports.yml b/test/fixtures/reports.yml index 9425488d21d..96ac2491bd9 100644 --- a/test/fixtures/reports.yml +++ b/test/fixtures/reports.yml @@ -350,3 +350,11 @@ report74: description: 休会します wip: true reported_on: "2019-12-31" + +report75: + user: kensyu + title: WIPの日報 + emotion: 1 + description: WIPです + wip: true + reported_on: "2022-04-02" diff --git a/test/queries/colleague_trainees_recent_reports_query_test.rb b/test/queries/colleague_trainees_recent_reports_query_test.rb new file mode 100644 index 00000000000..4353b97a2e9 --- /dev/null +++ b/test/queries/colleague_trainees_recent_reports_query_test.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'test_helper' + +class ColleagueTraineesRecentReportsQueryTest < ActiveSupport::TestCase + test 'should return colleague trainees recent reports' do + user = users(:senpai) + trainee_report = reports(:report11) + other_report = reports(:report10) + + result = ColleagueTraineesRecentReportsQuery.new(current_user: user).call + + assert_includes result, trainee_report + assert_not_includes result, other_report + end + + test 'should exclude report with wip' do + user = users(:senpai) + wip_report = reports(:report75) + + result = ColleagueTraineesRecentReportsQuery.new(current_user: user).call + + assert_not_includes result, wip_report + end + + test 'should be ordered by recent' do + user = users(:senpai) + + result = ColleagueTraineesRecentReportsQuery.new(current_user: user).call + + dates = result.map(&:reported_on) + assert_equal dates, dates.sort.reverse + end +end From e2478c2382d378dc45147e3e5c0794ba42716e34 Mon Sep 17 00:00:00 2001 From: hirokiej <123009866+hirokiej@users.noreply.github.com> Date: Sun, 17 Aug 2025 01:28:54 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fixture=E8=BF=BD=E5=8A=A0=E3=81=A7=E8=90=BD?= =?UTF-8?q?=E3=81=A1=E3=81=9FWIP=E6=97=A5=E5=A0=B1=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E7=A2=BA=E8=AA=8D=E3=82=92=E4=BB=B6=E6=95=B0=E5=B7=AE=E5=88=86?= =?UTF-8?q?=E3=81=8B=E3=82=89=E5=AD=98=E5=9C=A8=E7=A2=BA=E8=AA=8D=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/training_completion_test.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/system/training_completion_test.rb b/test/system/training_completion_test.rb index 61976cf5fbe..784faad9da8 100644 --- a/test/system/training_completion_test.rb +++ b/test/system/training_completion_test.rb @@ -86,12 +86,13 @@ class TrainingCompletionTest < ApplicationSystemTestCase visit new_training_completion_path find('label', text: 'とても良い').click - assert_difference '@user.reports.wip.count', -1 do - page.accept_confirm '本当によろしいですか?' do - click_on '研修を終了する' - end - assert_text '研修終了手続きが完了しました' + + page.accept_confirm '本当によろしいですか?' do + click_on '研修を終了する' end + + assert_text '研修終了手続きが完了しました' + assert_not @user.reports.wip.exists? assert_equal Time.current, @user.reload.training_completed_at end