snake-eyes 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +7 -5
  4. data/lib/snake-eyes.rb +6 -6
  5. data/lib/snake_eyes/compatibility.rb +19 -0
  6. data/lib/snake_eyes/configuration.rb +53 -0
  7. data/lib/{snake-eyes → snake_eyes}/engine.rb +4 -4
  8. data/lib/snake_eyes/interface_changes.rb +49 -0
  9. data/lib/snake_eyes/logging.rb +19 -0
  10. data/lib/snake_eyes/memoization.rb +27 -0
  11. data/lib/snake_eyes/transform.rb +124 -0
  12. data/lib/snake_eyes/version.rb +5 -0
  13. data/spec/dummy/Rakefile +3 -1
  14. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  15. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  16. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  17. data/spec/dummy/bin/bundle +3 -1
  18. data/spec/dummy/bin/rails +3 -1
  19. data/spec/dummy/bin/rake +2 -0
  20. data/spec/dummy/bin/setup +10 -8
  21. data/spec/dummy/config.ru +2 -0
  22. data/spec/dummy/config/application.rb +4 -3
  23. data/spec/dummy/config/boot.rb +4 -2
  24. data/spec/dummy/config/environment.rb +3 -1
  25. data/spec/dummy/config/environments/development.rb +6 -3
  26. data/spec/dummy/config/environments/production.rb +2 -0
  27. data/spec/dummy/config/environments/test.rb +3 -1
  28. data/spec/dummy/config/initializers/assets.rb +4 -1
  29. data/spec/dummy/config/initializers/backtrace_silencers.rb +6 -2
  30. data/spec/dummy/config/initializers/cookies_serializer.rb +2 -0
  31. data/spec/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  32. data/spec/dummy/config/initializers/inflections.rb +2 -0
  33. data/spec/dummy/config/initializers/mime_types.rb +2 -0
  34. data/spec/dummy/config/initializers/session_store.rb +2 -0
  35. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -0
  36. data/spec/dummy/config/routes.rb +2 -1
  37. data/spec/dummy/log/test.log +5615 -0
  38. data/spec/nested_attributes_spec.rb +116 -118
  39. data/spec/params_spec.rb +107 -106
  40. data/spec/spec_helper.rb +5 -3
  41. data/spec/substitutions_spec.rb +202 -172
  42. metadata +27 -8
  43. data/lib/snake-eyes/interface_changes.rb +0 -187
  44. data/lib/snake-eyes/version.rb +0 -3
@@ -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("../dummy/config/environment.rb", __FILE__)
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 { |f| require f }
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 = "random"
18
+ config.order = 'random'
17
19
 
18
20
  config.filter_run :focus
19
21
  config.run_all_when_everything_filtered = true
@@ -1,8 +1,10 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- RSpec.describe 'param\'s substituions option:', type: :controller do
3
+ require 'spec_helper'
4
4
 
5
- context "is empty" do
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 "then does not attempt to perform any substitutions" do
15
- get :index, {
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
- 'nestedAttribute' => 'value'
23
+ 'nestedAttribute' => 'value'
23
24
  }
24
- }
25
25
 
26
- expect(assigns(:params_snake_case)).to eql({
27
- "controller" => "anonymous",
28
- "action" => "index",
29
- 'string' => 'string',
30
- 'boolean' => true,
31
- 'simple_array' => [
32
- "0", "1", "2"
33
- ],
34
- 'shallow_object' => {
35
- 'nested_attribute' => 'value'
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 "is nil" do
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 "then does not attempt to perform any substitutions" do
51
- get :index, {
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
- 'nestedAttribute' => 'value'
56
+ 'nestedAttribute' => 'value'
59
57
  }
60
- }
61
58
 
62
- expect(assigns(:params_snake_case)).to eql({
63
- "controller" => "anonymous",
64
- "action" => "index",
65
- 'string' => 'string',
66
- 'boolean' => true,
67
- 'simple_array' => [
68
- "0", "1", "2"
69
- ],
70
- 'shallow_object' => {
71
- 'nested_attribute' => 'value'
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 "points to an attribute that is not a nested object" do
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 = params(substitutions: { string: { replace: 'abc', with: '123' } })
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 "and the value of the attribute does NOT match" do
87
- it "then does not do any substitution" do
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
- "controller" => "anonymous",
94
- "action" => "index",
95
- 'string' => 'string',
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 "and the value of the attribute does match" do
102
- it "then does not do any substitution" do
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
- "controller" => "anonymous",
109
- "action" => "index",
110
- 'string' => '123',
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 "points to an attribute that is a nested object" do
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 = params(substitutions: { shallow_object: { nested_attribute: { replace: 'abc', with: '123' } } })
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 "and the value of the attribute does NOT match" do
127
- it "then does not do any substitution" do
128
- get :index, {
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
- 'nestedAttribute' => 'value'
131
+ 'nestedAttribute' => 'value'
131
132
  }
132
- }
133
133
 
134
- expect(assigns(:params_snake_case)).to eql({
135
- "controller" => "anonymous",
136
- "action" => "index",
137
- 'shallow_object' => {
138
- 'nested_attribute' => 'value'
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 "and the value of the attribute does match" do
146
- it "then then performs the correct substitution" do
147
- get :index, {
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
- 'nestedAttribute' => 'abc'
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 "points to an attribute that is an array" do
165
+ context 'points to an attribute that is an array' do
165
166
  controller ApplicationController do
166
167
  def index
167
- @params_snake_case = params(substitutions: { array: { '*' => { shallow_object: { nested_attribute: { replace: 'abc', with: '123' } }} } })
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 "and the value of the attribute does NOT match" do
174
- it "then does not do any substitution" do
175
- get :index, {
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
- 'nestedAttribute' => 'value'
179
- },
192
+ 'nestedAttribute' => 'value'
193
+ }
194
+ },
195
+ {
180
196
  'shallowObject' => {
181
- 'nestedAttribute' => 'value'
197
+ 'nestedAttribute' => 'value'
182
198
  }
199
+ }
183
200
  ]
184
- }
185
201
 
186
- expect(assigns(:params_snake_case)).to eql({
187
- "controller" => "anonymous",
188
- "action" => "index",
189
- 'array' => [
190
- 'shallow_object' => {
191
- 'nested_attribute' => 'value'
192
- },
193
- 'shallow_object' => {
194
- 'nested_attribute' => 'value'
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 "and the value of the attribute does match" do
203
- it "then performs the correct substitution" do
204
- get :index, {
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
- 'nestedAttribute' => 'value'
208
- },
209
- 'shallowObject' => {
210
- 'nestedAttribute' => 'abc'
229
+ 'nestedAttribute' => 'value'
211
230
  }
212
- ]
213
- }
214
- expect(assigns(:params_snake_case)).to eql({
215
- "controller" => "anonymous",
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 "is an array" do
260
+ context 'is an array' do
232
261
  controller ApplicationController do
233
262
  def index
234
- @params_snake_case = params(substitutions: { string: [ { replace: 'abc', with: '123' }, { replace: 'cde', with: '456' }] })
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 "and the value of the attribute does NOT match" do
241
- it "then does not do any substitution" do
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
- "controller" => "anonymous",
248
- "action" => "index",
249
- 'string' => 'string',
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 "and the value of the attribute matches the first substitution" do
256
- it "then performs the correct substitution" do
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
- "controller" => "anonymous",
263
- "action" => "index",
264
- 'string' => '123',
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 "and the value of the attribute matches the second substitution" do
271
- it "then performs the correct substitution" do
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
- "controller" => "anonymous",
278
- "action" => "index",
279
- 'string' => '456',
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