From 7a5411805777476c759cb6b1e3eeab7f8b4a0065 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 29 Oct 2024 13:33:07 +0800 Subject: [PATCH] Fix OAuth2 test --- test/integration/oauth2_test.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/integration/oauth2_test.rb b/test/integration/oauth2_test.rb index 33aa766dbb..42c05d16aa 100644 --- a/test/integration/oauth2_test.rb +++ b/test/integration/oauth2_test.rb @@ -1,14 +1,14 @@ require "test_helper" require "oauth2" -class OAuth2Test < ActiveSupport::TestCase +class OAuth2Test < ActionDispatch::IntegrationTest attr_accessor :password, :user, :app, :client setup do - @password = "123123" - @user = FactoryBot.create(:user, password: password, password_confirmation: password) - @app = FactoryBot.create(:application) - @client = OAuth2::Client.new(@app.uid, @app.secret) do |b| + @password = "password" + @user = create(:user, password: password, password_confirmation: password) + @app = create(:application) + @client = OAuth2::Client.new(@app.uid, @app.secret, site: "http://localhost") do |b| b.request :url_encoded b.adapter :rack, Rails.application end @@ -16,7 +16,7 @@ class OAuth2Test < ActiveSupport::TestCase test "auth_code" do test_url = "/api/v3/hello.json" - grant = FactoryBot.create(:access_grant, application: app, redirect_uri: "#{app.redirect_uri}/callback") + grant = create(:access_grant, application: app, redirect_uri: "#{app.redirect_uri}/callback") assert_changes -> { Doorkeeper::AccessToken.count }, 1 do @access_token = client.auth_code.get_token(grant.token, redirect_uri: grant.redirect_uri) @@ -34,7 +34,7 @@ class OAuth2Test < ActiveSupport::TestCase assert_not_equal @access_token.token, @new_token.token # Revoke a new access_token, old access_token will invalid - grant = FactoryBot.create(:access_grant, application: app, redirect_uri: "#{app.redirect_uri}/callback") + grant = create(:access_grant, application: app, redirect_uri: "#{app.redirect_uri}/callback") @access_token1 = client.auth_code.get_token(grant.token, redirect_uri: grant.redirect_uri) assert_raise OAuth2::Error do