Skip to content

Commit 6cdb13f

Browse files
authored
Merge pull request #128 from tekin/global-non-expiring-ids
Allow expires_in to be configured to nil globally
2 parents 0f68538 + 433cae1 commit 6cdb13f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/global_id/railtie.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class Railtie < Rails::Railtie # :nodoc:
1919
default_app_name = app.railtie_name.remove('_application').dasherize
2020

2121
GlobalID.app = app.config.global_id.app ||= default_app_name
22-
SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in
22+
SignedGlobalID.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)
2323

2424
config.after_initialize do
2525
GlobalID.app = app.config.global_id.app ||= default_app_name
26-
SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in
26+
SignedGlobalID.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)
2727

2828
app.config.global_id.verifier ||= begin
2929
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)