oauth cleanup: test fakes and generic provider
This commit is contained in:
@ -1,15 +1,16 @@
|
||||
require 'test_helper'
|
||||
|
||||
class AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||
include TestAuthHelper
|
||||
|
||||
setup do
|
||||
get auth_path
|
||||
@account = accounts(:account1)
|
||||
# get login_path
|
||||
# session[:token] = 'fake-oauth-token'
|
||||
# session[:name] = "Fake User"
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get accounts_url
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
@ -1,8 +1,28 @@
|
||||
require 'test_helper'
|
||||
|
||||
class AuthControllerTest < ActionDispatch::IntegrationTest
|
||||
# test "should get auth" do
|
||||
# get auth_url
|
||||
# assert_response :redirect
|
||||
# end
|
||||
include TestAuthHelper
|
||||
|
||||
test "should get auth" do
|
||||
# This is not a real test of AuthController!
|
||||
# We are really testing that the monkey path is correct
|
||||
#
|
||||
# This simply tests to make sure the test suite is
|
||||
# properly monkey patching the oAuth network call and
|
||||
# faking the needed session variables.
|
||||
#
|
||||
# If you want to really test the oAuth flow you will need to
|
||||
# hit the real services, or stand up a proper fake service.
|
||||
get auth_path
|
||||
assert_redirected_to accounts_path
|
||||
end
|
||||
|
||||
test "should verify callbacks result" do
|
||||
# If AuthController#callback ever changes final
|
||||
# redirection, the patched version should also
|
||||
# be updated in (lin e10) of
|
||||
# test/test_helpers/test_auth_helper.rb
|
||||
|
||||
assert_equal "redirect_to accounts_path", last_line_in_callback
|
||||
end
|
||||
end
|
||||
|
0
test/fixtures/files/.keep
vendored
0
test/fixtures/files/.keep
vendored
@ -11,8 +11,11 @@ require File.expand_path('../../config/environment', __FILE__)
|
||||
require 'rails/test_help'
|
||||
require "minitest/autorun"
|
||||
require 'minitest/reporters'
|
||||
require 'webmock/minitest'
|
||||
Dir[Rails.root.join("test/test_helpers/**/*.rb")].each { |f| require f }
|
||||
|
||||
WebMock.disable_net_connect!(allow_localhost: true)
|
||||
|
||||
Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)]
|
||||
|
||||
class ActiveSupport::TestCase
|
||||
|
34
test/test_helpers/test_auth_helper.rb
Normal file
34
test/test_helpers/test_auth_helper.rb
Normal file
@ -0,0 +1,34 @@
|
||||
module TestAuthHelper
|
||||
## Monkey patch AuthController, because...auth.
|
||||
AuthController.class_eval do
|
||||
alias_method :org_callback, :callback
|
||||
|
||||
def callback
|
||||
session[:token] = "fake-auth-token-thing"
|
||||
session[:name] = "Fake Name"
|
||||
|
||||
redirect_to accounts_path
|
||||
end
|
||||
|
||||
alias_method :auth, :callback
|
||||
end
|
||||
|
||||
def auth_user
|
||||
get '/auth/callback'
|
||||
end
|
||||
|
||||
def last_line_in_callback
|
||||
path, line_no = AuthController.instance_method(:org_callback).source_location
|
||||
|
||||
file = File.open(path)
|
||||
line_no.times { file.readline }
|
||||
tmp_line = nil
|
||||
until tmp_line == 'end'
|
||||
last_line = tmp_line
|
||||
tmp_line = file.readline.strip
|
||||
end
|
||||
file.close
|
||||
|
||||
last_line
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user