File: test_helper.rb

package info (click to toggle)
ruby-omniauth-rails-csrf-protection 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 156 kB
  • sloc: ruby: 118; makefile: 4
file content (69 lines) | stat: -rw-r--r-- 1,918 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)

# Simple Rails application template, based on Rails issue template
# https://github.com/rails/rails/blob/master/guides/bug_report_templates/action_controller_gem.rb

# Helper method to silence warnings from bundler/inline
def silence_warnings
  old_verbose, $VERBOSE = $VERBOSE, nil
  yield
ensure
  $VERBOSE = old_verbose
end

silence_warnings do
  require "bundler/inline"

  # Define dependencies required by this test app
  gemfile do
#    source "https://rubygems.org"

    gem "rails"
    gem "omniauth"
    gem "omniauth-rails_csrf_protection", path: File.expand_path("..", __dir__)
  end
end

puts "Running test against Rails #{Rails.version}"

require "rack/test"
require "action_controller/railtie"
require "minitest/autorun"

# Build a test application which uses OmniAuth
class TestApp < Rails::Application
  config.root = __dir__
  config.session_store :cookie_store, key: "cookie_store_key"
  secrets.secret_key_base = "secret_key_base"
  config.eager_load = false
  config.hosts = []

  # This allow us to send all logs to STDOUT if we run test wth `VERBOSE=1`
  config.logger = if ENV["VERBOSE"]
                    Logger.new($stdout)
                  else
                    Logger.new("/dev/null")
                  end
  Rails.logger = config.logger
  OmniAuth.config.logger = Rails.logger

  # Setup a simple OmniAuth configuration with only developer provider
  config.middleware.use OmniAuth::Builder do
    provider :developer
  end

  # We need to call initialize! to run all railties
  initialize!

  # Define our custom routes. This needs to be called after initialize!
  routes.draw do
    get "token" => "application#token"
  end
end

# A small test controller which we use to retrive the valid authenticity token
class ApplicationController < ActionController::Base
  def token
    render plain: form_authenticity_token
  end
end