Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow expires_in to be configured to nil globally #128

Merged
merged 1 commit into from Sep 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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