Skip to content

Commit

Permalink
Merge pull request #128 from tekin/global-non-expiring-ids
Browse files Browse the repository at this point in the history
Allow expires_in to be configured to nil globally
  • Loading branch information
kaspth committed Sep 12, 2020
2 parents 0f68538 + 433cae1 commit 6cdb13f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/global_id/railtie.rb
Expand Up @@ -19,11 +19,11 @@ class Railtie < Rails::Railtie # :nodoc:
default_app_name = app.railtie_name.remove('_application').dasherize

GlobalID.app = app.config.global_id.app ||= default_app_name
SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in
SignedGlobalID.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)

config.after_initialize do
GlobalID.app = app.config.global_id.app ||= default_app_name
SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in
SignedGlobalID.expires_in = app.config.global_id.fetch(:expires_in, default_expires_in)

app.config.global_id.verifier ||= begin
GlobalID::Verifier.new(app.key_generator.generate_key('signed_global_ids'))
Expand Down
17 changes: 17 additions & 0 deletions test/cases/railtie_test.rb
Expand Up @@ -29,6 +29,12 @@ def setup
assert_equal 'foo', GlobalID.app
end

test 'SignedGlobalID.expires_in can be explicitly set to nil with config.global_id.expires_in' do
@app.config.global_id.expires_in = nil
@app.initialize!
assert_nil SignedGlobalID.expires_in
end

test 'config.global_id can be used to set configurations after the railtie has been loaded' do
@app.config.eager_load = true
@app.config.before_eager_load do
Expand All @@ -41,6 +47,17 @@ def setup
assert_equal 1.year, SignedGlobalID.expires_in
end

test 'config.global_id can be used to explicitly set SignedGlobalID.expires_in to nil after the railtie has been loaded' do
@app.config.eager_load = true
@app.config.before_eager_load do
@app.config.global_id.expires_in = nil
end

@app.initialize!
assert_nil SignedGlobalID.expires_in
end


test 'SignedGlobalID.verifier defaults to Blog::Application.message_verifier(:signed_global_ids) when secret_key_base is present' do
@app.initialize!
message = {id: 42}
Expand Down

0 comments on commit 6cdb13f

Please sign in to comment.