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
@@ -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
|
15
|
-
|
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
|
-
|
22
|
+
'nestedAttribute' => 'value'
|
23
23
|
}
|
24
|
-
}
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
'
|
35
|
-
|
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
|
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
|
51
|
-
|
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
|
-
|
55
|
+
'nestedAttribute' => 'value'
|
59
56
|
}
|
60
|
-
}
|
61
57
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
'
|
71
|
-
|
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
|
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: [
|
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
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
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: [
|
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
|
109
|
-
|
102
|
+
it 'then adds the _attributes suffix' do
|
103
|
+
# noinspection RubyStringKeysInHashInspection
|
104
|
+
get :index,
|
110
105
|
'shallowObject' => {
|
111
|
-
|
106
|
+
'nestedAttribute' => 'value'
|
112
107
|
}
|
113
|
-
}
|
114
108
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
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
|
135
|
-
|
129
|
+
it 'then adds the _attributes suffix to all parents' do
|
130
|
+
# noinspection RubyStringKeysInHashInspection
|
131
|
+
get :index,
|
136
132
|
'shallowObject' => {
|
137
|
-
|
133
|
+
'nestedAttribute' => 'value'
|
138
134
|
}
|
139
|
-
}
|
140
135
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
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: [
|
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
|
161
|
-
|
156
|
+
it 'then adds the _attributes suffix to all parents' do
|
157
|
+
# noinspection RubyStringKeysInHashInspection
|
158
|
+
get :index,
|
162
159
|
'shallowObject' => {
|
163
|
-
|
160
|
+
'nestedAttribute' => 'value'
|
164
161
|
}
|
165
|
-
}
|
166
162
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
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
|
187
|
-
|
183
|
+
it 'then adds the _attributes suffix to the inner object only' do
|
184
|
+
# noinspection RubyStringKeysInHashInspection
|
185
|
+
get :index,
|
188
186
|
'shallowObject' => {
|
189
|
-
|
187
|
+
'nestedAttribute' => 'value'
|
190
188
|
}
|
191
|
-
}
|
192
189
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
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: [
|
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
|
213
|
-
|
210
|
+
it 'then adds the _attributes suffix' do
|
211
|
+
# noinspection RubyStringKeysInHashInspection
|
212
|
+
get :index,
|
214
213
|
'array' => [
|
215
|
-
|
216
|
-
|
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
|
data/spec/params_spec.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
29
|
+
# noinspection RubyStringKeysInHashInspection
|
30
|
+
get :index,
|
27
31
|
'integer' => 3,
|
28
32
|
'string' => 'string',
|
29
33
|
'boolean' => true,
|
30
34
|
'simpleArray' => [
|
31
|
-
|
35
|
+
0, 1, 2
|
32
36
|
],
|
33
37
|
'shallowObject' => {
|
34
|
-
|
38
|
+
'nestedAttribute' => 'value'
|
35
39
|
},
|
36
40
|
'arrayOfObjects' => [
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
{
|
42
|
+
'name' => 'object1'
|
43
|
+
},
|
44
|
+
{
|
45
|
+
'name' => 'object2'
|
46
|
+
},
|
47
|
+
{
|
48
|
+
'name' => 'object3'
|
49
|
+
}
|
46
50
|
],
|
47
51
|
'complexObject' => {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
}
|
81
|
+
},
|
82
|
+
{
|
83
|
+
'level' => 1,
|
84
|
+
'parent' => {
|
85
|
+
'index' => 1
|
83
86
|
}
|
87
|
+
}
|
84
88
|
]
|
85
89
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|