Skip to content
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

Timesチャンネルの作成処理にログ出力を追加 #6953

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def new
end

def create
logger.info "[Signup] 1. start create. #{user_params[:email]}"

@user = User.new(user_params)
@user.course_id ||= Course.first.id
@user.free = true if @user.trainee?
Expand All @@ -80,11 +82,14 @@ def target_allowlist
end

def create_free_user!
logger.info "[Signup] 2. start create free user. #{@user.email}"
if @user.save
logger.info "[Signup] 3. after save free user. #{@user.email}"
UserMailer.welcome(@user).deliver_now
notify_to_mentors(@user)
notify_to_chat(@user)
Newspaper.publish(:student_or_trainee_create, @user) if @user.trainee?
logger.info "[Signup] 4. after create times channel for free user. #{@user.email}"
redirect_to root_url, notice: 'サインアップメールをお送りしました。メールからサインアップを完了させてください。'
else
render 'new'
Expand All @@ -93,6 +98,7 @@ def create_free_user!

# rubocop:disable Metrics/MethodLength, Metrics/BlockLength
def create_user!
logger.info "[Signup] 2. start create user. #{@user.email}"
@user.with_lock do
unless @user.validate
render 'new'
Expand All @@ -108,6 +114,7 @@ def create_user!

token = params[:idempotency_token]

logger.info "[Signup] 3. before create subscription. #{@user.email}"
begin
customer = Card.new.create(@user, params[:stripeToken], token)
subscription = Subscription.new.create(customer['id'], "#{token}-subscription")
Expand All @@ -117,15 +124,18 @@ def create_user!
render 'new'
return false
end
logger.info "[Signup] 4. after create subscription.#{@user.email}"

@user.customer_id = customer['id']
@user.subscription_id = subscription['id']

if @user.save
logger.info "[Signup] 5. after save user. #{@user.email}"
UserMailer.welcome(@user).deliver_now
notify_to_mentors(@user)
notify_to_chat(@user)
Newspaper.publish(:student_or_trainee_create, @user) if @user.student?
logger.info "[Signup] 8. after create times channel. #{@user.email}"
redirect_to root_url, notice: 'サインアップメールをお送りしました。メールからサインアップを完了させてください。'
else
render 'new'
Expand Down
5 changes: 4 additions & 1 deletion app/models/discord/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class Server
class << self
def create_text_channel(name:, parent: nil)
guild = Discord::Server.find_by(id: guild_id, token: authorize_token)
return nil if guild.blank?
if guild.blank?
Rails.logger.error "[Discord API] Do not find server. guild_id: #{guild_id}, token: #{authorize_token}"
return nil
end

channel_type = Discordrb::Channel::TYPES[:text]
guild.create_channel(name, channel_type, parent: parent)
Expand Down
2 changes: 2 additions & 0 deletions app/models/discord/times_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def to_channel_name(username)
end
end

attr_reader :name

def initialize(username)
@name = Discord::TimesChannel.to_channel_name(username)
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/discord/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ServerTest < ActiveSupport::TestCase
Discord::Server.authorize_token = 'Bot invalid token'
actual = Discord::Server.create_text_channel(name: 'wakaran🔰')
assert_nil actual
assert_equal '[Discord API] 401: Unauthorized', logs.pop
assert_equal '[Discord API] Do not find server. guild_id: 1234567890123456789, token: Bot invalid token', logs.pop
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/times_channel_destroyer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'test_helper'

class TimesChannelCreatorTest < ActiveSupport::TestCase
class TimesChannelDestroyerTest < ActiveSupport::TestCase
test '#call' do
logs = []
user = users(:hajime)
Expand Down