Skip to content

Commit

Permalink
テストが通るように修正する
Browse files Browse the repository at this point in the history
  • Loading branch information
yocchan-git committed Mar 24, 2024
1 parent 3e5f500 commit afeaaa9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ def callback
GithubAuthentication.new(current_user, auth)
end
result = authentication.authenticate

assign_flash_and_session(result)

return redirect_back_or_to result[:path] if result[:back]
redirect_to result[:path]
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/github_authentication.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def authenticate
if @user.blank?
user = User.find_by(github_id: @auth[:uid])
if user.blank?
{ path: root_url, alert: 'ログインに失敗しました。先にアカウントを作成後、GitHub連携を行ってください。' }
{ path: root_path, alert: 'ログインに失敗しました。先にアカウントを作成後、GitHub連携を行ってください。' }
elsif user.retired_on?
{ path: retirement_path }
else
{ path: root_url, notice: 'サインインしました。', user_id: user.id }
{ path: root_path, notice: 'サインインしました。', user_id: user.id, back: true }
end
else
link if @user.github_id.blank?
Expand Down
5 changes: 3 additions & 2 deletions test/models/github_authentication_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GithubAuthenticationTest < ActiveSupport::TestCase
github_authentication = GithubAuthentication.new(nil, { info: { nickname: 'kimura_github' }, uid: 'uid_test_data' })
result = github_authentication.authenticate

assert_equal result[:path], root_url
assert_equal result[:path], root_path
assert_equal result[:alert], 'ログインに失敗しました。先にアカウントを作成後、GitHub連携を行ってください。'
end

Expand All @@ -31,9 +31,10 @@ class GithubAuthenticationTest < ActiveSupport::TestCase
github_authentication = GithubAuthentication.new(nil, { info: { name: 'komagata_discord' }, uid: 'uid_test_data' })
result = github_authentication.authenticate

assert_equal result[:path], root_url
assert_equal result[:path], root_path
assert_equal result[:notice], 'サインインしました。'
assert_equal result[:user_id], user.id
assert_equal result[:back], true
end

test 'ログインしており、Github連携していないユーザーの場合' do
Expand Down

0 comments on commit afeaaa9

Please sign in to comment.