sinatra-strong-params 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -1
- data/lib/sinatra/strong-params.rb +8 -1
- data/lib/sinatra/strong-params/version.rb +3 -1
- data/sinatra-strong-params.gemspec +15 -11
- data/spec/spec_helper.rb +11 -0
- data/spec/strong-params_spec.rb +97 -0
- data/spec/test_helper.rb +21 -0
- metadata +43 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a395072291663098a8c4e241b4488bacc8e25f1
|
4
|
+
data.tar.gz: abb9249d19214474b81d7099e67ac6ba833260b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d6a12f59264e4c74e5580049d9ae7217ba9da4f40ca70d2c902fd50a34337729ad11bd6ded8be465c5518872869b60689f5bc7a36c217e5a9a4174d6580845a
|
7
|
+
data.tar.gz: 70e7dc32a003c0f82f59a06d0e078173afb395490d9bcb03d1ce4d6c1a5926b5c8acecab639838625a9d3530a417a8c841031a8fc7f9282dac59745bc433f56f
|
data/Rakefile
CHANGED
@@ -1,2 +1,13 @@
|
|
1
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
2
5
|
|
6
|
+
namespace :test do
|
7
|
+
desc 'Run the specs'
|
8
|
+
task :spec do
|
9
|
+
RSpec::Core::RakeTask.new('test:spec')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => 'test:spec'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
1
3
|
require 'sinatra/base'
|
2
4
|
require 'sinatra/strong-params/version'
|
3
5
|
|
@@ -23,10 +25,15 @@ module Sinatra
|
|
23
25
|
globals = settings.globally_allowed_parameters
|
24
26
|
passable = (globals | passable).map(&:to_sym) # make sure it's a symbol
|
25
27
|
|
26
|
-
#
|
28
|
+
# Select only the allowed parameters.
|
27
29
|
@params = @params.select do |param, _value|
|
28
30
|
passable.include?(param.to_sym)
|
29
31
|
end
|
32
|
+
|
33
|
+
# Copy Sinatra's default proc to allow indifferent access.
|
34
|
+
@params.tap do |params|
|
35
|
+
params.default_proc = @_params.default_proc.dup rescue nil
|
36
|
+
end
|
30
37
|
end
|
31
38
|
end
|
32
39
|
end
|
@@ -1,24 +1,28 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
|
3
5
|
require 'sinatra/strong-params/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = 'sinatra-strong-params'
|
7
9
|
spec.version = Sinatra::StrongParams::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
-
spec.summary =
|
10
|
+
spec.authors = ['Evan Lecklider']
|
11
|
+
spec.email = ['evan@lecklider.com']
|
12
|
+
spec.summary = 'Some super basic strong parameter filters for Sinatra.'
|
11
13
|
spec.description = spec.summary
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/evanleck/sinatra-strong-params'
|
15
|
+
spec.license = 'MIT'
|
14
16
|
|
15
17
|
spec.files = `git ls-files -z`.split("\x0")
|
16
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ['lib']
|
19
21
|
|
20
22
|
spec.add_dependency 'sinatra', '>= 1.4.0'
|
21
23
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
spec.add_development_dependency 'rack-test'
|
24
28
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require_relative 'spec_helper'
|
6
|
+
require 'json'
|
7
|
+
require 'sinatra/strong-params'
|
8
|
+
|
9
|
+
describe Sinatra::StrongParams do
|
10
|
+
context "using allows filter" do
|
11
|
+
context "with no nested params" do
|
12
|
+
let(:request_params) { { id: 'id', action: 'action', not_allows: 'not_allows' } }
|
13
|
+
|
14
|
+
it 'supports accessing params with string keys' do
|
15
|
+
actual_params = nil
|
16
|
+
mock_app do
|
17
|
+
register Sinatra::StrongParams
|
18
|
+
get '/', allows: [:id, :action] { actual_params = params }
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/', request_params
|
22
|
+
expect(actual_params['id']).to eq request_params[:id]
|
23
|
+
expect(actual_params['action']).to eq request_params[:action]
|
24
|
+
expect(actual_params['not_allows']).to eq nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'supports accessing params with symbol keys' do
|
28
|
+
actual_params = nil
|
29
|
+
mock_app do
|
30
|
+
register Sinatra::StrongParams
|
31
|
+
get '/', allows: [:id, :action] { actual_params = params }
|
32
|
+
end
|
33
|
+
|
34
|
+
get '/', request_params
|
35
|
+
expect(actual_params[:id]).to eq request_params[:id]
|
36
|
+
expect(actual_params[:action]).to eq request_params[:action]
|
37
|
+
expect(actual_params[:not_allows]).to eq nil
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with nested params" do
|
42
|
+
let(:request_params) { { id: [ { in_array: 'in_array'} ], action: { nested_hash: 'nested_hash'} }}
|
43
|
+
|
44
|
+
it 'supports accessing params with string keys' do
|
45
|
+
actual_params = nil
|
46
|
+
mock_app do
|
47
|
+
register Sinatra::StrongParams
|
48
|
+
get '/', allows: [:id, :action] { actual_params = params }
|
49
|
+
end
|
50
|
+
|
51
|
+
get '/', request_params
|
52
|
+
expect(actual_params['id'][0]['in_array']).to eq request_params[:id][0][:in_array]
|
53
|
+
expect(actual_params['action']['nested_hash']).to eq request_params[:action][:nested_hash]
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'supports accessing params with symbol keys' do
|
57
|
+
actual_params = nil
|
58
|
+
mock_app do
|
59
|
+
register Sinatra::StrongParams
|
60
|
+
get '/', allows: [:id, :action] { actual_params = params }
|
61
|
+
end
|
62
|
+
|
63
|
+
get '/', request_params
|
64
|
+
expect(actual_params[:id][0][:in_array]).to eq request_params[:id][0][:in_array]
|
65
|
+
expect(actual_params[:action][:nested_hash]).to eq request_params[:action][:nested_hash]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "using needs filter" do
|
71
|
+
it 'supports accessing params with string keys' do
|
72
|
+
actual_params = nil
|
73
|
+
mock_app do
|
74
|
+
register Sinatra::StrongParams
|
75
|
+
get '/', needs: [:id, :action] { actual_params = params }
|
76
|
+
end
|
77
|
+
params = { id: 'id', action: 'action' }
|
78
|
+
|
79
|
+
get '/', params
|
80
|
+
expect(actual_params['id']).to eq params[:id]
|
81
|
+
expect(actual_params['action']).to eq params[:action]
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'supports accessing params with symbol keys' do
|
85
|
+
actual_params = nil
|
86
|
+
mock_app do
|
87
|
+
register Sinatra::StrongParams
|
88
|
+
get '/', needs: [:id, :action] { actual_params = params }
|
89
|
+
end
|
90
|
+
params = { id: 'id', action: 'action' }
|
91
|
+
|
92
|
+
get '/', params
|
93
|
+
expect(actual_params[:id]).to eq params[:id]
|
94
|
+
expect(actual_params[:action]).to eq params[:action]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/spec/test_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'rack/test'
|
4
|
+
|
5
|
+
module TestHelper
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def mock_app(&block)
|
9
|
+
@app = Sinatra.new(Sinatra::Base) do
|
10
|
+
class_eval(&block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def app
|
15
|
+
@app
|
16
|
+
end
|
17
|
+
|
18
|
+
def json
|
19
|
+
JSON.parse(last_response.body, :symbolize_names => true)
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-strong-params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Lecklider
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
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: rack-test
|
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'
|
55
83
|
description: Some super basic strong parameter filters for Sinatra.
|
56
84
|
email:
|
57
85
|
- evan@lecklider.com
|
@@ -67,7 +95,10 @@ files:
|
|
67
95
|
- lib/sinatra/strong-params.rb
|
68
96
|
- lib/sinatra/strong-params/version.rb
|
69
97
|
- sinatra-strong-params.gemspec
|
70
|
-
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/strong-params_spec.rb
|
100
|
+
- spec/test_helper.rb
|
101
|
+
homepage: https://github.com/evanleck/sinatra-strong-params
|
71
102
|
licenses:
|
72
103
|
- MIT
|
73
104
|
metadata: {}
|
@@ -87,8 +118,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
118
|
version: '0'
|
88
119
|
requirements: []
|
89
120
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.10
|
91
122
|
signing_key:
|
92
123
|
specification_version: 4
|
93
124
|
summary: Some super basic strong parameter filters for Sinatra.
|
94
|
-
test_files:
|
125
|
+
test_files:
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
- spec/strong-params_spec.rb
|
128
|
+
- spec/test_helper.rb
|