any_strong_parameter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42ac48704f7c2b7cfa7332895fa2b63574c395de
4
+ data.tar.gz: efa42a4e31ca9f223732a8cef084bb3b659d35a9
5
+ SHA512:
6
+ metadata.gz: ad2cb3bbafecbca7a3a66cbab5ca237ad59c2e87e02a6c34a5761c2b35859df5237b029241d5cb2671964bb5bd179e300ad67c85acf3df48af47aa46596950f7
7
+ data.tar.gz: f60c5b6b9e1bd309e278a015b5f0657ecb3bd26b4f419cf9855e5a5fde5397ae2571016f8ff0ad404a90ba22f6f49979531734c9143f370711649dbfe7d545bd
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/config/database.yml
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
7
+ spec/dummy/.sass-cache
8
+ spec/dummy/public/uploads/*
9
+ tmp/*
10
+ coverage/*
11
+ *.gem
12
+ Gemfile.lock
13
+ spec/dummy/db/test.sqlite3
14
+ gemfiles/*.lock
15
+ .ruby-gemset
16
+ spec/internal
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise 'rails-4' do
2
+ gem 'rails', '4.2.7.1'
3
+ end
4
+
5
+ appraise 'rails-5' do
6
+ gem 'rails', '5.0.0'
7
+ end
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ any_strong_parameter
2
+ ====
3
+
4
+ This is a gemified version of the pull request in https://github.com/rails/strong_parameters/pull/231, tested with Rails 4.2.7.1 and Rails 5.0.0.
5
+
6
+ [This comment](https://github.com/rails/rails/issues/9454#issuecomment-242847373) explains it pretty well:
7
+
8
+ ![img](http://take.ms/hKtWKi)
9
+
10
+ ### Usage
11
+
12
+ ```rb
13
+ # Given a params hash:
14
+ #
15
+ # {
16
+ # product: {
17
+ # name: 'Foo',
18
+ # data: {
19
+ # custom: 'metadata',
20
+ # goes: 'here'
21
+ # }
22
+ # }
23
+ # }
24
+
25
+ def product_params
26
+ params.require(:product).permit(
27
+ :name,
28
+ :description,
29
+ data: AnyStrongParameter::ANY
30
+ )
31
+ end
32
+
33
+ # =>
34
+ # {
35
+ # name: 'Foo',
36
+ # data: {
37
+ # custom: 'metadata',
38
+ # goes: 'here'
39
+ # }
40
+ # }
41
+ ```
@@ -0,0 +1,23 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'any_strong_parameter'
5
+ s.version = '0.0.1'
6
+
7
+ s.required_ruby_version = Gem::Requirement.new('>= 2.0.0')
8
+ s.authors = ['Adam Becker']
9
+ s.summary = 'Gem of https://github.com/rails/strong_parameters/pull/231'
10
+ s.email = 'adam@dobt.co'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {features,spec}/*`.split("\n")
15
+
16
+ s.homepage = 'https://github.com/ajb/any_strong_parameter'
17
+
18
+ s.add_dependency 'rails', '>= 4.0.0'
19
+
20
+ s.add_development_dependency 'appraisal'
21
+ s.add_development_dependency 'combustion'
22
+ s.add_development_dependency 'rspec-rails'
23
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "4.2.7.1"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "5.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,25 @@
1
+ module AnyStrongParameter
2
+ ANY = :*
3
+
4
+ class Engine < Rails::Engine
5
+ initializer 'any_strong_parameter' do
6
+ ActionController::Parameters.prepend(
7
+ Module.new do
8
+ EMPTY_ARRAY = []
9
+ def hash_filter(params, filter)
10
+ filter = filter.with_indifferent_access
11
+
12
+ slice(*filter.keys).each do |key, value|
13
+ if filter[key] == AnyStrongParameter::ANY
14
+ filter.delete(key)
15
+ params[key] = value
16
+ end
17
+ end
18
+
19
+ super(params, filter)
20
+ end
21
+ end
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,67 @@
1
+ require 'combustion'
2
+ Combustion.initialize! :action_controller
3
+ require 'rspec-rails'
4
+
5
+ RSpec.describe ActionController::Parameters do
6
+ let(:params) do
7
+ ActionController::Parameters.new({
8
+ resource: {
9
+ id: 'foo',
10
+ custom_json: {
11
+ bar: 'baz',
12
+ qux: {
13
+ quux: 1
14
+ }
15
+ }
16
+ }
17
+ })
18
+ end
19
+
20
+ it 'preserves the old behavior' do
21
+ permitted = params.require(:resource).permit(
22
+ custom_json: [:bar]
23
+ )
24
+
25
+ expect(permitted[:id]).to eq nil
26
+
27
+ expect(permitted[:custom_json]).to eq(
28
+ ActionController::Parameters.new(
29
+ bar: 'baz'
30
+ ).permit!
31
+ )
32
+ end
33
+
34
+ it 'implmements AnyStrongParameter' do
35
+ permitted = params.require(:resource).permit(
36
+ custom_json: AnyStrongParameter::ANY
37
+ )
38
+
39
+ expect(permitted[:id]).to eq nil
40
+
41
+ expect(permitted[:custom_json]).to eq(
42
+ ActionController::Parameters.new(
43
+ bar: 'baz',
44
+ qux: {
45
+ quux: 1
46
+ }
47
+ ).permit!
48
+ )
49
+ end
50
+
51
+ it 'implements the test from https://github.com/rails/strong_parameters/pull/231' do
52
+ params = ActionController::Parameters.new({
53
+ :resource => {
54
+ :id => 'foo',
55
+ :custom_json => {
56
+ :bar => 'baz',
57
+ :qux => {
58
+ :quux => 1
59
+ }
60
+ }
61
+ }
62
+ })
63
+ permitted = params.permit(:resource => [{ :custom_json => AnyStrongParameter::ANY }])
64
+ expect(permitted[:resource][:id]).to be_nil
65
+ expect(permitted[:resource][:custom_json]).to_not be_nil
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: any_strong_parameter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Becker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-30 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: 4.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: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: combustion
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: rspec-rails
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
+ description:
70
+ email: adam@dobt.co
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".ruby-version"
77
+ - Appraisals
78
+ - Gemfile
79
+ - README.md
80
+ - any_strong_parameter.gemspec
81
+ - gemfiles/rails_4.gemfile
82
+ - gemfiles/rails_5.gemfile
83
+ - lib/any_strong_parameter.rb
84
+ - spec/any_strong_parameter_spec.rb
85
+ homepage: https://github.com/ajb/any_strong_parameter
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 2.0.0
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.5.1
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Gem of https://github.com/rails/strong_parameters/pull/231
109
+ test_files:
110
+ - spec/any_strong_parameter_spec.rb