From 855be2a5a7f2ea2292ed5f0f72e935045349ea30 Mon Sep 17 00:00:00 2001 From: yocchan-git Date: Sat, 30 Mar 2024 12:20:13 +0900 Subject: [PATCH] =?UTF-8?q?authentication=E3=83=95=E3=82=A9=E3=83=AB?= =?UTF-8?q?=E3=83=80=E3=81=AE=E4=B8=AD=E3=81=AB=E3=82=AF=E3=83=A9=E3=82=B9?= =?UTF-8?q?=E3=82=92=E4=BD=9C=E6=88=90=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/user_sessions_controller.rb | 4 ++-- .../discord.rb} | 2 +- .../github.rb} | 2 +- .../discord_test.rb} | 6 +++--- .../github_test.rb} | 10 +++++----- test/system/current_user_test.rb | 1 + 6 files changed, 13 insertions(+), 12 deletions(-) rename app/models/{discord_authentication.rb => authentication/discord.rb} (94%) rename app/models/{github_authentication.rb => authentication/github.rb} (97%) rename test/models/{discord_authentication_test.rb => authentication/discord_test.rb} (67%) rename test/models/{github_authentication_test.rb => authentication/github_test.rb} (72%) diff --git a/app/controllers/user_sessions_controller.rb b/app/controllers/user_sessions_controller.rb index e81d7e125e6..adec92fc69b 100644 --- a/app/controllers/user_sessions_controller.rb +++ b/app/controllers/user_sessions_controller.rb @@ -40,9 +40,9 @@ def callback authentication = case params[:provider] when 'discord' - DiscordAuthentication.new(current_user, auth) + Authentication::Discord.new(current_user, auth) when 'github' - GithubAuthentication.new(current_user, auth) + Authentication::Github.new(current_user, auth) end result = authentication.authenticate assign_flash_and_session(result) diff --git a/app/models/discord_authentication.rb b/app/models/authentication/discord.rb similarity index 94% rename from app/models/discord_authentication.rb rename to app/models/authentication/discord.rb index 87ff2596ac8..6e7f9aa1bd0 100644 --- a/app/models/discord_authentication.rb +++ b/app/models/authentication/discord.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class DiscordAuthentication +class Authentication::Discord include Rails.application.routes.url_helpers def initialize(login_user, auth) diff --git a/app/models/github_authentication.rb b/app/models/authentication/github.rb similarity index 97% rename from app/models/github_authentication.rb rename to app/models/authentication/github.rb index 52e747851d7..1ac94028132 100644 --- a/app/models/github_authentication.rb +++ b/app/models/authentication/github.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class GithubAuthentication +class Authentication::Github include Rails.application.routes.url_helpers def initialize(user, auth) diff --git a/test/models/discord_authentication_test.rb b/test/models/authentication/discord_test.rb similarity index 67% rename from test/models/discord_authentication_test.rb rename to test/models/authentication/discord_test.rb index e22a37d6753..febc0bbf1a9 100644 --- a/test/models/discord_authentication_test.rb +++ b/test/models/authentication/discord_test.rb @@ -2,12 +2,12 @@ require 'test_helper' -class DiscordAuthenticationTest < ActiveSupport::TestCase +class Authentication::DiscordTest < ActiveSupport::TestCase include Rails.application.routes.url_helpers test '引数が正常な値の時' do user = users(:komagata) - discord_authentication = DiscordAuthentication.new(user, { info: { name: 'komagata_discord' } }) + discord_authentication = Authentication::Discord.new(user, { info: { name: 'komagata_discord' } }) result = discord_authentication.authenticate assert_equal result[:notice], 'Discordと連携しました' @@ -15,7 +15,7 @@ class DiscordAuthenticationTest < ActiveSupport::TestCase end test '引数が不正な値の時' do - discord_authentication = DiscordAuthentication.new(nil, { info: { name: 'komagata_discord' } }) + discord_authentication = Authentication::Discord.new(nil, { info: { name: 'komagata_discord' } }) result = discord_authentication.authenticate assert_equal result[:alert], 'Discordの連携に失敗しました' diff --git a/test/models/github_authentication_test.rb b/test/models/authentication/github_test.rb similarity index 72% rename from test/models/github_authentication_test.rb rename to test/models/authentication/github_test.rb index 878e3a90b4e..3568582bc6f 100644 --- a/test/models/github_authentication_test.rb +++ b/test/models/authentication/github_test.rb @@ -2,11 +2,11 @@ require 'test_helper' -class GithubAuthenticationTest < ActiveSupport::TestCase +class Authentication::GithubTest < ActiveSupport::TestCase include Rails.application.routes.url_helpers test 'ログインユーザーが存在せず、githubのidが一致しない場合' do - github_authentication = GithubAuthentication.new(nil, { info: { nickname: 'kimura_github' }, uid: 'uid_test_data' }) + github_authentication = Authentication::Github.new(nil, { info: { nickname: 'kimura_github' }, uid: 'uid_test_data' }) result = github_authentication.authenticate assert_equal result[:path], root_path @@ -18,7 +18,7 @@ class GithubAuthenticationTest < ActiveSupport::TestCase user.github_id = 'uid_test_data' user.save! - github_authentication = GithubAuthentication.new(nil, { info: { nickname: 'yameo_github' }, uid: 'uid_test_data' }) + github_authentication = Authentication::Github.new(nil, { info: { nickname: 'yameo_github' }, uid: 'uid_test_data' }) assert_equal github_authentication.authenticate[:path], retirement_path end @@ -28,7 +28,7 @@ class GithubAuthenticationTest < ActiveSupport::TestCase user.github_id = 'uid_test_data' user.save! - github_authentication = GithubAuthentication.new(nil, { info: { name: 'komagata_discord' }, uid: 'uid_test_data' }) + github_authentication = Authentication::Github.new(nil, { info: { name: 'komagata_discord' }, uid: 'uid_test_data' }) result = github_authentication.authenticate assert_equal result[:path], root_path @@ -39,7 +39,7 @@ class GithubAuthenticationTest < ActiveSupport::TestCase test 'ログインしており、Github連携していないユーザーの場合' do user = users(:kimura) - github_authentication = GithubAuthentication.new(user, { info: { nickname: 'kimura_github' }, uid: 'uid_test_data' }) + github_authentication = Authentication::Github.new(user, { info: { nickname: 'kimura_github' }, uid: 'uid_test_data' }) result = github_authentication.authenticate assert_equal result[:path], root_path diff --git a/test/system/current_user_test.rb b/test/system/current_user_test.rb index e0a659e6108..eeef2160cb1 100644 --- a/test/system/current_user_test.rb +++ b/test/system/current_user_test.rb @@ -216,6 +216,7 @@ class CurrentUserTest < ApplicationSystemTestCase click_on '更新する' assert_text 'textbringer' + end test 'cannot register discord account already setting user' do visit_with_auth '/current_user/edit', 'kimura'