Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions app/queries/colleague_trainees_recent_reports_query.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/fixtures/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
34 changes: 34 additions & 0 deletions test/queries/colleague_trainees_recent_reports_query_test.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions test/system/training_completion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変更の理由について下記の理解であっていますでしょうか👀

変更前: テスト内でWIP状態の日報を一つ作成し、研修修了手続きの前後でのWIP日報の差分が-1になるアサーションだった。

機能としては研修終了手続きを完了するとすべてのWIP状態の日報が削除されるが、fixtureでユーザーkensyuに紐づくWIPの日報を一つ追加したので差分が-2になりテストが落ちるようになったのでassert_not @user.reports.wip.exists?存在確認に変更。

すべてのWIP状態の日報が削除されるなら、差分の確認より存在確認の方が良さそうですね👀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

その理解であってます!
あとは今後、fixtureでWIPの日報をn個作成する度にテストが失敗し、-nで差分を調整しなければならず、保守性の観点からもexistsにすべきだと思いました💡

assert_equal Time.current, @user.reload.training_completed_at
end

Expand Down