File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -14,14 +14,16 @@ class Railtie < Rails::Railtie # :nodoc:
1414 config . eager_load_namespaces << GlobalID
1515
1616 initializer 'global_id' do |app |
17+ default_expires_in = 1 . month
18+ default_app_name = app . railtie_name . remove ( '_application' ) . dasherize
1719
18- app . config . global_id . app ||= app . railtie_name . remove ( '_application' ) . dasherize
19- GlobalID . app = app . config . global_id . app
20-
21- app . config . global_id . expires_in ||= 1 . month
22- SignedGlobalID . expires_in = app . config . global_id . expires_in
20+ GlobalID . app = app . config . global_id . app ||= default_app_name
21+ SignedGlobalID . expires_in = app . config . global_id . expires_in ||= default_expires_in
2322
2423 config . after_initialize do
24+ GlobalID . app = app . config . global_id . app ||= default_app_name
25+ SignedGlobalID . expires_in = app . config . global_id . expires_in ||= default_expires_in
26+
2527 app . config . global_id . verifier ||= begin
2628 GlobalID ::Verifier . new ( app . key_generator . generate_key ( 'signed_global_ids' ) )
2729 rescue ArgumentError
Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ def setup
2828 assert_equal 'foo' , GlobalID . app
2929 end
3030
31+ test 'config.global_id can be used to set configurations after the railtie has been loaded' do
32+ @app . config . eager_load = true
33+ @app . config . before_eager_load do
34+ @app . config . global_id . app = 'foobar'
35+ @app . config . global_id . expires_in = 1 . year
36+ end
37+
38+ @app . initialize!
39+ assert_equal 'foobar' , GlobalID . app
40+ assert_equal 1 . year , SignedGlobalID . expires_in
41+ end
42+
3143 test 'SignedGlobalID.verifier defaults to Blog::Application.message_verifier(:signed_global_ids) when secret_token is present' do
3244 @app . config . secret_token = ( 'x' * 30 )
3345 @app . initialize!
You can’t perform that action at this time.
0 commit comments