-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathconfiguration_spec.rb
153 lines (137 loc) · 5.06 KB
/
configuration_spec.rb
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require 'rails_helper'
describe Stitches::Configuration do
before do
Stitches.configuration.reset_to_defaults!
end
describe "global configuration" do
let(:allowlist_regexp) { %r{foo} }
let(:custom_http_auth_scheme) { "Blah" }
let(:env_var_to_hold_api_client_primary_key) { "FOOBAR" }
let(:max_cache_ttl) { 11 }
let(:max_cache_size) { 111 }
it "can be configured globally" do
Stitches.configure do |config|
config.allowlist_regexp = allowlist_regexp
config.custom_http_auth_scheme = custom_http_auth_scheme
config.env_var_to_hold_api_client_primary_key = env_var_to_hold_api_client_primary_key
config.max_cache_ttl = max_cache_ttl
config.max_cache_size = max_cache_size
end
expect(Stitches.configuration.allowlist_regexp).to eq(allowlist_regexp)
expect(Stitches.configuration.custom_http_auth_scheme).to eq(custom_http_auth_scheme)
expect(Stitches.configuration.env_var_to_hold_api_client_primary_key).to eq(env_var_to_hold_api_client_primary_key)
expect(Stitches.configuration.max_cache_ttl).to eq(max_cache_ttl)
expect(Stitches.configuration.max_cache_size).to eq(max_cache_size)
end
it "defaults to nil for allowlist_regexp" do
expect(Stitches.configuration.allowlist_regexp).to be_nil
end
it "sets a default for env_var_to_hold_api_client_primary_key" do
expect(Stitches.configuration.env_var_to_hold_api_client_primary_key).to eq("STITCHES_API_CLIENT_ID")
end
it "defaults to 0 for max_cache_ttl" do
expect(Stitches.configuration.max_cache_ttl).to eq(0)
end
it "sets a default for max_cache_size" do
expect(Stitches.configuration.max_cache_size).to eq(0)
end
it "sets a default of false for disable_api_key_support" do
expect(Stitches.configuration.disable_api_key_support).to be false
end
it "blows up if you try to use custom_http_auth_scheme without having set it" do
expect {
Stitches.configuration.custom_http_auth_scheme
}.to raise_error(/you must set a value for custom_http_auth_scheme/i)
end
end
describe "allowlist_regexp" do
let(:config) { Stitches::Configuration.new }
it "must be a regexp" do
expect {
config.allowlist_regexp = "foo"
}.to raise_error(/allowlist_regexp must be a Regexp/i)
end
it "may be nil" do
expect {
config.allowlist_regexp = nil
}.not_to raise_error
end
it "may be a regexp" do
expect {
config.allowlist_regexp = /foo/
}.not_to raise_error
end
end
describe "custom_http_auth_scheme" do
let(:config) { Stitches::Configuration.new }
it "must be a string" do
expect {
config.custom_http_auth_scheme = 42
}.to raise_error(/custom_http_auth_scheme must be a String/i)
end
it "may not be nil" do
expect {
config.custom_http_auth_scheme = nil
}.to raise_error(/custom_http_auth_scheme may not be blank/i)
end
it "may not be a blank string" do
expect {
config.custom_http_auth_scheme = " "
}.to raise_error(/custom_http_auth_scheme may not be blank/i)
end
it "may be a String" do
expect {
config.custom_http_auth_scheme = "Foobar"
}.not_to raise_error
end
end
describe "env_var_to_hold_api_client_primary_key" do
let(:config) { Stitches::Configuration.new }
it "must be a string" do
expect {
config.env_var_to_hold_api_client_primary_key = 42
}.to raise_error(/env_var_to_hold_api_client_primary_key must be a String/i)
end
it "may not be nil" do
expect {
config.env_var_to_hold_api_client_primary_key = nil
}.to raise_error(/env_var_to_hold_api_client_primary_key may not be blank/i)
end
it "may not be a blank string" do
expect {
config.env_var_to_hold_api_client_primary_key = " "
}.to raise_error(/env_var_to_hold_api_client_primary_key may not be blank/i)
end
it "may be a String" do
expect {
config.env_var_to_hold_api_client_primary_key = "Foobar"
}.not_to raise_error
end
end
describe "max_cache_ttl" do
let(:config) { Stitches::Configuration.new }
it "must be an integer" do
expect {
config.max_cache_ttl = ""
}.to raise_error(/max_cache_ttl must be an Integer, not a String/)
end
it "may not be nil" do
expect {
config.max_cache_ttl = nil
}.to raise_error(/max_cache_ttl must be an Integer, not a NilClass/)
end
end
describe "max_cache_size" do
let(:config) { Stitches::Configuration.new }
it "must be an integer" do
expect {
config.max_cache_size = ""
}.to raise_error(/max_cache_size must be an Integer, not a String/)
end
it "may not be nil" do
expect {
config.max_cache_size = nil
}.to raise_error(/max_cache_size must be an Integer, not a NilClass/)
end
end
end