File tree 2 files changed +19
-5
lines changed
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:
14
14
config . eager_load_namespaces << GlobalID
15
15
16
16
initializer 'global_id' do |app |
17
+ default_expires_in = 1 . month
18
+ default_app_name = app . railtie_name . remove ( '_application' ) . dasherize
17
19
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
23
22
24
23
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
+
25
27
app . config . global_id . verifier ||= begin
26
28
GlobalID ::Verifier . new ( app . key_generator . generate_key ( 'signed_global_ids' ) )
27
29
rescue ArgumentError
Original file line number Diff line number Diff line change @@ -28,6 +28,18 @@ def setup
28
28
assert_equal 'foo' , GlobalID . app
29
29
end
30
30
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
+
31
43
test 'SignedGlobalID.verifier defaults to Blog::Application.message_verifier(:signed_global_ids) when secret_token is present' do
32
44
@app . config . secret_token = ( 'x' * 30 )
33
45
@app . initialize!
You can’t perform that action at this time.
0 commit comments