-
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
退会したらGitHubアカウントとの連携のデータを空になるように修正 #7931
base: main
Are you sure you want to change the base?
Changes from all commits
c6fd964
a89b32f
e317357
97358cb
7c12809
c793004
c77cfd6
7a51f8b
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# frozen_string_literal: true | ||
|
||
class UserRetirement | ||
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. こちらのテストが必要かと思います〜。 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. @komagata 退会時の通知に関しては test '.notify(:retired)' do
params = {
sender: users(:yameo),
receiver: users(:mentormentaro)
}
assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do
ActivityDelivery.notify!(:retired, **params)
end
assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do
ActivityDelivery.notify(:retired, **params)
end
assert_difference -> { AbstractNotifier::Testing::Driver.deliveries.count }, 1 do
ActivityDelivery.with(**params).notify!(:retired)
end
assert_difference -> { AbstractNotifier::Testing::Driver.enqueued_deliveries.count }, 1 do
ActivityDelivery.with(**params).notify(:retired)
end
end このように既存のテストがある場合でも、追加でテストを作成する必要があるかどうか、ご意見をいただけますでしょうか? 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. @su-su-su-su まず、 @su-su-su-su さんはどうするべきだと考えますか?? 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. @komagata 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. @su-su-su-su 確かにですね。 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. @komagata |
||
def initialize(user) | ||
@user = user | ||
end | ||
|
||
def execute | ||
@user.clear_github_data | ||
destroy_subscription | ||
destroy_card | ||
notify_to_user | ||
notify_to_admins | ||
notify_to_mentors | ||
end | ||
|
||
private | ||
|
||
def destroy_subscription | ||
Subscription.new.destroy(@user.subscription_id) if @user.subscription_id? | ||
end | ||
|
||
def destroy_card | ||
Card.destroy_all(@user.customer_id) if @user.customer_id? | ||
end | ||
|
||
def notify_to_user | ||
UserMailer.retire(@user).deliver_now | ||
rescue Postmark::InactiveRecipientError => e | ||
Rails.logger.warn "[Postmark] 受信者由来のエラーのためメールを送信できませんでした。:#{e.message}" | ||
end | ||
|
||
def notify_to_admins | ||
User.admins.each do |admin_user| | ||
ActivityDelivery.with(sender: @user, receiver: admin_user).notify(:retired) | ||
end | ||
end | ||
|
||
def notify_to_mentors | ||
User.mentor.each do |mentor_user| | ||
ActivityDelivery.with(sender: @user, receiver: mentor_user).notify(:retired) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class UserRetirementTest < ActiveSupport::TestCase | ||
test 'execute method performs all retirement steps' do | ||
user = users(:kimura) | ||
retirement = UserRetirement.new(user) | ||
|
||
methods_called = [] | ||
|
||
user.define_singleton_method(:clear_github_data) do | ||
methods_called << :clear_github_data | ||
end | ||
|
||
%i[destroy_subscription destroy_card notify_to_user notify_to_admins notify_to_mentors].each do |method_name| | ||
retirement.define_singleton_method(method_name) do | ||
methods_called << method_name | ||
end | ||
end | ||
|
||
retirement.execute | ||
|
||
expected_methods = %i[ | ||
clear_github_data | ||
destroy_subscription | ||
destroy_card | ||
notify_to_user | ||
notify_to_admins | ||
notify_to_mentors | ||
] | ||
|
||
assert_equal expected_methods, methods_called | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -754,4 +754,18 @@ class UserTest < ActiveSupport::TestCase | |||||
america_users = [users(:neverlogin), users(:tom)] | ||||||
assert_equal User.by_area('米国').to_a.sort, america_users.sort | ||||||
end | ||||||
|
||||||
test 'clear_github_data should clear GitHub related fields' 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.
Suggested change
モデルのテストで、代表的なテストだけだったら他と一緒でこういう名前でいいかもです。 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. ご指摘ありがとうございます。 test '#clear_github_data' do と修正いたしました。 |
||||||
user = users(:kimura) | ||||||
user.github_id = '12345' | ||||||
user.github_account = 'github_kimura' | ||||||
user.github_collaborator = true | ||||||
user.save!(validate: false) | ||||||
|
||||||
user.clear_github_data | ||||||
|
||||||
assert_nil user.github_id | ||||||
assert_nil user.github_account | ||||||
assert_not user.github_collaborator | ||||||
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.
@motohiro-mm すみません、ちょっと質問の意図が理解できてないかもです。
基本的にはモデルにメソッドを追加した場合、モデルのテスト(ユニットテスト)の追加は必要になります。
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.
@komagata
私が最初にレビューさせていただいたときには、モデルのテストが追加されていなかったため、このようにコメントさせていただきました。
その後、
test/models/user_test.rb:740
のtest 'clear_github_data should clear GitHub related fields'
が追加されています。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.
@motohiro-mm なるほどです〜