weak_parameters 0.1.4 → 0.1.5

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
2
  SHA1:
3
- metadata.gz: 896f293b140f5e4afe967ef16d88a8e532f9b48d
4
- data.tar.gz: ac0a4d7ddb63c355c5256733b4f376df4b8737f2
3
+ metadata.gz: 59ff95fe3c0c70019f9928aec5497ade558f8931
4
+ data.tar.gz: c89f0b1d89a105a945be5da03610b89ee6b6742b
5
5
  SHA512:
6
- metadata.gz: 2a84c2269bb8f81e5b1c181ed84fd952b3de7058fa6feb33dca007cdd18dcc64308fa71ce7c73118b610b2cd7c82e7ec953e0d968a7903581ba1d33f97524b44
7
- data.tar.gz: 118ea3ead740b96cc949daf77c69da1f7ab7291fb06dc4621fb62daaa09de1884da68ae5cc38f1c784b3e27407abcdbeef1712a8373ee2b77d0902e4cacfcb58
6
+ metadata.gz: 104f5d6733c9ada50db9c805329471d6042fd33004e2000a86e703b9f9ee6e8122a649633b5aeafed55eac18fcd3d7157b9a1e63c430143d169cf0d038603d03
7
+ data.tar.gz: 07f767852ee08f96bcbbdf709b7d3438b8df3fbc7d1956535ca75e42e9bd538eff2cc7f2b0821576268458898fbb7758d2e036aa35a14254badb7a474cfcb0f2
@@ -1,3 +1,6 @@
1
+ ## 0.1.5
2
+ * Support `file` validator (#6)
3
+
1
4
  ## 0.1.4
2
5
  * Tiny improvement about Validator#params
3
6
 
@@ -5,6 +5,7 @@ require "weak_parameters/base_validator"
5
5
  require "weak_parameters/any_validator"
6
6
  require "weak_parameters/array_validator"
7
7
  require "weak_parameters/boolean_validator"
8
+ require "weak_parameters/file_validator"
8
9
  require "weak_parameters/float_validator"
9
10
  require "weak_parameters/hash_validator"
10
11
  require "weak_parameters/integer_validator"
@@ -0,0 +1,20 @@
1
+ module WeakParameters
2
+ class FileValidator < WeakParameters::BaseValidator
3
+ private
4
+
5
+ VALID_TYPES = [
6
+ StringIO,
7
+ IO,
8
+ ActionDispatch::Http::UploadedFile,
9
+ Rack::Test::UploadedFile,
10
+ ]
11
+
12
+ def valid_type?
13
+ VALID_TYPES.any? {|type| value.is_a?(type) }
14
+ end
15
+
16
+ def error_message
17
+ "params[#{key.inspect}] must be a valid File"
18
+ end
19
+ end
20
+ end
@@ -48,5 +48,9 @@ module WeakParameters
48
48
  def float(key, options = {}, &block)
49
49
  validators << WeakParameters::FloatValidator.new(controller, key, options, &block)
50
50
  end
51
+
52
+ def file(key, options = {}, &block)
53
+ validators << WeakParameters::FileValidator.new(controller, key, options, &block)
54
+ end
51
55
  end
52
56
  end
@@ -1,3 +1,3 @@
1
1
  module WeakParameters
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -8,6 +8,7 @@ class RecipesController < ApplicationController
8
8
  hash :config
9
9
  array :tags
10
10
  float :rate
11
+ file :attachment
11
12
  integer :custom, only: 0..1, handler: :render_error
12
13
  string :zip_code do |value|
13
14
  value =~ /\A\d{3}-\d{4}\z/
@@ -10,6 +10,7 @@ describe "Recipes" do
10
10
  flag: true,
11
11
  config: {},
12
12
  tags: [],
13
+ attachment: Rack::Test::UploadedFile.new(__FILE__),
13
14
  zip_code: "123-4567",
14
15
  custom: 0,
15
16
  }
@@ -86,6 +87,13 @@ describe "Recipes" do
86
87
  include_examples "400"
87
88
  end
88
89
 
90
+ context "with wrong file param" do
91
+ before do
92
+ params[:attachment] = "x"
93
+ end
94
+ include_examples "400"
95
+ end
96
+
89
97
  context "with block failure" do
90
98
  before do
91
99
  params[:zip_code] = "123-456"
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weak_parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-12 00:00:00.000000000 Z
11
+ date: 2014-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.11
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.11
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.3'
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
40
  version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description:
@@ -73,7 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - .gitignore
76
+ - ".gitignore"
77
77
  - CHANGELOG.md
78
78
  - Gemfile
79
79
  - LICENSE.txt
@@ -85,6 +85,7 @@ files:
85
85
  - lib/weak_parameters/base_validator.rb
86
86
  - lib/weak_parameters/boolean_validator.rb
87
87
  - lib/weak_parameters/controller.rb
88
+ - lib/weak_parameters/file_validator.rb
88
89
  - lib/weak_parameters/float_validator.rb
89
90
  - lib/weak_parameters/hash_validator.rb
90
91
  - lib/weak_parameters/integer_validator.rb
@@ -140,17 +141,17 @@ require_paths:
140
141
  - lib
141
142
  required_ruby_version: !ruby/object:Gem::Requirement
142
143
  requirements:
143
- - - '>='
144
+ - - ">="
144
145
  - !ruby/object:Gem::Version
145
146
  version: '0'
146
147
  required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  requirements:
148
- - - '>='
149
+ - - ">="
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
151
152
  requirements: []
152
153
  rubyforge_project:
153
- rubygems_version: 2.0.3
154
+ rubygems_version: 2.2.2
154
155
  signing_key:
155
156
  specification_version: 4
156
157
  summary: Add a validation filter to your controller.
@@ -192,3 +193,4 @@ test_files:
192
193
  - spec/dummy/script/rails
193
194
  - spec/requests/recipes_spec.rb
194
195
  - spec/spec_helper.rb
196
+ has_rdoc: