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.
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,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe 'param\'s nested_attributes option:', type: :controller do
4
-
5
- context "when it is empty" do
6
+ context 'when it is empty' do
6
7
  controller ApplicationController do
7
8
  def index
8
9
  @params_snake_case = params(nested_attributes: {})
@@ -11,34 +12,31 @@ RSpec.describe 'param\'s nested_attributes option:', type: :controller do
11
12
  end
12
13
  end
13
14
 
14
- it "then does not attempt to add the _attributes suffix" do
15
- get :index, {
15
+ it 'then does not attempt to add the _attributes suffix' do
16
+ # noinspection RubyStringKeysInHashInspection
17
+ get :index,
16
18
  'string' => 'string',
17
19
  'boolean' => true,
18
- 'simpleArray' => [
19
- "0", "1", "2"
20
- ],
20
+ 'simpleArray' => %w[0 1 2],
21
21
  'shallowObject' => {
22
- 'nestedAttribute' => 'value'
22
+ 'nestedAttribute' => 'value'
23
23
  }
24
- }
25
24
 
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
- })
25
+ # noinspection RubyStringKeysInHashInspection
26
+ expect(assigns(:params_snake_case)).to eql(
27
+ 'controller' => 'anonymous',
28
+ 'action' => 'index',
29
+ 'string' => 'string',
30
+ 'boolean' => true,
31
+ 'simple_array' => %w[0 1 2],
32
+ 'shallow_object' => {
33
+ 'nested_attribute' => 'value'
34
+ }
35
+ )
38
36
  end
39
37
  end
40
38
 
41
- context "when it is nil" do
39
+ context 'when it is nil' do
42
40
  controller ApplicationController do
43
41
  def index
44
42
  @params_snake_case = params(nested_attributes: nil)
@@ -47,82 +45,79 @@ RSpec.describe 'param\'s nested_attributes option:', type: :controller do
47
45
  end
48
46
  end
49
47
 
50
- it "then does not attempt to add the _attributes suffix" do
51
- get :index, {
48
+ it 'then does not attempt to add the _attributes suffix' do
49
+ # noinspection RubyStringKeysInHashInspection
50
+ get :index,
52
51
  'string' => 'string',
53
52
  'boolean' => true,
54
- 'simpleArray' => [
55
- "0", "1", "2"
56
- ],
53
+ 'simpleArray' => %w[0 1 2],
57
54
  'shallowObject' => {
58
- 'nestedAttribute' => 'value'
55
+ 'nestedAttribute' => 'value'
59
56
  }
60
- }
61
57
 
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
- })
58
+ # noinspection RubyStringKeysInHashInspection
59
+ expect(assigns(:params_snake_case)).to eql(
60
+ 'controller' => 'anonymous',
61
+ 'action' => 'index',
62
+ 'string' => 'string',
63
+ 'boolean' => true,
64
+ 'simple_array' => %w[0 1 2],
65
+ 'shallow_object' => {
66
+ 'nested_attribute' => 'value'
67
+ }
68
+ )
74
69
  end
75
70
  end
76
71
 
77
- context "when it points to an attribute that is not a nested object" do
72
+ context 'when it points to an attribute that is not a nested object' do
78
73
  controller ApplicationController do
79
74
  def index
80
- @params_snake_case = params(nested_attributes: [ :string ])
75
+ @params_snake_case = params(nested_attributes: [:string])
81
76
 
82
77
  render nothing: true
83
78
  end
84
79
  end
85
80
 
86
- it "then adds the _attributes suffix" do
87
- get :index, {
88
- 'string' => 'string',
89
- }
81
+ it 'then adds the _attributes suffix' do
82
+ get :index,
83
+ 'string' => 'string'
90
84
 
91
- expect(assigns(:params_snake_case)).to eql({
92
- "controller" => "anonymous",
93
- "action" => "index",
94
- 'string_attributes' => 'string',
95
- })
85
+ expect(assigns(:params_snake_case)).to eql(
86
+ 'controller' => 'anonymous',
87
+ 'action' => 'index',
88
+ 'string_attributes' => 'string'
89
+ )
96
90
  end
97
91
  end
98
92
 
99
- context "when it points to an attribute that is a nested object" do
93
+ context 'when it points to an attribute that is a nested object' do
100
94
  controller ApplicationController do
101
95
  def index
102
- @params_snake_case = params(nested_attributes: [ :shallow_object ])
96
+ @params_snake_case = params(nested_attributes: [:shallow_object])
103
97
 
104
98
  render nothing: true
105
99
  end
106
100
  end
107
101
 
108
- it "then adds the _attributes suffix" do
109
- get :index, {
102
+ it 'then adds the _attributes suffix' do
103
+ # noinspection RubyStringKeysInHashInspection
104
+ get :index,
110
105
  'shallowObject' => {
111
- 'nestedAttribute' => 'value'
106
+ 'nestedAttribute' => 'value'
112
107
  }
113
- }
114
108
 
115
- expect(assigns(:params_snake_case)).to eql({
116
- "controller" => "anonymous",
117
- "action" => "index",
118
- 'shallow_object_attributes' => {
119
- 'nested_attribute' => 'value'
120
- }
121
- })
109
+ # noinspection RubyStringKeysInHashInspection
110
+ expect(assigns(:params_snake_case)).to eql(
111
+ 'controller' => 'anonymous',
112
+ 'action' => 'index',
113
+ 'shallow_object_attributes' => {
114
+ 'nested_attribute' => 'value'
115
+ }
116
+ )
122
117
  end
123
118
  end
124
119
 
125
- context "when it points to a deeply nested attribute" do
120
+ context 'when it points to a deeply nested attribute' do
126
121
  controller ApplicationController do
127
122
  def index
128
123
  @params_snake_case = params(nested_attributes: { shallow_object: :nested_attribute })
@@ -131,50 +126,52 @@ RSpec.describe 'param\'s nested_attributes option:', type: :controller do
131
126
  end
132
127
  end
133
128
 
134
- it "then adds the _attributes suffix to all parents" do
135
- get :index, {
129
+ it 'then adds the _attributes suffix to all parents' do
130
+ # noinspection RubyStringKeysInHashInspection
131
+ get :index,
136
132
  'shallowObject' => {
137
- 'nestedAttribute' => 'value'
133
+ 'nestedAttribute' => 'value'
138
134
  }
139
- }
140
135
 
141
- expect(assigns(:params_snake_case)).to eql({
142
- "controller" => "anonymous",
143
- "action" => "index",
144
- 'shallow_object_attributes' => {
145
- 'nested_attribute_attributes' => 'value'
146
- }
147
- })
136
+ # noinspection RubyStringKeysInHashInspection
137
+ expect(assigns(:params_snake_case)).to eql(
138
+ 'controller' => 'anonymous',
139
+ 'action' => 'index',
140
+ 'shallow_object_attributes' => {
141
+ 'nested_attribute_attributes' => 'value'
142
+ }
143
+ )
148
144
  end
149
145
  end
150
146
 
151
- context "when it points to a deeply nested attribute using nested array" do
147
+ context 'when it points to a deeply nested attribute using nested array' do
152
148
  controller ApplicationController do
153
149
  def index
154
- @params_snake_case = params(nested_attributes: { shallow_object: [ :nested_attribute ] })
150
+ @params_snake_case = params(nested_attributes: { shallow_object: [:nested_attribute] })
155
151
 
156
152
  render nothing: true
157
153
  end
158
154
  end
159
155
 
160
- it "then adds the _attributes suffix to all parents" do
161
- get :index, {
156
+ it 'then adds the _attributes suffix to all parents' do
157
+ # noinspection RubyStringKeysInHashInspection
158
+ get :index,
162
159
  'shallowObject' => {
163
- 'nestedAttribute' => 'value'
160
+ 'nestedAttribute' => 'value'
164
161
  }
165
- }
166
162
 
167
- expect(assigns(:params_snake_case)).to eql({
168
- "controller" => "anonymous",
169
- "action" => "index",
170
- 'shallow_object_attributes' => {
171
- 'nested_attribute_attributes' => 'value'
172
- }
173
- })
163
+ # noinspection RubyStringKeysInHashInspection
164
+ expect(assigns(:params_snake_case)).to eql(
165
+ 'controller' => 'anonymous',
166
+ 'action' => 'index',
167
+ 'shallow_object_attributes' => {
168
+ 'nested_attribute_attributes' => 'value'
169
+ }
170
+ )
174
171
  end
175
172
  end
176
173
 
177
- context "when it points to an attribute using the leading underscore convention" do
174
+ context 'when it points to an attribute using the leading underscore convention' do
178
175
  controller ApplicationController do
179
176
  def index
180
177
  @params_snake_case = params(nested_attributes: { _shallow_object: :nested_attribute })
@@ -183,49 +180,50 @@ RSpec.describe 'param\'s nested_attributes option:', type: :controller do
183
180
  end
184
181
  end
185
182
 
186
- it "then adds the _attributes suffix to the inner object only" do
187
- get :index, {
183
+ it 'then adds the _attributes suffix to the inner object only' do
184
+ # noinspection RubyStringKeysInHashInspection
185
+ get :index,
188
186
  'shallowObject' => {
189
- 'nestedAttribute' => 'value'
187
+ 'nestedAttribute' => 'value'
190
188
  }
191
- }
192
189
 
193
- expect(assigns(:params_snake_case)).to eql({
194
- "controller" => "anonymous",
195
- "action" => "index",
196
- 'shallow_object' => {
197
- 'nested_attribute_attributes' => 'value'
198
- }
199
- })
190
+ # noinspection RubyStringKeysInHashInspection
191
+ expect(assigns(:params_snake_case)).to eql(
192
+ 'controller' => 'anonymous',
193
+ 'action' => 'index',
194
+ 'shallow_object' => {
195
+ 'nested_attribute_attributes' => 'value'
196
+ }
197
+ )
200
198
  end
201
199
  end
202
200
 
203
201
  context "when it points to an attribute using the '*' array index wildcard" do
204
202
  controller ApplicationController do
205
203
  def index
206
- @params_snake_case = params(nested_attributes: [ _array: { '*' => :string } ])
204
+ @params_snake_case = params(nested_attributes: [_array: { '*' => :string }])
207
205
 
208
206
  render nothing: true
209
207
  end
210
208
  end
211
209
 
212
- it "then adds the _attributes suffix" do
213
- get :index, {
210
+ it 'then adds the _attributes suffix' do
211
+ # noinspection RubyStringKeysInHashInspection
212
+ get :index,
214
213
  'array' => [
215
- { 'string' => 'string' },
216
- { 'string' => 'string2' },
217
- ],
218
-
219
- }
220
-
221
- expect(assigns(:params_snake_case)).to eql({
222
- "controller" => "anonymous",
223
- "action" => "index",
224
- 'array' => [
225
- { 'string_attributes' => 'string' },
226
- { 'string_attributes' => 'string2' },
214
+ { 'string' => 'string' },
215
+ { 'string' => 'string2' }
227
216
  ]
228
- })
217
+
218
+ # noinspection RubyStringKeysInHashInspection
219
+ expect(assigns(:params_snake_case)).to eql(
220
+ 'controller' => 'anonymous',
221
+ 'action' => 'index',
222
+ 'array' => [
223
+ { 'string_attributes' => 'string' },
224
+ { 'string_attributes' => 'string2' }
225
+ ]
226
+ )
229
227
  end
230
228
  end
231
229
  end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
- RSpec.describe "params default behaviour:", type: :controller do
5
+ # rubocop:disable Metrics/BlockLength
6
+ RSpec.describe 'params default behaviour:', type: :controller do
4
7
  context 'when no arguments are passed' do
5
8
  controller ApplicationController do
6
9
  def index
@@ -14,141 +17,139 @@ RSpec.describe "params default behaviour:", type: :controller do
14
17
  it 'then returns an empty object' do
15
18
  get :index
16
19
 
17
- expect(assigns(:params_snake_case)).to eql({
18
- "controller" => "anonymous",
19
- "action" => "index"
20
- })
20
+ expect(assigns(:params_snake_case)).to eql(
21
+ 'controller' => 'anonymous',
22
+ 'action' => 'index'
23
+ )
21
24
  end
22
25
  end
23
26
 
24
27
  context 'and there are params' do
25
28
  it 'then returns correctly snake cased params' do
26
- get :index, {
29
+ # noinspection RubyStringKeysInHashInspection
30
+ get :index,
27
31
  'integer' => 3,
28
32
  'string' => 'string',
29
33
  'boolean' => true,
30
34
  'simpleArray' => [
31
- 0, 1, 2
35
+ 0, 1, 2
32
36
  ],
33
37
  'shallowObject' => {
34
- 'nestedAttribute' => 'value'
38
+ 'nestedAttribute' => 'value'
35
39
  },
36
40
  'arrayOfObjects' => [
37
- {
38
- 'name' => 'object1'
39
- },
40
- {
41
- 'name' => 'object2'
42
- },
43
- {
44
- 'name' => 'object3'
45
- },
41
+ {
42
+ 'name' => 'object1'
43
+ },
44
+ {
45
+ 'name' => 'object2'
46
+ },
47
+ {
48
+ 'name' => 'object3'
49
+ }
46
50
  ],
47
51
  'complexObject' => {
48
- 'nestedObject' => {
49
- 'deeperNestedObject' => {
50
- 'name' => 'deeplyNested'
51
- }
52
- },
53
- 'anotherNestedObject' => {
54
- 'deeperNestedObject' => {
55
- 'name' => 'anotherDeeplyNested',
56
- 'deepestNestedObject' => {
57
- 'name' => 'deeplyNested'
58
- }
59
- }
60
- },
52
+ 'nestedObject' => {
53
+ 'deeperNestedObject' => {
54
+ 'name' => 'deeplyNested'
55
+ }
56
+ },
57
+ 'anotherNestedObject' => {
58
+ 'deeperNestedObject' => {
59
+ 'name' => 'anotherDeeplyNested',
60
+ 'deepestNestedObject' => {
61
+ 'name' => 'deeplyNested'
62
+ }
63
+ }
64
+ }
61
65
  },
62
66
  'arrayOfNestedObjects' => [
63
- {
64
- 'level' => 1,
65
- 'children' => [
66
- {
67
- 'index' => 1,
68
- },
69
- {
70
- 'index' => 2,
71
- },
72
- {
73
- 'index' => 3,
74
- },
75
- ]
67
+ {
68
+ 'level' => 1,
69
+ 'children' => [
70
+ {
71
+ 'index' => 1
72
+ },
73
+ {
74
+ 'index' => 2
75
+ },
76
+ {
77
+ 'index' => 3
78
+ }
79
+ ]
76
80
 
77
- },
78
- {
79
- 'level' => 1,
80
- 'parent' => {
81
- 'index' => 1,
82
- }
81
+ },
82
+ {
83
+ 'level' => 1,
84
+ 'parent' => {
85
+ 'index' => 1
83
86
  }
87
+ }
84
88
  ]
85
89
 
86
- }
87
-
88
- expect(assigns(:params_snake_case)).to eql({
89
- "controller" => "anonymous",
90
- "action" => "index",
91
- 'integer' => "3",
92
- 'string' => 'string',
93
- 'boolean' => true,
94
- 'simple_array' => [
95
- "0", "1", "2"
96
- ],
97
- 'shallow_object' => {
98
- 'nested_attribute' => 'value'
90
+ # noinspection RubyStringKeysInHashInspection
91
+ expect(assigns(:params_snake_case)).to eql(
92
+ 'controller' => 'anonymous',
93
+ 'action' => 'index',
94
+ 'integer' => '3',
95
+ 'string' => 'string',
96
+ 'boolean' => true,
97
+ 'simple_array' => %w[0 1 2],
98
+ 'shallow_object' => {
99
+ 'nested_attribute' => 'value'
100
+ },
101
+ 'array_of_objects' => [
102
+ {
103
+ 'name' => 'object1'
99
104
  },
100
- 'array_of_objects' => [
101
- {
102
- 'name' => 'object1'
103
- },
104
- {
105
- 'name' => 'object2'
106
- },
105
+ {
106
+ 'name' => 'object2'
107
+ },
108
+ {
109
+ 'name' => 'object3'
110
+ }
111
+ ],
112
+ 'complex_object' => {
113
+ 'nested_object' => {
114
+ 'deeper_nested_object' => {
115
+ 'name' => 'deeplyNested'
116
+ }
117
+ },
118
+ 'another_nested_object' => {
119
+ 'deeper_nested_object' => {
120
+ 'name' => 'anotherDeeplyNested',
121
+ 'deepest_nested_object' => {
122
+ 'name' => 'deeplyNested'
123
+ }
124
+ }
125
+ }
126
+ },
127
+ 'array_of_nested_objects' => [
128
+ {
129
+ 'level' => '1',
130
+ 'children' => [
107
131
  {
108
- 'name' => 'object3'
109
- },
110
- ],
111
- 'complex_object' => {
112
- 'nested_object' => {
113
- 'deeper_nested_object' => {
114
- 'name' => 'deeplyNested'
115
- }
116
- },
117
- 'another_nested_object' => {
118
- 'deeper_nested_object' => {
119
- 'name' => 'anotherDeeplyNested',
120
- 'deepest_nested_object' => {
121
- 'name' => 'deeplyNested'
122
- }
123
- }
132
+ 'index' => '1'
124
133
  },
125
- },
126
- 'array_of_nested_objects' => [
127
134
  {
128
- 'level' => "1",
129
- 'children' => [
130
- {
131
- 'index' => "1",
132
- },
133
- {
134
- 'index' => "2",
135
- },
136
- {
137
- 'index' => "3",
138
- },
139
- ]
140
-
135
+ 'index' => '2'
141
136
  },
142
137
  {
143
- 'level' => "1",
144
- 'parent' => {
145
- 'index' => "1",
146
- }
138
+ 'index' => '3'
147
139
  }
148
- ]
140
+ ]
149
141
 
150
- })
142
+ },
143
+ {
144
+ 'level' => '1',
145
+ 'parent' => {
146
+ 'index' => '1'
147
+ }
148
+ }
149
+ ]
150
+ )
151
151
  end
152
152
  end
153
153
  end
154
154
  end
155
+ # rubocop:enable Metrics/BlockLength