diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 01bb48bcc1f..3e6a3731e7c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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? @@ -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' @@ -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' @@ -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") @@ -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' diff --git a/app/models/discord/server.rb b/app/models/discord/server.rb index 0627d68b89e..d3f784e16a2 100644 --- a/app/models/discord/server.rb +++ b/app/models/discord/server.rb @@ -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) diff --git a/app/models/discord/times_channel.rb b/app/models/discord/times_channel.rb index 2fb6f78bf07..c5666f099b6 100644 --- a/app/models/discord/times_channel.rb +++ b/app/models/discord/times_channel.rb @@ -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 diff --git a/test/models/discord/server_test.rb b/test/models/discord/server_test.rb index 87ff1763e5b..5c43da5859e 100644 --- a/test/models/discord/server_test.rb +++ b/test/models/discord/server_test.rb @@ -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 diff --git a/test/models/times_channel_destroyer_test.rb b/test/models/times_channel_destroyer_test.rb index edda241daa7..91d736156a7 100644 --- a/test/models/times_channel_destroyer_test.rb +++ b/test/models/times_channel_destroyer_test.rb @@ -2,7 +2,7 @@ require 'test_helper' -class TimesChannelCreatorTest < ActiveSupport::TestCase +class TimesChannelDestroyerTest < ActiveSupport::TestCase test '#call' do logs = [] user = users(:hajime)