Skip to content

Commit

Permalink
Merge pull request #8256 from fjordllc/bug/regular-event-test-fails
Browse files Browse the repository at this point in the history
Regular Event のテストが失敗していたバグを修正
  • Loading branch information
komagata authored Dec 20, 2024
2 parents 557f5f9 + 1a9a8d3 commit 68c89b4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions app/models/regular_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def scheduled_on?(date)

def next_event_date
event_dates =
hold_national_holiday ? feature_scheduled_dates : feature_scheduled_dates.reject { |d| HolidayJp.holiday?(d) }
hold_national_holiday ? upcoming_scheduled_dates : upcoming_scheduled_dates.reject { |d| HolidayJp.holiday?(d) }

event_dates.min
end
Expand Down Expand Up @@ -109,8 +109,8 @@ def assign_admin_as_organizer_if_none
end

def all_scheduled_dates(
from: Date.new(Time.current.year, 1, 1),
to: Date.new(Time.current.year, 12, 31)
from: Date.current,
to: Date.current.next_year
)
(from..to).filter { |d| date_match_the_rules?(d, regular_event_repeat_rules) }
end
Expand All @@ -129,10 +129,7 @@ def transform_for_subscription(event_date)
def self.fetch_participated_regular_events(user)
participated_regular_events = []
user.participated_regular_event_ids.find_each do |regular_event|
regular_event.all_scheduled_dates(
from: Time.current.to_date,
to: Time.current.to_date.next_year
).each do |event_date|
regular_event.all_scheduled_dates.each do |event_date|
participated_regular_events << regular_event.transform_for_subscription(event_date)
end
end
Expand All @@ -148,7 +145,7 @@ def end_at_be_greater_than_start_at
errors.add(:end_at, ': イベント終了時刻はイベント開始時刻よりも後の時刻にしてください。')
end

def feature_scheduled_dates
def upcoming_scheduled_dates
# 時刻が過ぎたイベントを排除するためだけに、一時的にstart_timeを与える。後でDate型に戻す。
event_dates_with_start_time = all_scheduled_dates.map { |d| d.in_time_zone.change(hour: start_at.hour, min: start_at.min) }

Expand Down
4 changes: 2 additions & 2 deletions test/models/regular_event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class RegularEventTest < ActiveSupport::TestCase
end

test '#all_scheduled_dates' do
start_date = Date.new(Time.current.year, 1, 1)
end_date = Date.new(Time.current.year, 12, 31)
start_date = Date.current
end_date = Date.current.next_year
wednesday_for_year = (start_date..end_date).select(&:wednesday?)

regular_event = regular_events(:regular_event34)
Expand Down

0 comments on commit 68c89b4

Please sign in to comment.