-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
「近日開催のイベント」で、当日の開催時間を過ぎたイベントは非表示にする #8280
base: main
Are you sure you want to change the base?
Changes from all commits
8541147
1572fde
9c86dc2
7a5cc91
ed505b9
2b33e0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. modelテストなので、メソッドのみをテストした方がよさそうです🙆 test '.scheduled_on_without_ended' do
# テストを記述する
end のような形になりそうですかね👀
は、システムテストで確認した方がまとまりがよいかと思います〜 システムテストが非常に重いため増やしたくない意図からmodelテストに書かれたかもしれないのですが、他のテストもメソッドをテストする書き方をしているので整合性の面でもシステムテストで書いた方が良い気がします🧐(折角fixtureでイベントも作成しているので) また、実際にシステムテストを書く際の補足ですが、私が過去にこのように指摘されたことがあるので、「表示されるorされない」のどちらかを確認するテストだけで十分だと思います👌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Judeeeee |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここのモデルテストもevent_testのコメントと同様です🙆 |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
レビューのために質問させてください🙏
scheduled_on_without_ended
をEvent
クラスとRegularEvent
クラスの両方で定義している意図って何でしょうか?👀それぞれのイベント(特別イベント・定期イベント)の違いで混乱しており、補足があればご教示いただけると幸いです🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Judeeeee
意味合いとしては同じ「今日開催でまだ終わっていないイベント」で命名も
scheduled_on_without_ended
で共通なのですが、中身のロジックが異なるものとして定義する必要があるのは、特別イベントと定期イベントで「開催日」の扱いがかなり異なっているという事情があります🙏まず、自分が作業する前の段階から存在していた
scheduled_on
スコープがありまして、これも同名であるにも関わらずEvent
クラスとRegularEvent
クラスの両方で異なる内容で定義してあるという前提がございます。このように同名でも中身の異なる
scheduled_on
スコープを拡張するような形で今回のスコープを定義したという背景があるのですが、要はEvent
とRegularEvent
で開催日の管理方法が異なるため共通化することは難しく、意味合いとしてはどちらも「今日開催でまだ終わっていないイベント」になるのですが、それぞれ別の方法で定義している、ということになります。うまく説明できたかどうかわからないのですが、いかがでしょうか。
ご不明点あれば何なりとお聞きください!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
丁寧な説明ありがとうございます🙏
scheduled_on
スコープがEvent
とRegularEvent
でそれぞれ定義されていることから共通化が難しかったのですね👀
理解できたため追加の質問はないですー🙇