Skip to content

Commit 332ed94

Browse files
committed
Allow expires_in to be configured to nil globally
This makes it possible to turn off expiration globally. Closes #127.
1 parent 0f68538 commit 332ed94

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/global_id/railtie.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ class Railtie < Rails::Railtie # :nodoc:
1818
default_expires_in = 1.month
1919
default_app_name = app.railtie_name.remove('_application').dasherize
2020

21+
app.config.global_id.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)
22+
2123
GlobalID.app = app.config.global_id.app ||= default_app_name
22-
SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in
24+
SignedGlobalID.expires_in = app.config.global_id.expires_in
2325

2426
config.after_initialize do
27+
app.config.global_id.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)
28+
2529
GlobalID.app = app.config.global_id.app ||= default_app_name
26-
SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in
30+
SignedGlobalID.expires_in = app.config.global_id.expires_in
2731

2832
app.config.global_id.verifier ||= begin
2933
GlobalID::Verifier.new(app.key_generator.generate_key('signed_global_ids'))

test/cases/railtie_test.rb

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ def setup
2929
assert_equal 'foo', GlobalID.app
3030
end
3131

32+
test 'SignedGlobalID.expires_in can be explicitly set to nil with config.global_id.expires_in' do
33+
@app.config.global_id.expires_in = nil
34+
@app.initialize!
35+
assert_nil SignedGlobalID.expires_in
36+
end
37+
3238
test 'config.global_id can be used to set configurations after the railtie has been loaded' do
3339
@app.config.eager_load = true
3440
@app.config.before_eager_load do
@@ -41,6 +47,17 @@ def setup
4147
assert_equal 1.year, SignedGlobalID.expires_in
4248
end
4349

50+
test 'config.global_id can be used to explicitly set SignedGlobalID.expires_in to nil after the railtie has been loaded' do
51+
@app.config.eager_load = true
52+
@app.config.before_eager_load do
53+
@app.config.global_id.expires_in = nil
54+
end
55+
56+
@app.initialize!
57+
assert_nil SignedGlobalID.expires_in
58+
end
59+
60+
4461
test 'SignedGlobalID.verifier defaults to Blog::Application.message_verifier(:signed_global_ids) when secret_key_base is present' do
4562
@app.initialize!
4663
message = {id: 42}

0 commit comments

Comments
 (0)