action_params_sanitizer 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 +22 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +154 -0
- data/Rakefile +10 -0
- data/action_params_sanitizer.gemspec +29 -0
- data/lib/action_params_sanitizer.rb +15 -0
- data/lib/action_params_sanitizer/base.rb +4 -0
- data/lib/action_params_sanitizer/concerns/resource_param_builder.rb +39 -0
- data/lib/action_params_sanitizer/concerns/single_param_builder.rb +31 -0
- data/lib/action_params_sanitizer/helpers/controller.rb +24 -0
- data/lib/action_params_sanitizer/helpers/sanitizer_class_builder.rb +23 -0
- data/lib/action_params_sanitizer/railtie.rb +9 -0
- data/lib/action_params_sanitizer/version.rb +3 -0
- data/spec/lib/action_params_sanitizer/base_spec.rb +14 -0
- data/spec/lib/action_params_sanitizer/concerns/resource_param_spec.rb +38 -0
- data/spec/lib/action_params_sanitizer/concerns/single_param_spec.rb +36 -0
- data/spec/lib/action_params_sanitizer/helpers/controller_spec.rb +24 -0
- data/spec/lib/action_params_sanitizer/helpers/sanitizer_class_builder_spec.rb +29 -0
- data/spec/spec_helper.rb +22 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38d2b8dd48af0275ab3810b63f04fe4aabdca560
|
4
|
+
data.tar.gz: 50a8184913e36c7fb221fb527b3fcc55394ed0b5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48bb4d1ef1d127e094f1d69f84012f2fb59334f83667f317607b2008d2136d5103266e5e2cef4e606dc221dfa5316e2ce4896307c30fc87b26ee4a553bea82c9
|
7
|
+
data.tar.gz: 62bdfeaca63230ac6bbb26b08d6fab7c82e8e17a0040ecf72390d86a86e9f4bee1205dfb28ec6fffa07b445aec054778fe01190448372ab7841405dca4a613d1
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- 2.1.2
|
6
|
+
|
7
|
+
script: 'CODECLIMATE_REPO_TOKEN=85a4bf6c462720b53a31ea40d510834bb603149c27b5c1759cc9d91b73963048 bundle exec rake'
|
8
|
+
|
9
|
+
addons:
|
10
|
+
code_climate:
|
11
|
+
repo_token: 85a4bf6c462720b53a31ea40d510834bb603149c27b5c1759cc9d91b73963048
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sergey Gernyak
|
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,154 @@
|
|
1
|
+
# ActionParamsSanitizer
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/alterego-labs/action_params_sanitizer/badges/gpa.svg)](https://codeclimate.com/github/alterego-labs/action_params_sanitizer)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/alterego-labs/action_params_sanitizer/badges/coverage.svg)](https://codeclimate.com/github/alterego-labs/action_params_sanitizer)
|
5
|
+
[![Build Status](https://travis-ci.org/alterego-labs/action_params_sanitizer.svg)](https://travis-ci.org/alterego-labs/action_params_sanitizer)
|
6
|
+
|
7
|
+
Pretty simple objectifying wrapper for action params.
|
8
|
+
|
9
|
+
Allows to describe the input parameters with a simple DSL. In result you take:
|
10
|
+
|
11
|
+
1. The data encapsulation
|
12
|
+
2. Work with the parameters as an object
|
13
|
+
3. Easy testable service object
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'action_params_sanitizer'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install action_params_sanitizer
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Defining new params sanitizers
|
32
|
+
|
33
|
+
Default place for params wrappers is `app/params_sanitizers`. By convention all
|
34
|
+
wrappers of one controller must be contained in namespace accordingly to a
|
35
|
+
controller name. Name of class is accordingly to a action name. For
|
36
|
+
example:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class Users::CreateParamsSanitizer < ActionParamsSanitizer::Base
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
And the class above must be contained in next folder structure `app/params_sanitizers/users/create_params_sanitizer.rb`.
|
44
|
+
|
45
|
+
### Describe single param
|
46
|
+
|
47
|
+
For example, input params is:
|
48
|
+
|
49
|
+
```json
|
50
|
+
{
|
51
|
+
some_key: :some_value,
|
52
|
+
another_key: :another_value
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
For describing this case use `ActionParamsSanitizer::Base.param` method:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
class Users::CreateParamsSanitizer < ActionParamsSanitizer::Base
|
60
|
+
param :some_key
|
61
|
+
param :another_key
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
Also you may passing keys array:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class Users::CreateParamsSanitizer < ActionParamsSanitizer::Base
|
69
|
+
param :some_key, :another_key
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
### Describe resource
|
74
|
+
|
75
|
+
For example, input params contains resource attributes:
|
76
|
+
|
77
|
+
```json
|
78
|
+
{
|
79
|
+
user:{
|
80
|
+
email: 'some@mail.com',
|
81
|
+
nickname: 'some_user'
|
82
|
+
}
|
83
|
+
}
|
84
|
+
```
|
85
|
+
|
86
|
+
For describing resource you must use
|
87
|
+
`ActionParamsSanitizer::Base.resource` method:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
class Users::CreateParamsSanitizer < ActionParamsSanitizer::Base
|
91
|
+
resource :user
|
92
|
+
end
|
93
|
+
```
|
94
|
+
|
95
|
+
By default all subparameters are permitted, but you can specify
|
96
|
+
permitted ones:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
class Users::CreateParamsSanitizer < ActionParamsSanitizer::Base
|
100
|
+
resource user: [:nickname]
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
Resource describing creates public method containing resource name and
|
105
|
+
`_params` prefix. Looking to example above it will be `user_params`
|
106
|
+
method.
|
107
|
+
|
108
|
+
### Using in controller
|
109
|
+
|
110
|
+
You may calling params sanitizers implicitly and explicitly.
|
111
|
+
|
112
|
+
Implicitly calling `create_params` somewhere in `UsersController` will
|
113
|
+
instantiate `Users::CreateParamsSanitizer` and return params object.
|
114
|
+
|
115
|
+
For calling explicitly see following example:
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class UsersController
|
119
|
+
private
|
120
|
+
|
121
|
+
def useful_params
|
122
|
+
Users::SomeAnotherParamsSanitizer.new(params)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
### Scoping single params
|
128
|
+
|
129
|
+
In some cases you want to extract single param from resource. Explicit
|
130
|
+
scope passing to single param definition will help you:
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
class Users::CreateParamsSanitizer < ActionParamsSanitizer::Base
|
134
|
+
resource :user
|
135
|
+
param :nickname, scope: -> { user_params }
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
Scope is a lambda where _self_ takes _Users::CreateParamsSanitizer_ instance.
|
140
|
+
|
141
|
+
## Further work
|
142
|
+
|
143
|
+
1. Default values for single param
|
144
|
+
2. Custom names
|
145
|
+
3. Prefix for scoped single params
|
146
|
+
4. Ability for permitting and single param access by user role
|
147
|
+
|
148
|
+
## Contributing
|
149
|
+
|
150
|
+
1. Fork it ( https://github.com/[my-github-username]/action_params_sanitizer/fork )
|
151
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
152
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
153
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
154
|
+
5. Create a new Pull Request
|
data/Rakefile
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 'action_params_sanitizer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "action_params_sanitizer"
|
8
|
+
spec.version = ActionParamsSanitizer::VERSION
|
9
|
+
spec.authors = ["Sergey Gernyak"]
|
10
|
+
spec.email = ["sergeg1990@gmail.com"]
|
11
|
+
spec.summary = %q{Pretty simple objectifying wrapper for action params}
|
12
|
+
spec.description = %q{Allows to describe the input parameters with a simple DSL}
|
13
|
+
spec.homepage = "https://github.com/alterego-labs/action_params_sanitizer"
|
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 "activesupport", ">= 4.0.4"
|
22
|
+
spec.add_dependency "actionpack", ">= 4.0.4"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec", "3.2.0"
|
27
|
+
spec.add_development_dependency "rspec-its", "1.2.0"
|
28
|
+
spec.add_development_dependency "pry-nav", "0.2.3"
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "action_params_sanitizer/version"
|
2
|
+
|
3
|
+
module ActionParamsSanitizer
|
4
|
+
autoload :Base, 'action_params_sanitizer/base.rb'
|
5
|
+
|
6
|
+
module Concerns
|
7
|
+
autoload :SingleParamBuilder, 'action_params_sanitizer/concerns/single_param_builder.rb'
|
8
|
+
autoload :ResourceParamBuilder, 'action_params_sanitizer/concerns/resource_param_builder.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
module Helpers
|
12
|
+
autoload :Controller, 'action_params_sanitizer/helpers/controller.rb'
|
13
|
+
autoload :SanitizerClassBuilder, 'action_params_sanitizer/helpers/sanitizer_class_builder.rb'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module ActionParamsSanitizer
|
2
|
+
module Concerns
|
3
|
+
module ResourceParamBuilder
|
4
|
+
def self.included(base)
|
5
|
+
base.send :extend, ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def resource(resource)
|
10
|
+
if resource.is_a? Hash
|
11
|
+
define_fetch_params_method(*resource.to_a.first)
|
12
|
+
else
|
13
|
+
define_fetch_params_method resource
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def define_fetch_params_method(resource_name, attributes = [])
|
20
|
+
class_eval make_fetch_param_method_code(resource_name, make_permit(attributes))
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_permit(attributes)
|
24
|
+
attributes.any? ? "(#{attributes})" : '!'
|
25
|
+
end
|
26
|
+
|
27
|
+
def make_fetch_param_method_code(resource_name, permit)
|
28
|
+
<<-CODE
|
29
|
+
def #{resource_name}_params
|
30
|
+
params.require(:#{resource_name}).permit#{permit}
|
31
|
+
end
|
32
|
+
CODE
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ActionParamsSanitizer
|
2
|
+
module Concerns
|
3
|
+
module SingleParamBuilder
|
4
|
+
def self.included(base)
|
5
|
+
base.send :extend, ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
DEFAULT_SCOPE = ->{ params }
|
10
|
+
|
11
|
+
def param(*names, scope: nil)
|
12
|
+
scope = scope || DEFAULT_SCOPE
|
13
|
+
define_single_params [*names], scope
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def define_single_params(names, scope)
|
19
|
+
names.each { |name| define_single_param_method(name, scope) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def define_single_param_method(name, scope)
|
23
|
+
define_method name do
|
24
|
+
self.instance_exec(&scope)[name]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ActionParamsSanitizer
|
2
|
+
module Helpers
|
3
|
+
module Controller
|
4
|
+
def method_missing(name, *args, &_block)
|
5
|
+
if params_fetching?(name)
|
6
|
+
build_params_sanitizer(name)
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def params_fetching?(name)
|
15
|
+
name =~ /_params$/
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_params_sanitizer(name)
|
19
|
+
klass = SanitizerClassBuilder.new(name, self.class.name).build_class
|
20
|
+
klass.new params
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ActionParamsSanitizer
|
2
|
+
module Helpers
|
3
|
+
class SanitizerClassBuilder < Struct.new(:method_name, :controller_name)
|
4
|
+
def build_class
|
5
|
+
"#{namespace}::#{sanitizer_class_name}".constantize
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def namespace
|
11
|
+
controller_name.to_s.gsub(/Controller$/, '')
|
12
|
+
end
|
13
|
+
|
14
|
+
def action
|
15
|
+
method_name.to_s.gsub(/_params$/, '')
|
16
|
+
end
|
17
|
+
|
18
|
+
def sanitizer_class_name
|
19
|
+
"#{action.capitalize}ParamsSanitizer"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActionParamsSanitizer::Base do
|
4
|
+
subject(:base_sanitizer) { described_class.new(params) }
|
5
|
+
|
6
|
+
let(:params) { ActionController::Parameters.new(raw_params) }
|
7
|
+
let(:raw_params) { {} }
|
8
|
+
|
9
|
+
it { is_expected.to respond_to :params }
|
10
|
+
|
11
|
+
context 'sets params properly' do
|
12
|
+
its(:params) { is_expected.to eq params }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class ResourceParamsSanitizer < ActionParamsSanitizer::Base
|
4
|
+
resource :user
|
5
|
+
resource picture: [:url]
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'Defining resource params' do
|
9
|
+
subject(:sanitizer) { ResourceParamsSanitizer.new(params) }
|
10
|
+
|
11
|
+
let(:params) { ActionController::Parameters.new(raw_params) }
|
12
|
+
let(:raw_params) do
|
13
|
+
{
|
14
|
+
user: {
|
15
|
+
nickname: 'nickname',
|
16
|
+
email: 'some@mail.com'
|
17
|
+
},
|
18
|
+
picture: {
|
19
|
+
url: 'http://some.url',
|
20
|
+
weight: 200,
|
21
|
+
height: 100
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'by default' do
|
27
|
+
it { is_expected.to respond_to :user_params }
|
28
|
+
|
29
|
+
its('user_params.keys') { is_expected.to include('nickname', 'email') }
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with permitting' do
|
33
|
+
it { is_expected.to respond_to :picture_params }
|
34
|
+
|
35
|
+
its('picture_params.keys') { is_expected.to include('url') }
|
36
|
+
its('picture_params.keys') { is_expected.to_not include('weight', 'height') }
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SomeParamsSanitizer < ActionParamsSanitizer::Base
|
4
|
+
param :some_single
|
5
|
+
param :another_single, scope: -> { scope_for_another }
|
6
|
+
|
7
|
+
def scope_for_another
|
8
|
+
params[:some_resource]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'Defining single params' do
|
13
|
+
subject(:sanitizer) { SomeParamsSanitizer.new(params) }
|
14
|
+
|
15
|
+
let(:params) { ActionController::Parameters.new(raw_params) }
|
16
|
+
let(:raw_params) do
|
17
|
+
{
|
18
|
+
some_single: 'single_value',
|
19
|
+
some_resource: {
|
20
|
+
another_single: 'another_value'
|
21
|
+
}
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'by default' do
|
26
|
+
it { is_expected.to respond_to :some_single }
|
27
|
+
|
28
|
+
its(:some_single) { is_expected.to eq 'single_value' }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with scope' do
|
32
|
+
it { is_expected.to respond_to :another_single }
|
33
|
+
|
34
|
+
its(:another_single) { is_expected.to eq 'another_value' }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class UsersController
|
4
|
+
include ActionParamsSanitizer::Helpers::Controller
|
5
|
+
|
6
|
+
def params
|
7
|
+
{}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Users
|
12
|
+
class CreateParamsSanitizer < ActionParamsSanitizer::Base
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe ActionParamsSanitizer::Helpers::Controller do
|
17
|
+
let(:controller) { UsersController.new }
|
18
|
+
|
19
|
+
context 'provides catching implicitly calling params sanitizer' do
|
20
|
+
subject(:sanitizer) { controller.create_params }
|
21
|
+
|
22
|
+
it { is_expected.to be_kind_of Users::CreateParamsSanitizer }
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Users
|
4
|
+
class CreateParamsSanitizer
|
5
|
+
end
|
6
|
+
|
7
|
+
module Api
|
8
|
+
class SearchParamsSanitizer
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ActionParamsSanitizer::Helpers::SanitizerClassBuilder do
|
14
|
+
subject(:builder) { described_class.new(method_name, controller_name) }
|
15
|
+
|
16
|
+
context 'when controller is not namespaced' do
|
17
|
+
let(:method_name) { :create }
|
18
|
+
let(:controller_name) { 'UsersController' }
|
19
|
+
|
20
|
+
its(:build_class) { is_expected.to eq Users::CreateParamsSanitizer }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when controller is namespaced' do
|
24
|
+
let(:method_name) { :search }
|
25
|
+
let(:controller_name) { 'Users::ApiController' }
|
26
|
+
|
27
|
+
its(:build_class) { is_expected.to eq Users::Api::SearchParamsSanitizer }
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$TESTING=true
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
|
4
|
+
require 'rspec/its'
|
5
|
+
require 'active_support'
|
6
|
+
require 'action_controller'
|
7
|
+
require 'action_params_sanitizer'
|
8
|
+
require 'pry-nav'
|
9
|
+
|
10
|
+
require "codeclimate-test-reporter"
|
11
|
+
CodeClimate::TestReporter.start
|
12
|
+
|
13
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.mock_with :rspec
|
17
|
+
|
18
|
+
config.filter_run focus: true
|
19
|
+
config.run_all_when_everything_filtered = true
|
20
|
+
|
21
|
+
config.order = "random"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action_params_sanitizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Gernyak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.4
|
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.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
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
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-its
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.2.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-nav
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.2.3
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.2.3
|
111
|
+
description: Allows to describe the input parameters with a simple DSL
|
112
|
+
email:
|
113
|
+
- sergeg1990@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .travis.yml
|
120
|
+
- Gemfile
|
121
|
+
- LICENSE.txt
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- action_params_sanitizer.gemspec
|
125
|
+
- lib/action_params_sanitizer.rb
|
126
|
+
- lib/action_params_sanitizer/base.rb
|
127
|
+
- lib/action_params_sanitizer/concerns/resource_param_builder.rb
|
128
|
+
- lib/action_params_sanitizer/concerns/single_param_builder.rb
|
129
|
+
- lib/action_params_sanitizer/helpers/controller.rb
|
130
|
+
- lib/action_params_sanitizer/helpers/sanitizer_class_builder.rb
|
131
|
+
- lib/action_params_sanitizer/railtie.rb
|
132
|
+
- lib/action_params_sanitizer/version.rb
|
133
|
+
- spec/lib/action_params_sanitizer/base_spec.rb
|
134
|
+
- spec/lib/action_params_sanitizer/concerns/resource_param_spec.rb
|
135
|
+
- spec/lib/action_params_sanitizer/concerns/single_param_spec.rb
|
136
|
+
- spec/lib/action_params_sanitizer/helpers/controller_spec.rb
|
137
|
+
- spec/lib/action_params_sanitizer/helpers/sanitizer_class_builder_spec.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: https://github.com/alterego-labs/action_params_sanitizer
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.0.14
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Pretty simple objectifying wrapper for action params
|
163
|
+
test_files:
|
164
|
+
- spec/lib/action_params_sanitizer/base_spec.rb
|
165
|
+
- spec/lib/action_params_sanitizer/concerns/resource_param_spec.rb
|
166
|
+
- spec/lib/action_params_sanitizer/concerns/single_param_spec.rb
|
167
|
+
- spec/lib/action_params_sanitizer/helpers/controller_spec.rb
|
168
|
+
- spec/lib/action_params_sanitizer/helpers/sanitizer_class_builder_spec.rb
|
169
|
+
- spec/spec_helper.rb
|