zendesk_api 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -7,7 +7,7 @@ GIT
7
7
  PATH
8
8
  remote: .
9
9
  specs:
10
- zendesk_api (1.0.0)
10
+ zendesk_api (1.0.1)
11
11
  faraday (>= 0.8.0)
12
12
  faraday_middleware (>= 0.8.7)
13
13
  hashie (>= 1.2)
@@ -126,7 +126,7 @@ module ZendeskAPI
126
126
  raise "this collection is for #{@resource_class}"
127
127
  end
128
128
  else
129
- @resources << wrap_resource(item)
129
+ @resources << wrap_resource(item, true)
130
130
  end
131
131
  end
132
132
 
@@ -363,14 +363,17 @@ module ZendeskAPI
363
363
  end
364
364
 
365
365
  # Simplified Associations#wrap_resource
366
- def wrap_resource(res)
366
+ def wrap_resource(res, with_association = @resource_class == Tag)
367
367
  case res
368
368
  when Array
369
369
  wrap_resource(Hash[*res])
370
370
  when Hash
371
- @resource_class.new(@client, res.merge(:association => association))
371
+ res = res.merge(:association => @association) if with_association
372
+ @resource_class.new(@client, res)
372
373
  else
373
- @resource_class.new(@client, :id => res, :association => association)
374
+ res = { :id => res }
375
+ res.merge!(:association => @association) if with_association
376
+ @resource_class.new(@client, res)
374
377
  end
375
378
  end
376
379
 
@@ -4,6 +4,13 @@ module ZendeskAPI
4
4
  module Middleware
5
5
  module Response
6
6
  class RaiseError < Faraday::Response::RaiseError
7
+
8
+ def call(env)
9
+ super
10
+ rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed => e
11
+ raise Error::NetworkError.new(e)
12
+ end
13
+
7
14
  def on_complete(env)
8
15
  case env[:status]
9
16
  when 404
@@ -92,8 +92,8 @@ module ZendeskAPI
92
92
  end
93
93
 
94
94
  # Returns the path to the resource
95
- def path(*args)
96
- @association.generate_path(self, *args)
95
+ def path(options = {})
96
+ @association.generate_path(self, options)
97
97
  end
98
98
 
99
99
  # Passes #to_json to the underlying attributes hash
@@ -1,3 +1,3 @@
1
1
  module ZendeskAPI
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -703,5 +703,21 @@ describe ZendeskAPI::Collection do
703
703
  subject.create
704
704
  end
705
705
  end
706
+
707
+ context "resources" do
708
+ before(:each) do
709
+ stub_json_request(:get, %r{test_resources/active},
710
+ json(:test_resources => [{ :id => 1 }]))
711
+
712
+ subject.fetch
713
+
714
+ stub_json_request(:put, %r{test_resources/1})
715
+ end
716
+
717
+ it "should not save using the collection path" do
718
+ resource = subject.first
719
+ resource.save
720
+ end
721
+ end
706
722
  end
707
723
  end
@@ -1,40 +1,63 @@
1
1
  require 'core/spec_helper'
2
2
 
3
3
  describe ZendeskAPI::Middleware::Response::RaiseError do
4
- before(:each) do
5
- stub_request(:any, /.*/).to_return(:status => status)
6
- end
4
+ context "with a failed connection" do
5
+ context "connection failed" do
6
+ before(:each) do
7
+ stub_request(:any, /.*/).to_raise(Faraday::Error::ConnectionFailed)
8
+ end
9
+
10
+ it "should raise NetworkError" do
11
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
12
+ end
13
+ end
7
14
 
8
- context "with status = 404" do
9
- let(:status) { 404 }
15
+ context "connection timeout" do
16
+ before(:each) do
17
+ stub_request(:any, /.*/).to_timeout
18
+ end
10
19
 
11
- it "should raise RecordNotFound when status is 404" do
12
- expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordNotFound)
20
+ it "should raise NetworkError" do
21
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
22
+ end
13
23
  end
14
24
  end
15
25
 
16
- context "with status in 400...600" do
17
- let(:status) { 500 }
26
+ context "status errors" do
27
+ before(:each) do
28
+ stub_request(:any, /.*/).to_return(:status => status)
29
+ end
18
30
 
19
- it "should raise NetworkError" do
20
- expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
31
+ context "with status = 404" do
32
+ let(:status) { 404 }
33
+
34
+ it "should raise RecordNotFound when status is 404" do
35
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordNotFound)
36
+ end
21
37
  end
22
- end
23
38
 
24
- context "with status = 422" do
25
- let(:status) { 422 }
39
+ context "with status in 400...600" do
40
+ let(:status) { 500 }
26
41
 
27
- it "should raise RecordInvalid" do
28
- expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordInvalid)
42
+ it "should raise NetworkError" do
43
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::NetworkError)
44
+ end
29
45
  end
30
- end
31
46
 
32
- context "with status = 200" do
33
- let(:status) { 200 }
47
+ context "with status = 422" do
48
+ let(:status) { 422 }
34
49
 
35
- it "should not raise" do
36
- client.connection.get "/abcdef"
50
+ it "should raise RecordInvalid" do
51
+ expect { client.connection.get "/non_existent" }.to raise_error(ZendeskAPI::Error::RecordInvalid)
52
+ end
53
+ end
54
+
55
+ context "with status = 200" do
56
+ let(:status) { 200 }
57
+
58
+ it "should not raise" do
59
+ client.connection.get "/abcdef"
60
+ end
37
61
  end
38
62
  end
39
63
  end
40
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-08-06 00:00:00.000000000 Z
13
+ date: 2013-08-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bump