strong_like_bull 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +10 -0
- data/lib/strong_like_bull.rb +47 -0
- data/lib/strong_like_bull/version.rb +3 -0
- data/spec/integration/strong_like_bull_spec.rb +186 -0
- data/spec/spec_helper.rb +9 -0
- data/strong_like_bull.gemspec +29 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b0393c6ceebf9d7248d563b6dd8230fbbe55c25
|
4
|
+
data.tar.gz: d696c836d5f3e5a79c34ca7d56b70c3e89f89a8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e53260b390969696c03c0d8de9d9418a749d4368012a9522ca0c87e48843281bce37918b8a64c96e12177e66bd90c514470f02ae8ca76ca4e77c8e2494dd2bf4
|
7
|
+
data.tar.gz: 018f697777a1727559713549c7c2dfa5838cf59a22dddacdee5d1c25fdc9d78d25c6afdad5a9e23d725dc83641ffb6d86456890fe6974a92dd1de0eb62322194
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
strong_like_bull
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Andrew Hunter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# StrongLikeBull
|
2
|
+
|
3
|
+
Makes it super simple to add strong parameters into your application by examining request parameters and recommending what feeds should be permitted.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'strong_like_bull'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install strong_like_bull
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In application_controller.rb or a specific controller, add the following line:
|
24
|
+
include StrongLikeBull
|
25
|
+
|
26
|
+
In any controller action where you want a recommendation for the strong parameters permitted parameters based on the request parameters, add the following inside the action:
|
27
|
+
|
28
|
+
def CONTROLLER_ACTION
|
29
|
+
log_suggested_strong_parameters_format(PARAMETER_NAME_TO_INSPECT)
|
30
|
+
# perform action
|
31
|
+
end
|
32
|
+
|
33
|
+
When the controller action gets hit, it will log the recommended strong params permitted params to use in the following format:
|
34
|
+
|
35
|
+
STRONG PARAMETERS: #{self.class}##{action_name} - suggested format: RECOMMENDED_PERMITTED_PARAMS
|
36
|
+
|
37
|
+
If we don't want this to be logged, we could utilize the method "suggested_strong_parameters_format", which will return the object representation of the strong parameters format. Like "log_suggested_strong_parameters_format", it also takes the PARAMETER_NAME_TO_INSPECT as a parameter.
|
38
|
+
|
39
|
+
## Caution
|
40
|
+
StrongLikeBull only serves to recommend params to permit based on what is passed in to the request. It cannot make guesses about the security of your application, or which parameters should be restricted. With this in mind, it is recommended to carefully examine the results to determine if some permitted params should be removed from the recommendation before permitting your params.
|
41
|
+
|
42
|
+
## Example
|
43
|
+
|
44
|
+
If you wanted the recommended params to permit for the update action of a Posts Controller, it would like:
|
45
|
+
|
46
|
+
def update
|
47
|
+
log_suggested_strong_parameters_format(:post)
|
48
|
+
# perform update
|
49
|
+
end
|
50
|
+
|
51
|
+
The above example would assume the a a parameter is passed to the controller called "post" which contained all the fields we want to permit. The request parameters might look something like this:
|
52
|
+
|
53
|
+
{ post: { name: "My Post", tags: ["Personal", "Life"], description: "A description about my post" }}
|
54
|
+
|
55
|
+
If those request parameters were passed to the update action above, we'd see the following as a result in our logs:
|
56
|
+
|
57
|
+
STRONG PARAMETERS: PostsController#update - suggested format: params.require(:post).permit [:name, {:tags=>[]}, :description]
|
58
|
+
|
59
|
+
Using that suggested format, we could then modify our update action to the following:
|
60
|
+
|
61
|
+
def update
|
62
|
+
permitted_params = params.require(:post).permit [:name, {:tags=>[]}, :description]
|
63
|
+
# perform update
|
64
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "strong_like_bull/version"
|
2
|
+
|
3
|
+
module StrongLikeBull
|
4
|
+
def log_suggested_strong_parameters_format(key)
|
5
|
+
Rails.logger.info "STRONG PARAMETERS: #{self.class}##{action_name} - suggested format: params.require(:#{key}).permit #{suggested_strong_parameters_format key}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def suggested_strong_parameters_format(key)
|
9
|
+
hash = params[key]
|
10
|
+
recursive_suggested_strong_parameters_format(hash) if hash
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def recursive_suggested_strong_parameters_format(object)
|
15
|
+
if object.is_a? Hash
|
16
|
+
if object.keys.first.match(/^\d+$/)
|
17
|
+
hash = {}
|
18
|
+
object.values.each do |value|
|
19
|
+
hash.deep_merge!(value)
|
20
|
+
end
|
21
|
+
ret = recursive_suggested_strong_parameters_format(hash)
|
22
|
+
ret << :id unless ret.include?(:id)
|
23
|
+
ret
|
24
|
+
else
|
25
|
+
permitted_params = []
|
26
|
+
object.each do |key, value|
|
27
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
28
|
+
permitted_params << {:"#{key}" => recursive_suggested_strong_parameters_format(value)}
|
29
|
+
else
|
30
|
+
permitted_params << :"#{key}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
permitted_params
|
34
|
+
end
|
35
|
+
elsif object.is_a?(Array)
|
36
|
+
if object.first.is_a?(Hash)
|
37
|
+
hash = {}
|
38
|
+
object.each do |value|
|
39
|
+
hash.deep_merge!(value)
|
40
|
+
end
|
41
|
+
recursive_suggested_strong_parameters_format(hash)
|
42
|
+
else
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "action_controller"
|
3
|
+
|
4
|
+
describe "StrongLikeBull" do
|
5
|
+
before :each do
|
6
|
+
@object = Object.new
|
7
|
+
@object.extend(StrongLikeBull)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to suggest the appropriate format for the example from http://www.railsexperiments.com/using-strong-parameters-with-nested-forms/" do
|
11
|
+
inner_params = HashWithIndifferentAccess.new username: "john", data: { foo: "bar" }
|
12
|
+
expected_format = [:username, data: [:foo]]
|
13
|
+
params = ActionController::Parameters.new(user: inner_params)
|
14
|
+
# sanity check that our expected format indeed does extract the inner_params out
|
15
|
+
expect(params.require(:user).permit(expected_format)).to eql inner_params
|
16
|
+
@object.expects(:params).returns params
|
17
|
+
expect(@object.suggested_strong_parameters_format(:user)).to eql expected_format
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to suggest the appropriate format for the nested params example from https://github.com/rails/strong_parameters/" do
|
21
|
+
inner_params = HashWithIndifferentAccess.new name: "john",
|
22
|
+
emails: ["test@test.com", "test2@test.com"],
|
23
|
+
friends: [ name: "Andrew", family: [:name => "Hunter"], hobbies: ["Programming"] ]
|
24
|
+
expected_format = [:name, {:emails => []}, :friends => [ :name, { :family => [ :name ] }, { :hobbies => [] }]]
|
25
|
+
params = ActionController::Parameters.new(user: inner_params )
|
26
|
+
# sanity check that our expected format indeed does extract the inner_params out
|
27
|
+
expect(params.require(:user).permit(expected_format)).to eql inner_params
|
28
|
+
@object.expects(:params).returns params
|
29
|
+
expect(@object.suggested_strong_parameters_format(:user)).to eql expected_format
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be able to suggest the appropriate format for a complex example from work (with field names randomized)" do
|
33
|
+
inner_params = HashWithIndifferentAccess.new "random_field_1"=>"", "random_field_2"=>"",
|
34
|
+
"random_field_3"=>"", "random_field_4"=>"",
|
35
|
+
"random_field_5"=>"", "random_field_6"=>"",
|
36
|
+
"random_field_7"=>"", "random_field_8"=>"", "random_field_9"=>"",
|
37
|
+
"random_field_10"=>"", "random_field_11"=>"",
|
38
|
+
"random_field_12"=>"", "random_field_13"=>"", "random_field_14"=>"",
|
39
|
+
"random_field_15"=>"", "random_field_16"=>"",
|
40
|
+
"random_field_17"=>"",
|
41
|
+
"random_field_18"=>{"1234"=>{"random_field_19"=>"2", "value"=>"20", "id"=>"", "random_field_20"=>{"id"=>"3"}},
|
42
|
+
"1"=>{"random_field_19"=>"2", "value"=>"30", "random_field_20"=>{"id"=>"5"}}}
|
43
|
+
expected_format = [:random_field_1, :random_field_2, :random_field_3, :random_field_4, :random_field_5, :random_field_6, :random_field_7, :random_field_8,
|
44
|
+
:random_field_9, :random_field_10, :random_field_11, :random_field_12, :random_field_13, :random_field_14, :random_field_15, :random_field_16, :random_field_17,
|
45
|
+
{:random_field_18=>[:random_field_19, :value, :id, {:random_field_20=>[:id]}]}]
|
46
|
+
params = ActionController::Parameters.new(variant: inner_params )
|
47
|
+
# sanity check that our expected format indeed does extract the inner_params out
|
48
|
+
expect(params.require(:variant).permit(expected_format)).to eql inner_params
|
49
|
+
@object.expects(:params).returns params
|
50
|
+
expect(@object.suggested_strong_parameters_format(:variant)).to eql expected_format
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should be able to suggest the appropriate format for a second complex example from work (with field names randomized)" do
|
54
|
+
inner_params = HashWithIndifferentAccess.new "random_field_1"=>"", "random_field_2"=>"",
|
55
|
+
"random_field_3"=>"", "random_field_4"=>"234asfdsfd", "random_field_5"=>"23",
|
56
|
+
"random_field_6"=>"1", "random_field_7"=>"0.0",
|
57
|
+
"random_field_8"=>"23", "random_field_9"=>"7.5",
|
58
|
+
"random_field_10"=>"32323", "random_field_11"=>"2015-04-22",
|
59
|
+
"random_field_12"=>"", "random_field_13"=>"",
|
60
|
+
"random_field_14"=>"2", "random_field_15"=>"0",
|
61
|
+
"random_field_16"=>["", "10", "12", "30"],
|
62
|
+
"random_field_17"=>"0", "tag_list"=>["tag 1", "tag 2", "tag 3"],
|
63
|
+
"random_field_19"=>"506", "position"=>"23",
|
64
|
+
"random_field_20"=>{"0"=>{"value"=>"", "pid"=>"2"}},
|
65
|
+
"random_field_21"=>"1", "random_field_22"=>"1", "random_field_23"=>"1",
|
66
|
+
"random_field_24"=>"2fsasd", "random_field_25"=>{"value"=>"sdfafsd"},
|
67
|
+
"random_field_26"=>"", "random_field_27"=>"",
|
68
|
+
"random_field_28"=>"1", "random_field_29"=>"fadsfds",
|
69
|
+
"random_field_30"=>{"name"=>"Tim Teseterson", "random_field_97"=>"", "random_field_98"=>"", "id"=>"1234"},
|
70
|
+
"random_field_31"=>"1730", "random_field_116"=>"1", "random_field_117"=>"1", "random_field_118"=>"0",
|
71
|
+
"random_field_32"=>"", "random_field_33"=>"",
|
72
|
+
"random_field_34"=>{"title_tag"=>"", "description"=>"", "h1"=>""}
|
73
|
+
expected_format = [:random_field_1, :random_field_2, :random_field_3, :random_field_4, :random_field_5, :random_field_6, :random_field_7,
|
74
|
+
:random_field_8, :random_field_9, :random_field_10, :random_field_11, :random_field_12, :random_field_13,
|
75
|
+
:random_field_14, :random_field_15, {:random_field_16 => []}, :random_field_17, {:tag_list => []}, :random_field_19, :position,
|
76
|
+
{:random_field_20 => [:value, :pid, :id]}, :random_field_21, :random_field_22, :random_field_23,
|
77
|
+
:random_field_24,
|
78
|
+
{:random_field_25 => [:value] }, :random_field_26, :random_field_27, :random_field_28, :random_field_29,
|
79
|
+
{:random_field_30 => [:name, :random_field_97, :random_field_98, :id]},
|
80
|
+
:random_field_31, :random_field_116, :random_field_117, :random_field_118, :random_field_32,
|
81
|
+
:random_field_33, {:random_field_34 => [:title_tag, :description, :h1]}]
|
82
|
+
params = ActionController::Parameters.new(product: inner_params )
|
83
|
+
# sanity check that our expected format indeed does extract the inner_params out
|
84
|
+
expect(params.require(:product).permit(expected_format)).to eql inner_params
|
85
|
+
@object.expects(:params).returns params
|
86
|
+
expect(@object.suggested_strong_parameters_format(:product)).to eql expected_format
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should be able to suggest the appropriate format for a third complex example from work (with field names randomized)" do
|
90
|
+
inner_params = HashWithIndifferentAccess.new "random_field_1"=>"1", "random_field_3"=>"", "random_field_4"=>"", "random_field_5"=>"1", "random_field_6"=>"1", "random_field_7"=>"0",
|
91
|
+
"random_field_8"=>{"random_field_40"=>"", "url"=>"http://www.google.com", "random_field_9"=>"", "random_field_10"=>"gi",
|
92
|
+
"random_field_11"=>"", "id"=>"1234"},
|
93
|
+
"random_field_12"=>{"created_by"=>"1234", "random_field_85"=>"true", "random_field_108"=>"", "random_field_109"=>"",
|
94
|
+
"random_field_13"=>"", "random_field_98"=>"", "random_field_110"=>"", "random_field_97"=>"",
|
95
|
+
"id"=>"1234"},
|
96
|
+
"random_field_14"=>"",
|
97
|
+
"random_field_15"=>{"random_field_16"=>"", "id"=>"1234"},
|
98
|
+
"random_field_17"=>"",
|
99
|
+
"random_field_18"=>{"0"=>{"random_field_19"=>"1", "random_field_20"=>"", "random_field_21"=>"",
|
100
|
+
"random_field_22"=>"", "random_field_23"=>"", "random_field_24"=>"", "random_field_25"=>"1", "id"=>"1234"}},
|
101
|
+
"random_field_26"=>{"random_field_27"=>"", "random_field_28"=>"", "random_field_29"=>"", "id"=>"1234"},
|
102
|
+
"random_field_30"=>"1234", "random_field_31"=>"0", "random_field_32"=>"100.0", "random_field_33"=>"other", "random_field_34"=>"2011-01-20",
|
103
|
+
"random_field_35"=>"", "random_field_36"=>"", "random_field_37"=>"0", "random_field_38"=>"1",
|
104
|
+
"random_field_39"=>{"0"=>{"random_field_40"=>"random_field_40 1", "value"=>"0", "id"=>"1"},
|
105
|
+
"1"=>{"random_field_40"=>"random_field_40 2", "value"=>""},
|
106
|
+
"2"=>{"random_field_40"=>"random_field_40 3", "value"=>"value 3", "id"=>"2"},
|
107
|
+
"3"=>{"random_field_40"=>"random_field_40 4", "value"=>"value 4", "id"=>"3"},
|
108
|
+
"4"=>{"random_field_40"=>"random_field_40 5", "value"=>"http://www.google.com", "id"=>"4"},
|
109
|
+
"5"=>{"random_field_40"=>"random_field_40 6", "value"=>"0", "id"=>"5"},
|
110
|
+
"6"=>{"random_field_40"=>"random_field_40 7", "value"=>"0", "id"=>"6"},
|
111
|
+
"7"=>{"random_field_40"=>"random_field_40 8", "value"=>"0", "id"=>"7"},
|
112
|
+
"8"=>{"random_field_40"=>"random_field_40 9", "value"=>"0", "id"=>"8"},
|
113
|
+
"9"=>{"random_field_40"=>"random_field_40 10", "value"=>"0", "id"=>"9"},
|
114
|
+
"10"=>{"random_field_40"=>"random_field_40 11", "value"=>"0", "id"=>"10"},
|
115
|
+
"11"=>{"random_field_40"=>"random_field_40 12", "value"=>"0", "id"=>"11"},
|
116
|
+
"12"=>{"random_field_40"=>"random_field_40 13", "value"=>"0", "id"=>"12"},
|
117
|
+
"13"=>{"random_field_40"=>"random_field_40 14", "value"=>"some value", "id"=>"13"}},
|
118
|
+
"random_field_41"=>"0", "random_field_42"=>"0", "random_field_43"=>"0", "random_field_44"=>"0", "random_field_45"=>"0", "random_field_46"=>"0", "random_field_47"=>"0", "random_field_48"=>"0", "random_field_49"=>"1",
|
119
|
+
"random_field_50"=>"0",
|
120
|
+
"random_field_51"=>{"random_field_52"=>"0", "random_field_53"=>"1", "random_field_54"=>"0", "random_field_55"=>"0", "random_field_56"=>"0", "id"=>"1234"},
|
121
|
+
"random_field_57"=>"0", "random_field_58"=>"", "random_field_59"=>"0", "random_field_60"=>"0", "random_field_61"=>"0", "random_field_62"=>"1",
|
122
|
+
"random_field_63"=>"0", "random_field_64"=>"0", "random_field_65"=>{"random_field_66"=>""}, "random_field_67"=>"", "random_field_68"=>["1", "2"],
|
123
|
+
"random_field_69"=>"",
|
124
|
+
"random_field_70"=>{"0"=>{"random_field_13"=>"", "random_field_71(1i)"=>"2000", "random_field_71(2i)"=>"1",
|
125
|
+
"random_field_71(3i)"=>"1", "random_field_71(4i)"=>"1", "random_field_71(5i)"=>"1", "random_field_71(6i)"=>"00",
|
126
|
+
"random_field_72"=>{"random_field_73"=>"1234", "random_field_74(1i)"=>"2000", "random_field_74(2i)"=>"1", "random_field_74(3i)"=>"1", "random_field_74(4i)"=>"1", "random_field_74(5i)"=>"1", "id"=>"1234"},
|
127
|
+
"e_attributes"=>{"0"=>{"random_field_40"=>"random_field_40 1", "value"=>"3.5"},
|
128
|
+
"1"=>{"random_field_40"=>"random_field_40 2", "value"=>"0", "id"=>"1234"},
|
129
|
+
"2"=>{"random_field_40"=>"random_field_40 3", "value"=>"0", "id"=>"1234"},
|
130
|
+
"3"=>{"random_field_40"=>"random_field_40 4", "value"=>"http://www.flickr.com"}},
|
131
|
+
"random_field_75"=>"", "value"=>"1", "random_field_2"=>"1", "random_field_76"=>{"0"=>{"random_field_77"=>"0.0", "id"=>"1234"}},
|
132
|
+
"random_field_78"=>"n/a", "random_field_79"=>"-1", "random_field_80"=>"n/a", "random_field_81"=>"0",
|
133
|
+
"random_field_82"=>"1", "random_field_83"=>"1", "random_field_84"=>"1", "random_field_85"=>"1", "random_field_6"=>"1",
|
134
|
+
"random_field_115"=>"1", "random_field_114"=>"", "random_field_113"=>"", "random_field_112"=>"", "random_field_111"=>"false", "_destroy"=>"false", "id"=>"1234"}},
|
135
|
+
"random_field_79"=>"-1", "random_field_86"=>"0", "random_field_87"=>"1", "random_field_88"=>"No", "random_field_89"=>"1",
|
136
|
+
"random_field_90"=>"random_field_90",
|
137
|
+
"random_field_91"=>"",
|
138
|
+
"random_field_92"=>"",
|
139
|
+
"random_field_93"=>{"0"=>{"random_field_94"=>"0", "_destroy"=>"0", "id"=>"1234"},
|
140
|
+
"1"=>{"random_field_94"=>"0", "_destroy"=>"0", "id"=>"1234"},
|
141
|
+
"2"=>{"random_field_94"=>"1", "_destroy"=>"1", "random_field_98"=>""},
|
142
|
+
"3"=>{"random_field_94"=>"2", "_destroy"=>"1"},
|
143
|
+
"4"=>{"random_field_94"=>"3", "_destroy"=>"1", "random_field_97"=>""},
|
144
|
+
"5"=>{"random_field_94"=>"4", "_destroy"=>"1", "random_field_95"=>"0", "random_field_96"=>""}},
|
145
|
+
"random_field_102"=>{"0"=>{"random_field_20"=>"", "random_field_21"=>"", "random_field_22"=>"", "random_field_23"=>"", "random_field_24"=>"", "random_field_25"=>"1", "random_field_97"=>"",
|
146
|
+
"random_field_85"=>"0", "id"=>"2134", "_destroy"=>"false"}},
|
147
|
+
"random_field_99"=>"", "random_field_100"=>"0", "random_field_101"=>"0", "random_field_103"=>{"random_field_104"=>"", "random_field_105"=>"", "random_field_106"=>""}, "random_field_107"=>"edit"
|
148
|
+
params = ActionController::Parameters.new(product: inner_params )
|
149
|
+
expected_format = [:random_field_1, :random_field_3, :random_field_4, :random_field_5, :random_field_6, :random_field_7,
|
150
|
+
{:random_field_8=>[:random_field_40, :url, :random_field_9, :random_field_10, :random_field_11, :id]},
|
151
|
+
{:random_field_12=>[:created_by, :random_field_85, :random_field_108, :random_field_109, :random_field_13, :random_field_98, :random_field_110, :random_field_97, :id]},
|
152
|
+
:random_field_14, {:random_field_15=>[:random_field_16, :id]}, :random_field_17,
|
153
|
+
{:random_field_18=>[:random_field_19, :random_field_20, :random_field_21, :random_field_22, :random_field_23, :random_field_24, :random_field_25, :id]},
|
154
|
+
{:random_field_26=>[:random_field_27, :random_field_28, :random_field_29, :id]}, :random_field_30, :random_field_31,
|
155
|
+
:random_field_32, :random_field_33, :random_field_34, :random_field_35, :random_field_36, :random_field_37, :random_field_38,
|
156
|
+
{:random_field_39=>[:random_field_40, :value, :id]}, :random_field_41, :random_field_42, :random_field_43, :random_field_44, :random_field_45, :random_field_46, :random_field_47,
|
157
|
+
:random_field_48, :random_field_49, :random_field_50, {:random_field_51=>[:random_field_52, :random_field_53, :random_field_54, :random_field_55, :random_field_56, :id]},
|
158
|
+
:random_field_57, :random_field_58, :random_field_59, :random_field_60, :random_field_61, :random_field_62, :random_field_63, :random_field_64,
|
159
|
+
{:random_field_65=>[:random_field_66]}, :random_field_67, {:random_field_68=>[]}, :random_field_69,
|
160
|
+
{:random_field_70=>[:random_field_13, :"random_field_71(1i)", :"random_field_71(2i)", :"random_field_71(3i)", :"random_field_71(4i)", :"random_field_71(5i)", :"random_field_71(6i)",
|
161
|
+
{:random_field_72=>[:random_field_73, :"random_field_74(1i)", :"random_field_74(2i)", :"random_field_74(3i)", :"random_field_74(4i)", :"random_field_74(5i)", :id]},
|
162
|
+
{:e_attributes=>[:random_field_40, :value, :id]}, :random_field_75, :value, :random_field_2, {:random_field_76=>[:random_field_77, :id]},
|
163
|
+
:random_field_78, :random_field_79, :random_field_80, :random_field_81, :random_field_82, :random_field_83,
|
164
|
+
:random_field_84, :random_field_85, :random_field_6, :random_field_115, :random_field_114, :random_field_113, :random_field_112, :random_field_111, :_destroy, :id]},
|
165
|
+
:random_field_79, :random_field_86, :random_field_87, :random_field_88, :random_field_89, :random_field_90,
|
166
|
+
:random_field_91, :random_field_92, {:random_field_93=>[:random_field_94, :_destroy, :id, :random_field_98, :random_field_97, :random_field_95, :random_field_96]},
|
167
|
+
{:random_field_102=>[:random_field_20, :random_field_21, :random_field_22, :random_field_23, :random_field_24, :random_field_25, :random_field_97, :random_field_85, :id, :_destroy]}, :random_field_99, :random_field_100, :random_field_101,
|
168
|
+
{:random_field_103=>[:random_field_104, :random_field_105, :random_field_106]}, :random_field_107]
|
169
|
+
@object.expects(:params).returns params
|
170
|
+
# sanity check that our expected format indeed does extract the inner_params out
|
171
|
+
expect(params.require(:product).permit(expected_format)).to eql inner_params
|
172
|
+
expect(@object.suggested_strong_parameters_format(:product)).to eql expected_format
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should combine the attributes of nested hashes" do
|
176
|
+
inner_params = HashWithIndifferentAccess.new :products => [{:id => 50, :name => "Name 1"},
|
177
|
+
{:id => 51, :name => "Name 2", :description => "My description"},
|
178
|
+
{:name => "Name 3", :caption => "My caption"}]
|
179
|
+
params = ActionController::Parameters.new(object: inner_params )
|
180
|
+
expected_format = [{:products => [:id, :name, :description, :caption]}]
|
181
|
+
@object.expects(:params).returns params
|
182
|
+
# sanity check that our expected format indeed does extract the inner_params out
|
183
|
+
expect(params.require(:object).permit(expected_format)).to eql inner_params
|
184
|
+
expect(@object.suggested_strong_parameters_format(:object)).to eql expected_format
|
185
|
+
end
|
186
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'strong_like_bull/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "strong_like_bull"
|
8
|
+
spec.version = StrongLikeBull::VERSION
|
9
|
+
spec.authors = ["Andrew Hunter"]
|
10
|
+
spec.email = ["andrew.hunter@livingsocial.com"]
|
11
|
+
spec.summary = %q{Upgrade to strong parameters the easy way}
|
12
|
+
spec.description = %q{Makes it super simple to add strong parameters into your application by examining request parameters and recommending what feeds should be permitted.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 3.0.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
|
+
spec.add_development_dependency "rspec-rails"
|
27
|
+
spec.add_development_dependency "mocha"
|
28
|
+
spec.add_development_dependency "byebug"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strong_like_bull
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Hunter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
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
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mocha
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Makes it super simple to add strong parameters into your application
|
112
|
+
by examining request parameters and recommending what feeds should be permitted.
|
113
|
+
email:
|
114
|
+
- andrew.hunter@livingsocial.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".ruby-gemset"
|
121
|
+
- ".ruby-version"
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/strong_like_bull.rb
|
127
|
+
- lib/strong_like_bull/version.rb
|
128
|
+
- spec/integration/strong_like_bull_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- strong_like_bull.gemspec
|
131
|
+
homepage: ''
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.4.3
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Upgrade to strong parameters the easy way
|
155
|
+
test_files:
|
156
|
+
- spec/integration/strong_like_bull_spec.rb
|
157
|
+
- spec/spec_helper.rb
|