Skip to content
Open
4 changes: 2 additions & 2 deletions app/controllers/hibernation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def show; end

def new
@hibernation = Hibernation.new
@holding_regular_events = RegularEvent.organizer_event(current_user).holding
@regular_events_without_finished = RegularEvent.organizer_event(current_user).exclude_finished
end

def create
Expand All @@ -23,7 +23,7 @@ def create
logout
redirect_to hibernation_path
else
@holding_regular_events = RegularEvent.organizer_event(current_user).holding
@regular_events_without_finished = RegularEvent.organizer_event(current_user).exclude_finished
render :new
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/retirement_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RetirementController < ApplicationController
def show; end

def new
@holding_regular_events = RegularEvent.organizer_event(current_user).holding
@regular_events_without_finished = RegularEvent.organizer_event(current_user).exclude_finished
end

def create
Expand All @@ -17,7 +17,7 @@ def create
redirect_to retirement_url
else
current_user.retired_on = nil
@holding_regular_events = RegularEvent.organizer_event(current_user).holding
@regular_events_without_finished = RegularEvent.organizer_event(current_user).exclude_finished
render :new
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/training_completion_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TrainingCompletionController < ApplicationController
def show; end

def new
@holding_regular_events = RegularEvent.organizer_event(current_user).holding
@regular_events_without_finished = RegularEvent.organizer_event(current_user).exclude_finished
end

def create
Expand All @@ -26,7 +26,7 @@ def create
redirect_to training_completion_url
else
current_user.training_completed_at = nil
@holding_regular_events = RegularEvent.organizer_event(current_user).holding
@regular_events_without_finished = RegularEvent.organizer_event(current_user).exclude_finished
render :new
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Event < ApplicationRecord # rubocop:todo Metrics/ClassLength

scope :wip, -> { where(wip: true) }
scope :related_to, ->(user) { user.job_seeker ? all : where.not(job_hunting: true) }
scope :scheduled_on, ->(date) { where(start_at: date.midnight...(date + 1.day).midnight) }
scope :scheduled_on, ->(date) { where(start_at: date.midnight...(date + 1.day).midnight, wip: false) }
scope :not_ended, -> { where('end_at > ?', Time.current) }
scope :scheduled_on_without_ended, ->(date) { scheduled_on(date).not_ended }

Expand Down
8 changes: 4 additions & 4 deletions app/models/regular_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class RegularEvent < ApplicationRecord # rubocop:disable Metrics/ClassLength
validates :regular_event_repeat_rules, presence: true
validates_associated :regular_event_repeat_rules

scope :not_finished, -> { where(finished: false) }
scope :exclude_finished, -> { where(finished: false) }

with_options if: -> { start_at && end_at } do
validate :end_at_be_greater_than_start_at
end

scope :holding, -> { where(finished: false) }
scope :not_finished, -> { where(finished: false, wip: false) }
scope :participated_by, ->(user) { where(id: all.filter { |e| e.participated_by?(user) }.map(&:id)) }
scope :organizer_event, ->(user) { joins(:organizers).where(organizers: { user_id: user.id }) }
scope :scheduled_on, ->(date) { holding.filter { |event| event.scheduled_on?(date) } }
scope :scheduled_on_without_ended, ->(date) { holding.filter { |event| event.scheduled_on?(date) && !event.ended?(date) } }
scope :scheduled_on, ->(date) { not_finished.filter { |event| event.scheduled_on?(date) } }
scope :scheduled_on_without_ended, ->(date) { not_finished.filter { |event| event.scheduled_on?(date) && !event.ended?(date) } }

scope :fetch_target_events, lambda { |target|
case target
Expand Down
2 changes: 1 addition & 1 deletion app/models/regular_event_participation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class RegularEventParticipation < ApplicationRecord

validates :user_id, uniqueness: { scope: :regular_event_id }

scope :for_holding_events, -> { joins(:regular_event).merge(RegularEvent.holding) }
scope :for_unfinished_events, -> { joins(:regular_event).merge(RegularEvent.not_finished) }
end
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ def reports_with_learning_times
end

def clean_up_regular_events
regular_event_participations.for_holding_events.destroy_all
organize_regular_events.holding.each { |event| event.close_or_destroy_organizer(self) }
regular_event_participations.for_unfinished_events.destroy_all
organize_regular_events.exclude_finished.each { |event| event.close_or_destroy_organizer(self) }
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/views/hibernation/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ hr.a-border
| こちら
| のページの「分報 URL」欄に分報チャンネルの URL を登録してください。

- if @holding_regular_events.any?
- if @regular_events_without_finished.any?
.form-item
= render 'shared/regular_events_warning',
events: @holding_regular_events,
events: @regular_events_without_finished,
case_text: '休会をお考えの',
action_text: '休会'

Expand Down
4 changes: 2 additions & 2 deletions app/views/retirement/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ hr.a-border
= render 'errors', object: current_user
= form_with model: current_user, local: true, url: retirement_path, method: :post, class: 'form' do |f|
.form__items
- if @holding_regular_events.any?
- if @regular_events_without_finished.any?
.form-item
= render 'shared/regular_events_warning',
events: @holding_regular_events,
events: @regular_events_without_finished,
case_text: '退会をお考えの',
action_text: '退会'

Expand Down
4 changes: 2 additions & 2 deletions app/views/training_completion/new.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ hr.a-border
= render 'errors', object: current_user
= form_with model: current_user, local: true, url: training_completion_path, method: :post, class: 'form' do |f|
.form__items
- if @holding_regular_events.any?
- if @regular_events_without_finished.any?
.form-item
= render 'shared/regular_events_warning',
events: @holding_regular_events,
events: @regular_events_without_finished,
case_text: '研修を終了される',
action_text: '研修終了'

Expand Down
12 changes: 12 additions & 0 deletions db/fixtures/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,15 @@ event32:
open_start_at: <%= Time.current %>
open_end_at: <%= Time.current + 3.day + 1.hours %>
user: komagata

event33:
title: "wipの特別イベント"
description: "wip状態のイベントが近日開催のイベントに表示されないことを確認するためのイベント"
location: "FJORDオフィス"
capacity: 40
start_at: <%= Time.current + 1.day %>
end_at: <%= Time.current + 1.day + 1.hours %>
open_start_at: <%= Time.current %>
open_end_at: <%= Time.current + 1.day + 1.hours %>
user: komagata
wip: true
5 changes: 5 additions & 0 deletions db/fixtures/regular_event_repeat_rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,8 @@ regular_event_repeat_rule35:
frequency: 0
day_of_the_week: 6
regular_event: regular_event30

regular_event_repeat_rule36:
frequency: 0
day_of_the_week: <%= Time.current.wday %>
regular_event: regular_event31
11 changes: 11 additions & 0 deletions db/fixtures/regular_events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,14 @@ regular_event30:
end_at: <%= Time.zone.local(2020, 1, 1, 12, 0, 0) %>
user: komagata
published_at: "2023-08-01 00:00:00"

regular_event31:
title: WIPの定期イベント
description: WIP状態の定期イベントが近日開催のイベントに表示されないことを確認する用のデータ
finished: false
hold_national_holiday: false
start_at: <%= Time.current + 1.day %>
end_at: <%= Time.current + 1.day + 1.hours %>
user: komagata
published_at: "2023-08-01 00:00:00"
wip: true
27 changes: 25 additions & 2 deletions test/fixtures/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,35 @@ event35:
user: kimura

event36:
title: "2024/12/1(日)6:00〜7:00開催の特別イベント"
title: "2024/12/1(日)6:00〜10:00開催の特別イベント"
description: "本日開催で終了時刻を過ぎた特別イベントの表示テスト用"
location: "FJORDオフィス"
capacity: 40
start_at: <%= Time.zone.local(2024, 12, 1, 6, 0, 0) %>
end_at: <%= Time.zone.local(2024, 12, 1, 7, 0, 0) %>
end_at: <%= Time.zone.local(2024, 12, 1, 10, 0, 0) %>
open_start_at: <%= Time.zone.local(2024, 11, 1, 6, 0, 0) %>
open_end_at: <%= Time.zone.local(2024, 12, 1, 6, 0, 0) %>
user: kimura

event37:
title: "2024/12/1(日)9:00〜12:00開催予定のWIPイベント"
description: "本日開催でまだ終了時刻を迎えていないWIPイベントの非表示確認用"
location: "FJORDオフィス"
capacity: 40
start_at: <%= Time.zone.local(2024, 12, 1, 9, 0, 0) %>
end_at: <%= Time.zone.local(2024, 12, 1, 12, 0, 0) %>
open_start_at: <%= Time.zone.local(2024, 11, 1, 9, 0, 0) %>
open_end_at: <%= Time.zone.local(2024, 12, 1, 9, 0, 0) %>
user: hatsuno
wip: true

event38:
title: "2024/12/2(月)0:00開始の特別イベント"
description: "翌日の0時開催のイベントの非表示テスト用"
location: "FJORDオフィス"
capacity: 40
start_at: <%= Time.zone.local(2024, 12, 2, 0, 0, 0) %>
end_at: <%= Time.zone.local(2024, 12, 2, 1, 0, 0) %>
open_start_at: <%= Time.zone.local(2024, 11, 1, 6, 0, 0) %>
open_end_at: <%= Time.zone.local(2024, 12, 1, 6, 0, 0) %>
user: kimura
10 changes: 10 additions & 0 deletions test/fixtures/regular_event_repeat_rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,13 @@ regular_event_repeat_rule43:
frequency: 6
day_of_the_week: 4
regular_event: regular_event41

regular_event_repeat_rule44:
frequency: 0
day_of_the_week: 0
regular_event: regular_event42

regular_event_repeat_rule45:
frequency: 0
day_of_the_week: 6
regular_event: regular_event43
22 changes: 22 additions & 0 deletions test/fixtures/regular_events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,25 @@ regular_event41:
user: komagata
category: 3
published_at: "2023-08-01 00:00:00"

regular_event42:
title: 日曜日開催で15:00に終了するWIP定期イベント
description: 日曜日開催で15:00に終了するWIP定期イベントの非表示テスト用
finished: false
hold_national_holiday: false
start_at: <%= Time.zone.local(2024, 12, 1, 10, 0, 0) %>
end_at: <%= Time.zone.local(2024, 12, 1, 15, 0, 0) %>
user: komagata
published_at: "2024-12-01 00:00:00"
wip: true

regular_event43:
title: Discord通知が来ないwipイベント(土曜日開催)
description: wipイベントなのでDiscord通知が来ないです。(土曜日開催)
finished: false
hold_national_holiday: true
start_at: <%= Time.zone.local(2020, 1, 1, 10, 0, 0) %>
end_at: <%= Time.zone.local(2020, 1, 1, 11, 0, 0) %>
user: komagata
published_at: "2023-08-01 00:00:00"
wip: true
16 changes: 14 additions & 2 deletions test/models/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class EventTest < ActiveSupport::TestCase
end
end

test '.scheduled_on exclude wip' do
travel_to Time.zone.local(2024, 12, 1, 8, 0, 0) do
today_date = Time.zone.today
wip_event = events(:event37)
today_events = Event.scheduled_on(today_date)
assert_not_includes today_events, wip_event
end
end

test '#opening?' do
event = events(:event2)
assert event.opening?
Expand Down Expand Up @@ -141,9 +150,12 @@ class EventTest < ActiveSupport::TestCase
today_date = Time.zone.today
events = Event.scheduled_on_without_ended(today_date)
event_in_progress = events(:event35)
event_ended = events(:event36)
event_start_at_tomorrow_midnight = events(:event38)
event_ended_at_today_10am = events(:event36)

assert_includes events, event_in_progress
assert_not_includes events, event_ended
assert_not_includes events, event_ended_at_today_10am
assert_not_includes events, event_start_at_tomorrow_midnight
end
end
end
9 changes: 9 additions & 0 deletions test/models/regular_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class RegularEventTest < ActiveSupport::TestCase
regular_events = RegularEvent.scheduled_on_without_ended(today_date)
regular_event_in_progress = regular_events(:regular_event36)
regular_event_ended = regular_events(:regular_event37)

assert_includes regular_events, regular_event_in_progress
assert_not_includes regular_events, regular_event_ended
end
Expand All @@ -186,4 +187,12 @@ class RegularEventTest < ActiveSupport::TestCase
assert_includes regular_events, regular_event_scheduled_for_tomorrow
end
end

test '.not_finished exclude wip and finished events' do
events = RegularEvent.not_finished
wip_event = regular_events(:regular_event42)
finished_event = regular_events(:regular_event39)
assert_not_includes events, wip_event
assert_not_includes events, finished_event
end
end
22 changes: 11 additions & 11 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,30 +682,30 @@ class UserTest < ActiveSupport::TestCase
assert_empty User.users_role(not_scope_name, allowed_targets:)
end

test '#clean_up_regular_events removes participant from holding regular event' do
test '#clean_up_regular_events removes participant from unfinished regular event' do
user = users(:kimura)
holding_paticipated_event = regular_events(:regular_event1)
holding_paticipated_event.regular_event_participations.create!(user: user)
finished_paticipated_event = regular_events(:regular_event2)
finished_paticipated_event.update!(finished: true)
finished_paticipated_event.regular_event_participations.create!(user: user)
unfinished_participated_event = regular_events(:regular_event1)
unfinished_participated_event.regular_event_participations.create!(user: user)
finished_participated_event = regular_events(:regular_event2)
finished_participated_event.update!(finished: true)
finished_participated_event.regular_event_participations.create!(user: user)

user.clean_up_regular_events

assert_not holding_paticipated_event.regular_event_participations.exists?(user:)
assert finished_paticipated_event.regular_event_participations.exists?(user:)
assert_not unfinished_participated_event.regular_event_participations.exists?(user:)
assert finished_participated_event.regular_event_participations.exists?(user:)
end

test '#clean_up_regular_events removes organizer from holding regular event' do
test '#clean_up_regular_events removes organizer from unfinished regular event' do
user = users(:kimura)
# kimuraが主催しているイベント
holding_organized_event = regular_events(:regular_event4)
unfinished_organized_event = regular_events(:regular_event4)
finished_organized_event = regular_events(:regular_event5)
finished_organized_event.update!(finished: true)

user.clean_up_regular_events

assert_not holding_organized_event.regular_event_organizers.exists?(user:)
assert_not unfinished_organized_event.regular_event_organizers.exists?(user:)
assert finished_organized_event.regular_event_organizers.exists?(user:)
end

Expand Down
18 changes: 17 additions & 1 deletion test/system/home/events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class EventsTest < ApplicationSystemTestCase
end
end

test 'show all regular events and special events on dashbord' do
test 'show upcoming regular and special events in upcoming events section' do
travel_to Time.zone.local(2017, 4, 3, 8, 0, 0) do
visit_with_auth '/', 'kimura'
today_event_label = find('.card-list__label', text: '今日開催')
Expand Down Expand Up @@ -51,6 +51,22 @@ class EventsTest < ApplicationSystemTestCase
end
end

test 'should not show wip regular and special events in upcoming events section' do
travel_to Time.zone.local(2024, 12, 1, 0, 0, 0) do
wip_regular_event = regular_events(:regular_event42)
wip_special_event = events(:event37)
regular_event = regular_events(:regular_event37)
special_event = events(:event35)
visit_with_auth '/', 'kimura'
within(:xpath, "//div[contains(@class, 'card-list__items')][.//text()='今日開催']") do
assert_no_text wip_regular_event.title
assert_no_text wip_special_event.title
assert_text regular_event.title
assert_text special_event.title
end
end
end

test 'show registered to participate only participating events' do
Event.where.not(title: ['kimura専用イベント', '直近イベントの表示テスト用(当日)']).destroy_all
RegularEvent.where.not(title: ['ダッシュボード表示確認用テスト定期イベント', '質問・雑談タイム']).destroy_all
Expand Down
3 changes: 2 additions & 1 deletion test/system/notification/regular_events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class Notification::RegularEventsTest < NotificationSystemTestCase
body['content'].include?('Discord通知確認用イベント(土曜日午前8時から開催)') &&
body['content'].include?('Discord通知確認用イベント(土曜日 + 日曜日開催)') &&
body['content'].include?('Discord通知確認用イベント(土曜日開催)') &&
body['content'].include?('Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催)')
body['content'].include?('Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催)') &&
body['content'].exclude?('Discord通知が来ないwipイベント(土曜日開催)')
end

travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do
Expand Down
Loading
Loading