sinatra-param 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/Gemfile +9 -1
  2. data/Gemfile.lock +7 -1
  3. data/README.md +4 -9
  4. data/Rakefile +0 -1
  5. data/coverage/assets/0.7.1/application.css +1110 -0
  6. data/coverage/assets/0.7.1/application.js +626 -0
  7. data/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
  8. data/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
  9. data/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
  10. data/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
  11. data/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
  12. data/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
  13. data/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
  14. data/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
  15. data/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
  16. data/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
  17. data/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
  18. data/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
  19. data/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
  20. data/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
  21. data/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
  22. data/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
  23. data/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
  24. data/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
  25. data/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
  26. data/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
  27. data/coverage/assets/0.7.1/favicon_green.png +0 -0
  28. data/coverage/assets/0.7.1/favicon_red.png +0 -0
  29. data/coverage/assets/0.7.1/favicon_yellow.png +0 -0
  30. data/coverage/assets/0.7.1/loading.gif +0 -0
  31. data/coverage/assets/0.7.1/magnify.png +0 -0
  32. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  33. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  34. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  35. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  36. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  37. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  38. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  39. data/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  40. data/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
  41. data/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  42. data/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
  43. data/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
  44. data/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  45. data/coverage/index.html +788 -0
  46. data/{lib/example → example}/Gemfile +0 -0
  47. data/{lib/example → example}/Gemfile.lock +0 -0
  48. data/{lib/example → example}/Procfile +0 -0
  49. data/{lib/example → example}/app.rb +7 -7
  50. data/{lib/example → example}/config.ru +0 -0
  51. data/lib/sinatra/param.rb +36 -32
  52. data/lib/sinatra/param/version.rb +1 -1
  53. data/sinatra-param.gemspec +3 -6
  54. data/spec/dummy/app.rb +146 -0
  55. data/spec/parameter_sets_spec.rb +33 -0
  56. data/spec/parameter_transformations_spec.rb +21 -0
  57. data/spec/parameter_type_coercion_spec.rb +90 -0
  58. data/spec/parameter_validations_spec.rb +174 -0
  59. data/spec/spec_helper.rb +19 -2
  60. metadata +65 -39
  61. data/sinatra-param-0.1.0.gem +0 -0
  62. data/spec/exclude_spec.rb +0 -36
@@ -0,0 +1,174 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Parameter Validations' do
4
+ describe 'required' do
5
+ it 'returns 406 on requests without required fields' do
6
+ get('/validation/required') do |response|
7
+ response.status.should eq(406)
8
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
9
+ end
10
+ end
11
+
12
+ it 'returns 200 on requests when required field present' do
13
+ get('/validation/required', arg: 'foo') do |response|
14
+ response.status.should eq(200)
15
+ end
16
+ end
17
+ end
18
+
19
+ describe 'blank' do
20
+ it 'returns 406 on requests when string is blank' do
21
+ get('/validation/blank/string', arg: '') do |response|
22
+ response.status.should eq(406)
23
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
24
+ end
25
+ end
26
+
27
+ it 'returns 406 on requests when array is blank' do
28
+ get('/validation/blank/array', arg: '') do |response|
29
+ response.status.should eq(406)
30
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
31
+ end
32
+ end
33
+
34
+ it 'returns 406 on requests when hash is blank' do
35
+ get('/validation/blank/hash', arg: '') do |response|
36
+ response.status.should eq(406)
37
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
38
+ end
39
+ end
40
+
41
+ it 'returns 406 on requests when hash is blank' do
42
+ get('/validation/blank/other', arg: '') do |response|
43
+ response.status.should eq(406)
44
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
45
+ end
46
+ end
47
+
48
+ it 'returns 200 on request when blank is true' do
49
+ get('/validation/nonblank/string', arg: '') do |response|
50
+ response.status.should eq(200)
51
+ end
52
+ end
53
+ end
54
+
55
+ describe 'is' do
56
+ it 'returns 406 on requests when value is other than defined' do
57
+ get('/validation/is', arg: 'bar') do |response|
58
+ response.status.should eq(406)
59
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
60
+ end
61
+ end
62
+
63
+ it 'returns 200 on requests with a value is other than defined' do
64
+ get('/validation/is', arg: 'foo') do |response|
65
+ response.status.should eq(200)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe 'in' do
71
+ it 'returns 406 on requests with a value not in the set' do
72
+ get('/validation/in', arg: 'MISC') do |response|
73
+ response.status.should eq(406)
74
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
75
+ end
76
+ end
77
+
78
+ it 'returns 200 on requests with a value in the set' do
79
+ get('/validation/in', arg: 'ASC') do |response|
80
+ response.status.should eq(200)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe 'within' do
86
+ it 'returns 406 on requests with a value outside the range' do
87
+ get('/validation/within', arg: 20) do |response|
88
+ response.status.should eq(406)
89
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
90
+ end
91
+ end
92
+
93
+ it 'returns 200 on requests with a value within the range' do
94
+ get('/validation/within', arg: 5) do |response|
95
+ response.status.should eq(200)
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'range' do
101
+ it 'returns 406 on requests with a value outside the range' do
102
+ get('/validation/range', arg: 20) do |response|
103
+ response.status.should eq(406)
104
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
105
+ end
106
+ end
107
+
108
+ it 'returns 200 on requests within the range' do
109
+ get('/validation/range', arg: 10) do |response|
110
+ response.status.should eq(200)
111
+ end
112
+ end
113
+ end
114
+
115
+ describe 'min' do
116
+ it 'returns 406 on requests with a value smaller than min' do
117
+ get('/validation/min', arg: 5) do |response|
118
+ response.status.should eq(406)
119
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
120
+ end
121
+ end
122
+
123
+ it 'returns 200 on requests with a value larger than min' do
124
+ get('/validation/min', arg: 200) do |response|
125
+ response.status.should eq(200)
126
+ end
127
+ end
128
+ end
129
+
130
+ describe 'max' do
131
+ it 'returns 406 on requests with a value larger than max' do
132
+ get('/validation/max', arg: 100) do |response|
133
+ response.status.should eq(406)
134
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
135
+ end
136
+ end
137
+
138
+ it 'returns 200 on requests with a value smaller than max' do
139
+ get('/validation/max', arg: 2) do |response|
140
+ response.status.should eq(200)
141
+ end
142
+ end
143
+ end
144
+
145
+ describe 'min_length' do
146
+ it 'returns 406 on requests with a string shorter than min_length' do
147
+ get('/validation/min_length', arg: 'hi') do |response|
148
+ response.status.should eq(406)
149
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
150
+ end
151
+ end
152
+
153
+ it 'returns 200 on requests with a string longer than min_length' do
154
+ get('/validation/max_length', arg: 'longer') do |response|
155
+ response.status.should eq(200)
156
+ end
157
+ end
158
+ end
159
+
160
+ describe 'max_length' do
161
+ it 'returns 406 on requests with a string longer than max_length' do
162
+ get('/validation/max_length', arg: 'reallylongstringlongerthanmax') do |response|
163
+ response.status.should eq(406)
164
+ JSON.parse(response.body)['message'].should eq('Invalid parameter, arg')
165
+ end
166
+ end
167
+
168
+ it 'returns 200 on requests with a string shorter than max_length' do
169
+ get('/validation/max_length', arg: 'short') do |response|
170
+ response.status.should eq(200)
171
+ end
172
+ end
173
+ end
174
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,20 @@
1
- require 'bundler/setup'
1
+ unless ENV['CI']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter 'spec'
5
+ add_filter '.bundle'
6
+ end
7
+ end
8
+
2
9
  require 'sinatra/param'
3
- require 'example/app'
10
+
11
+ require 'rspec'
12
+ require 'rack/test'
13
+
14
+ require 'dummy/app'
15
+
16
+ def app
17
+ App
18
+ end
19
+
20
+ include Rack::Test::Methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-param
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-01 00:00:00.000000000Z
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70210869854140 !ruby/object:Gem::Requirement
16
+ requirement: &70339153513320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70210869854140
24
+ version_requirements: *70339153513320
25
25
  - !ruby/object:Gem::Dependency
26
- name: rspec
27
- requirement: &70210869853020 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '2.10'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70210869853020
36
- - !ruby/object:Gem::Dependency
37
- name: rack-test
38
- requirement: &70210869852560 !ruby/object:Gem::Requirement
26
+ name: simplecov
27
+ requirement: &70339153510080 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ! '>='
@@ -43,39 +32,72 @@ dependencies:
43
32
  version: '0'
44
33
  type: :development
45
34
  prerelease: false
46
- version_requirements: *70210869852560
47
- - !ruby/object:Gem::Dependency
48
- name: rake
49
- requirement: &70210869852020 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 0.9.2
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70210869852020
35
+ version_requirements: *70339153510080
58
36
  description: Parameter Contracts for Sinatra
59
37
  email: m@mattt.me
60
38
  executables: []
61
39
  extensions: []
62
40
  extra_rdoc_files: []
63
41
  files:
42
+ - ./coverage/assets/0.7.1/application.css
43
+ - ./coverage/assets/0.7.1/application.js
44
+ - ./coverage/assets/0.7.1/fancybox/blank.gif
45
+ - ./coverage/assets/0.7.1/fancybox/fancy_close.png
46
+ - ./coverage/assets/0.7.1/fancybox/fancy_loading.png
47
+ - ./coverage/assets/0.7.1/fancybox/fancy_nav_left.png
48
+ - ./coverage/assets/0.7.1/fancybox/fancy_nav_right.png
49
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_e.png
50
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_n.png
51
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png
52
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png
53
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_s.png
54
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_se.png
55
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png
56
+ - ./coverage/assets/0.7.1/fancybox/fancy_shadow_w.png
57
+ - ./coverage/assets/0.7.1/fancybox/fancy_title_left.png
58
+ - ./coverage/assets/0.7.1/fancybox/fancy_title_main.png
59
+ - ./coverage/assets/0.7.1/fancybox/fancy_title_over.png
60
+ - ./coverage/assets/0.7.1/fancybox/fancy_title_right.png
61
+ - ./coverage/assets/0.7.1/fancybox/fancybox-x.png
62
+ - ./coverage/assets/0.7.1/fancybox/fancybox-y.png
63
+ - ./coverage/assets/0.7.1/fancybox/fancybox.png
64
+ - ./coverage/assets/0.7.1/favicon_green.png
65
+ - ./coverage/assets/0.7.1/favicon_red.png
66
+ - ./coverage/assets/0.7.1/favicon_yellow.png
67
+ - ./coverage/assets/0.7.1/loading.gif
68
+ - ./coverage/assets/0.7.1/magnify.png
69
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
70
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
71
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
72
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
73
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png
74
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
75
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
76
+ - ./coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
77
+ - ./coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png
78
+ - ./coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png
79
+ - ./coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png
80
+ - ./coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png
81
+ - ./coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png
82
+ - ./coverage/index.html
83
+ - ./example/app.rb
84
+ - ./example/config.ru
85
+ - ./example/Gemfile
86
+ - ./example/Gemfile.lock
87
+ - ./example/Procfile
64
88
  - ./Gemfile
65
89
  - ./Gemfile.lock
66
- - ./lib/example/app.rb
67
- - ./lib/example/config.ru
68
- - ./lib/example/Gemfile
69
- - ./lib/example/Gemfile.lock
70
- - ./lib/example/Procfile
71
90
  - ./lib/sinatra/param/version.rb
72
91
  - ./lib/sinatra/param.rb
73
92
  - ./LICENSE
74
93
  - ./Rakefile
75
94
  - ./README.md
76
- - ./sinatra-param-0.1.0.gem
77
95
  - ./sinatra-param.gemspec
78
- - spec/exclude_spec.rb
96
+ - spec/dummy/app.rb
97
+ - spec/parameter_sets_spec.rb
98
+ - spec/parameter_transformations_spec.rb
99
+ - spec/parameter_type_coercion_spec.rb
100
+ - spec/parameter_validations_spec.rb
79
101
  - spec/spec_helper.rb
80
102
  homepage: http://github.com/mattt/sinatra-param
81
103
  licenses: []
@@ -91,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
113
  version: '0'
92
114
  segments:
93
115
  - 0
94
- hash: -4354181681426426125
116
+ hash: 1586099901428040771
95
117
  required_rubygems_version: !ruby/object:Gem::Requirement
96
118
  none: false
97
119
  requirements:
@@ -100,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
122
  version: '0'
101
123
  segments:
102
124
  - 0
103
- hash: -4354181681426426125
125
+ hash: 1586099901428040771
104
126
  requirements: []
105
127
  rubyforge_project:
106
128
  rubygems_version: 1.8.15
@@ -108,5 +130,9 @@ signing_key:
108
130
  specification_version: 3
109
131
  summary: sinatra-param
110
132
  test_files:
111
- - spec/exclude_spec.rb
133
+ - spec/dummy/app.rb
134
+ - spec/parameter_sets_spec.rb
135
+ - spec/parameter_transformations_spec.rb
136
+ - spec/parameter_type_coercion_spec.rb
137
+ - spec/parameter_validations_spec.rb
112
138
  - spec/spec_helper.rb
Binary file
data/spec/exclude_spec.rb DELETED
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
- require 'rack/test'
3
-
4
- describe 'parameter exclusion' do
5
- include Rack::Test::Methods
6
- def app; App; end
7
-
8
- it 'returns 406 on requests that contain more than one mutually exclusive parameter' do
9
- params = [
10
- {a: 1, b: 2},
11
- {b: 2, c: 3},
12
- {a: 1, b: 2, c: 3}
13
- ]
14
- params.each do |param|
15
- get('/exclude', param) do |response|
16
- response.status.should == 406
17
- JSON.parse(response.body)['message'].should =~ /mutually exclusive/
18
- end
19
- end
20
- end
21
-
22
- it 'returns successfully for requests that only have one parameter' do
23
- params = [
24
- {a: 1},
25
- {b: 2},
26
- {c: 3},
27
- {a: 1, c: 3},
28
- ]
29
- params.each do |param|
30
- get('/exclude', param) do |response|
31
- response.status.should == 200
32
- JSON.parse(response.body)['message'].should =~ /OK/
33
- end
34
- end
35
- end
36
- end