strong_like_bull 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8b0393c6ceebf9d7248d563b6dd8230fbbe55c25
4
- data.tar.gz: d696c836d5f3e5a79c34ca7d56b70c3e89f89a8e
2
+ SHA256:
3
+ metadata.gz: 8d77c3395f1e522af013ce0b2881cdaaee74d783a0b29484d414f41511682692
4
+ data.tar.gz: 14230a740a04f9f4c04aa0b55d35009e1de61ee0ddf7965e97bea66a0dcc9663
5
5
  SHA512:
6
- metadata.gz: e53260b390969696c03c0d8de9d9418a749d4368012a9522ca0c87e48843281bce37918b8a64c96e12177e66bd90c514470f02ae8ca76ca4e77c8e2494dd2bf4
7
- data.tar.gz: 018f697777a1727559713549c7c2dfa5838cf59a22dddacdee5d1c25fdc9d78d25c6afdad5a9e23d725dc83641ffb6d86456890fe6974a92dd1de0eb62322194
6
+ metadata.gz: 595c78dffff3b1268959e83106282d15892b8dd9a22a59153afa27e03ada98e97ad8028dbf499f0001297c46fc94d4b40a507679d4ee93aa63f4905b55cd1946
7
+ data.tar.gz: 151fb4f1b60fcb3d6a04475f711d31643ac03b0c00f91262e8b3974d3f9f263c1c441e23eafc9af6030063bbc3b14083e68fa663b8fb8a8295d09d082110a8d3
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.7.0
@@ -0,0 +1,2 @@
1
+ 0.0.2
2
+ * StrongLikeBull now properly works on Rails >= 5
data/Gemfile CHANGED
@@ -2,3 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in strong_like_bull.gemspec
4
4
  gemspec
5
+
6
+ gem "rails", github: "rails/rails", branch: "6-0-stable"
7
+
8
+ group :development, :test do
9
+ gem "rspec", "~> 3.6.0"
10
+ gem "byebug"
11
+ end
data/README.md CHANGED
@@ -21,13 +21,14 @@ Or install it yourself as:
21
21
  ## Usage
22
22
 
23
23
  In application_controller.rb or a specific controller, add the following line:
24
+
24
25
  include StrongLikeBull
25
26
 
26
27
  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
 
28
29
  def CONTROLLER_ACTION
29
- log_suggested_strong_parameters_format(PARAMETER_NAME_TO_INSPECT)
30
- # perform action
30
+ log_suggested_strong_parameters_format(PARAMETER_NAME_TO_INSPECT)
31
+ # perform action
31
32
  end
32
33
 
33
34
  When the controller action gets hit, it will log the recommended strong params permitted params to use in the following format:
@@ -44,8 +45,8 @@ StrongLikeBull only serves to recommend params to permit based on what is passed
44
45
  If you wanted the recommended params to permit for the update action of a Posts Controller, it would like:
45
46
 
46
47
  def update
47
- log_suggested_strong_parameters_format(:post)
48
- # perform update
48
+ log_suggested_strong_parameters_format(:post)
49
+ # perform update
49
50
  end
50
51
 
51
52
  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:
@@ -59,6 +60,6 @@ If those request parameters were passed to the update action above, we'd see the
59
60
  Using that suggested format, we could then modify our update action to the following:
60
61
 
61
62
  def update
62
- permitted_params = params.require(:post).permit [:name, {:tags=>[]}, :description]
63
- # perform update
63
+ permitted_params = params.require(:post).permit [:name, {:tags=>[]}, :description]
64
+ # perform update
64
65
  end
@@ -6,13 +6,14 @@ module StrongLikeBull
6
6
  end
7
7
 
8
8
  def suggested_strong_parameters_format(key)
9
- hash = params[key]
9
+ hash = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
10
+ hash = hash[key]
10
11
  recursive_suggested_strong_parameters_format(hash) if hash
11
12
  end
12
13
 
13
14
  private
14
15
  def recursive_suggested_strong_parameters_format(object)
15
- if object.is_a? Hash
16
+ if object.is_a?(Hash)
16
17
  if object.keys.first.match(/^\d+$/)
17
18
  hash = {}
18
19
  object.values.each do |value|
@@ -1,3 +1,3 @@
1
1
  module StrongLikeBull
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -2,19 +2,20 @@ require "spec_helper"
2
2
  require "action_controller"
3
3
 
4
4
  describe "StrongLikeBull" do
5
- before :each do
6
- @object = Object.new
7
- @object.extend(StrongLikeBull)
8
- end
5
+ subject {
6
+ Object.new.tap do |object|
7
+ object.extend(StrongLikeBull)
8
+ end
9
+ }
9
10
 
10
11
  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
12
  inner_params = HashWithIndifferentAccess.new username: "john", data: { foo: "bar" }
12
13
  expected_format = [:username, data: [:foo]]
13
14
  params = ActionController::Parameters.new(user: inner_params)
14
15
  # 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
16
+ expect(params.require(:user).permit(expected_format)).to match_hash inner_params
17
+ allow(subject).to receive(:params).and_return params
18
+ expect(subject.suggested_strong_parameters_format(:user)).to eql expected_format
18
19
  end
19
20
 
20
21
  it "should be able to suggest the appropriate format for the nested params example from https://github.com/rails/strong_parameters/" do
@@ -24,9 +25,9 @@ describe "StrongLikeBull" do
24
25
  expected_format = [:name, {:emails => []}, :friends => [ :name, { :family => [ :name ] }, { :hobbies => [] }]]
25
26
  params = ActionController::Parameters.new(user: inner_params )
26
27
  # 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
28
+ expect(params.require(:user).permit(expected_format)).to match_hash inner_params
29
+ allow(subject).to receive(:params).and_return params
30
+ expect(subject.suggested_strong_parameters_format(:user)).to eql expected_format
30
31
  end
31
32
 
32
33
  it "should be able to suggest the appropriate format for a complex example from work (with field names randomized)" do
@@ -45,9 +46,9 @@ describe "StrongLikeBull" do
45
46
  {:random_field_18=>[:random_field_19, :value, :id, {:random_field_20=>[:id]}]}]
46
47
  params = ActionController::Parameters.new(variant: inner_params )
47
48
  # 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
49
+ expect(params.require(:variant).permit(expected_format)).to match_hash inner_params
50
+ allow(subject).to receive(:params).and_return params
51
+ expect(subject.suggested_strong_parameters_format(:variant)).to eql expected_format
51
52
  end
52
53
 
53
54
  it "should be able to suggest the appropriate format for a second complex example from work (with field names randomized)" do
@@ -81,9 +82,9 @@ describe "StrongLikeBull" do
81
82
  :random_field_33, {:random_field_34 => [:title_tag, :description, :h1]}]
82
83
  params = ActionController::Parameters.new(product: inner_params )
83
84
  # 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
85
+ expect(params.require(:product).permit(expected_format)).to match_hash inner_params
86
+ allow(subject).to receive(:params).and_return params
87
+ expect(subject.suggested_strong_parameters_format(:product)).to eql expected_format
87
88
  end
88
89
 
89
90
  it "should be able to suggest the appropriate format for a third complex example from work (with field names randomized)" do
@@ -166,21 +167,25 @@ describe "StrongLikeBull" do
166
167
  :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
168
  {: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
169
  {:random_field_103=>[:random_field_104, :random_field_105, :random_field_106]}, :random_field_107]
169
- @object.expects(:params).returns params
170
+ allow(subject).to receive(:params).and_return params
170
171
  # 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
172
+ expect(params.require(:product).permit(expected_format)).to match_hash inner_params
173
+ expect(subject.suggested_strong_parameters_format(:product)).to eql expected_format
173
174
  end
174
175
 
175
176
  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 )
177
+ inner_params = {
178
+ products: [
179
+ {:id => 50, :name => "Name 1"},
180
+ {:id => 51, :name => "Name 2", :description => "My description"},
181
+ {:name => "Name 3", :caption => "My caption"}
182
+ ]
183
+ }
184
+ params = ActionController::Parameters.new(object: inner_params)
180
185
  expected_format = [{:products => [:id, :name, :description, :caption]}]
181
- @object.expects(:params).returns params
186
+ allow(subject).to receive(:params).and_return params
182
187
  # 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
188
+ expect(params.require(:object).permit(expected_format)).to match_hash inner_params
189
+ expect(subject.suggested_strong_parameters_format(:object)).to eql expected_format
185
190
  end
186
191
  end
@@ -3,7 +3,11 @@ require 'bundler/setup'
3
3
  require 'byebug'
4
4
  require 'strong_like_bull'
5
5
 
6
+ RSpec::Matchers.define :match_hash do |expected|
7
+ match { |actual| expect(actual.to_unsafe_h).to match(expected) }
8
+ end
9
+
6
10
  RSpec.configure do |config|
7
- config.mock_with :mocha
11
+ config.mock_with :rspec
8
12
  end
9
13
 
@@ -4,26 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'strong_like_bull/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "strong_like_bull"
7
+ spec.name = 'strong_like_bull'
8
8
  spec.version = StrongLikeBull::VERSION
9
- spec.authors = ["Andrew Hunter"]
10
- spec.email = ["andrew.hunter@livingsocial.com"]
9
+ spec.authors = ['Andrew Hunter']
10
+ spec.email = ['andrew.hunter@livingsocial.com']
11
11
  spec.summary = %q{Upgrade to strong parameters the easy way}
12
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"
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
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"
21
+ spec.add_dependency 'rails', '>= 3.0.0'
29
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: strong_like_bull
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Hunter
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-11 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,90 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
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
27
  description: Makes it super simple to add strong parameters into your application
112
28
  by examining request parameters and recommending what feeds should be permitted.
113
29
  email:
@@ -117,8 +33,8 @@ extensions: []
117
33
  extra_rdoc_files: []
118
34
  files:
119
35
  - ".gitignore"
120
- - ".ruby-gemset"
121
36
  - ".ruby-version"
37
+ - CHANGELOG.md
122
38
  - Gemfile
123
39
  - LICENSE.txt
124
40
  - README.md
@@ -132,7 +48,7 @@ homepage: ''
132
48
  licenses:
133
49
  - MIT
134
50
  metadata: {}
135
- post_install_message:
51
+ post_install_message:
136
52
  rdoc_options: []
137
53
  require_paths:
138
54
  - lib
@@ -147,9 +63,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
63
  - !ruby/object:Gem::Version
148
64
  version: '0'
149
65
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.4.3
152
- signing_key:
66
+ rubygems_version: 3.1.2
67
+ signing_key:
153
68
  specification_version: 4
154
69
  summary: Upgrade to strong parameters the easy way
155
70
  test_files:
@@ -1 +0,0 @@
1
- strong_like_bull