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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '09e8c53c2c8454671bcdc7b74e641d830a4198bc'
4
- data.tar.gz: a70b4dc7bbdbea50696e8eda91a0101c230b9b49
3
+ metadata.gz: 03f86fee7935cf4a8b244375fbdb46eb73fc6275
4
+ data.tar.gz: fc5950fcb0e5eb83a7d75ffbb9b337bce829ea48
5
5
  SHA512:
6
- metadata.gz: 89b575f9765feb386807dd60ffdcdaa34d8741a09ab5bb1137f3ccbe20358456dad70f2a7eb2178e64966a05cd7eee4cb453701a01af82c2a1f4dec2428e0de7
7
- data.tar.gz: 6f3bdc9e43d62048c604155551187e9547531d9e4a5c9529db29993b24085611be8185735fbaaed5adf95a20c318aa6408be68ee88cdfbd415d333ab0712efc7
6
+ metadata.gz: b05e98be7e6a35c672427de36e4bafda39c57e72bf7bae7350c006cda2e0c379ea0c4a25a0ce8baf4a164613ddbedafc140c9c5df2558eb24fde3c608e5ab02e
7
+ data.tar.gz: 37bb921a7553778dc3d2e87b71d6855285d562c37ac63455a012e47666bf49cde8930d62e2c05fc0ca2e38c4e7bd404b97f30bff12784e3d155b516fe490e892
@@ -1,3 +1,7 @@
1
+ ## 0.5.0
2
+
3
+ - Change options name from `:only` to `:format` (Thx @ganmacs)
4
+
1
5
  ## 0.4.3
2
6
 
3
7
  - Support date and time validator (Thx @shimomuh)
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, only: ["%Y/%m/%d", "%Y.%m.%d"]
30
- time :time, only: "%Y/%m/%d %H:%M:%S"
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[:only]
11
- Array(options[:only]).any? do |format|
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)
@@ -1,3 +1,3 @@
1
1
  module WeakParameters
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -12,9 +12,9 @@ module WithRecipe
12
12
  array :tags
13
13
  float :rate
14
14
  date :date
15
- date :custom_date, only: %w[%Y/%m/%d %Y.%m.%d]
15
+ date :custom_date, format: %w[%Y/%m/%d %Y.%m.%d]
16
16
  time :time
17
- time :custom_time, only: '%Y/%m/%d %H:%M:%S'
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.3
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-10-02 00:00:00.000000000 Z
11
+ date: 2017-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails