-
Notifications
You must be signed in to change notification settings - Fork 71
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
ベストアンサーなし通知が本番で動作しないバグを修正 #6970
Changes from all commits
281534a
670ca83
042f9e0
878fa49
5e75b03
63298c5
8e49357
4ce1914
1023269
132848a
d87ce58
32973ea
fa5565b
d45e5e5
03d531f
da12474
5ba8640
f546eb4
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 |
---|---|---|
|
@@ -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] | ||
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. TOKENが未設定だとエラー、paramsのtokenが不一致だったらエラー、というパターンもテストしたい。 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. それぞれのテストについて、TOKENが未設定のケースと不一致のケースのテストを加えました。 |
||
|
||
head :unauthorized | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'supports/mock_env_helper' | ||
|
||
class Scheduler::Daily::AutoRetireTest < ActionDispatch::IntegrationTest | ||
include MockEnvHelper | ||
|
||
test 'token evaluation' do | ||
mock_env('TOKEN' => '') do | ||
get scheduler_daily_auto_retire_path(token: '') | ||
assert_response 401 | ||
end | ||
|
||
mock_env('TOKEN' => 'token') do | ||
get scheduler_daily_auto_retire_path(token: 'invalid') | ||
assert_response 401 | ||
|
||
Scheduler::Daily::AutoRetireController.stub_any_instance(:auto_retire) do | ||
get scheduler_daily_auto_retire_path(token: 'token') | ||
assert_response 200 | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'supports/mock_env_helper' | ||
|
||
class Scheduler::Daily::FetchExternalEntryTest < ActionDispatch::IntegrationTest | ||
include MockEnvHelper | ||
|
||
test 'token evaluation' do | ||
mock_env('TOKEN' => '') do | ||
get scheduler_daily_fetch_external_entry_path(token: '') | ||
assert_response 401 | ||
end | ||
|
||
mock_env('TOKEN' => 'token') do | ||
get scheduler_daily_fetch_external_entry_path(token: 'invalid') | ||
assert_response 401 | ||
|
||
ExternalEntry.stub(:fetch_and_save_rss_feeds, nil) 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. 質問)nilって付けないと問題が起きるんでしょうか? 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. stubメソッドでは第2引数で戻り値を指定する必要があるようです。省略するとエラーになりました。ここでは戻り値はとくに問題ではないので、nilを指定することにしました。 |
||
get scheduler_daily_fetch_external_entry_path(token: 'token') | ||
assert_response 200 | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'supports/mock_env_helper' | ||
|
||
class Scheduler::Daily::NotifyCertainPeriodPassedAfterLastAnswerTest < ActionDispatch::IntegrationTest | ||
include MockEnvHelper | ||
|
||
test 'token evaluation' do | ||
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 | ||
get scheduler_daily_notify_certain_period_passed_after_last_answer_path(token: 'invalid') | ||
assert_response 401 | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
require 'supports/mock_env_helper' | ||
|
||
class Scheduler::Daily::NotifyComingSoonRegularEventsTest < ActionDispatch::IntegrationTest | ||
include MockEnvHelper | ||
|
||
test 'token evaluation' do | ||
mock_env('TOKEN' => '') do | ||
get scheduler_daily_notify_coming_soon_regular_events_path(token: '') | ||
assert_response 401 | ||
end | ||
|
||
mock_env('TOKEN' => 'token') do | ||
get scheduler_daily_notify_coming_soon_regular_events_path(token: 'invalid') | ||
assert_response 401 | ||
|
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module MockEnvHelper | ||
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 |
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.
テストを書いてないのでちゃんと動くかどうか不安だけど、ローカルでは動作確認済みですよね?
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.
こちらと同じ方法で確認しました!
#6970 (comment)