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,20 @@
1
+ require 'awesome_print'
2
+ ENV['RAILS_ENV'] ||= 'test'
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ Rails.backtrace_cleaner.remove_silencers!
8
+
9
+ # Load support files
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :rspec
14
+ config.use_transactional_fixtures = true
15
+ config.infer_base_class_for_anonymous_controllers = false
16
+ config.order = "random"
17
+
18
+ config.filter_run :focus
19
+ config.run_all_when_everything_filtered = true
20
+ end
@@ -0,0 +1,286 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 'param\'s substituions option:', type: :controller do
4
+
5
+ context "is empty" do
6
+ controller ApplicationController do
7
+ def index
8
+ @params_snake_case = params(substitutions: {})
9
+
10
+ render nothing: true
11
+ end
12
+ end
13
+
14
+ it "then does not attempt to perform any substitutions" 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 "is nil" do
42
+ controller ApplicationController do
43
+ def index
44
+ @params_snake_case = params(substitutions: nil)
45
+
46
+ render nothing: true
47
+ end
48
+ end
49
+
50
+ it "then does not attempt to perform any substitutions" 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 "points to an attribute that is not a nested object" do
78
+ controller ApplicationController do
79
+ def index
80
+ @params_snake_case = params(substitutions: { string: { replace: 'abc', with: '123' } })
81
+
82
+ render nothing: true
83
+ end
84
+ end
85
+
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
+ }
91
+
92
+ expect(assigns(:params_snake_case)).to eql({
93
+ "controller" => "anonymous",
94
+ "action" => "index",
95
+ 'string' => 'string',
96
+ })
97
+ end
98
+
99
+ end
100
+
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
+ }
106
+
107
+ expect(assigns(:params_snake_case)).to eql({
108
+ "controller" => "anonymous",
109
+ "action" => "index",
110
+ 'string' => '123',
111
+ })
112
+ end
113
+
114
+ end
115
+ end
116
+
117
+ context "points to an attribute that is a nested object" do
118
+ controller ApplicationController do
119
+ def index
120
+ @params_snake_case = params(substitutions: { shallow_object: { nested_attribute: { replace: 'abc', with: '123' } } })
121
+
122
+ render nothing: true
123
+ end
124
+ end
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, {
129
+ 'shallowObject' => {
130
+ 'nestedAttribute' => 'value'
131
+ }
132
+ }
133
+
134
+ expect(assigns(:params_snake_case)).to eql({
135
+ "controller" => "anonymous",
136
+ "action" => "index",
137
+ 'shallow_object' => {
138
+ 'nested_attribute' => 'value'
139
+ }
140
+ })
141
+ end
142
+
143
+ end
144
+
145
+ context "and the value of the attribute does match" do
146
+ it "then then performs the correct substitution" do
147
+ get :index, {
148
+ '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'
157
+ }
158
+ })
159
+ end
160
+
161
+ end
162
+ end
163
+
164
+ context "points to an attribute that is an array" do
165
+ controller ApplicationController do
166
+ def index
167
+ @params_snake_case = params(substitutions: { array: { '*' => { shallow_object: { nested_attribute: { replace: 'abc', with: '123' } }} } })
168
+
169
+ render nothing: true
170
+ end
171
+ end
172
+
173
+ context "and the value of the attribute does NOT match" do
174
+ it "then does not do any substitution" do
175
+ get :index, {
176
+ 'array' => [
177
+ 'shallowObject' => {
178
+ 'nestedAttribute' => 'value'
179
+ },
180
+ 'shallowObject' => {
181
+ 'nestedAttribute' => 'value'
182
+ }
183
+ ]
184
+ }
185
+
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
+ })
198
+ end
199
+
200
+ end
201
+
202
+ context "and the value of the attribute does match" do
203
+ it "then performs the correct substitution" do
204
+ get :index, {
205
+ 'array' => [
206
+ 'shallowObject' => {
207
+ 'nestedAttribute' => 'value'
208
+ },
209
+ 'shallowObject' => {
210
+ 'nestedAttribute' => 'abc'
211
+ }
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'
223
+ }
224
+ ]
225
+ })
226
+ end
227
+
228
+ end
229
+ end
230
+
231
+ context "is an array" do
232
+ controller ApplicationController do
233
+ def index
234
+ @params_snake_case = params(substitutions: { string: [ { replace: 'abc', with: '123' }, { replace: 'cde', with: '456' }] })
235
+
236
+ render nothing: true
237
+ end
238
+ end
239
+
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
+ }
245
+
246
+ expect(assigns(:params_snake_case)).to eql({
247
+ "controller" => "anonymous",
248
+ "action" => "index",
249
+ 'string' => 'string',
250
+ })
251
+ end
252
+
253
+ end
254
+
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
+ }
260
+
261
+ expect(assigns(:params_snake_case)).to eql({
262
+ "controller" => "anonymous",
263
+ "action" => "index",
264
+ 'string' => '123',
265
+ })
266
+ end
267
+
268
+ end
269
+
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
+ }
275
+
276
+ expect(assigns(:params_snake_case)).to eql({
277
+ "controller" => "anonymous",
278
+ "action" => "index",
279
+ 'string' => '456',
280
+ })
281
+ end
282
+
283
+ end
284
+ end
285
+
286
+ end
metadata CHANGED
@@ -1,41 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snake-eyes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleck Greenham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-31 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
19
+ version: 4.2.5
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: 4.2.5
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: awesome_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
39
81
  - !ruby/object:Gem::Version
40
82
  version: '0'
41
83
  description: Automatically convert params in your controllers from camel case to snake
@@ -46,15 +88,53 @@ executables: []
46
88
  extensions: []
47
89
  extra_rdoc_files: []
48
90
  files:
49
- - ".gitignore"
50
- - Gemfile
51
- - LICENSE.txt
91
+ - LICENSE
52
92
  - README.md
53
93
  - Rakefile
54
94
  - lib/snake-eyes.rb
95
+ - lib/snake-eyes/engine.rb
55
96
  - lib/snake-eyes/interface_changes.rb
56
97
  - lib/snake-eyes/version.rb
57
- - snake-eyes.gemspec
98
+ - spec/dummy/README.rdoc
99
+ - spec/dummy/Rakefile
100
+ - spec/dummy/app/assets/javascripts/application.js
101
+ - spec/dummy/app/assets/stylesheets/application.css
102
+ - spec/dummy/app/controllers/application_controller.rb
103
+ - spec/dummy/app/helpers/application_helper.rb
104
+ - spec/dummy/app/views/layouts/application.html.erb
105
+ - spec/dummy/bin/bundle
106
+ - spec/dummy/bin/rails
107
+ - spec/dummy/bin/rake
108
+ - spec/dummy/bin/setup
109
+ - spec/dummy/config.ru
110
+ - spec/dummy/config/application.rb
111
+ - spec/dummy/config/boot.rb
112
+ - spec/dummy/config/database.yml
113
+ - spec/dummy/config/environment.rb
114
+ - spec/dummy/config/environments/development.rb
115
+ - spec/dummy/config/environments/production.rb
116
+ - spec/dummy/config/environments/test.rb
117
+ - spec/dummy/config/initializers/assets.rb
118
+ - spec/dummy/config/initializers/backtrace_silencers.rb
119
+ - spec/dummy/config/initializers/cookies_serializer.rb
120
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
121
+ - spec/dummy/config/initializers/inflections.rb
122
+ - spec/dummy/config/initializers/mime_types.rb
123
+ - spec/dummy/config/initializers/session_store.rb
124
+ - spec/dummy/config/initializers/wrap_parameters.rb
125
+ - spec/dummy/config/locales/en.yml
126
+ - spec/dummy/config/routes.rb
127
+ - spec/dummy/config/secrets.yml
128
+ - spec/dummy/db/test.sqlite3
129
+ - spec/dummy/log/test.log
130
+ - spec/dummy/public/404.html
131
+ - spec/dummy/public/422.html
132
+ - spec/dummy/public/500.html
133
+ - spec/dummy/public/favicon.ico
134
+ - spec/nested_attributes_spec.rb
135
+ - spec/params_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/substitutions_spec.rb
58
138
  homepage: https://github.com/greena13/snake-eyes
59
139
  licenses:
60
140
  - MIT
@@ -67,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
147
  requirements:
68
148
  - - ">="
69
149
  - !ruby/object:Gem::Version
70
- version: '1.9'
150
+ version: '0'
71
151
  required_rubygems_version: !ruby/object:Gem::Requirement
72
152
  requirements:
73
153
  - - ">="
@@ -80,4 +160,44 @@ signing_key:
80
160
  specification_version: 4
81
161
  summary: Automatically convert params in your controllers from camel case to snake
82
162
  case
83
- test_files: []
163
+ test_files:
164
+ - spec/dummy/app/assets/javascripts/application.js
165
+ - spec/dummy/app/assets/stylesheets/application.css
166
+ - spec/dummy/app/controllers/application_controller.rb
167
+ - spec/dummy/app/helpers/application_helper.rb
168
+ - spec/dummy/app/views/layouts/application.html.erb
169
+ - spec/dummy/bin/bundle
170
+ - spec/dummy/bin/rails
171
+ - spec/dummy/bin/rake
172
+ - spec/dummy/bin/setup
173
+ - spec/dummy/config/application.rb
174
+ - spec/dummy/config/boot.rb
175
+ - spec/dummy/config/database.yml
176
+ - spec/dummy/config/environment.rb
177
+ - spec/dummy/config/environments/development.rb
178
+ - spec/dummy/config/environments/production.rb
179
+ - spec/dummy/config/environments/test.rb
180
+ - spec/dummy/config/initializers/assets.rb
181
+ - spec/dummy/config/initializers/backtrace_silencers.rb
182
+ - spec/dummy/config/initializers/cookies_serializer.rb
183
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
184
+ - spec/dummy/config/initializers/inflections.rb
185
+ - spec/dummy/config/initializers/mime_types.rb
186
+ - spec/dummy/config/initializers/session_store.rb
187
+ - spec/dummy/config/initializers/wrap_parameters.rb
188
+ - spec/dummy/config/locales/en.yml
189
+ - spec/dummy/config/routes.rb
190
+ - spec/dummy/config/secrets.yml
191
+ - spec/dummy/config.ru
192
+ - spec/dummy/db/test.sqlite3
193
+ - spec/dummy/log/test.log
194
+ - spec/dummy/public/404.html
195
+ - spec/dummy/public/422.html
196
+ - spec/dummy/public/500.html
197
+ - spec/dummy/public/favicon.ico
198
+ - spec/dummy/Rakefile
199
+ - spec/dummy/README.rdoc
200
+ - spec/nested_attributes_spec.rb
201
+ - spec/params_spec.rb
202
+ - spec/spec_helper.rb
203
+ - spec/substitutions_spec.rb