weak_parameters 0.0.9 → 0.1.0

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: 80441093aeafd1c3ab763657a7abaf130aa040a9
4
- data.tar.gz: 4218d72117b187a0b8bb5c4604f3f3d5977d23ce
3
+ metadata.gz: 85725f4ac0c2a36ca6158bb56342ef10c559381e
4
+ data.tar.gz: 22952cd5107d5446762e90d58c9470491278270d
5
5
  SHA512:
6
- metadata.gz: 2868dfff63a99b7c01b041a56589dd4b234276d879e625d8399697ac095183ff1ecde34b54dafb17821858cc8d4673aec8f4137c0badcb2f32027ef86011706c
7
- data.tar.gz: b51907dbbd0c0e5e0d25b46cf3c77b5c5bd4cc7da0323bf8fe98b5a1ff86bdf55df472560f63e9c540302d6fb9c353eacf22489bdea4fed8957e9525dbe5be57
6
+ metadata.gz: 1e63d3e62024bed8f9a47a7a9e1aff8cef35b8bdd6e4d7934864256f325bc2bc766747ef373f3aab47356d015d6fec8497a45b16f8cdfe20dedcfc780c6b2f56
7
+ data.tar.gz: 7aa8fa5a0340426603b0e9e61e676bfd401309aa0b73d2840d56bcdc403d53eb00cbf67f6f4b8bd4e2cc4ff86a836b1e788512eac0728336039d9686c0e733ce
@@ -1,4 +1,7 @@
1
1
  module WeakParameters
2
2
  class StringValidator < WeakParameters::BaseValidator
3
+ def valid_type?
4
+ value.is_a?(String)
5
+ end
3
6
  end
4
7
  end
@@ -1,3 +1,3 @@
1
1
  module WeakParameters
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -13,133 +13,107 @@ describe "Recipes" do
13
13
  }
14
14
  end
15
15
 
16
+ shared_examples_for "400" do
17
+ it "returns 400" do
18
+ post "/recipes", params
19
+ response.status.should == 400
20
+ end
21
+ end
22
+
23
+ shared_examples_for "201" do
24
+ it "creates a new recipe" do
25
+ post "/recipes", params
26
+ response.status.should == 201
27
+ end
28
+ end
29
+
16
30
  describe "POST /recipes" do
17
31
  context "without required param" do
18
32
  before do
19
33
  params.delete(:name)
20
34
  end
35
+ include_examples "400"
36
+ end
21
37
 
22
- it "returns 400" do
23
- post "/recipes", params
24
- response.status.should == 400
38
+ context "with wrong string param" do
39
+ before do
40
+ params[:name] = ["x"]
25
41
  end
42
+ include_examples "400"
26
43
  end
27
44
 
28
45
  context "with wrong integer param" do
29
46
  before do
30
47
  params[:type] = "x"
31
48
  end
32
-
33
- it "returns 400" do
34
- post "/recipes", params
35
- response.status.should == 400
36
- end
49
+ include_examples "400"
37
50
  end
38
51
 
39
52
  context "with exceptional interger param" do
40
53
  before do
41
54
  params[:number] = true
42
55
  end
43
-
44
- it "returns 400" do
45
- post "/recipes", params
46
- response.status.should == 400
47
- end
56
+ include_examples "400"
48
57
  end
49
58
 
50
59
  context "with wrong boolean param" do
51
60
  before do
52
61
  params[:flag] = "x"
53
62
  end
54
-
55
- it "returns 400" do
56
- post "/recipes", params
57
- response.status.should == 400
58
- end
63
+ include_examples "400"
59
64
  end
60
65
 
61
66
  context "with wrong array param" do
62
67
  before do
63
68
  params[:tags] = "x"
64
69
  end
65
-
66
- it "returns 400" do
67
- post "/recipes", params
68
- response.status.should == 400
69
- end
70
+ include_examples "400"
70
71
  end
71
72
 
72
73
  context "with wrong hash param" do
73
74
  before do
74
75
  params[:config] = "x"
75
76
  end
76
-
77
- it "returns 400" do
78
- post "/recipes", params
79
- response.status.should == 400
80
- end
77
+ include_examples "400"
81
78
  end
82
79
 
83
80
  context "with wrong float param" do
84
81
  before do
85
82
  params[:rate] = "-x"
86
83
  end
87
-
88
- it "returns 400" do
89
- post "/recipes", params
90
- response.status.should == 400
91
- end
84
+ include_examples "400"
92
85
  end
93
86
 
94
87
  context "with block failure" do
95
88
  before do
96
89
  params[:zip_code] = "123-456"
97
90
  end
98
-
99
- it "returns 400" do
100
- post "/recipes", params
101
- response.status.should == 400
102
- end
103
- end
104
-
105
- context "without non-required param" do
106
- before do
107
- params.delete(:type)
108
- end
109
-
110
- it "creates a new recipe" do
111
- post "/recipes", params
112
- response.status.should == 201
113
- end
91
+ include_examples "400"
114
92
  end
115
93
 
116
94
  context "with invalid param to :only condition" do
117
95
  before do
118
96
  params[:type] = 4
119
97
  end
120
-
121
- it "returns 400" do
122
- post "/recipes", params
123
- response.status.should == 400
124
- end
98
+ include_examples "400"
125
99
  end
126
100
 
127
101
  context "with invalid param to :except condition" do
128
102
  before do
129
103
  params[:name] = "invalid"
130
104
  end
105
+ include_examples "400"
106
+ end
131
107
 
132
- it "returns 400" do
133
- post "/recipes", params
134
- response.status.should == 400
108
+ context "without non-required param" do
109
+ before do
110
+ params.delete(:type)
135
111
  end
112
+ include_examples "201"
136
113
  end
137
114
 
138
115
  context "with valid condition", :autodoc do
139
- it "creates a new recipe" do
140
- post "/recipes", params
141
- response.status.should == 201
142
- end
116
+ include_examples "201"
143
117
  end
144
118
  end
145
119
  end
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.0.9
4
+ version: 0.1.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: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2013-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails