snake-eyes 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → LICENSE} +1 -1
  3. data/README.md +104 -20
  4. data/Rakefile +29 -1
  5. data/lib/snake-eyes/engine.rb +12 -0
  6. data/lib/snake-eyes/interface_changes.rb +117 -71
  7. data/lib/snake-eyes/version.rb +1 -1
  8. data/spec/dummy/README.rdoc +28 -0
  9. data/spec/dummy/Rakefile +6 -0
  10. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  11. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  12. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  13. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  14. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  15. data/spec/dummy/bin/bundle +3 -0
  16. data/spec/dummy/bin/rails +4 -0
  17. data/spec/dummy/bin/rake +4 -0
  18. data/spec/dummy/bin/setup +29 -0
  19. data/spec/dummy/config.ru +4 -0
  20. data/spec/dummy/config/application.rb +26 -0
  21. data/spec/dummy/config/boot.rb +5 -0
  22. data/spec/dummy/config/database.yml +25 -0
  23. data/spec/dummy/config/environment.rb +5 -0
  24. data/spec/dummy/config/environments/development.rb +41 -0
  25. data/spec/dummy/config/environments/production.rb +79 -0
  26. data/spec/dummy/config/environments/test.rb +42 -0
  27. data/spec/dummy/config/initializers/assets.rb +11 -0
  28. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  29. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  30. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  31. data/spec/dummy/config/initializers/inflections.rb +16 -0
  32. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  33. data/spec/dummy/config/initializers/session_store.rb +3 -0
  34. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  35. data/spec/dummy/config/locales/en.yml +23 -0
  36. data/spec/dummy/config/routes.rb +3 -0
  37. data/spec/dummy/config/secrets.yml +22 -0
  38. data/spec/dummy/db/test.sqlite3 +0 -0
  39. data/spec/dummy/log/test.log +7104 -0
  40. data/spec/dummy/public/404.html +67 -0
  41. data/spec/dummy/public/422.html +67 -0
  42. data/spec/dummy/public/500.html +66 -0
  43. data/spec/dummy/public/favicon.ico +0 -0
  44. data/spec/nested_attributes_spec.rb +231 -0
  45. data/spec/params_spec.rb +154 -0
  46. data/spec/spec_helper.rb +20 -0
  47. data/spec/substitutions_spec.rb +286 -0
  48. metadata +135 -15
  49. data/.gitignore +0 -22
  50. data/Gemfile +0 -3
  51. data/snake-eyes.gemspec +0 -25
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,231 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'param\'s nested_attributes option:', type: :controller do
4
+
5
+ context "when it is empty" do
6
+ controller ApplicationController do
7
+ def index
8
+ @params_snake_case = params(nested_attributes: {})
9
+
10
+ render nothing: true
11
+ end
12
+ end
13
+
14
+ it "then does not attempt to add the _attributes suffix" do
15
+ get :index, {
16
+ 'string' => 'string',
17
+ 'boolean' => true,
18
+ 'simpleArray' => [
19
+ "0", "1", "2"
20
+ ],
21
+ 'shallowObject' => {
22
+ 'nestedAttribute' => 'value'
23
+ }
24
+ }
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
+ })
38
+ end
39
+ end
40
+
41
+ context "when it is nil" do
42
+ controller ApplicationController do
43
+ def index
44
+ @params_snake_case = params(nested_attributes: nil)
45
+
46
+ render nothing: true
47
+ end
48
+ end
49
+
50
+ it "then does not attempt to add the _attributes suffix" do
51
+ get :index, {
52
+ 'string' => 'string',
53
+ 'boolean' => true,
54
+ 'simpleArray' => [
55
+ "0", "1", "2"
56
+ ],
57
+ 'shallowObject' => {
58
+ 'nestedAttribute' => 'value'
59
+ }
60
+ }
61
+
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
+ })
74
+ end
75
+ end
76
+
77
+ context "when it points to an attribute that is not a nested object" do
78
+ controller ApplicationController do
79
+ def index
80
+ @params_snake_case = params(nested_attributes: [ :string ])
81
+
82
+ render nothing: true
83
+ end
84
+ end
85
+
86
+ it "then adds the _attributes suffix" do
87
+ get :index, {
88
+ 'string' => 'string',
89
+ }
90
+
91
+ expect(assigns(:params_snake_case)).to eql({
92
+ "controller" => "anonymous",
93
+ "action" => "index",
94
+ 'string_attributes' => 'string',
95
+ })
96
+ end
97
+ end
98
+
99
+ context "when it points to an attribute that is a nested object" do
100
+ controller ApplicationController do
101
+ def index
102
+ @params_snake_case = params(nested_attributes: [ :shallow_object ])
103
+
104
+ render nothing: true
105
+ end
106
+ end
107
+
108
+ it "then adds the _attributes suffix" do
109
+ get :index, {
110
+ 'shallowObject' => {
111
+ 'nestedAttribute' => 'value'
112
+ }
113
+ }
114
+
115
+ expect(assigns(:params_snake_case)).to eql({
116
+ "controller" => "anonymous",
117
+ "action" => "index",
118
+ 'shallow_object_attributes' => {
119
+ 'nested_attribute' => 'value'
120
+ }
121
+ })
122
+ end
123
+ end
124
+
125
+ context "when it points to a deeply nested attribute" do
126
+ controller ApplicationController do
127
+ def index
128
+ @params_snake_case = params(nested_attributes: { shallow_object: :nested_attribute })
129
+
130
+ render nothing: true
131
+ end
132
+ end
133
+
134
+ it "then adds the _attributes suffix to all parents" do
135
+ get :index, {
136
+ 'shallowObject' => {
137
+ 'nestedAttribute' => 'value'
138
+ }
139
+ }
140
+
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
+ })
148
+ end
149
+ end
150
+
151
+ context "when it points to a deeply nested attribute using nested array" do
152
+ controller ApplicationController do
153
+ def index
154
+ @params_snake_case = params(nested_attributes: { shallow_object: [ :nested_attribute ] })
155
+
156
+ render nothing: true
157
+ end
158
+ end
159
+
160
+ it "then adds the _attributes suffix to all parents" do
161
+ get :index, {
162
+ 'shallowObject' => {
163
+ 'nestedAttribute' => 'value'
164
+ }
165
+ }
166
+
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
+ })
174
+ end
175
+ end
176
+
177
+ context "when it points to an attribute using the leading underscore convention" do
178
+ controller ApplicationController do
179
+ def index
180
+ @params_snake_case = params(nested_attributes: { _shallow_object: :nested_attribute })
181
+
182
+ render nothing: true
183
+ end
184
+ end
185
+
186
+ it "then adds the _attributes suffix to the inner object only" do
187
+ get :index, {
188
+ 'shallowObject' => {
189
+ 'nestedAttribute' => 'value'
190
+ }
191
+ }
192
+
193
+ expect(assigns(:params_snake_case)).to eql({
194
+ "controller" => "anonymous",
195
+ "action" => "index",
196
+ 'shallow_object' => {
197
+ 'nested_attribute_attributes' => 'value'
198
+ }
199
+ })
200
+ end
201
+ end
202
+
203
+ context "when it points to an attribute using the '*' array index wildcard" do
204
+ controller ApplicationController do
205
+ def index
206
+ @params_snake_case = params(nested_attributes: [ _array: { '*' => :string } ])
207
+
208
+ render nothing: true
209
+ end
210
+ end
211
+
212
+ it "then adds the _attributes suffix" do
213
+ get :index, {
214
+ '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' },
227
+ ]
228
+ })
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe "params default behaviour:", type: :controller do
4
+ context 'when no arguments are passed' do
5
+ controller ApplicationController do
6
+ def index
7
+ @params_snake_case = params
8
+
9
+ render nothing: true
10
+ end
11
+ end
12
+
13
+ context 'and there are no params' do
14
+ it 'then returns an empty object' do
15
+ get :index
16
+
17
+ expect(assigns(:params_snake_case)).to eql({
18
+ "controller" => "anonymous",
19
+ "action" => "index"
20
+ })
21
+ end
22
+ end
23
+
24
+ context 'and there are params' do
25
+ it 'then returns correctly snake cased params' do
26
+ get :index, {
27
+ 'integer' => 3,
28
+ 'string' => 'string',
29
+ 'boolean' => true,
30
+ 'simpleArray' => [
31
+ 0, 1, 2
32
+ ],
33
+ 'shallowObject' => {
34
+ 'nestedAttribute' => 'value'
35
+ },
36
+ 'arrayOfObjects' => [
37
+ {
38
+ 'name' => 'object1'
39
+ },
40
+ {
41
+ 'name' => 'object2'
42
+ },
43
+ {
44
+ 'name' => 'object3'
45
+ },
46
+ ],
47
+ '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
+ },
61
+ },
62
+ 'arrayOfNestedObjects' => [
63
+ {
64
+ 'level' => 1,
65
+ 'children' => [
66
+ {
67
+ 'index' => 1,
68
+ },
69
+ {
70
+ 'index' => 2,
71
+ },
72
+ {
73
+ 'index' => 3,
74
+ },
75
+ ]
76
+
77
+ },
78
+ {
79
+ 'level' => 1,
80
+ 'parent' => {
81
+ 'index' => 1,
82
+ }
83
+ }
84
+ ]
85
+
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'
99
+ },
100
+ 'array_of_objects' => [
101
+ {
102
+ 'name' => 'object1'
103
+ },
104
+ {
105
+ 'name' => 'object2'
106
+ },
107
+ {
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
+ }
124
+ },
125
+ },
126
+ 'array_of_nested_objects' => [
127
+ {
128
+ 'level' => "1",
129
+ 'children' => [
130
+ {
131
+ 'index' => "1",
132
+ },
133
+ {
134
+ 'index' => "2",
135
+ },
136
+ {
137
+ 'index' => "3",
138
+ },
139
+ ]
140
+
141
+ },
142
+ {
143
+ 'level' => "1",
144
+ 'parent' => {
145
+ 'index' => "1",
146
+ }
147
+ }
148
+ ]
149
+
150
+ })
151
+ end
152
+ end
153
+ end
154
+ end