hello_sign 1.1.0 → 1.1.1

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.
Files changed (32) hide show
  1. data/lib/hello_sign.rb +29 -5
  2. data/lib/hello_sign/client.rb +13 -38
  3. data/lib/hello_sign/connection.rb +53 -0
  4. data/lib/hello_sign/error.rb +13 -9
  5. data/lib/hello_sign/middleware/parse_json.rb +22 -0
  6. data/lib/hello_sign/middleware/raise_error.rb +2 -0
  7. data/lib/hello_sign/parameters/reusable_form_signature_request.rb +27 -14
  8. data/lib/hello_sign/parameters/signature_request.rb +29 -21
  9. data/lib/hello_sign/parameters/unclaimed_draft.rb +8 -5
  10. data/lib/hello_sign/proxy/signature_request.rb +30 -18
  11. data/lib/hello_sign/version.rb +1 -1
  12. data/spec/helper.rb +0 -6
  13. data/spec/integration/hello_sign_spec.rb +7 -1
  14. data/spec/integration/helper.rb +17 -4
  15. data/spec/shared_examples/proxy.rb +58 -15
  16. data/spec/unit/client_spec.rb +42 -27
  17. data/spec/unit/connection_spec.rb +38 -0
  18. data/spec/unit/error_spec.rb +65 -13
  19. data/spec/unit/hello_sign_spec.rb +66 -23
  20. data/spec/unit/middleware/parse_json_spec.rb +38 -0
  21. data/spec/unit/middleware/raise_error_spec.rb +36 -23
  22. data/spec/unit/parameters/reusable_form_signature_request_spec.rb +74 -37
  23. data/spec/unit/parameters/signature_request_spec.rb +11 -5
  24. data/spec/unit/parameters/unclaimed_draft_spec.rb +14 -6
  25. data/spec/unit/proxy/account_spec.rb +17 -9
  26. data/spec/unit/proxy/reusable_form_spec.rb +31 -14
  27. data/spec/unit/proxy/settings_spec.rb +11 -4
  28. data/spec/unit/proxy/signature_request_spec.rb +74 -38
  29. data/spec/unit/proxy/team_spec.rb +39 -20
  30. data/spec/unit/proxy/unclaimed_draft_spec.rb +25 -6
  31. data/spec/unit/upload_io_spec.rb +69 -27
  32. metadata +20 -40
@@ -1,3 +1,3 @@
1
1
  module HelloSign
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
@@ -6,9 +6,3 @@ RSpec.configure do |config|
6
6
  config.color_enabled = true
7
7
  config.tty = true
8
8
  end
9
-
10
- class Module
11
- def _set_internal_collaborator(role, collaborator)
12
- instance_variable_set("@#{role.to_s}", collaborator)
13
- end
14
- end
@@ -3,7 +3,13 @@ require 'json'
3
3
 
4
4
  describe HelloSign do
5
5
  context "when returning a response with a body" do
6
- before { stub_get_with_auth('/json').to_return(body: {account_id: 1}.to_json) }
6
+ before do
7
+ stub_get_with_auth('/json')
8
+ .to_return(
9
+ headers: {'Content-Type' => 'application/json'},
10
+ body: {account_id: 1}.to_json
11
+ )
12
+ end
7
13
 
8
14
  it "parses the body into a hash with symbols as keys" do
9
15
  expect(HelloSign.client.get('/json')).to eq({account_id: 1})
@@ -22,15 +22,25 @@ def stub_post(path)
22
22
  end
23
23
 
24
24
  def stub_get_with_auth(path)
25
- stub_request(:get, "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}")
25
+ stub_request(
26
+ :get,
27
+ "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}"
28
+ )
26
29
  end
27
30
 
28
31
  def stub_post_with_auth(path)
29
- stub_request(:post, "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}")
32
+ stub_request(
33
+ :post,
34
+ "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}"
35
+ )
30
36
  end
31
37
 
32
38
  def stub_request_with_error(error)
33
- stub_request(:any, /api\.hellosign\.com/).to_return(body: {error: {error_name: error}})
39
+ stub_request(:any, /api\.hellosign\.com/)
40
+ .to_return(
41
+ headers: {'Content-Type' => 'application/json'},
42
+ body: {error: {error_name: error}}.to_json
43
+ )
34
44
  end
35
45
 
36
46
  def a_get(path)
@@ -46,5 +56,8 @@ def a_get_with_auth(path)
46
56
  end
47
57
 
48
58
  def a_post_with_auth(path)
49
- a_request(:post, "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}")
59
+ a_request(
60
+ :post,
61
+ "https://david@bowman.com:foobar@api.hellosign.com/v3#{path}"
62
+ )
50
63
  end
@@ -2,46 +2,89 @@ shared_examples_for 'a proxy' do
2
2
  let(:proxy) { double('proxy') }
3
3
 
4
4
  describe "#account" do
5
+ before do
6
+ allow(HelloSign::Proxy::Account).to(
7
+ receive(:new).with(client).and_return(proxy)
8
+ )
9
+ end
10
+
5
11
  it "returns an account proxy" do
6
- HelloSign::Proxy::Account.should_receive(:new).with(client).and_return(proxy)
7
12
  expect(client.account).to eq proxy
8
13
  end
9
14
  end
10
15
 
11
16
  describe "#signature_request" do
12
- it "returns a signature request proxy" do
13
- HelloSign::Proxy::SignatureRequest.should_receive(:new).with(client, nil).and_return(proxy)
14
- expect(client.signature_request).to eq proxy
17
+ before { allow(HelloSign::Proxy::SignatureRequest).to receive(:new) }
18
+
19
+ context "when called without a signature request ID" do
20
+ before do
21
+ allow(HelloSign::Proxy::SignatureRequest).to(
22
+ receive(:new).with(client, nil).and_return(proxy)
23
+ )
24
+ end
25
+
26
+ it "returns a signature request proxy" do
27
+ expect(client.signature_request).to eq proxy
28
+ end
15
29
  end
16
30
 
17
- it "passes on an optional signature request ID" do
18
- HelloSign::Proxy::SignatureRequest.should_receive(:new).with(client, 'signature_request_id')
19
- client.signature_request('signature_request_id')
31
+ context "when called with a signature request ID" do
32
+ before { client.signature_request('signature_request_id') }
33
+
34
+ it "passes on the signature request ID" do
35
+ expect(HelloSign::Proxy::SignatureRequest).to(
36
+ have_received(:new).with(client, 'signature_request_id')
37
+ )
38
+ end
20
39
  end
21
40
  end
22
41
 
23
42
  describe "#reusable_form" do
24
- it "returns a reusable form proxy" do
25
- HelloSign::Proxy::ReusableForm.should_receive(:new).with(client, nil).and_return(proxy)
26
- expect(client.reusable_form).to eq proxy
43
+ before { allow(HelloSign::Proxy::ReusableForm).to receive(:new) }
44
+
45
+ context "when called without a reusable form ID" do
46
+ before do
47
+ allow(HelloSign::Proxy::ReusableForm).to(
48
+ receive(:new).with(client, nil).and_return(proxy)
49
+ )
50
+ end
51
+
52
+ it "returns a reusable form proxy" do
53
+ expect(client.reusable_form).to eq proxy
54
+ end
27
55
  end
28
56
 
29
- it "passes on an optional reusable form ID" do
30
- HelloSign::Proxy::ReusableForm.should_receive(:new).with(client, 'reusable_form_id')
31
- client.reusable_form('reusable_form_id')
57
+ context "when called with a reusable form ID" do
58
+ before { client.reusable_form('reusable_form_id') }
59
+
60
+ it "passes on an optional reusable form ID" do
61
+ expect(HelloSign::Proxy::ReusableForm).to(
62
+ have_received(:new).with(client, 'reusable_form_id')
63
+ )
64
+ end
32
65
  end
33
66
  end
34
67
 
35
68
  describe "#team" do
69
+ before do
70
+ allow(HelloSign::Proxy::Team).to(
71
+ receive(:new).with(client).and_return(proxy)
72
+ )
73
+ end
74
+
36
75
  it "returns a team proxy" do
37
- HelloSign::Proxy::Team.should_receive(:new).with(client).and_return(proxy)
38
76
  expect(client.team).to eq proxy
39
77
  end
40
78
  end
41
79
 
42
80
  describe "#unclaimed_draft" do
81
+ before do
82
+ allow(HelloSign::Proxy::UnclaimedDraft).to(
83
+ receive(:new).with(client).and_return(proxy)
84
+ )
85
+ end
86
+
43
87
  it "returns an unclaimed draft proxy" do
44
- HelloSign::Proxy::UnclaimedDraft.should_receive(:new).with(client).and_return(proxy)
45
88
  expect(client.unclaimed_draft).to eq proxy
46
89
  end
47
90
  end
@@ -3,53 +3,68 @@ require 'hello_sign/client'
3
3
  require 'shared_examples/proxy'
4
4
 
5
5
  describe HelloSign::Client do
6
- let(:email_address) { double('email_address') }
7
- let(:password) { double('password') }
8
- subject(:hs_client) { HelloSign::Client.new(email_address, password) }
6
+ let(:connection) { double('connection') }
7
+ let(:response) { double('response') }
8
+
9
+ subject(:hs_client) { HelloSign::Client.new('email address', 'password') }
9
10
 
10
11
  it_behaves_like 'a proxy' do
11
12
  let(:client) { hs_client }
12
13
  end
13
14
 
14
- describe "request methods" do
15
- let(:path) { double('path') }
16
- let(:options) { double('options') }
17
- let(:response) { double('response') }
15
+ before do
16
+ allow(HelloSign::Connection).to receive(:new).and_return(connection)
17
+ end
18
+
19
+ describe "#get" do
20
+ before do
21
+ allow(connection).to receive(:get).and_return(response)
18
22
 
19
- before { hs_client.stub(:request).and_return(response) }
23
+ @response = hs_client.get('/path', options: 'hash')
24
+ end
20
25
 
21
- describe "#get" do
22
- it "sends a request" do
23
- hs_client.should_receive(:request).with(:get, path, options)
24
- hs_client.get(path, options)
25
- end
26
+ it "delegates to the connection" do
27
+ expect(connection).to have_received(:get).with('/path', options: 'hash')
28
+ end
26
29
 
27
- it "returns the response" do
28
- expect(hs_client.get(path, options)).to eq response
29
- end
30
+ it "returns the response" do
31
+ expect(@response).to eq response
30
32
  end
33
+ end
31
34
 
32
- describe "#post" do
33
- it "sends a request" do
34
- hs_client.should_receive(:request).with(:post, path, options)
35
- hs_client.post(path, options)
36
- end
35
+ describe "#post" do
36
+ before do
37
+ allow(connection).to receive(:post).and_return(response)
37
38
 
38
- it "returns the response" do
39
- expect(hs_client.post(path, options)).to eq response
40
- end
39
+ @response = hs_client.post('/path', options: 'hash')
40
+ end
41
+
42
+ it "delegates to the connection" do
43
+ expect(connection).to(
44
+ have_received(:post).with('/path', options: 'hash')
45
+ )
46
+ end
47
+
48
+ it "returns the response" do
49
+ expect(@response).to eq response
41
50
  end
42
51
  end
43
52
 
44
53
  context "when a hash is passed to the constructor" do
45
- subject(:hs_client) { HelloSign::Client.new(email_address: email_address, password: password) }
54
+ subject(:hs_client) do
55
+ HelloSign::Client.new(email_address: email_address, password: password)
56
+ end
46
57
 
47
58
  it "raises an exception if an email address is not provided" do
48
- expect { HelloSign::Client.new(password: 'space') }.to raise_error ArgumentError
59
+ expect { HelloSign::Client.new(password: 'space') }.to(
60
+ raise_error ArgumentError
61
+ )
49
62
  end
50
63
 
51
64
  it "raises an exception if a password is not provided" do
52
- expect { HelloSign::Client.new(email_address: 'david@bowman.com') }.to raise_error ArgumentError
65
+ expect { HelloSign::Client.new(email_address: 'david@bowman.com') }.to(
66
+ raise_error ArgumentError
67
+ )
53
68
  end
54
69
  end
55
70
  end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+ require 'hello_sign/connection'
3
+
4
+ describe HelloSign::Connection do
5
+ let(:response) { double('response') }
6
+
7
+ subject(:connection) { HelloSign::Connection.new }
8
+
9
+ before { allow(connection).to receive(:request).and_return(response) }
10
+
11
+ describe "#get" do
12
+ before { @response = connection.get('/path', options: 'hash') }
13
+
14
+ it "sends a request" do
15
+ expect(connection).to(
16
+ have_received(:request).with(:get, '/path', options: 'hash')
17
+ )
18
+ end
19
+
20
+ it "returns the response" do
21
+ expect(@response).to eq response
22
+ end
23
+ end
24
+
25
+ describe "#post" do
26
+ before { @response = connection.post('/path', options: 'hash') }
27
+
28
+ it "sends a request" do
29
+ expect(connection).to(
30
+ have_received(:request).with(:post, '/path', options: 'hash')
31
+ )
32
+ end
33
+
34
+ it "returns the response" do
35
+ expect(@response).to eq response
36
+ end
37
+ end
38
+ end
@@ -2,23 +2,75 @@ require 'helper'
2
2
  require 'hello_sign/error'
3
3
 
4
4
  describe HelloSign::Error do
5
- specify { expect { raise HelloSign::Error }.to raise_error StandardError }
6
- specify { expect { raise HelloSign::Error::BadRequest }.to raise_error HelloSign::Error }
7
- specify { expect { raise HelloSign::Error::Unauthorized }.to raise_error HelloSign::Error }
8
- specify { expect { raise HelloSign::Error::Forbidden }.to raise_error HelloSign::Error }
9
- specify { expect { raise HelloSign::Error::NotFound }.to raise_error HelloSign::Error }
10
- specify { expect { raise HelloSign::Error::Unknown }.to raise_error HelloSign::Error }
11
- specify { expect { raise HelloSign::Error::TeamInviteFailed }.to raise_error HelloSign::Error }
12
- specify { expect { raise HelloSign::Error::InvalidRecipient }.to raise_error HelloSign::Error }
13
- specify { expect { raise HelloSign::Error::ConvertFailed }.to raise_error HelloSign::Error }
14
- specify { expect { raise HelloSign::Error::SignatureRequestCancelFailed }.to raise_error HelloSign::Error }
5
+ specify do
6
+ expect { raise HelloSign::Error }.to(
7
+ raise_error StandardError
8
+ )
9
+ end
10
+
11
+ specify do
12
+ expect { raise HelloSign::Error::BadRequest }.to(
13
+ raise_error HelloSign::Error
14
+ )
15
+ end
16
+
17
+ specify do
18
+ expect { raise HelloSign::Error::Unauthorized }.to(
19
+ raise_error HelloSign::Error
20
+ )
21
+ end
22
+
23
+ specify do
24
+ expect { raise HelloSign::Error::Forbidden }.to(
25
+ raise_error HelloSign::Error
26
+ )
27
+ end
28
+
29
+ specify do
30
+ expect { raise HelloSign::Error::NotFound }.to(
31
+ raise_error HelloSign::Error
32
+ )
33
+ end
34
+
35
+ specify do
36
+ expect { raise HelloSign::Error::Unknown }.to(
37
+ raise_error HelloSign::Error
38
+ )
39
+ end
40
+
41
+ specify do
42
+ expect { raise HelloSign::Error::TeamInviteFailed }.to(
43
+ raise_error HelloSign::Error
44
+ )
45
+ end
46
+
47
+ specify do
48
+ expect { raise HelloSign::Error::InvalidRecipient }.to(
49
+ raise_error HelloSign::Error
50
+ )
51
+ end
52
+
53
+ specify do
54
+ expect { raise HelloSign::Error::ConvertFailed }.to(
55
+ raise_error HelloSign::Error
56
+ )
57
+ end
58
+
59
+ specify do
60
+ expect { raise HelloSign::Error::SignatureRequestCancelFailed }.to(
61
+ raise_error HelloSign::Error
62
+ )
63
+ end
15
64
 
16
65
  describe "#to_s" do
17
- let(:error) { HelloSign::Error.new('This is why an error was received.', 401) }
18
- let(:expected) { '[Status code: 401] This is why an error was received.' }
66
+ let(:error) {
67
+ HelloSign::Error.new('This is why an error was received.', 401)
68
+ }
19
69
 
20
70
  it "displays a helpful message" do
21
- expect(error.to_s).to eq expected
71
+ expect(error.to_s).to(
72
+ eq '[Status code: 401] This is why an error was received.'
73
+ )
22
74
  end
23
75
  end
24
76
  end
@@ -13,18 +13,26 @@ describe HelloSign do
13
13
  describe "::client" do
14
14
  let(:client) { double('client') }
15
15
 
16
- it "passes the credentials when creating the client" do
17
- HelloSign::Client.should_receive(:new).with(email_address, password)
18
- HelloSign.client
16
+ before { allow(HelloSign::Client).to receive(:new) }
17
+
18
+ context "when it has not previously been called" do
19
+ before { HelloSign.client }
20
+
21
+ it "passes the credentials when creating the client" do
22
+ expect(HelloSign::Client).to(
23
+ have_received(:new).with(email_address, password)
24
+ )
25
+ end
19
26
  end
20
27
 
21
28
  context "when it has previously been called" do
22
29
  let(:new_client) { double('new client') }
23
30
 
24
31
  before do
25
- HelloSign::Client.stub(:new).and_return(client, new_client)
26
- client.stub(:email_address).and_return(email_address)
27
- client.stub(:password).and_return(password)
32
+ allow(HelloSign::Client).to receive(:new).and_return(client, new_client)
33
+ allow(client).to receive(:email_address).and_return(email_address)
34
+ allow(client).to receive(:password).and_return(password)
35
+
28
36
  HelloSign.client
29
37
  end
30
38
 
@@ -44,35 +52,70 @@ describe HelloSign do
44
52
  end
45
53
 
46
54
  context "when calling delegated methods" do
47
- let(:client) { double('client') }
55
+ let(:client) { double('client') }
48
56
 
49
- before { HelloSign::Client.stub(:new).and_return(client) }
57
+ before { allow(HelloSign::Client).to receive(:new).and_return(client) }
50
58
 
51
59
  after { HelloSign.instance_variable_set(:@client, nil) }
52
60
 
53
- it "delegates ::account to the client" do
54
- client.should_receive(:account)
55
- HelloSign.account
61
+ describe "::account" do
62
+ before do
63
+ allow(client).to receive(:account)
64
+
65
+ HelloSign.account
66
+ end
67
+
68
+ it "delegates to the client" do
69
+ expect(client).to have_received(:account)
70
+ end
56
71
  end
57
72
 
58
- it "delegates ::signature_request to the client" do
59
- client.should_receive(:signature_request)
60
- HelloSign.signature_request
73
+ describe "::signature_request" do
74
+ before do
75
+ allow(client).to receive(:signature_request)
76
+
77
+ HelloSign.signature_request
78
+ end
79
+
80
+ it "delegates ::signature_request to the client" do
81
+ expect(client).to have_received(:signature_request)
82
+ end
61
83
  end
62
84
 
63
- it "delegates ::reusable_form to the client" do
64
- client.should_receive(:reusable_form)
65
- HelloSign.reusable_form
85
+ describe "::reusable_form" do
86
+ before do
87
+ allow(client).to receive(:reusable_form)
88
+
89
+ HelloSign.reusable_form
90
+ end
91
+
92
+ it "delegates ::reusable_form to the client" do
93
+ expect(client).to have_received(:reusable_form)
94
+ end
66
95
  end
67
96
 
68
- it "delegates ::team to the client" do
69
- client.should_receive(:team)
70
- HelloSign.team
97
+ describe "::team" do
98
+ before do
99
+ allow(client).to receive(:team)
100
+
101
+ HelloSign.team
102
+ end
103
+
104
+ it "delegates ::team to the client" do
105
+ expect(client).to have_received(:team)
106
+ end
71
107
  end
72
108
 
73
- it "delegates ::unclaimed_draft to the client" do
74
- client.should_receive(:unclaimed_draft)
75
- HelloSign.unclaimed_draft
109
+ describe "::unclaimed_draft" do
110
+ before do
111
+ allow(client).to receive(:unclaimed_draft)
112
+
113
+ HelloSign.unclaimed_draft
114
+ end
115
+
116
+ it "delegates ::unclaimed_draft to the client" do
117
+ expect(client).to have_received(:unclaimed_draft)
118
+ end
76
119
  end
77
120
  end
78
121