batch_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,24 @@
1
+ shared_examples_for "a get request" do
2
+ it "returns the body as objects" do
3
+ @result = JSON.parse(response.body)["results"][0]
4
+ @result["body"].should == get_result[:body]
5
+ end
6
+
7
+ it "returns the expected status" do
8
+ @result["status"].should == get_result[:status]
9
+ end
10
+
11
+ it "returns the expected headers" do
12
+ @result["headers"].should include(get_result[:headers])
13
+ end
14
+
15
+ it "verifies that the right headers were received" do
16
+ @result["headers"]["REQUEST_HEADERS"].should include(
17
+ headerize(get_headers)
18
+ )
19
+ end
20
+ end
21
+
1
22
  shared_examples_for "integrating with a server" do
2
23
  def headerize(hash)
3
24
  Hash[hash.map do |k, v|
@@ -25,6 +46,12 @@ shared_examples_for "integrating with a server" do
25
46
  params: get_params
26
47
  } }
27
48
 
49
+ let(:get_by_default_request) { {
50
+ url: "/endpoint",
51
+ headers: get_headers,
52
+ params: get_params
53
+ } }
54
+
28
55
  let(:get_result) { {
29
56
  status: 422,
30
57
  body: {
@@ -123,7 +150,8 @@ shared_examples_for "integrating with a server" do
123
150
  missing_request,
124
151
  parameter_request,
125
152
  silent_request,
126
- failed_silent_request
153
+ failed_silent_request,
154
+ get_by_default_request
127
155
  ],
128
156
  sequential: true
129
157
  }.to_json, "CONTENT_TYPE" => "application/json"
@@ -138,29 +166,20 @@ shared_examples_for "integrating with a server" do
138
166
  end
139
167
 
140
168
  context "for a get request" do
141
- describe "the response" do
169
+ describe "with an explicit get" do
142
170
  before :each do
143
171
  @result = JSON.parse(response.body)["results"][0]
144
172
  end
145
173
 
146
- it "returns the body as objects" do
147
- @result = JSON.parse(response.body)["results"][0]
148
- @result["body"].should == get_result[:body]
149
- end
150
-
151
- it "returns the expected status" do
152
- @result["status"].should == get_result[:status]
153
- end
174
+ it_should_behave_like "a get request"
175
+ end
154
176
 
155
- it "returns the expected headers" do
156
- @result["headers"].should include(get_result[:headers])
177
+ describe "with no method" do
178
+ before :each do
179
+ @result = JSON.parse(response.body)["results"][7]
157
180
  end
158
181
 
159
- it "verifies that the right headers were received" do
160
- @result["headers"]["REQUEST_HEADERS"].should include(
161
- headerize(get_headers)
162
- )
163
- end
182
+ it_should_behave_like "a get request"
164
183
  end
165
184
  end
166
185
 
@@ -182,15 +201,7 @@ shared_examples_for "integrating with a server" do
182
201
  @result = JSON.parse(response.body)["results"][1]
183
202
  end
184
203
 
185
- it "returns the body raw if decode_json_responses = false" do
186
- # BatchApi.config.decode_bodies = false
187
- xhr :post, "/batch", {ops: [post_request], sequential: true}.to_json,
188
- "CONTENT_TYPE" => "application/json"
189
- @result = JSON.parse(response.body)["results"][0]
190
- @result["body"].should == JSON.parse(post_result[:body].to_json)
191
- end
192
-
193
- it "returns the body as objects if decode_json_responses = true" do
204
+ it "returns the body as objects (since DecodeJsonBody is default)" do
194
205
  @result["body"].should == post_result[:body]
195
206
  end
196
207
 
@@ -40,6 +40,11 @@ describe BatchApi::Operation::Rack do
40
40
  operation.options.should == op_params
41
41
  end
42
42
 
43
+ it "defaults method to get if not provided" do
44
+ op = BatchApi::Operation::Rack.new(op_params.except("method"), env, app)
45
+ op.method.should == "get"
46
+ end
47
+
43
48
  it "defaults params to {} if not provided" do
44
49
  op = BatchApi::Operation::Rack.new(op_params.except("params"), env, app)
45
50
  op.params.should == {}
@@ -63,21 +68,11 @@ describe BatchApi::Operation::Rack do
63
68
  end
64
69
  end
65
70
 
66
- it "raises a MalformedOperationError if method or URL are missing" do
67
- no_method = op_params.dup.tap {|o| o.delete("method") }
68
- expect {
69
- BatchApi::Operation::Rack.new(no_method, env, app)
70
- }.to raise_exception(BatchApi::Errors::MalformedOperationError)
71
-
71
+ it "raises a MalformedOperationError if URL is missing" do
72
72
  no_url = op_params.dup.tap {|o| o.delete("url") }
73
73
  expect {
74
74
  BatchApi::Operation::Rack.new(no_url, env, app)
75
75
  }.to raise_exception(BatchApi::Errors::MalformedOperationError)
76
-
77
- nothing = op_params.dup.tap {|o| o.delete("url"); o.delete("method") }
78
- expect {
79
- BatchApi::Operation::Rack.new(nothing, env, app)
80
- }.to raise_exception(BatchApi::Errors::MalformedOperationError)
81
76
  end
82
77
  end
83
78
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: batch_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: middleware
@@ -226,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  segments:
228
228
  - 0
229
- hash: 1297509053132292607
229
+ hash: -4458634048209158378
230
230
  required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  none: false
232
232
  requirements:
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  segments:
237
237
  - 0
238
- hash: 1297509053132292607
238
+ hash: -4458634048209158378
239
239
  requirements: []
240
240
  rubyforge_project:
241
241
  rubygems_version: 1.8.24