weak_parameters 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -2
- data/lib/weak_parameters/date_validator.rb +2 -2
- data/lib/weak_parameters/version.rb +1 -1
- data/spec/dummy/app/controllers/concerns/with_recipe.rb +2 -2
- data/spec/requests/recipes_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03f86fee7935cf4a8b244375fbdb46eb73fc6275
|
4
|
+
data.tar.gz: fc5950fcb0e5eb83a7d75ffbb9b337bce829ea48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05e98be7e6a35c672427de36e4bafda39c57e72bf7bae7350c006cda2e0c379ea0c4a25a0ce8baf4a164613ddbedafc140c9c5df2558eb24fde3c608e5ab02e
|
7
|
+
data.tar.gz: 37bb921a7553778dc3d2e87b71d6855285d562c37ac63455a012e47666bf49cde8930d62e2c05fc0ca2e38c4e7bd404b97f30bff12784e3d155b516fe490e892
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -26,8 +26,8 @@ class RecipesController < ApplicationController
|
|
26
26
|
string :quantity do |value|
|
27
27
|
value =~ /\A\d+(?:\.\d+)g\z/
|
28
28
|
end
|
29
|
-
date :date,
|
30
|
-
time :time,
|
29
|
+
date :date, format: ["%Y/%m/%d", "%Y.%m.%d"]
|
30
|
+
time :time, format: "%Y/%m/%d %H:%M:%S"
|
31
31
|
end
|
32
32
|
|
33
33
|
def create
|
@@ -70,6 +70,7 @@ irb(main):005:0> app.post "/recipes", name: "alice", type: "bob"
|
|
70
70
|
* except
|
71
71
|
* handler
|
72
72
|
* strong
|
73
|
+
* format (only for date and time)
|
73
74
|
|
74
75
|
## Tips
|
75
76
|
WeakParameters.stats returns its validation metadata, and this is useful for auto-generating API documents.
|
@@ -7,8 +7,8 @@ module WeakParameters
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def valid_type?
|
10
|
-
if options[:
|
11
|
-
Array(options[:
|
10
|
+
if options[:format]
|
11
|
+
Array(options[:format]).any? do |format|
|
12
12
|
begin
|
13
13
|
parser_class.strptime(value, format)
|
14
14
|
return false unless strictly?(format)
|
@@ -12,9 +12,9 @@ module WithRecipe
|
|
12
12
|
array :tags
|
13
13
|
float :rate
|
14
14
|
date :date
|
15
|
-
date :custom_date,
|
15
|
+
date :custom_date, format: %w[%Y/%m/%d %Y.%m.%d]
|
16
16
|
time :time
|
17
|
-
time :custom_time,
|
17
|
+
time :custom_time, format: '%Y/%m/%d %H:%M:%S'
|
18
18
|
file :attachment
|
19
19
|
integer :custom, only: 0..1, handler: :render_error
|
20
20
|
string :zip_code do |value|
|
@@ -120,6 +120,13 @@ describe "Recipes", type: :request do
|
|
120
120
|
include_examples "400"
|
121
121
|
end
|
122
122
|
|
123
|
+
context "with valid custom_date param" do
|
124
|
+
before do
|
125
|
+
params[:custom_date] = Date.current.strftime('%Y/%m/%d')
|
126
|
+
end
|
127
|
+
include_examples "201"
|
128
|
+
end
|
129
|
+
|
123
130
|
context "with wrong time param" do
|
124
131
|
before do
|
125
132
|
params[:time] = '2017-01-31 24:00:01'
|
@@ -127,6 +134,13 @@ describe "Recipes", type: :request do
|
|
127
134
|
include_examples "400"
|
128
135
|
end
|
129
136
|
|
137
|
+
context "with valid time param" do
|
138
|
+
before do
|
139
|
+
params[:custom_time] = Time.current.strftime('%Y/%m/%d %H:%M:%S')
|
140
|
+
end
|
141
|
+
include_examples "201"
|
142
|
+
end
|
143
|
+
|
130
144
|
context "with wrong custom_time param" do
|
131
145
|
before do
|
132
146
|
params[:custom_time] = Time.current.strftime('%Y-%m-%d %H:%M:%S')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weak_parameters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|