Skip to content

Commit cd962f4

Browse files
committedJul 29, 2014
add specs for pushing json to Wombat
1 parent b55d1ce commit cd962f4

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed
 

‎lib/wombat/client.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Client
1010

1111
def self.push(json_payload)
1212
res = HTTParty.post(
13-
Spree::configuration.push_url,
13+
Wombat.configuration.push_url,
1414
{
1515
body: json_payload,
1616
headers: {
@@ -25,11 +25,10 @@ def self.push(json_payload)
2525
end
2626

2727
private
28-
def validate(res)
28+
def self.validate(res)
2929
raise PushApiError, "Push not successful. Wombat returned response code #{res.code} and message: #{res.body}" if res.code != 202
3030
end
31-
end
32-
33-
class PushApiError < StandardError; end
3431

32+
class PushApiError < StandardError; end
33+
end
3534
end

‎spec/spec_helper.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'wombat'
2+
require 'webmock/rspec'
23

34
RSpec.configure do |config|
45
config.color = true

‎spec/wombat/client_spec.rb

+42
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,46 @@
11
require "spec_helper"
22

33
describe Wombat::Client do
4+
5+
context "push json" do
6+
7+
before do
8+
Wombat.configure do |config|
9+
config.connection_id = "123"
10+
config.connection_token = "token"
11+
end
12+
stub_request(:post, "https://push.wombat.co/").
13+
with(
14+
:body => "name:value",
15+
:headers => {
16+
'Content-Type'=>'application/json',
17+
'X-Hub-Access-Token'=>'token',
18+
'X-Hub-Store'=>'123',
19+
'X-Hub-Timestamp'=>/.*/}
20+
).to_return(:status => 202, :body => "", :headers => {})
21+
end
22+
23+
it "sends the connection_id and token as headers" do
24+
Wombat::Client.push("name:value")
25+
end
26+
27+
context "with response not 202" do
28+
before do
29+
stub_request(:post, "https://push.wombat.co/").
30+
with(
31+
:body => "name:value",
32+
:headers => {
33+
'Content-Type'=>'application/json',
34+
'X-Hub-Access-Token'=>'token',
35+
'X-Hub-Store'=>'123',
36+
'X-Hub-Timestamp'=>/.*/}
37+
).to_return(:status => 404, :body => "wombat error", :headers => {})
38+
end
39+
40+
it "will raise PushApiException" do
41+
expect{ Wombat::Client.push("name:value")}.to raise_error(Wombat::Client::PushApiError, "Push not successful. Wombat returned response code 404 and message: wombat error")
42+
end
43+
end
44+
end
45+
446
end

‎wombat-ruby.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
2121
spec.add_development_dependency "bundler", "~> 1.5"
2222
spec.add_development_dependency "rake"
2323
spec.add_development_dependency "rspec", "~> 3.0.0"
24+
spec.add_development_dependency "webmock"
2425
spec.add_dependency 'active_model_serializers', '0.9.0.alpha1'
2526
spec.add_dependency 'httparty'
2627
end

0 commit comments

Comments
 (0)
Please sign in to comment.