From 85411470c4b6aa0425b32d217302828b8fff6373 Mon Sep 17 00:00:00 2001 From: hiromisugie Date: Fri, 6 Dec 2024 05:43:24 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=E3=80=8C=E8=BF=91=E6=97=A5=E9=96=8B?= =?UTF-8?q?=E5=82=AC=E3=81=AE=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=80=8D?= =?UTF-8?q?=E3=82=92=E3=80=81=E7=8F=BE=E5=9C=A8=E6=99=82=E5=88=BB=E3=81=8B?= =?UTF-8?q?=E3=82=89=E8=A8=88=E7=AE=97=E3=81=97=E3=81=A6=E7=B5=82=E3=82=8F?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=81=A0=E3=81=91=E3=82=92=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/event.rb | 2 ++ app/models/regular_event.rb | 2 ++ app/models/upcoming_event.rb | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/event.rb b/app/models/event.rb index 2e812a4878f..0213506854a 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -44,6 +44,8 @@ class Event < ApplicationRecord 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 :not_ended, -> { where('end_at > ?', Time.current) } + scope :scheduled_on_without_ended, ->(date) { scheduled_on(date).not_ended } def opening? Time.current.between?(open_start_at, open_end_at) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index 0689f9447b9..e47c1e75a78 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -58,6 +58,8 @@ class RegularEvent < ApplicationRecord # rubocop:disable Metrics/ClassLength scope :participated_by, ->(user) { where(id: all.filter { |e| e.participated_by?(user) }.map(&:id)) } scope :organizer_event, ->(user) { where(id: user.organizers.map(&:regular_event_id)) } scope :scheduled_on, ->(date) { holding.filter { |event| event.scheduled_on?(date) } } + scope :not_ended, -> { where('end_at > ?', Time.current) } + scope :scheduled_on_without_ended, ->(date) { holding.not_ended.filter { |event| event.scheduled_on?(date) } } belongs_to :user has_many :organizers, dependent: :destroy diff --git a/app/models/upcoming_event.rb b/app/models/upcoming_event.rb index 9a9dcb5bae5..baaedeabbf4 100644 --- a/app/models/upcoming_event.rb +++ b/app/models/upcoming_event.rb @@ -86,7 +86,7 @@ def date_key_to_date_class(date_key) def original_events_scheduled_on(date) [Event, RegularEvent].map do |model| - model.public_send(:scheduled_on, date) + model.public_send(:scheduled_on_without_ended, date) end.flatten end end From 1572fde01361b953bf97208d81a699beb8de1167 Mon Sep 17 00:00:00 2001 From: hiromisugie Date: Wed, 11 Dec 2024 05:35:52 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=E7=89=B9=E5=88=A5=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E7=94=A8=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/events.yml | 22 ++++++++++++++++++++++ test/models/event_test.rb | 16 ++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/test/fixtures/events.yml b/test/fixtures/events.yml index bd51f94f84b..ef8dd4a23fb 100644 --- a/test/fixtures/events.yml +++ b/test/fixtures/events.yml @@ -191,3 +191,25 @@ event34: open_start_at: 2024-02-26 10:00 open_end_at: 2024-03-26 09:00 user: kimura + +event35: + title: "2024/12/1(日)9:00〜12:00開催の特別イベント" + description: "本日開催でまだ終了時刻を迎えていない特別イベントの表示テスト用" + 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: kimura + +event36: + title: "2024/12/1(日)6:00〜7: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) %> + 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 diff --git a/test/models/event_test.rb b/test/models/event_test.rb index 1fb71063434..89fe00cc1c6 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -135,4 +135,20 @@ class EventTest < ActiveSupport::TestCase assert 994_018_171, ids assert 205_042_674, ids end + + test 'Events in progress today should be displayed' do + travel_to Time.zone.local(2024, 12, 1, 10, 0, 0) do + today_date = Time.zone.today + events = Event.scheduled_on_without_ended(today_date) + assert_includes events, events(:event35) + end + end + + test 'Events that have already ended today should not be displayed' do + travel_to Time.zone.local(2024, 12, 1, 10, 0, 0) do + today_date = Time.zone.today + events = Event.scheduled_on_without_ended(today_date) + assert_not_includes events, events(:event36) + end + end end From 9c86dc2e68e1a61115b67daa89c6a50fbce9160f Mon Sep 17 00:00:00 2001 From: hiromisugie Date: Thu, 12 Dec 2024 06:02:42 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=E5=AE=9A=E6=9C=9F=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E7=94=A8=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/fixtures/regular_event_repeat_rules.yml | 10 ++++++++++ test/fixtures/regular_events.yml | 20 ++++++++++++++++++++ test/models/regular_event_test.rb | 16 ++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/test/fixtures/regular_event_repeat_rules.yml b/test/fixtures/regular_event_repeat_rules.yml index 250f3476cfd..a6265b514a0 100644 --- a/test/fixtures/regular_event_repeat_rules.yml +++ b/test/fixtures/regular_event_repeat_rules.yml @@ -99,3 +99,13 @@ regular_event_repeat_rule37: frequency: 1 day_of_the_week: 6 regular_event: regular_event33 + +regular_event_repeat_rule38: + frequency: 0 + day_of_the_week: 0 + regular_event: regular_event36 + +regular_event_repeat_rule39: + frequency: 0 + day_of_the_week: 0 + regular_event: regular_event37 diff --git a/test/fixtures/regular_events.yml b/test/fixtures/regular_events.yml index c0459ec4bcd..b91ecc5f45b 100644 --- a/test/fixtures/regular_events.yml +++ b/test/fixtures/regular_events.yml @@ -187,3 +187,23 @@ regular_event35: user: komagata category: 0 published_at: "2023-08-01 00:00:00" + +regular_event36: + title: 本日開催でまだ終了時刻を迎えていない定期イベント + description: 本日開催でまだ終了時刻を迎えていない定期イベントの表示テスト用 + finished: false + hold_national_holiday: false + start_at: <%= Time.zone.local(2024, 12, 1, 9, 0, 0) %> + end_at: <%= Time.zone.local(2024, 12, 1, 12, 0, 0) %> + user: komagata + published_at: "2024-12-01 00:00:00" + +regular_event37: + title: 本日開催で終了時刻を過ぎた定期イベント + description: 本日開催で終了時刻を過ぎた定期イベントの表示テスト用 + finished: false + hold_national_holiday: false + start_at: <%= Time.zone.local(2024, 12, 1, 9, 0, 0) %> + end_at: <%= Time.zone.local(2024, 12, 1, 10, 0, 0) %> + user: komagata + published_at: "2024-12-01 00:00:00" diff --git a/test/models/regular_event_test.rb b/test/models/regular_event_test.rb index cc138367e0b..c6820b12fa8 100644 --- a/test/models/regular_event_test.rb +++ b/test/models/regular_event_test.rb @@ -154,4 +154,20 @@ class RegularEventTest < ActiveSupport::TestCase assert_equal 157, participated_regular_events.count end end + + test 'Regular event in progress today should be displayed' do + travel_to Time.zone.local(2024, 12, 1, 10, 0, 0) do + today_date = Time.zone.today + regular_event = RegularEvent.scheduled_on_without_ended(today_date) + assert_includes regular_event, regular_events(:regular_event36) + end + end + + test 'Regular event that have already ended today should not be displayed' do + travel_to Time.zone.local(2024, 12, 1, 10, 0, 0) do + today_date = Time.zone.today + regular_event = RegularEvent.scheduled_on_without_ended(today_date) + assert_not_includes regular_event, regular_events(:regular_event37) + end + end end From 7a5cc91150c78260bcfe375c8fb717b577e8426d Mon Sep 17 00:00:00 2001 From: hiromisugie Date: Fri, 20 Dec 2024 06:10:06 +0900 Subject: [PATCH 4/6] =?UTF-8?q?RegularEvent=E3=81=AE=E6=96=B9=E3=81=AEnot?= =?UTF-8?q?=5Fended=E3=81=AE=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/regular_event.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/regular_event.rb b/app/models/regular_event.rb index e47c1e75a78..24c032366f7 100644 --- a/app/models/regular_event.rb +++ b/app/models/regular_event.rb @@ -58,8 +58,7 @@ class RegularEvent < ApplicationRecord # rubocop:disable Metrics/ClassLength scope :participated_by, ->(user) { where(id: all.filter { |e| e.participated_by?(user) }.map(&:id)) } scope :organizer_event, ->(user) { where(id: user.organizers.map(&:regular_event_id)) } scope :scheduled_on, ->(date) { holding.filter { |event| event.scheduled_on?(date) } } - scope :not_ended, -> { where('end_at > ?', Time.current) } - scope :scheduled_on_without_ended, ->(date) { holding.not_ended.filter { |event| event.scheduled_on?(date) } } + scope :scheduled_on_without_ended, ->(date) { holding.filter { |event| event.scheduled_on?(date) && event.not_ended? } } belongs_to :user has_many :organizers, dependent: :destroy @@ -79,6 +78,10 @@ def scheduled_on?(date) all_scheduled_dates.include?(date) end + def not_ended? + Time.current.strftime('%H:%M') < end_at.strftime('%H:%M') + end + def next_event_date event_dates = hold_national_holiday ? upcoming_scheduled_dates : upcoming_scheduled_dates.reject { |d| HolidayJp.holiday?(d) } From ed505b90abfb2af232466a1cad27a6c0ee00b6c8 Mon Sep 17 00:00:00 2001 From: hiromisugie Date: Fri, 17 Jan 2025 06:00:44 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E5=BD=93=E6=97=A5=E9=96=8B=E5=82=AC?= =?UTF-8?q?=E3=81=A7=E7=B5=82=E4=BA=86=E6=B8=88=E3=81=BF=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=82=92=E9=9D=9E=E8=A1=A8=E7=A4=BA=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F=E5=A4=89=E6=9B=B4=E3=81=AB=E4=BC=B4=E3=81=84?= =?UTF-8?q?=E6=97=A2=E5=AD=98=E3=81=AE=E3=82=B7=E3=82=B9=E3=83=86=E3=83=A0?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=A7=E8=A8=AD=E5=AE=9A=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=9F=E6=99=82=E9=96=93=E3=82=922?= =?UTF-8?q?=E6=99=82=E9=96=93=E9=81=8E=E5=8E=BB=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/models/event_test.rb | 2 +- test/models/upcoming_event_test.rb | 2 +- test/system/events_test.rb | 2 +- test/system/home_test.rb | 2 +- test/system/regular_events_test.rb | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/models/event_test.rb b/test/models/event_test.rb index 89fe00cc1c6..94988e12901 100644 --- a/test/models/event_test.rb +++ b/test/models/event_test.rb @@ -4,7 +4,7 @@ class EventTest < ActiveSupport::TestCase test '.scheduled_on(date)' do - travel_to Time.zone.local(2017, 4, 3, 10, 0, 0) do + travel_to Time.zone.local(2017, 4, 3, 8, 0, 0) do today_date = Time.zone.today today_events_count = 2 today_events = Event.scheduled_on(today_date) diff --git a/test/models/upcoming_event_test.rb b/test/models/upcoming_event_test.rb index 89b1f2eb13f..ebe1b9256d9 100644 --- a/test/models/upcoming_event_test.rb +++ b/test/models/upcoming_event_test.rb @@ -10,7 +10,7 @@ class UpcomingEventTest < ActiveSupport::TestCase # not testing '.build_group' because this method is used in '.upcoming_events_grpups'. test '.upcoming_events_groups' do - travel_to Time.zone.local(2017, 4, 3, 10, 0, 0) do + travel_to Time.zone.local(2017, 4, 3, 8, 0, 0) do today_events = [ events(:event27), events(:event33), diff --git a/test/system/events_test.rb b/test/system/events_test.rb index 80232edea63..a4ae8153e5e 100644 --- a/test/system/events_test.rb +++ b/test/system/events_test.rb @@ -532,7 +532,7 @@ class EventsTest < ApplicationSystemTestCase today_events_count = 5 tomorrow_events_count = 2 day_after_tomorrow_events_count = 4 - travel_to Time.zone.local(2017, 4, 3, 10, 0, 0) do + travel_to Time.zone.local(2017, 4, 3, 8, 0, 0) do visit_with_auth events_path, 'komagata' within('.upcoming_events_groups') do assert_text '近日開催のイベント' diff --git a/test/system/home_test.rb b/test/system/home_test.rb index cbb3443b996..0a21366c61b 100644 --- a/test/system/home_test.rb +++ b/test/system/home_test.rb @@ -217,7 +217,7 @@ class HomeTest < ApplicationSystemTestCase end test 'show all regular events and special events on dashbord' do - travel_to Time.zone.local(2017, 4, 3, 10, 0, 0) 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: '今日開催') tomorrow_event_label = find('.card-list__label', text: '明日開催') diff --git a/test/system/regular_events_test.rb b/test/system/regular_events_test.rb index 91a63d5b682..a8f74182773 100644 --- a/test/system/regular_events_test.rb +++ b/test/system/regular_events_test.rb @@ -369,7 +369,7 @@ class RegularEventsTest < ApplicationSystemTestCase today_events_count = 5 tomorrow_events_count = 2 day_after_tomorrow_events_count = 4 - travel_to Time.zone.local(2017, 4, 3, 10, 0, 0) do + travel_to Time.zone.local(2017, 4, 3, 8, 0, 0) do visit_with_auth events_path, 'komagata' within('.upcoming_events_groups') do assert_text '近日開催のイベント' From 2b33e0d8ccc4d00ae1208289e2f1d373218d0e68 Mon Sep 17 00:00:00 2001 From: hiromisugie Date: Mon, 20 Jan 2025 06:19:18 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=83=87=E3=83=BC=E3=82=BF?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=AB=E4=BC=B4=E3=81=84=E3=82=B7=E3=82=B9?= =?UTF-8?q?=E3=83=86=E3=83=A0=E3=83=86=E3=82=B9=E3=83=88=E5=86=85=E3=81=AE?= =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E6=95=B0=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/regular_events_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/regular_events_test.rb b/test/system/regular_events_test.rb index a8f74182773..dda36d594a4 100644 --- a/test/system/regular_events_test.rb +++ b/test/system/regular_events_test.rb @@ -196,7 +196,7 @@ class RegularEventsTest < ApplicationSystemTestCase test 'show listing not finished regular events' do visit_with_auth regular_events_path(target: 'not_finished'), 'kimura' - assert_selector '.card-list.a-card .card-list-item', count: 17 + assert_selector '.card-list.a-card .card-list-item', count: 19 end test 'show listing all regular events' do