From 281534afd95eb02fbb795cffbb940294d3a5773f Mon Sep 17 00:00:00 2001 From: tomo Date: Wed, 11 Oct 2023 21:27:25 +0900 Subject: [PATCH 01/18] =?UTF-8?q?=E3=83=99=E3=82=B9=E3=83=88=E3=82=A2?= =?UTF-8?q?=E3=83=B3=E3=82=B5=E3=83=BC=E3=81=AA=E3=81=97=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E3=82=92=E3=82=AD=E3=83=83=E3=82=AF=E3=81=99=E3=82=8B=E3=82=B3?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=83=AD=E3=83=BC=E3=83=A9=E3=81=ABScheduler?= =?UTF-8?q?Controller=E3=82=92=E7=B6=99=E6=89=BF=E3=81=95=E3=81=9B?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...notify_certain_period_passed_after_last_answer_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/scheduler/daily/notify_certain_period_passed_after_last_answer_controller.rb b/app/controllers/scheduler/daily/notify_certain_period_passed_after_last_answer_controller.rb index 8bfb4752fbd..c66537ff7fa 100644 --- a/app/controllers/scheduler/daily/notify_certain_period_passed_after_last_answer_controller.rb +++ b/app/controllers/scheduler/daily/notify_certain_period_passed_after_last_answer_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Scheduler::Daily::NotifyCertainPeriodPassedAfterLastAnswerController < ApplicationController +class Scheduler::Daily::NotifyCertainPeriodPassedAfterLastAnswerController < SchedulerController def show Question.notify_certain_period_passed_after_last_answer head :ok From 670ca8375319e37d79a587c041324c358b136ec8 Mon Sep 17 00:00:00 2001 From: tomo Date: Sun, 15 Oct 2023 09:26:39 +0900 Subject: [PATCH 02/18] =?UTF-8?q?=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0TOKEN?= =?UTF-8?q?=E3=81=8C=E6=8C=87=E5=AE=9A=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=80=81SchedulerControlle?= =?UTF-8?q?r=E3=81=AE=E8=AA=8D=E8=A8=BC=E3=82=92=E3=83=91=E3=82=B9?= =?UTF-8?q?=E3=81=95=E3=81=9B=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/scheduler_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/scheduler_controller.rb b/app/controllers/scheduler_controller.rb index a99ddd0040b..7af6e9f6835 100644 --- a/app/controllers/scheduler_controller.rb +++ b/app/controllers/scheduler_controller.rb @@ -8,7 +8,7 @@ class SchedulerController < ApplicationController protected def require_token - return if ENV['TOKEN'] == params[:token] + return if ENV['TOKEN'].present? && ENV['TOKEN'] == params[:token] head :unauthorized end From 042f9e0a6847058e7828bde9147236cc14838145 Mon Sep 17 00:00:00 2001 From: tomo Date: Sun, 15 Oct 2023 10:13:44 +0900 Subject: [PATCH 03/18] =?UTF-8?q?=E3=83=99=E3=82=B9=E3=83=88=E3=82=A2?= =?UTF-8?q?=E3=83=B3=E3=82=B5=E3=83=BC=E3=81=AA=E3=81=97=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88=E3=82=B3=E3=83=BC=E3=83=89?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/scheduler_controller.rb | 1 + test/system/notification/questions_test.rb | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/scheduler_controller.rb b/app/controllers/scheduler_controller.rb index 7af6e9f6835..4fcb4d58ec0 100644 --- a/app/controllers/scheduler_controller.rb +++ b/app/controllers/scheduler_controller.rb @@ -8,6 +8,7 @@ class SchedulerController < ApplicationController protected def require_token + return if Rails.env.test? return if ENV['TOKEN'].present? && ENV['TOKEN'] == params[:token] head :unauthorized diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index 55b003603c8..92e14c630b2 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -303,15 +303,16 @@ class Notification::QuestionsTest < ApplicationSystemTestCase ) travel_to Time.zone.local(2022, 11, 6, 0, 0, 0) do - visit_with_auth '/scheduler/daily/notify_certain_period_passed_after_last_answer', 'kimura' - visit '/notifications' + visit '/scheduler/daily/notify_certain_period_passed_after_last_answer' + visit_with_auth '/notifications', 'kimura' assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' end + logout travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do - visit_with_auth '/scheduler/daily/notify_certain_period_passed_after_last_answer', 'kimura' - visit '/notifications' + visit '/scheduler/daily/notify_certain_period_passed_after_last_answer' + visit_with_auth '/notifications', 'kimura' assert_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' end From 878fa49cf7ca670243f9cf3b28d4d7cc01427121 Mon Sep 17 00:00:00 2001 From: tomo Date: Sun, 15 Oct 2023 10:44:56 +0900 Subject: [PATCH 04/18] =?UTF-8?q?=E8=87=AA=E5=8B=95=E9=80=80=E4=BC=9A?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E3=83=AD=E3=82=B0=E3=82=A2?= =?UTF-8?q?=E3=82=A6=E3=83=88=E7=8A=B6=E6=85=8B=E3=81=A7=E5=AE=9F=E6=96=BD?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/auto_retire_test.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/system/auto_retire_test.rb b/test/system/auto_retire_test.rb index 9d97ebe3d77..0bc56d85a7c 100644 --- a/test/system/auto_retire_test.rb +++ b/test/system/auto_retire_test.rb @@ -16,7 +16,7 @@ class AutoRetireTest < ApplicationSystemTestCase user = users(:kyuukai) travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path end assert_equal Date.current, user.reload.retired_on end @@ -49,7 +49,7 @@ class AutoRetireTest < ApplicationSystemTestCase user = users(:kyuukai) travel_to Time.zone.local(2020, 7, 1, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path end assert_nil user.reload.retired_on end @@ -64,7 +64,7 @@ class AutoRetireTest < ApplicationSystemTestCase logout travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path assert_nil user.reload.retired_on end end @@ -76,7 +76,7 @@ class AutoRetireTest < ApplicationSystemTestCase user.update!(retired_on: retired_date) travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path assert_equal retired_date, user.reload.retired_on end end @@ -89,7 +89,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path end assert_equal Date.current, user.reload.retired_on end @@ -106,7 +106,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do Discord::Server.stub(:delete_text_channel, true) do VCR.use_cassette 'subscription/update' do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path end end assert_equal Date.current, user.reload.retired_on @@ -123,7 +123,7 @@ class AutoRetireTest < ApplicationSystemTestCase UserMailer.stub(:auto_retire, stub_postmark_error) do travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path end assert_equal Date.current, user.reload.retired_on end @@ -140,7 +140,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit_with_auth scheduler_daily_auto_retire_path, 'komagata' + visit scheduler_daily_auto_retire_path end assert_equal Date.current, user.reload.retired_on end From 5e75b03a30977cd0f25e863ef7e9f5b47a496bd4 Mon Sep 17 00:00:00 2001 From: tomo Date: Mon, 23 Oct 2023 21:15:01 +0900 Subject: [PATCH 05/18] =?UTF-8?q?=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0TOKEN?= =?UTF-8?q?=E3=82=92=E8=A8=AD=E5=AE=9A=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D?= =?UTF-8?q?=E3=81=AB=E6=AD=A3=E3=81=97=E3=81=84=E3=82=AF=E3=82=A8=E3=83=AA?= =?UTF-8?q?=E3=81=A7=E3=82=A2=E3=82=AF=E3=82=BB=E3=82=B9=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=A8=E5=AE=9A=E6=9C=9F=E5=87=A6=E7=90=86=E3=81=8C=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/scheduler_controller.rb | 1 - test/application_system_test_case.rb | 4 +++ test/supports/mock_env_helper.rb | 13 ++++++++ test/supports/query_helper.rb | 9 ++++++ test/system/auto_retire_test.rb | 32 ++++++++++++++----- test/system/notification/questions_test.rb | 8 +++-- .../notification/regular_events_test.rb | 4 ++- 7 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 test/supports/mock_env_helper.rb create mode 100644 test/supports/query_helper.rb diff --git a/app/controllers/scheduler_controller.rb b/app/controllers/scheduler_controller.rb index 4fcb4d58ec0..7af6e9f6835 100644 --- a/app/controllers/scheduler_controller.rb +++ b/app/controllers/scheduler_controller.rb @@ -8,7 +8,6 @@ class SchedulerController < ApplicationController protected def require_token - return if Rails.env.test? return if ENV['TOKEN'].present? && ENV['TOKEN'] == params[:token] head :unauthorized diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 31d9439265d..5214bccef96 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -8,6 +8,8 @@ require 'supports/report_helper' require 'supports/comment_helper' require 'supports/tag_helper' +require 'supports/query_helper' +require 'supports/mock_env_helper' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include LoginHelper @@ -17,6 +19,8 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include ReportHelper include CommentHelper include TagHelper + include QueryHelper + include MockEnvHelper if ENV['HEADED'] driven_by :selenium, using: :chrome diff --git a/test/supports/mock_env_helper.rb b/test/supports/mock_env_helper.rb new file mode 100644 index 00000000000..d4607296a51 --- /dev/null +++ b/test/supports/mock_env_helper.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module MockEnvHelper + def mock_env(partial_env_hash) + old = ENV.to_hash + ENV.update partial_env_hash + begin + yield + ensure + ENV.replace old + end + end +end diff --git a/test/supports/query_helper.rb b/test/supports/query_helper.rb new file mode 100644 index 00000000000..5c9b45efda2 --- /dev/null +++ b/test/supports/query_helper.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module QueryHelper + def visit_with_query(url, query_hash) + uri = URI.parse(url) + uri.query = query_hash.to_query + visit uri.to_s + end +end diff --git a/test/system/auto_retire_test.rb b/test/system/auto_retire_test.rb index 0bc56d85a7c..65bc3692690 100644 --- a/test/system/auto_retire_test.rb +++ b/test/system/auto_retire_test.rb @@ -16,7 +16,9 @@ class AutoRetireTest < ApplicationSystemTestCase user = users(:kyuukai) travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end end assert_equal Date.current, user.reload.retired_on end @@ -49,7 +51,9 @@ class AutoRetireTest < ApplicationSystemTestCase user = users(:kyuukai) travel_to Time.zone.local(2020, 7, 1, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end end assert_nil user.reload.retired_on end @@ -64,7 +68,9 @@ class AutoRetireTest < ApplicationSystemTestCase logout travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end assert_nil user.reload.retired_on end end @@ -76,7 +82,9 @@ class AutoRetireTest < ApplicationSystemTestCase user.update!(retired_on: retired_date) travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end assert_equal retired_date, user.reload.retired_on end end @@ -89,7 +97,9 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end end assert_equal Date.current, user.reload.retired_on end @@ -106,7 +116,9 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do Discord::Server.stub(:delete_text_channel, true) do VCR.use_cassette 'subscription/update' do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end end end assert_equal Date.current, user.reload.retired_on @@ -123,7 +135,9 @@ class AutoRetireTest < ApplicationSystemTestCase UserMailer.stub(:auto_retire, stub_postmark_error) do travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end end assert_equal Date.current, user.reload.retired_on end @@ -140,7 +154,9 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - visit scheduler_daily_auto_retire_path + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + end end assert_equal Date.current, user.reload.retired_on end diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index 92e14c630b2..8782485324c 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -303,7 +303,9 @@ class Notification::QuestionsTest < ApplicationSystemTestCase ) travel_to Time.zone.local(2022, 11, 6, 0, 0, 0) do - visit '/scheduler/daily/notify_certain_period_passed_after_last_answer' + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_notify_certain_period_passed_after_last_answer_path, { token: 'token' } + end visit_with_auth '/notifications', 'kimura' assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' @@ -311,7 +313,9 @@ class Notification::QuestionsTest < ApplicationSystemTestCase logout travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do - visit '/scheduler/daily/notify_certain_period_passed_after_last_answer' + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_notify_certain_period_passed_after_last_answer_path, { token: 'token' } + end visit_with_auth '/notifications', 'kimura' assert_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' diff --git a/test/system/notification/regular_events_test.rb b/test/system/notification/regular_events_test.rb index 066a620066c..a791ea571ac 100644 --- a/test/system/notification/regular_events_test.rb +++ b/test/system/notification/regular_events_test.rb @@ -67,7 +67,9 @@ class Notification::RegularEventsTest < ApplicationSystemTestCase headers: { 'Content-Type' => 'application/json' }) travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do - visit '/scheduler/daily/notify_coming_soon_regular_events' + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_notify_coming_soon_regular_events_path, { token: 'token' } + end end assert_requested(stub_message) From 63298c55c6480490673797349541847b6a2cc35a Mon Sep 17 00:00:00 2001 From: tomo Date: Mon, 23 Oct 2023 22:20:16 +0900 Subject: [PATCH 06/18] =?UTF-8?q?=E5=AE=9A=E6=9C=9F=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=8CSchedulerController=E3=82=92=E7=B6=99=E6=89=BF?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E3=81=A8=E3=81=8D?= =?UTF-8?q?=E3=82=A8=E3=83=A9=E3=83=BC=E3=82=92=E8=BF=94=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 190348f9ab7..6540499b5ab 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base before_action :allow_cross_domain_access before_action :set_host_for_disk_storage before_action :require_active_user_login + before_action :require_scheduler_inheritation protected @@ -50,6 +51,13 @@ def require_subscription redirect_to root_path, notice: 'サブスクリプション登録が必要です。' unless current_user&.subscription? end + def require_scheduler_inheritation + return unless request.path_info.start_with?('/scheduler') + return if is_a?(SchedulerController) + + head :internal_server_error + end + protected def staging? From 8e49357bddd76cddb199c2d60ac11a56e912e5e0 Mon Sep 17 00:00:00 2001 From: tomo Date: Wed, 25 Oct 2023 20:27:41 +0900 Subject: [PATCH 07/18] =?UTF-8?q?fetch=5Fexternal=5Fentry=5Fcontroller?= =?UTF-8?q?=E3=81=ABSchedulerController=E3=82=92=E7=B6=99=E6=89=BF?= =?UTF-8?q?=E3=81=95=E3=81=9B=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/daily/fetch_external_entry_controller.rb | 2 +- test/system/external_entries_test.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/scheduler/daily/fetch_external_entry_controller.rb b/app/controllers/scheduler/daily/fetch_external_entry_controller.rb index 9d28c417dfe..360ced5eadd 100644 --- a/app/controllers/scheduler/daily/fetch_external_entry_controller.rb +++ b/app/controllers/scheduler/daily/fetch_external_entry_controller.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Scheduler::Daily::FetchExternalEntryController < ApplicationController +class Scheduler::Daily::FetchExternalEntryController < SchedulerController def show ExternalEntry.fetch_and_save_rss_feeds(User.unretired) head :ok diff --git a/test/system/external_entries_test.rb b/test/system/external_entries_test.rb index d01a415e1be..4a228d529fd 100644 --- a/test/system/external_entries_test.rb +++ b/test/system/external_entries_test.rb @@ -13,7 +13,9 @@ class ExternalEntriesTest < ApplicationSystemTestCase assert_difference 'ExternalEntry.count', 26 do VCR.use_cassette 'external_entry/fetch2', vcr_options do VCR.use_cassette 'external_entry/fetch' do - visit_with_auth '/scheduler/daily/fetch_external_entry', 'komagata' + mock_env({ 'TOKEN' => 'token' }) do + visit_with_query scheduler_daily_fetch_external_entry_path, { token: 'token' } + end end end end From 4ce19141942d43b6efa81db2acc4a2f8d23d8ea4 Mon Sep 17 00:00:00 2001 From: tomo Date: Sat, 28 Oct 2023 20:42:09 +0900 Subject: [PATCH 08/18] =?UTF-8?q?=E5=BC=95=E6=95=B0=E3=81=AE{}=E3=82=92?= =?UTF-8?q?=E7=9C=81=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/auto_retire_test.rb | 16 ++++++++-------- test/system/external_entries_test.rb | 2 +- test/system/notification/questions_test.rb | 4 ++-- test/system/notification/regular_events_test.rb | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/system/auto_retire_test.rb b/test/system/auto_retire_test.rb index 65bc3692690..db4437ae693 100644 --- a/test/system/auto_retire_test.rb +++ b/test/system/auto_retire_test.rb @@ -16,7 +16,7 @@ class AutoRetireTest < ApplicationSystemTestCase user = users(:kyuukai) travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end end @@ -51,7 +51,7 @@ class AutoRetireTest < ApplicationSystemTestCase user = users(:kyuukai) travel_to Time.zone.local(2020, 7, 1, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end end @@ -68,7 +68,7 @@ class AutoRetireTest < ApplicationSystemTestCase logout travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end assert_nil user.reload.retired_on @@ -82,7 +82,7 @@ class AutoRetireTest < ApplicationSystemTestCase user.update!(retired_on: retired_date) travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end assert_equal retired_date, user.reload.retired_on @@ -97,7 +97,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end end @@ -116,7 +116,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do Discord::Server.stub(:delete_text_channel, true) do VCR.use_cassette 'subscription/update' do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end end @@ -135,7 +135,7 @@ class AutoRetireTest < ApplicationSystemTestCase UserMailer.stub(:auto_retire, stub_postmark_error) do travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end end @@ -154,7 +154,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } end end diff --git a/test/system/external_entries_test.rb b/test/system/external_entries_test.rb index 4a228d529fd..9218672ba3e 100644 --- a/test/system/external_entries_test.rb +++ b/test/system/external_entries_test.rb @@ -13,7 +13,7 @@ class ExternalEntriesTest < ApplicationSystemTestCase assert_difference 'ExternalEntry.count', 26 do VCR.use_cassette 'external_entry/fetch2', vcr_options do VCR.use_cassette 'external_entry/fetch' do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_fetch_external_entry_path, { token: 'token' } end end diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index 8782485324c..cbc87164bac 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -303,7 +303,7 @@ class Notification::QuestionsTest < ApplicationSystemTestCase ) travel_to Time.zone.local(2022, 11, 6, 0, 0, 0) do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_notify_certain_period_passed_after_last_answer_path, { token: 'token' } end visit_with_auth '/notifications', 'kimura' @@ -313,7 +313,7 @@ class Notification::QuestionsTest < ApplicationSystemTestCase logout travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_notify_certain_period_passed_after_last_answer_path, { token: 'token' } end visit_with_auth '/notifications', 'kimura' diff --git a/test/system/notification/regular_events_test.rb b/test/system/notification/regular_events_test.rb index a791ea571ac..8e4c6670141 100644 --- a/test/system/notification/regular_events_test.rb +++ b/test/system/notification/regular_events_test.rb @@ -67,7 +67,7 @@ class Notification::RegularEventsTest < ApplicationSystemTestCase headers: { 'Content-Type' => 'application/json' }) travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do - mock_env({ 'TOKEN' => 'token' }) do + mock_env('TOKEN' => 'token') do visit_with_query scheduler_daily_notify_coming_soon_regular_events_path, { token: 'token' } end end From 10232697daa4ae9092d6e782021a2888abb6244c Mon Sep 17 00:00:00 2001 From: tomo Date: Sat, 28 Oct 2023 20:54:36 +0900 Subject: [PATCH 09/18] =?UTF-8?q?QueryHelper=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/application_system_test_case.rb | 2 -- test/supports/query_helper.rb | 9 --------- test/system/auto_retire_test.rb | 16 ++++++++-------- test/system/external_entries_test.rb | 2 +- test/system/notification/questions_test.rb | 4 ++-- test/system/notification/regular_events_test.rb | 2 +- 6 files changed, 12 insertions(+), 23 deletions(-) delete mode 100644 test/supports/query_helper.rb diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index 5214bccef96..445a50117d3 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -8,7 +8,6 @@ require 'supports/report_helper' require 'supports/comment_helper' require 'supports/tag_helper' -require 'supports/query_helper' require 'supports/mock_env_helper' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase @@ -19,7 +18,6 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase include ReportHelper include CommentHelper include TagHelper - include QueryHelper include MockEnvHelper if ENV['HEADED'] diff --git a/test/supports/query_helper.rb b/test/supports/query_helper.rb deleted file mode 100644 index 5c9b45efda2..00000000000 --- a/test/supports/query_helper.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module QueryHelper - def visit_with_query(url, query_hash) - uri = URI.parse(url) - uri.query = query_hash.to_query - visit uri.to_s - end -end diff --git a/test/system/auto_retire_test.rb b/test/system/auto_retire_test.rb index db4437ae693..a92d55df59d 100644 --- a/test/system/auto_retire_test.rb +++ b/test/system/auto_retire_test.rb @@ -17,7 +17,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end end assert_equal Date.current, user.reload.retired_on @@ -52,7 +52,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 1, 0, 0, 0) do VCR.use_cassette 'subscription/update' do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end end assert_nil user.reload.retired_on @@ -69,7 +69,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end assert_nil user.reload.retired_on end @@ -83,7 +83,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end assert_equal retired_date, user.reload.retired_on end @@ -98,7 +98,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end end assert_equal Date.current, user.reload.retired_on @@ -117,7 +117,7 @@ class AutoRetireTest < ApplicationSystemTestCase Discord::Server.stub(:delete_text_channel, true) do VCR.use_cassette 'subscription/update' do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end end end @@ -136,7 +136,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end end assert_equal Date.current, user.reload.retired_on @@ -155,7 +155,7 @@ class AutoRetireTest < ApplicationSystemTestCase travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do VCR.use_cassette 'subscription/update' do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_auto_retire_path, { token: 'token' } + visit scheduler_daily_auto_retire_path(token: 'token') end end assert_equal Date.current, user.reload.retired_on diff --git a/test/system/external_entries_test.rb b/test/system/external_entries_test.rb index 9218672ba3e..fad1bc4406b 100644 --- a/test/system/external_entries_test.rb +++ b/test/system/external_entries_test.rb @@ -14,7 +14,7 @@ class ExternalEntriesTest < ApplicationSystemTestCase VCR.use_cassette 'external_entry/fetch2', vcr_options do VCR.use_cassette 'external_entry/fetch' do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_fetch_external_entry_path, { token: 'token' } + visit scheduler_daily_fetch_external_entry_path(token: 'token') end end end diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index cbc87164bac..7a65c86391a 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -304,7 +304,7 @@ class Notification::QuestionsTest < ApplicationSystemTestCase travel_to Time.zone.local(2022, 11, 6, 0, 0, 0) do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_notify_certain_period_passed_after_last_answer_path, { token: 'token' } + visit scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'token') end visit_with_auth '/notifications', 'kimura' @@ -314,7 +314,7 @@ class Notification::QuestionsTest < ApplicationSystemTestCase travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_notify_certain_period_passed_after_last_answer_path, { token: 'token' } + visit scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'token') end visit_with_auth '/notifications', 'kimura' diff --git a/test/system/notification/regular_events_test.rb b/test/system/notification/regular_events_test.rb index 8e4c6670141..3276488444c 100644 --- a/test/system/notification/regular_events_test.rb +++ b/test/system/notification/regular_events_test.rb @@ -68,7 +68,7 @@ class Notification::RegularEventsTest < ApplicationSystemTestCase travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do mock_env('TOKEN' => 'token') do - visit_with_query scheduler_daily_notify_coming_soon_regular_events_path, { token: 'token' } + visit scheduler_daily_notify_coming_soon_regular_events_path(token: 'token') end end From 132848a53ad36784989ee6057372a40d2b52bc61 Mon Sep 17 00:00:00 2001 From: tomo Date: Sat, 28 Oct 2023 21:06:31 +0900 Subject: [PATCH 10/18] =?UTF-8?q?no=5Ftext=E3=81=AE=E6=A4=9C=E8=A8=BC?= =?UTF-8?q?=E3=81=AB=E7=8F=BE=E5=9C=A8=E3=81=AE=E3=83=91=E3=82=B9=E3=81=AE?= =?UTF-8?q?=E6=A4=9C=E8=A8=BC=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/notification/questions_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index 7a65c86391a..91d5d1fec2d 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -309,6 +309,7 @@ class Notification::QuestionsTest < ApplicationSystemTestCase visit_with_auth '/notifications', 'kimura' assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' + assert_current_path(notifications_path(_login_name: 'kimura')) end logout From d87ce5806c3243c8ccf38842e8dff29db351d84e Mon Sep 17 00:00:00 2001 From: tomo Date: Sat, 28 Oct 2023 21:58:39 +0900 Subject: [PATCH 11/18] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=81=AE=E6=95=B0?= =?UTF-8?q?=E3=81=8C=E5=A4=89=E5=8C=96=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=81=93=E3=81=A8=E3=81=AE=E6=A4=9C=E8=A8=BC=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/notification/questions_test.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index 91d5d1fec2d..a45e63a2b73 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -303,13 +303,15 @@ class Notification::QuestionsTest < ApplicationSystemTestCase ) travel_to Time.zone.local(2022, 11, 6, 0, 0, 0) do - mock_env('TOKEN' => 'token') do - visit scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'token') + assert_no_difference 'questioner.notifications.count' do + mock_env('TOKEN' => 'token') do + visit scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'token') + end + visit_with_auth '/notifications', 'kimura' + + assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' + assert_current_path(notifications_path(_login_name: 'kimura')) end - visit_with_auth '/notifications', 'kimura' - - assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' - assert_current_path(notifications_path(_login_name: 'kimura')) end logout From 32973ea99a180b2d44b7a14a9f8d8feabce54825 Mon Sep 17 00:00:00 2001 From: tomo Date: Sun, 29 Oct 2023 20:21:31 +0900 Subject: [PATCH 12/18] =?UTF-8?q?TOKEN=E3=81=8C=E6=9C=AA=E8=A8=AD=E5=AE=9A?= =?UTF-8?q?=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=A8=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/auto_retire_test.rb | 22 +++++ test/system/external_entries_test.rb | 22 +++++ test/system/notification/questions_test.rb | 62 ++++++++++++ .../notification/regular_events_test.rb | 94 +++++++++++++++++++ 4 files changed, 200 insertions(+) diff --git a/test/system/auto_retire_test.rb b/test/system/auto_retire_test.rb index a92d55df59d..242a91f3b4f 100644 --- a/test/system/auto_retire_test.rb +++ b/test/system/auto_retire_test.rb @@ -161,4 +161,26 @@ class AutoRetireTest < ApplicationSystemTestCase assert_equal Date.current, user.reload.retired_on end end + + test 'not retire when token is invalid' do + user = users(:kyuukai) + travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do + VCR.use_cassette 'subscription/update' do + mock_env('TOKEN' => 'token') do + visit scheduler_daily_auto_retire_path(token: 'invalid') + end + end + assert_nil user.reload.retired_on + end + end + + test 'not retire when token is not set' do + user = users(:kyuukai) + travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do + VCR.use_cassette 'subscription/update' do + visit scheduler_daily_auto_retire_path + end + assert_nil user.reload.retired_on + end + end end diff --git a/test/system/external_entries_test.rb b/test/system/external_entries_test.rb index fad1bc4406b..01340711c33 100644 --- a/test/system/external_entries_test.rb +++ b/test/system/external_entries_test.rb @@ -20,4 +20,26 @@ class ExternalEntriesTest < ApplicationSystemTestCase end end end + + test 'not fetch and save rss feeds when token is invalid' do + assert_no_difference 'ExternalEntry.count' do + VCR.use_cassette 'external_entry/fetch2', vcr_options do + VCR.use_cassette 'external_entry/fetch' do + mock_env('TOKEN' => 'token') do + visit scheduler_daily_fetch_external_entry_path(token: 'invalid') + end + end + end + end + end + + test 'not fetch and save rss feeds when token is not set' do + assert_no_difference 'ExternalEntry.count' do + VCR.use_cassette 'external_entry/fetch2', vcr_options do + VCR.use_cassette 'external_entry/fetch' do + visit scheduler_daily_fetch_external_entry_path + end + end + end + end end diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index a45e63a2b73..69f28931346 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -324,4 +324,66 @@ class Notification::QuestionsTest < ApplicationSystemTestCase assert_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' end end + + test 'not notify to questioner when a week has passed since last answer when token is invalid' do + questioner = users(:kimura) + answerer = users(:komagata) + question = Question.create!( + title: 'テストの質問', + description: 'テスト', + user: questioner, + created_at: '2022-10-31', + updated_at: '2022-10-31', + published_at: '2022-10-31' + ) + Answer.create!( + description: '最後の回答', + user: answerer, + question: question, + created_at: '2022-10-31', + updated_at: '2022-10-31' + ) + + travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do + assert_no_difference 'questioner.notifications.count' do + mock_env('TOKEN' => 'token') do + visit scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'invalid') + end + visit_with_auth '/notifications', 'kimura' + + assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' + assert_current_path(notifications_path(_login_name: 'kimura')) + end + end + end + + test 'not notify to questioner when a week has passed since last answer when token is not set' do + questioner = users(:kimura) + answerer = users(:komagata) + question = Question.create!( + title: 'テストの質問', + description: 'テスト', + user: questioner, + created_at: '2022-10-31', + updated_at: '2022-10-31', + published_at: '2022-10-31' + ) + Answer.create!( + description: '最後の回答', + user: answerer, + question: question, + created_at: '2022-10-31', + updated_at: '2022-10-31' + ) + + travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do + assert_no_difference 'questioner.notifications.count' do + visit scheduler_daily_notify_certain_period_passed_after_last_answer_path + visit_with_auth '/notifications', 'kimura' + + assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' + assert_current_path(notifications_path(_login_name: 'kimura')) + end + end + end end diff --git a/test/system/notification/regular_events_test.rb b/test/system/notification/regular_events_test.rb index 3276488444c..172b69c5151 100644 --- a/test/system/notification/regular_events_test.rb +++ b/test/system/notification/regular_events_test.rb @@ -74,4 +74,98 @@ class Notification::RegularEventsTest < ApplicationSystemTestCase assert_requested(stub_message) end + + test 'not notify_coming_soon_regular_events when token is invalid' do + event_info = <<~TEXT.chomp + ⚡️⚡️⚡️イベントのお知らせ⚡️⚡️⚡️ + + < 今日 (05/05 金) 開催 > + + ⚠️ Discord通知確認用、祝日非開催イベント(金曜日開催) + ⚠️ Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) + はお休みです。 + + ------------------------------ + + < 明日 (05/06 土) 開催 > + + Discord通知確認用イベント(土曜日開催) + 時間: 21:00〜22:00 + 詳細: http://localhost:3000/regular_events/284302086 + + Discord通知確認用イベント(土曜日 + 日曜日開催) + 時間: 21:00〜22:00 + 詳細: http://localhost:3000/regular_events/670378901 + + Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) + 時間: 21:00〜22:00 + 詳細: http://localhost:3000/regular_events/808817380 + + ⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️ + TEXT + params = { + url: 'https://discord.com/api/webhooks/0123456789/all', + username: 'ピヨルド', + avatar_url: 'https://i.gyazo.com/7099977680d8d8c2d72a3f14ddf14cc6.png', + content: event_info + } + + stub_message = stub_request(:post, 'https://discord.com/api/webhooks/0123456789/all') + .with(body: params, + headers: { 'Content-Type' => 'application/json' }) + + travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do + mock_env('TOKEN' => 'token') do + visit scheduler_daily_notify_coming_soon_regular_events_path(token: 'invalid') + end + end + + assert_not_requested(stub_message) + end + + test 'not notify_coming_soon_regular_events when token is not set' do + event_info = <<~TEXT.chomp + ⚡️⚡️⚡️イベントのお知らせ⚡️⚡️⚡️ + + < 今日 (05/05 金) 開催 > + + ⚠️ Discord通知確認用、祝日非開催イベント(金曜日開催) + ⚠️ Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) + はお休みです。 + + ------------------------------ + + < 明日 (05/06 土) 開催 > + + Discord通知確認用イベント(土曜日開催) + 時間: 21:00〜22:00 + 詳細: http://localhost:3000/regular_events/284302086 + + Discord通知確認用イベント(土曜日 + 日曜日開催) + 時間: 21:00〜22:00 + 詳細: http://localhost:3000/regular_events/670378901 + + Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) + 時間: 21:00〜22:00 + 詳細: http://localhost:3000/regular_events/808817380 + + ⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️ + TEXT + params = { + url: 'https://discord.com/api/webhooks/0123456789/all', + username: 'ピヨルド', + avatar_url: 'https://i.gyazo.com/7099977680d8d8c2d72a3f14ddf14cc6.png', + content: event_info + } + + stub_message = stub_request(:post, 'https://discord.com/api/webhooks/0123456789/all') + .with(body: params, + headers: { 'Content-Type' => 'application/json' }) + + travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do + visit scheduler_daily_notify_coming_soon_regular_events_path + end + + assert_not_requested(stub_message) + end end From fa5565b7b4e04bd66fc058435d597113fc629a80 Mon Sep 17 00:00:00 2001 From: tomo Date: Sun, 29 Oct 2023 20:37:31 +0900 Subject: [PATCH 13/18] =?UTF-8?q?=E3=82=AC=E3=83=BC=E3=83=89=E7=AF=80?= =?UTF-8?q?=E3=82=92=E5=BE=8C=E7=BD=AEif=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6540499b5ab..f5981fcb5ac 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -52,10 +52,7 @@ def require_subscription end def require_scheduler_inheritation - return unless request.path_info.start_with?('/scheduler') - return if is_a?(SchedulerController) - - head :internal_server_error + head :internal_server_error if request.path_info.start_with?('/scheduler') && !is_a?(SchedulerController) end protected From d45e5e5f949891a63a48c22d636690e6bd38b232 Mon Sep 17 00:00:00 2001 From: tomo Date: Tue, 31 Oct 2023 22:09:19 +0900 Subject: [PATCH 14/18] =?UTF-8?q?require=5Fscheduler=5Finheritation?= =?UTF-8?q?=E3=81=8C=E6=9C=80=E5=88=9D=E3=81=AB=E5=AE=9F=E8=A1=8C=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f5981fcb5ac..4e6b670203e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,13 +6,13 @@ class ApplicationController < ActionController::Base include PolicyHelper helper_method :staging? protect_from_forgery with: :exception + before_action :require_scheduler_inheritation before_action :basic_auth, if: :staging? before_action :test_login, if: :test? before_action :init_user before_action :allow_cross_domain_access before_action :set_host_for_disk_storage before_action :require_active_user_login - before_action :require_scheduler_inheritation protected From 03d531f8b5a48f2aac31349a944ab7aeeb27bba8 Mon Sep 17 00:00:00 2001 From: tomo Date: Sat, 4 Nov 2023 21:22:39 +0900 Subject: [PATCH 15/18] =?UTF-8?q?token=E9=96=A2=E9=80=A3=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92integration=20test=E3=81=AB=E7=BD=AE?= =?UTF-8?q?=E3=81=8D=E6=8F=9B=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 2 + .../scheduler/daily/auto_retire_test.rb | 28 ++++++ .../daily/fetch_external_entry_test.rb | 28 ++++++ ...in_period_passed_after_last_answer_test.rb | 28 ++++++ .../notify_coming_soon_regular_events_test.rb | 28 ++++++ test/system/auto_retire_test.rb | 22 ----- test/system/external_entries_test.rb | 22 ----- test/system/notification/questions_test.rb | 62 ------------ .../notification/regular_events_test.rb | 94 ------------------- 10 files changed, 115 insertions(+), 200 deletions(-) create mode 100644 test/integration/scheduler/daily/auto_retire_test.rb create mode 100644 test/integration/scheduler/daily/fetch_external_entry_test.rb create mode 100644 test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb create mode 100644 test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb diff --git a/Gemfile b/Gemfile index e448339456d..db9b95422b4 100644 --- a/Gemfile +++ b/Gemfile @@ -104,6 +104,7 @@ group :test do gem 'capybara' gem 'minitest-ci' gem 'minitest-retry' + gem 'minitest-stub_any_instance' gem 'selenium-webdriver' gem 'vcr' gem 'webmock' diff --git a/Gemfile.lock b/Gemfile.lock index 7aa3c896ffa..e0b8c9bc3c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -290,6 +290,7 @@ GEM minitest-retry (0.2.2) minitest (>= 5.0) msgpack (1.7.2) + minitest-stub_any_instance (1.0.3) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.3.0) @@ -625,6 +626,7 @@ DEPENDENCIES mini_magick minitest-ci minitest-retry + minitest-stub_any_instance net-imap net-pop net-smtp diff --git a/test/integration/scheduler/daily/auto_retire_test.rb b/test/integration/scheduler/daily/auto_retire_test.rb new file mode 100644 index 00000000000..53307ff159b --- /dev/null +++ b/test/integration/scheduler/daily/auto_retire_test.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'supports/mock_env_helper' + +class Scheduler::Daily::AutoRetireTest < ActionDispatch::IntegrationTest + include MockEnvHelper + + test 'token evaluation' do + # サーバー側のTOKENが未設定 + mock_env('TOKEN' => '') do + get scheduler_daily_auto_retire_path(token: '') + assert_response 401 + end + + mock_env('TOKEN' => 'token') do + # リクエストで指定したtokenが不正 + get scheduler_daily_auto_retire_path(token: 'invalid') + assert_response 401 + + # tokenが正しい + Scheduler::Daily::AutoRetireController.stub_any_instance(:auto_retire) do + get scheduler_daily_auto_retire_path(token: 'token') + assert_response 200 + end + end + end +end diff --git a/test/integration/scheduler/daily/fetch_external_entry_test.rb b/test/integration/scheduler/daily/fetch_external_entry_test.rb new file mode 100644 index 00000000000..4865287655b --- /dev/null +++ b/test/integration/scheduler/daily/fetch_external_entry_test.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'supports/mock_env_helper' + +class Scheduler::Daily::FetchExternalEntryTest < ActionDispatch::IntegrationTest + include MockEnvHelper + + test 'token evaluation' do + # サーバー側のTOKENが未設定 + mock_env('TOKEN' => '') do + get scheduler_daily_fetch_external_entry_path(token: '') + assert_response 401 + end + + mock_env('TOKEN' => 'token') do + # リクエストで指定したtokenが不正 + get scheduler_daily_fetch_external_entry_path(token: 'invalid') + assert_response 401 + + # tokenが正しい + ExternalEntry.stub(:fetch_and_save_rss_feeds, nil) do + get scheduler_daily_fetch_external_entry_path(token: 'token') + assert_response 200 + end + end + end +end diff --git a/test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb b/test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb new file mode 100644 index 00000000000..c7d6b7fb12d --- /dev/null +++ b/test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'supports/mock_env_helper' + +class Scheduler::Daily::NotifyCertainPeriodPassedAfterLastAnswerTest < ActionDispatch::IntegrationTest + include MockEnvHelper + + test 'token evaluation' do + # サーバー側のTOKENが未設定 + mock_env('TOKEN' => '') do + get scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: '') + assert_response 401 + end + + mock_env('TOKEN' => 'token') do + # リクエストで指定したtokenが不正 + get scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'invalid') + assert_response 401 + + # tokenが正しい + Question.stub(:notify_certain_period_passed_after_last_answer, nil) do + get scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'token') + assert_response 200 + end + end + end +end diff --git a/test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb b/test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb new file mode 100644 index 00000000000..580db617971 --- /dev/null +++ b/test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'test_helper' +require 'supports/mock_env_helper' + +class Scheduler::Daily::NotifyComingSoonRegularEventsTest < ActionDispatch::IntegrationTest + include MockEnvHelper + + test 'token evaluation' do + # サーバー側のTOKENが未設定 + mock_env('TOKEN' => '') do + get scheduler_daily_notify_coming_soon_regular_events_path(token: '') + assert_response 401 + end + + mock_env('TOKEN' => 'token') do + # リクエストで指定したtokenが不正 + get scheduler_daily_notify_coming_soon_regular_events_path(token: 'invalid') + assert_response 401 + + # tokenが正しい + Scheduler::Daily::NotifyComingSoonRegularEventsController.stub_any_instance(:notify_coming_soon_regular_events) do + get scheduler_daily_notify_coming_soon_regular_events_path(token: 'token') + assert_response 200 + end + end + end +end diff --git a/test/system/auto_retire_test.rb b/test/system/auto_retire_test.rb index 242a91f3b4f..a92d55df59d 100644 --- a/test/system/auto_retire_test.rb +++ b/test/system/auto_retire_test.rb @@ -161,26 +161,4 @@ class AutoRetireTest < ApplicationSystemTestCase assert_equal Date.current, user.reload.retired_on end end - - test 'not retire when token is invalid' do - user = users(:kyuukai) - travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - VCR.use_cassette 'subscription/update' do - mock_env('TOKEN' => 'token') do - visit scheduler_daily_auto_retire_path(token: 'invalid') - end - end - assert_nil user.reload.retired_on - end - end - - test 'not retire when token is not set' do - user = users(:kyuukai) - travel_to Time.zone.local(2020, 7, 2, 0, 0, 0) do - VCR.use_cassette 'subscription/update' do - visit scheduler_daily_auto_retire_path - end - assert_nil user.reload.retired_on - end - end end diff --git a/test/system/external_entries_test.rb b/test/system/external_entries_test.rb index 01340711c33..fad1bc4406b 100644 --- a/test/system/external_entries_test.rb +++ b/test/system/external_entries_test.rb @@ -20,26 +20,4 @@ class ExternalEntriesTest < ApplicationSystemTestCase end end end - - test 'not fetch and save rss feeds when token is invalid' do - assert_no_difference 'ExternalEntry.count' do - VCR.use_cassette 'external_entry/fetch2', vcr_options do - VCR.use_cassette 'external_entry/fetch' do - mock_env('TOKEN' => 'token') do - visit scheduler_daily_fetch_external_entry_path(token: 'invalid') - end - end - end - end - end - - test 'not fetch and save rss feeds when token is not set' do - assert_no_difference 'ExternalEntry.count' do - VCR.use_cassette 'external_entry/fetch2', vcr_options do - VCR.use_cassette 'external_entry/fetch' do - visit scheduler_daily_fetch_external_entry_path - end - end - end - end end diff --git a/test/system/notification/questions_test.rb b/test/system/notification/questions_test.rb index 69f28931346..a45e63a2b73 100644 --- a/test/system/notification/questions_test.rb +++ b/test/system/notification/questions_test.rb @@ -324,66 +324,4 @@ class Notification::QuestionsTest < ApplicationSystemTestCase assert_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' end end - - test 'not notify to questioner when a week has passed since last answer when token is invalid' do - questioner = users(:kimura) - answerer = users(:komagata) - question = Question.create!( - title: 'テストの質問', - description: 'テスト', - user: questioner, - created_at: '2022-10-31', - updated_at: '2022-10-31', - published_at: '2022-10-31' - ) - Answer.create!( - description: '最後の回答', - user: answerer, - question: question, - created_at: '2022-10-31', - updated_at: '2022-10-31' - ) - - travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do - assert_no_difference 'questioner.notifications.count' do - mock_env('TOKEN' => 'token') do - visit scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'invalid') - end - visit_with_auth '/notifications', 'kimura' - - assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' - assert_current_path(notifications_path(_login_name: 'kimura')) - end - end - end - - test 'not notify to questioner when a week has passed since last answer when token is not set' do - questioner = users(:kimura) - answerer = users(:komagata) - question = Question.create!( - title: 'テストの質問', - description: 'テスト', - user: questioner, - created_at: '2022-10-31', - updated_at: '2022-10-31', - published_at: '2022-10-31' - ) - Answer.create!( - description: '最後の回答', - user: answerer, - question: question, - created_at: '2022-10-31', - updated_at: '2022-10-31' - ) - - travel_to Time.zone.local(2022, 11, 7, 0, 0, 0) do - assert_no_difference 'questioner.notifications.count' do - visit scheduler_daily_notify_certain_period_passed_after_last_answer_path - visit_with_auth '/notifications', 'kimura' - - assert_no_text 'Q&A「テストの質問」のベストアンサーがまだ選ばれていません。' - assert_current_path(notifications_path(_login_name: 'kimura')) - end - end - end end diff --git a/test/system/notification/regular_events_test.rb b/test/system/notification/regular_events_test.rb index 172b69c5151..3276488444c 100644 --- a/test/system/notification/regular_events_test.rb +++ b/test/system/notification/regular_events_test.rb @@ -74,98 +74,4 @@ class Notification::RegularEventsTest < ApplicationSystemTestCase assert_requested(stub_message) end - - test 'not notify_coming_soon_regular_events when token is invalid' do - event_info = <<~TEXT.chomp - ⚡️⚡️⚡️イベントのお知らせ⚡️⚡️⚡️ - - < 今日 (05/05 金) 開催 > - - ⚠️ Discord通知確認用、祝日非開催イベント(金曜日開催) - ⚠️ Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) - はお休みです。 - - ------------------------------ - - < 明日 (05/06 土) 開催 > - - Discord通知確認用イベント(土曜日開催) - 時間: 21:00〜22:00 - 詳細: http://localhost:3000/regular_events/284302086 - - Discord通知確認用イベント(土曜日 + 日曜日開催) - 時間: 21:00〜22:00 - 詳細: http://localhost:3000/regular_events/670378901 - - Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) - 時間: 21:00〜22:00 - 詳細: http://localhost:3000/regular_events/808817380 - - ⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️ - TEXT - params = { - url: 'https://discord.com/api/webhooks/0123456789/all', - username: 'ピヨルド', - avatar_url: 'https://i.gyazo.com/7099977680d8d8c2d72a3f14ddf14cc6.png', - content: event_info - } - - stub_message = stub_request(:post, 'https://discord.com/api/webhooks/0123456789/all') - .with(body: params, - headers: { 'Content-Type' => 'application/json' }) - - travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do - mock_env('TOKEN' => 'token') do - visit scheduler_daily_notify_coming_soon_regular_events_path(token: 'invalid') - end - end - - assert_not_requested(stub_message) - end - - test 'not notify_coming_soon_regular_events when token is not set' do - event_info = <<~TEXT.chomp - ⚡️⚡️⚡️イベントのお知らせ⚡️⚡️⚡️ - - < 今日 (05/05 金) 開催 > - - ⚠️ Discord通知確認用、祝日非開催イベント(金曜日開催) - ⚠️ Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) - はお休みです。 - - ------------------------------ - - < 明日 (05/06 土) 開催 > - - Discord通知確認用イベント(土曜日開催) - 時間: 21:00〜22:00 - 詳細: http://localhost:3000/regular_events/284302086 - - Discord通知確認用イベント(土曜日 + 日曜日開催) - 時間: 21:00〜22:00 - 詳細: http://localhost:3000/regular_events/670378901 - - Discord通知確認用、祝日非開催イベント(金曜日 + 土曜日開催) - 時間: 21:00〜22:00 - 詳細: http://localhost:3000/regular_events/808817380 - - ⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️⚡️ - TEXT - params = { - url: 'https://discord.com/api/webhooks/0123456789/all', - username: 'ピヨルド', - avatar_url: 'https://i.gyazo.com/7099977680d8d8c2d72a3f14ddf14cc6.png', - content: event_info - } - - stub_message = stub_request(:post, 'https://discord.com/api/webhooks/0123456789/all') - .with(body: params, - headers: { 'Content-Type' => 'application/json' }) - - travel_to Time.zone.local(2023, 5, 5, 6, 0, 0) do - visit scheduler_daily_notify_coming_soon_regular_events_path - end - - assert_not_requested(stub_message) - end end From da124745c46e3379a42f1ec7e2ea232ffa54e942 Mon Sep 17 00:00:00 2001 From: tomo Date: Tue, 7 Nov 2023 20:22:30 +0900 Subject: [PATCH 16/18] =?UTF-8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/integration/scheduler/daily/auto_retire_test.rb | 3 --- test/integration/scheduler/daily/fetch_external_entry_test.rb | 3 --- .../notify_certain_period_passed_after_last_answer_test.rb | 3 --- .../scheduler/daily/notify_coming_soon_regular_events_test.rb | 3 --- 4 files changed, 12 deletions(-) diff --git a/test/integration/scheduler/daily/auto_retire_test.rb b/test/integration/scheduler/daily/auto_retire_test.rb index 53307ff159b..1cab9df0a6c 100644 --- a/test/integration/scheduler/daily/auto_retire_test.rb +++ b/test/integration/scheduler/daily/auto_retire_test.rb @@ -7,18 +7,15 @@ class Scheduler::Daily::AutoRetireTest < ActionDispatch::IntegrationTest include MockEnvHelper test 'token evaluation' do - # サーバー側のTOKENが未設定 mock_env('TOKEN' => '') do get scheduler_daily_auto_retire_path(token: '') assert_response 401 end mock_env('TOKEN' => 'token') do - # リクエストで指定したtokenが不正 get scheduler_daily_auto_retire_path(token: 'invalid') assert_response 401 - # tokenが正しい Scheduler::Daily::AutoRetireController.stub_any_instance(:auto_retire) do get scheduler_daily_auto_retire_path(token: 'token') assert_response 200 diff --git a/test/integration/scheduler/daily/fetch_external_entry_test.rb b/test/integration/scheduler/daily/fetch_external_entry_test.rb index 4865287655b..bf267fc1e43 100644 --- a/test/integration/scheduler/daily/fetch_external_entry_test.rb +++ b/test/integration/scheduler/daily/fetch_external_entry_test.rb @@ -7,18 +7,15 @@ class Scheduler::Daily::FetchExternalEntryTest < ActionDispatch::IntegrationTest include MockEnvHelper test 'token evaluation' do - # サーバー側のTOKENが未設定 mock_env('TOKEN' => '') do get scheduler_daily_fetch_external_entry_path(token: '') assert_response 401 end mock_env('TOKEN' => 'token') do - # リクエストで指定したtokenが不正 get scheduler_daily_fetch_external_entry_path(token: 'invalid') assert_response 401 - # tokenが正しい ExternalEntry.stub(:fetch_and_save_rss_feeds, nil) do get scheduler_daily_fetch_external_entry_path(token: 'token') assert_response 200 diff --git a/test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb b/test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb index c7d6b7fb12d..42228ba7c83 100644 --- a/test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb +++ b/test/integration/scheduler/daily/notify_certain_period_passed_after_last_answer_test.rb @@ -7,18 +7,15 @@ class Scheduler::Daily::NotifyCertainPeriodPassedAfterLastAnswerTest < ActionDis include MockEnvHelper test 'token evaluation' do - # サーバー側のTOKENが未設定 mock_env('TOKEN' => '') do get scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: '') assert_response 401 end mock_env('TOKEN' => 'token') do - # リクエストで指定したtokenが不正 get scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'invalid') assert_response 401 - # tokenが正しい Question.stub(:notify_certain_period_passed_after_last_answer, nil) do get scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'token') assert_response 200 diff --git a/test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb b/test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb index 580db617971..c26e9386aae 100644 --- a/test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb +++ b/test/integration/scheduler/daily/notify_coming_soon_regular_events_test.rb @@ -7,18 +7,15 @@ class Scheduler::Daily::NotifyComingSoonRegularEventsTest < ActionDispatch::Inte include MockEnvHelper test 'token evaluation' do - # サーバー側のTOKENが未設定 mock_env('TOKEN' => '') do get scheduler_daily_notify_coming_soon_regular_events_path(token: '') assert_response 401 end mock_env('TOKEN' => 'token') do - # リクエストで指定したtokenが不正 get scheduler_daily_notify_coming_soon_regular_events_path(token: 'invalid') assert_response 401 - # tokenが正しい Scheduler::Daily::NotifyComingSoonRegularEventsController.stub_any_instance(:notify_coming_soon_regular_events) do get scheduler_daily_notify_coming_soon_regular_events_path(token: 'token') assert_response 200 From 5ba8640de27f42c1be824df083ed96f7f7884050 Mon Sep 17 00:00:00 2001 From: tomo Date: Tue, 7 Nov 2023 20:26:09 +0900 Subject: [PATCH 17/18] =?UTF-8?q?SchedulerController=E3=81=AE=E7=B6=99?= =?UTF-8?q?=E6=89=BF=E3=82=92=E8=A6=81=E6=B1=82=E3=81=99=E3=82=8B=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4e6b670203e..e5bddd87767 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base include PolicyHelper helper_method :staging? protect_from_forgery with: :exception - before_action :require_scheduler_inheritation + before_action :require_scheduler_inheritation, if: -> { request.path_info.start_with?('/scheduler') } before_action :basic_auth, if: :staging? before_action :test_login, if: :test? before_action :init_user @@ -52,7 +52,7 @@ def require_subscription end def require_scheduler_inheritation - head :internal_server_error if request.path_info.start_with?('/scheduler') && !is_a?(SchedulerController) + head :internal_server_error unless is_a?(SchedulerController) end protected From f546eb451dd35777758efb5c09b75772102b433a Mon Sep 17 00:00:00 2001 From: tomo Date: Tue, 7 Nov 2023 20:42:56 +0900 Subject: [PATCH 18/18] =?UTF-8?q?=E7=92=B0=E5=A2=83=E5=A4=89=E6=95=B0?= =?UTF-8?q?=E3=82=92=E3=83=A2=E3=83=83=E3=82=AF=E3=81=99=E3=82=8B=E5=87=A6?= =?UTF-8?q?=E7=90=86=E3=82=92stub=E3=82=92=E4=BD=BF=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/supports/mock_env_helper.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/test/supports/mock_env_helper.rb b/test/supports/mock_env_helper.rb index d4607296a51..9dfba9f3989 100644 --- a/test/supports/mock_env_helper.rb +++ b/test/supports/mock_env_helper.rb @@ -1,13 +1,8 @@ # frozen_string_literal: true module MockEnvHelper - def mock_env(partial_env_hash) - old = ENV.to_hash - ENV.update partial_env_hash - begin - yield - ensure - ENV.replace old - end + def mock_env(hash_for_mock, &block) + env_hash = ENV.to_hash.merge(hash_for_mock) + ENV.stub(:[], ->(key) { env_hash[key] }, &block) end end