-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathconfiguration_spec.rb
More file actions
212 lines (173 loc) · 5.88 KB
/
configuration_spec.rb
File metadata and controls
212 lines (173 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
RSpec.describe 'Inertia configuration', type: :request do
after { reset_config! }
describe "InertiaRails::Configuration" do
it "does not allow to modify options after frozen" do
config = InertiaRails::Configuration.default
config.ssr_enabled = true
expect(config.ssr_enabled).to eq true
config.freeze
expect { config.ssr_enabled = false }.to raise_error(FrozenError)
expect { config.merge!(InertiaRails::Configuration.default) }.to raise_error(FrozenError)
expect {
merged_config = config.merge(InertiaRails::Configuration.default)
expect(merged_config.ssr_enabled).to eq false
}.not_to raise_error
end
end
describe 'inertia_config' do
it 'overrides the global values' do
get configuration_path
expect(response.parsed_body.symbolize_keys).to include(
deep_merge_shared_data: true,
default_render: false,
layout: "test",
ssr_enabled: true,
ssr_url: "http://localhost:7777",
version: "2.0",
)
end
end
describe '.version' do
subject { JSON.parse(response.body)['version'] }
context 'base case' do
before { get empty_test_path, headers: {'X-Inertia' => true} }
it { is_expected.to be_nil }
end
context 'version is a string' do
before do
InertiaRails.configure {|c| c.version = '1.0'}
get empty_test_path, headers: {'X-Inertia' => true, 'HTTP_X_INERTIA_VERSION' => '1.0'}
end
it { is_expected.to eq '1.0' }
end
context 'version is a callable' do
before do
InertiaRails.configure {|c| c.version = -> {'1.0'}}
get empty_test_path, headers: {'X-Inertia' => true, 'X-Inertia-Version' => '1.0'}
end
it { is_expected.to eq '1.0' }
end
context 'string vs float mismatches' do
before do
InertiaRails.configure {|c| c.version = 1.0}
get empty_test_path, headers: {'X-Inertia' => true, 'X-Inertia-Version' => '1.0'}
end
it { is_expected.to eq 1.0 }
end
context 'with a new version' do
before do
InertiaRails.configure { |c| c.version = '1.0' }
end
context 'request in same thread' do
before do
get empty_test_path, headers: {'X-Inertia' => true, 'X-Inertia-Version' => '1.0'}
end
it { is_expected.to eq '1.0' }
end
context 'request in other thread' do
before do
Thread.new do
get empty_test_path, headers: {'X-Inertia' => true, 'X-Inertia-Version' => '1.0'}
end.join
end
it { is_expected.to eq '1.0' }
end
end
end
describe '.layout' do
subject { response.body }
context 'base case' do
before { get empty_test_path }
it { is_expected.to render_template 'inertia' }
it { is_expected.to render_template 'application' }
end
context 'with a new layout' do
before do
InertiaRails.configure {|c| c.layout = 'testing' }
end
context 'request in same thread' do
before do
get empty_test_path
end
it { is_expected.to render_template 'inertia' }
it { is_expected.to render_template 'testing' }
it { is_expected.not_to render_template 'application' }
end
context 'request in other thread' do
before do
Thread.new do
get empty_test_path
end.join
end
it { is_expected.to render_template 'inertia' }
it { is_expected.to render_template 'testing' }
it { is_expected.not_to render_template 'application' }
end
context 'opting out of a different layout for Inertia' do
before do
InertiaRails.configure {|c| c.layout = true }
end
it 'uses default layout for controller' do
get empty_test_path
is_expected.to render_template 'inertia'
is_expected.to render_template 'application'
is_expected.not_to render_template 'testing'
end
it 'applies conditional layouts as needed' do
get with_different_layout_path
is_expected.to render_template 'inertia'
is_expected.to render_template 'conditional'
is_expected.not_to render_template 'application'
is_expected.not_to render_template 'testing'
end
end
end
end
describe '.action_on_unoptimized_partial_reload' do
let(:headers) {{
'X-Inertia' => true,
'X-Inertia-Partial-Data' => 'nested.first',
'X-Inertia-Partial-Component' => 'TestComponent',
}}
context 'default case' do
let(:headers) {{
'X-Inertia' => true,
'X-Inertia-Partial-Data' => 'nested.first',
'X-Inertia-Partial-Component' => 'TestComponent',
}}
it 'logs a warning' do
expect(Rails.logger).to receive(:debug).with(/flat, nested\.second/)
get except_props_path, headers: headers
end
end
context 'when set to :raise' do
before do
InertiaRails.configure {|c| c.action_on_unoptimized_partial_reload = :raise}
end
let(:headers) {{
'X-Inertia' => true,
'X-Inertia-Partial-Data' => 'nested.first',
'X-Inertia-Partial-Component' => 'TestComponent',
}}
it 'raises an exception' do
expect { get except_props_path, headers: headers }.to raise_error(InertiaRails::UnoptimizedPartialReload).with_message(/flat, nested\.second/)
end
end
context 'with an unknown value' do
before do
InertiaRails.configure {|c| c.action_on_unoptimized_partial_reload = :unknown}
end
it 'does nothing' do
expect(Rails.logger).not_to receive(:debug)
get except_props_path, headers: headers
end
end
end
end
def reset_config!
InertiaRails.configure do |config|
config.version = nil
config.layout = 'application'
config.action_on_unoptimized_partial_reload = :log
end
end