snake-eyes 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/Rakefile +7 -5
- data/lib/snake-eyes.rb +6 -6
- data/lib/snake_eyes/compatibility.rb +19 -0
- data/lib/snake_eyes/configuration.rb +53 -0
- data/lib/{snake-eyes → snake_eyes}/engine.rb +4 -4
- data/lib/snake_eyes/interface_changes.rb +49 -0
- data/lib/snake_eyes/logging.rb +19 -0
- data/lib/snake_eyes/memoization.rb +27 -0
- data/lib/snake_eyes/transform.rb +124 -0
- data/lib/snake_eyes/version.rb +5 -0
- data/spec/dummy/Rakefile +3 -1
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +1 -1
- data/spec/dummy/bin/bundle +3 -1
- data/spec/dummy/bin/rails +3 -1
- data/spec/dummy/bin/rake +2 -0
- data/spec/dummy/bin/setup +10 -8
- data/spec/dummy/config.ru +2 -0
- data/spec/dummy/config/application.rb +4 -3
- data/spec/dummy/config/boot.rb +4 -2
- data/spec/dummy/config/environment.rb +3 -1
- data/spec/dummy/config/environments/development.rb +6 -3
- data/spec/dummy/config/environments/production.rb +2 -0
- data/spec/dummy/config/environments/test.rb +3 -1
- data/spec/dummy/config/initializers/assets.rb +4 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +6 -2
- data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
- data/spec/dummy/config/initializers/inflections.rb +2 -0
- data/spec/dummy/config/initializers/mime_types.rb +2 -0
- data/spec/dummy/config/initializers/session_store.rb +2 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
- data/spec/dummy/config/routes.rb +2 -1
- data/spec/dummy/log/test.log +5615 -0
- data/spec/nested_attributes_spec.rb +116 -118
- data/spec/params_spec.rb +107 -106
- data/spec/spec_helper.rb +5 -3
- data/spec/substitutions_spec.rb +202 -172
- metadata +27 -8
- data/lib/snake-eyes/interface_changes.rb +0 -187
- data/lib/snake-eyes/version.rb +0 -3
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'awesome_print'
|
2
4
|
ENV['RAILS_ENV'] ||= 'test'
|
3
5
|
|
4
|
-
require File.expand_path(
|
6
|
+
require File.expand_path('dummy/config/environment.rb', __dir__)
|
5
7
|
require 'rspec/rails'
|
6
8
|
|
7
9
|
Rails.backtrace_cleaner.remove_silencers!
|
8
10
|
|
9
11
|
# Load support files
|
10
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each(&method(:require))
|
11
13
|
|
12
14
|
RSpec.configure do |config|
|
13
15
|
config.mock_with :rspec
|
14
16
|
config.use_transactional_fixtures = true
|
15
17
|
config.infer_base_class_for_anonymous_controllers = false
|
16
|
-
config.order =
|
18
|
+
config.order = 'random'
|
17
19
|
|
18
20
|
config.filter_run :focus
|
19
21
|
config.run_all_when_everything_filtered = true
|
data/spec/substitutions_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
|
-
|
5
|
+
# rubocop:disable Metrics/BlockLength
|
6
|
+
RSpec.describe 'param\'s substitutions option:', type: :controller do
|
7
|
+
context 'is empty' do
|
6
8
|
controller ApplicationController do
|
7
9
|
def index
|
8
10
|
@params_snake_case = params(substitutions: {})
|
@@ -11,34 +13,31 @@ RSpec.describe 'param\'s substituions option:', type: :controller do
|
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
it
|
15
|
-
|
16
|
+
it 'then does not attempt to perform any substitutions' do
|
17
|
+
# noinspection RubyStringKeysInHashInspection
|
18
|
+
get :index,
|
16
19
|
'string' => 'string',
|
17
20
|
'boolean' => true,
|
18
|
-
'simpleArray' => [
|
19
|
-
"0", "1", "2"
|
20
|
-
],
|
21
|
+
'simpleArray' => %w[0 1 2],
|
21
22
|
'shallowObject' => {
|
22
|
-
|
23
|
+
'nestedAttribute' => 'value'
|
23
24
|
}
|
24
|
-
}
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
'
|
35
|
-
|
36
|
-
|
37
|
-
})
|
26
|
+
# noinspection RubyStringKeysInHashInspection
|
27
|
+
expect(assigns(:params_snake_case)).to eql(
|
28
|
+
'controller' => 'anonymous',
|
29
|
+
'action' => 'index',
|
30
|
+
'string' => 'string',
|
31
|
+
'boolean' => true,
|
32
|
+
'simple_array' => %w[0 1 2],
|
33
|
+
'shallow_object' => {
|
34
|
+
'nested_attribute' => 'value'
|
35
|
+
}
|
36
|
+
)
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
context
|
40
|
+
context 'is nil' do
|
42
41
|
controller ApplicationController do
|
43
42
|
def index
|
44
43
|
@params_snake_case = params(substitutions: nil)
|
@@ -47,240 +46,271 @@ RSpec.describe 'param\'s substituions option:', type: :controller do
|
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
it
|
51
|
-
|
49
|
+
it 'then does not attempt to perform any substitutions' do
|
50
|
+
# noinspection RubyStringKeysInHashInspection
|
51
|
+
get :index,
|
52
52
|
'string' => 'string',
|
53
53
|
'boolean' => true,
|
54
|
-
'simpleArray' => [
|
55
|
-
"0", "1", "2"
|
56
|
-
],
|
54
|
+
'simpleArray' => %w[0 1 2],
|
57
55
|
'shallowObject' => {
|
58
|
-
|
56
|
+
'nestedAttribute' => 'value'
|
59
57
|
}
|
60
|
-
}
|
61
58
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
'
|
71
|
-
|
72
|
-
|
73
|
-
})
|
59
|
+
# noinspection RubyStringKeysInHashInspection
|
60
|
+
expect(assigns(:params_snake_case)).to eql(
|
61
|
+
'controller' => 'anonymous',
|
62
|
+
'action' => 'index',
|
63
|
+
'string' => 'string',
|
64
|
+
'boolean' => true,
|
65
|
+
'simple_array' => %w[0 1 2],
|
66
|
+
'shallow_object' => {
|
67
|
+
'nested_attribute' => 'value'
|
68
|
+
}
|
69
|
+
)
|
74
70
|
end
|
75
71
|
end
|
76
72
|
|
77
|
-
context
|
73
|
+
context 'points to an attribute that is not a nested object' do
|
78
74
|
controller ApplicationController do
|
79
75
|
def index
|
80
|
-
@params_snake_case =
|
76
|
+
@params_snake_case =
|
77
|
+
params(substitutions: { string: { replace: 'abc', with: '123' } })
|
81
78
|
|
82
79
|
render nothing: true
|
83
80
|
end
|
84
81
|
end
|
85
82
|
|
86
|
-
context
|
87
|
-
it
|
88
|
-
get :index,
|
89
|
-
'string' => 'string'
|
90
|
-
}
|
83
|
+
context 'and the value of the attribute does NOT match' do
|
84
|
+
it 'then does not do any substitution' do
|
85
|
+
get :index,
|
86
|
+
'string' => 'string'
|
91
87
|
|
92
|
-
expect(assigns(:params_snake_case)).to eql(
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
88
|
+
expect(assigns(:params_snake_case)).to eql(
|
89
|
+
'controller' => 'anonymous',
|
90
|
+
'action' => 'index',
|
91
|
+
'string' => 'string'
|
92
|
+
)
|
97
93
|
end
|
98
|
-
|
99
94
|
end
|
100
95
|
|
101
|
-
context
|
102
|
-
it
|
103
|
-
get :index,
|
104
|
-
'string' => 'abc'
|
105
|
-
}
|
96
|
+
context 'and the value of the attribute does match' do
|
97
|
+
it 'then does not do any substitution' do
|
98
|
+
get :index,
|
99
|
+
'string' => 'abc'
|
106
100
|
|
107
|
-
expect(assigns(:params_snake_case)).to eql(
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
101
|
+
expect(assigns(:params_snake_case)).to eql(
|
102
|
+
'controller' => 'anonymous',
|
103
|
+
'action' => 'index',
|
104
|
+
'string' => '123'
|
105
|
+
)
|
112
106
|
end
|
113
|
-
|
114
107
|
end
|
115
108
|
end
|
116
109
|
|
117
|
-
context
|
110
|
+
context 'points to an attribute that is a nested object' do
|
118
111
|
controller ApplicationController do
|
119
112
|
def index
|
120
|
-
@params_snake_case =
|
113
|
+
@params_snake_case =
|
114
|
+
params(
|
115
|
+
substitutions: {
|
116
|
+
shallow_object: {
|
117
|
+
nested_attribute: { replace: 'abc', with: '123' }
|
118
|
+
}
|
119
|
+
}
|
120
|
+
)
|
121
121
|
|
122
122
|
render nothing: true
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
context
|
127
|
-
it
|
128
|
-
|
126
|
+
context 'and the value of the attribute does NOT match' do
|
127
|
+
it 'then does not do any substitution' do
|
128
|
+
# noinspection RubyStringKeysInHashInspection
|
129
|
+
get :index,
|
129
130
|
'shallowObject' => {
|
130
|
-
|
131
|
+
'nestedAttribute' => 'value'
|
131
132
|
}
|
132
|
-
}
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
134
|
+
# noinspection RubyStringKeysInHashInspection
|
135
|
+
expect(assigns(:params_snake_case)).to eql(
|
136
|
+
'controller' => 'anonymous',
|
137
|
+
'action' => 'index',
|
138
|
+
'shallow_object' => {
|
139
|
+
'nested_attribute' => 'value'
|
140
|
+
}
|
141
|
+
)
|
141
142
|
end
|
142
|
-
|
143
143
|
end
|
144
144
|
|
145
|
-
context
|
146
|
-
it
|
147
|
-
|
145
|
+
context 'and the value of the attribute does match' do
|
146
|
+
it 'then then performs the correct substitution' do
|
147
|
+
# noinspection RubyStringKeysInHashInspection
|
148
|
+
get :index,
|
148
149
|
'shallowObject' => {
|
149
|
-
|
150
|
-
}
|
151
|
-
}
|
152
|
-
expect(assigns(:params_snake_case)).to eql({
|
153
|
-
"controller" => "anonymous",
|
154
|
-
"action" => "index",
|
155
|
-
'shallow_object' => {
|
156
|
-
'nested_attribute' => '123'
|
150
|
+
'nestedAttribute' => 'abc'
|
157
151
|
}
|
158
|
-
})
|
159
|
-
end
|
160
152
|
|
153
|
+
# noinspection RubyStringKeysInHashInspection
|
154
|
+
expect(assigns(:params_snake_case)).to eql(
|
155
|
+
'controller' => 'anonymous',
|
156
|
+
'action' => 'index',
|
157
|
+
'shallow_object' => {
|
158
|
+
'nested_attribute' => '123'
|
159
|
+
}
|
160
|
+
)
|
161
|
+
end
|
161
162
|
end
|
162
163
|
end
|
163
164
|
|
164
|
-
context
|
165
|
+
context 'points to an attribute that is an array' do
|
165
166
|
controller ApplicationController do
|
166
167
|
def index
|
167
|
-
@params_snake_case =
|
168
|
+
@params_snake_case =
|
169
|
+
params(
|
170
|
+
substitutions: {
|
171
|
+
array: {
|
172
|
+
'*' => {
|
173
|
+
shallow_object: {
|
174
|
+
nested_attribute: { replace: 'abc', with: '123' }
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
)
|
168
180
|
|
169
181
|
render nothing: true
|
170
182
|
end
|
171
183
|
end
|
172
184
|
|
173
|
-
context
|
174
|
-
it
|
175
|
-
|
185
|
+
context 'and the value of the attribute does NOT match' do
|
186
|
+
it 'then does not do any substitution' do
|
187
|
+
# noinspection RubyStringKeysInHashInspection
|
188
|
+
get :index,
|
176
189
|
'array' => [
|
190
|
+
{
|
177
191
|
'shallowObject' => {
|
178
|
-
|
179
|
-
}
|
192
|
+
'nestedAttribute' => 'value'
|
193
|
+
}
|
194
|
+
},
|
195
|
+
{
|
180
196
|
'shallowObject' => {
|
181
|
-
|
197
|
+
'nestedAttribute' => 'value'
|
182
198
|
}
|
199
|
+
}
|
183
200
|
]
|
184
|
-
}
|
185
201
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
'
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
202
|
+
# noinspection RubyStringKeysInHashInspection
|
203
|
+
expect(assigns(:params_snake_case)).to eql(
|
204
|
+
'controller' => 'anonymous',
|
205
|
+
'action' => 'index',
|
206
|
+
'array' => [
|
207
|
+
{
|
208
|
+
'shallow_object' => {
|
209
|
+
'nested_attribute' => 'value'
|
210
|
+
}
|
211
|
+
},
|
212
|
+
{
|
213
|
+
'shallow_object' => {
|
214
|
+
'nested_attribute' => 'value'
|
215
|
+
}
|
216
|
+
}
|
217
|
+
]
|
218
|
+
)
|
198
219
|
end
|
199
|
-
|
200
220
|
end
|
201
221
|
|
202
|
-
context
|
203
|
-
it
|
204
|
-
|
222
|
+
context 'and the value of the attribute does match' do
|
223
|
+
it 'then performs the correct substitution' do
|
224
|
+
# noinspection RubyStringKeysInHashInspection
|
225
|
+
get :index,
|
205
226
|
'array' => [
|
227
|
+
{
|
206
228
|
'shallowObject' => {
|
207
|
-
|
208
|
-
},
|
209
|
-
'shallowObject' => {
|
210
|
-
'nestedAttribute' => 'abc'
|
229
|
+
'nestedAttribute' => 'value'
|
211
230
|
}
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
"action" => "index",
|
217
|
-
'array' => [
|
218
|
-
'shallow_object' => {
|
219
|
-
'nested_attribute' => 'value'
|
220
|
-
},
|
221
|
-
'shallow_object' => {
|
222
|
-
'nested_attribute' => '123'
|
231
|
+
},
|
232
|
+
{
|
233
|
+
'shallowObject' => {
|
234
|
+
'nestedAttribute' => 'abc'
|
223
235
|
}
|
236
|
+
}
|
224
237
|
]
|
225
|
-
})
|
226
|
-
end
|
227
238
|
|
239
|
+
# noinspection RubyStringKeysInHashInspection
|
240
|
+
expect(assigns(:params_snake_case)).to eql(
|
241
|
+
'controller' => 'anonymous',
|
242
|
+
'action' => 'index',
|
243
|
+
'array' => [
|
244
|
+
{
|
245
|
+
'shallow_object' => {
|
246
|
+
'nested_attribute' => 'value'
|
247
|
+
}
|
248
|
+
},
|
249
|
+
{
|
250
|
+
'shallow_object' => {
|
251
|
+
'nested_attribute' => '123'
|
252
|
+
}
|
253
|
+
}
|
254
|
+
]
|
255
|
+
)
|
256
|
+
end
|
228
257
|
end
|
229
258
|
end
|
230
259
|
|
231
|
-
context
|
260
|
+
context 'is an array' do
|
232
261
|
controller ApplicationController do
|
233
262
|
def index
|
234
|
-
@params_snake_case =
|
263
|
+
@params_snake_case =
|
264
|
+
params(
|
265
|
+
substitutions: {
|
266
|
+
string:
|
267
|
+
[{ replace: 'abc', with: '123' }, { replace: 'cde', with: '456' }]
|
268
|
+
}
|
269
|
+
)
|
235
270
|
|
236
271
|
render nothing: true
|
237
272
|
end
|
238
273
|
end
|
239
274
|
|
240
|
-
context
|
241
|
-
it
|
242
|
-
get :index,
|
243
|
-
'string' => 'string'
|
244
|
-
}
|
275
|
+
context 'and the value of the attribute does NOT match' do
|
276
|
+
it 'then does not do any substitution' do
|
277
|
+
get :index,
|
278
|
+
'string' => 'string'
|
245
279
|
|
246
|
-
expect(assigns(:params_snake_case)).to eql(
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
280
|
+
expect(assigns(:params_snake_case)).to eql(
|
281
|
+
'controller' => 'anonymous',
|
282
|
+
'action' => 'index',
|
283
|
+
'string' => 'string'
|
284
|
+
)
|
251
285
|
end
|
252
|
-
|
253
286
|
end
|
254
287
|
|
255
|
-
context
|
256
|
-
it
|
257
|
-
get :index,
|
258
|
-
'string' => 'abc'
|
259
|
-
}
|
288
|
+
context 'and the value of the attribute matches the first substitution' do
|
289
|
+
it 'then performs the correct substitution' do
|
290
|
+
get :index,
|
291
|
+
'string' => 'abc'
|
260
292
|
|
261
|
-
expect(assigns(:params_snake_case)).to eql(
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
293
|
+
expect(assigns(:params_snake_case)).to eql(
|
294
|
+
'controller' => 'anonymous',
|
295
|
+
'action' => 'index',
|
296
|
+
'string' => '123'
|
297
|
+
)
|
266
298
|
end
|
267
|
-
|
268
299
|
end
|
269
300
|
|
270
|
-
context
|
271
|
-
it
|
272
|
-
get :index,
|
273
|
-
'string' => 'cde'
|
274
|
-
}
|
301
|
+
context 'and the value of the attribute matches the second substitution' do
|
302
|
+
it 'then performs the correct substitution' do
|
303
|
+
get :index,
|
304
|
+
'string' => 'cde'
|
275
305
|
|
276
|
-
expect(assigns(:params_snake_case)).to eql(
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
306
|
+
expect(assigns(:params_snake_case)).to eql(
|
307
|
+
'controller' => 'anonymous',
|
308
|
+
'action' => 'index',
|
309
|
+
'string' => '456'
|
310
|
+
)
|
281
311
|
end
|
282
|
-
|
283
312
|
end
|
284
313
|
end
|
285
|
-
|
286
314
|
end
|
315
|
+
|
316
|
+
# rubocop:enable Metrics/BlockLength
|