File tree 6 files changed +99
-9
lines changed
6 files changed +99
-9
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,9 @@ Gem::Specification.new do |s|
23
23
s . add_dependency 'omniauth' , '~> 1.0'
24
24
s . add_dependency 'omniauth-oauth2' , '~> 1.1'
25
25
s . add_dependency 'rails' , [ ">= 5.2" , "< 7.0" ]
26
+ s . add_dependency 'redis'
26
27
27
- s . add_development_dependency 'pry'
28
- s . add_development_dependency 'pry-nav'
28
+ s . add_development_dependency 'pry-byebug'
29
29
s . add_development_dependency 'rspec-rails' , '~> 3.5'
30
30
s . add_development_dependency 'webmock' , '~> 3.8'
31
31
end
Original file line number Diff line number Diff line change 3
3
module Kracken
4
4
class Config
5
5
attr_accessor :app_id , :app_secret
6
- attr_writer :provider_url
6
+ attr_writer :provider_url , :redis_options
7
7
8
8
# @deprecated the associated reader returns static `::User`
9
9
attr_writer :user_class
@@ -16,6 +16,10 @@ def provider_url
16
16
@provider_url ||= PROVIDER_URL
17
17
end
18
18
19
+ def redis_options
20
+ @redis_options ||= { }
21
+ end
22
+
19
23
def user_class
20
24
::User
21
25
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
+ require 'redis'
4
+
3
5
module Kracken
4
6
module SessionManager
5
7
def self . conn
6
- @conn ||= if ENV [ "REDIS_SESSION_URL" ] . present?
7
- Redis . new ( url : ENV [ "REDIS_SESSION_URL" ] )
8
- else
9
- NullRedis . new
10
- end
8
+ @conn ||=
9
+ begin
10
+ default_redis_options = { url : ENV [ 'REDIS_SESSION_URL' ] }
11
+ redis_options = default_redis_options . merge ( Kracken . config . redis_options ) . compact
12
+
13
+ if redis_options . any?
14
+ Redis . new ( **redis_options )
15
+ else
16
+ NullRedis . new
17
+ end
18
+ end
19
+ end
20
+
21
+ # @api private
22
+ # For use in testing only
23
+ def self . reset_conn
24
+ @conn = nil
11
25
end
12
26
13
27
def self . get ( user_id )
Original file line number Diff line number Diff line change 5
5
module Kracken
6
6
RSpec . describe Config do
7
7
8
- subject ( :config ) { Kracken ::Config . new }
8
+ subject ( :config ) { Kracken ::Config . new }
9
9
10
10
it "sets a default url" do
11
11
expect ( config . provider_url ) . to eq "https://account.radiusnetworks.com"
@@ -22,5 +22,18 @@ module Kracken
22
22
expect ( config . provider_url ) . to eq "http://joe.com"
23
23
end
24
24
25
+ describe "#redis_options" do
26
+ it 'defaults to {}' do
27
+ expect ( config . redis_options ) . to eq ( { } )
28
+ end
29
+ end
30
+
31
+ describe "#redis_options=" do
32
+ it 'allows redis_options to be set' do
33
+ config . redis_options = { url : "redis://www.example.com" }
34
+
35
+ expect ( config . redis_options ) . to eq ( { url : "redis://www.example.com" } )
36
+ end
37
+ end
25
38
end
26
39
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ module Kracken
6
+ RSpec . describe SessionManager do
7
+ include Kracken ::Spec ::UsingEnv
8
+
9
+ describe "::conn" do
10
+ before { SessionManager . reset_conn }
11
+
12
+ context "when the REDIS_SESSION_URL env var is present" do
13
+ it 'is a Redis instance' do
14
+ using_env ( { "REDIS_SESSION_URL" => "redis://www.example.com" } ) do
15
+ expect ( SessionManager . conn ) . to be_an_instance_of Redis
16
+ end
17
+ end
18
+ end
19
+
20
+ context "when the REDIS_SESSION_URL env var is not present" do
21
+ it 'is a NullRedis instance' do
22
+ expect ( SessionManager . conn ) . to be_an_instance_of SessionManager ::NullRedis
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module Kracken
4
+ module Spec
5
+ module UsingEnv
6
+ # By forcing the use of a block, this makes working within the context of
7
+ # a single spec much easier. If this needs to be wrapped around multiple
8
+ # specs, then an appropriate #around(:example) hook may be used.
9
+ #
10
+ # This is stolen with love from https://github.com/RadiusNetworks/captain/blob/master/spec/support/using_env.rb
11
+ #
12
+ # @param env_stubs [Hash{String => Object}]
13
+ #
14
+ # @yieldreturn
15
+ def using_env ( env_stubs ) # rubocop:disable Metrics/MethodLength
16
+ keys_to_delete = env_stubs . keys - ENV . keys
17
+ original_values = env_stubs . each_with_object ( { } ) { |( k , v ) , env |
18
+ env [ k ] = ENV [ k ] if ENV . key? ( k )
19
+ ENV [ k ] = v
20
+ }
21
+ yield
22
+ ensure
23
+ keys_to_delete . each do |k |
24
+ ENV . delete ( k )
25
+ end
26
+ original_values . each do |k , v |
27
+ ENV [ k ] = v
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
You can’t perform that action at this time.
0 commit comments