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
@@ -5,11 +5,14 @@ describe HelloSign::Proxy::SignatureRequest do
5
5
  let(:client) { double('client') }
6
6
  let(:request_id) { 'request_id' }
7
7
  let(:api_response) { double('API response') }
8
- subject(:sr_proxy) { HelloSign::Proxy::SignatureRequest.new(client, request_id) }
8
+
9
+ subject(:sr_proxy) do
10
+ HelloSign::Proxy::SignatureRequest.new(client, request_id)
11
+ end
9
12
 
10
13
  before do
11
- client.stub(:get).and_return(api_response)
12
- client.stub(:post).and_return(api_response)
14
+ allow(client).to receive(:get).and_return(api_response)
15
+ allow(client).to receive(:post).and_return(api_response)
13
16
  end
14
17
 
15
18
  describe "#deliver" do
@@ -17,80 +20,103 @@ describe HelloSign::Proxy::SignatureRequest do
17
20
  let(:request_parameters) { double('request parameters') }
18
21
 
19
22
  before do
20
- request_parameters.stub(:foo=)
21
- request_parameters.stub(:formatted).and_return(formatted_request_body)
22
- HelloSign::Parameters::SignatureRequest.stub(:new).and_return(request_parameters)
23
+ allow(request_parameters).to receive(:foo=)
24
+ allow(request_parameters).to(
25
+ receive(:formatted).and_return(formatted_request_body)
26
+ )
27
+ allow(HelloSign::Parameters::SignatureRequest).to(
28
+ receive(:new).and_return(request_parameters)
29
+ )
30
+
31
+ @response = sr_proxy.deliver { |params| params.foo = 'bar' }
23
32
  end
24
33
 
25
34
  it "yields the request parameters to the block" do
26
- request_parameters.should_receive(:foo=).with('bar')
27
- sr_proxy.deliver { |params| params.foo = 'bar' }
35
+ expect(request_parameters).to have_received(:foo=).with('bar')
28
36
  end
29
37
 
30
38
  it "sends a signature request" do
31
- client.should_receive(:post).with('/signature_request/send', body: formatted_request_body)
32
- sr_proxy.deliver { |params| params.foo = 'bar' }
39
+ expect(client).to have_received(:post).with(
40
+ '/signature_request/send',
41
+ body: formatted_request_body
42
+ )
33
43
  end
34
44
 
35
45
  it "returns the response" do
36
- expect(sr_proxy.deliver {}).to eq api_response
46
+ expect(@response).to eq api_response
37
47
  end
38
48
 
39
49
  context "when a reusable form is specified" do
40
50
  before do
41
- request_parameters.stub(:reusable_form_id=)
42
- HelloSign::Parameters::ReusableFormSignatureRequest.stub(:new).and_return(request_parameters)
51
+ allow(request_parameters).to receive(:reusable_form_id=)
52
+ allow(HelloSign::Parameters::ReusableFormSignatureRequest).to(
53
+ receive(:new).and_return(request_parameters)
54
+ )
55
+
56
+ @response = sr_proxy.deliver(form: 'form_id') { }
43
57
  end
44
58
 
45
59
  it "sets the reusable form ID in the request parameters" do
46
- request_parameters.should_receive(:reusable_form_id=).with('form_id')
47
- sr_proxy.deliver(form: 'form_id') {}
60
+ expect(request_parameters).to(
61
+ have_received(:reusable_form_id=).with('form_id')
62
+ )
48
63
  end
49
64
 
50
65
  it "sends a reusable form signature request" do
51
- client.should_receive(:post).with('/signature_request/send_with_reusable_form', body: formatted_request_body)
52
- sr_proxy.deliver(form: 'form_id') {}
66
+ expect(client).to have_received(:post).with(
67
+ '/signature_request/send_with_reusable_form',
68
+ body: formatted_request_body
69
+ )
53
70
  end
54
71
 
55
72
  it "returns the response" do
56
- expect(sr_proxy.deliver(form: 'form_id') {}).to eq api_response
73
+ expect(@response).to eq api_response
57
74
  end
58
75
  end
59
76
  end
60
77
 
61
78
  describe "#status" do
79
+ before { @response = sr_proxy.status }
80
+
62
81
  it "fetches the signature request status" do
63
- client.should_receive(:get).with("/signature_request/#{request_id}")
64
- sr_proxy.status
82
+ expect(client).to have_received(:get).with(
83
+ "/signature_request/#{request_id}"
84
+ )
65
85
  end
66
86
 
67
87
  it "returns the response" do
68
- expect(sr_proxy.status).to eq api_response
88
+ expect(@response).to eq api_response
69
89
  end
70
90
  end
71
91
 
72
92
  describe "#list" do
73
93
  context "when called without a page number" do
94
+ before { @response = sr_proxy.list }
95
+
74
96
  it "fetches the first page of signature requests" do
75
- client.should_receive(:get).with('/signature_request/list', params: {page: 1})
76
- sr_proxy.list
97
+ expect(client).to have_received(:get).with(
98
+ '/signature_request/list',
99
+ params: {page: 1}
100
+ )
77
101
  end
78
102
 
79
103
  it "returns the response" do
80
- client.stub(:get).and_return(api_response)
81
- expect(sr_proxy.list).to eq api_response
104
+ expect(@response).to eq api_response
82
105
  end
83
106
  end
84
107
 
85
108
  context "when called with a page number" do
109
+ before { @response = sr_proxy.list(page: 10) }
110
+
86
111
  it "fetches a list of signature requests from the specified page" do
87
- client.should_receive(:get).with('/signature_request/list', params: {page: 10})
88
- sr_proxy.list(page: 10)
112
+ expect(client).to have_received(:get).with(
113
+ '/signature_request/list',
114
+ params: {page: 10}
115
+ )
89
116
  end
90
117
 
91
118
  it "returns the response" do
92
- client.stub(:get).and_return(api_response)
93
- expect(sr_proxy.list(page: 10)).to eq api_response
119
+ expect(@response).to eq api_response
94
120
  end
95
121
  end
96
122
  end
@@ -98,35 +124,45 @@ describe HelloSign::Proxy::SignatureRequest do
98
124
  describe "#remind" do
99
125
  let(:email) { 'john@johnson.com' }
100
126
 
127
+ before { @response = sr_proxy.remind(email: email) }
128
+
101
129
  it "sends a signature request reminder" do
102
- client.should_receive(:post).with("/signature_request/remind/#{request_id}", body: {email_address: email})
103
- sr_proxy.remind(email: email)
130
+ expect(client).to have_received(:post).with(
131
+ "/signature_request/remind/#{request_id}",
132
+ body: {email_address: email}
133
+ )
104
134
  end
105
135
 
106
136
  it "returns the response" do
107
- expect(sr_proxy.remind(email: email)).to eq api_response
137
+ expect(@response).to eq api_response
108
138
  end
109
139
  end
110
140
 
111
141
  describe "#cancel" do
142
+ before { @response = sr_proxy.cancel }
143
+
112
144
  it "cancels a signature request" do
113
- client.should_receive(:post).with("/signature_request/cancel/#{request_id}")
114
- sr_proxy.cancel
145
+ expect(client).to have_received(:post).with(
146
+ "/signature_request/cancel/#{request_id}"
147
+ )
115
148
  end
116
149
 
117
150
  it "returns the response" do
118
- expect(sr_proxy.cancel).to eq api_response
151
+ expect(@response).to eq api_response
119
152
  end
120
153
  end
121
154
 
122
155
  describe "#final_copy" do
156
+ before { @response = sr_proxy.final_copy }
157
+
123
158
  it "fetches a final copy of the signature request" do
124
- client.should_receive(:get).with("/signature_request/final_copy/#{request_id}")
125
- sr_proxy.final_copy
159
+ expect(client).to have_received(:get).with(
160
+ "/signature_request/final_copy/#{request_id}"
161
+ )
126
162
  end
127
163
 
128
164
  it "returns the response" do
129
- expect(sr_proxy.final_copy).to eq api_response
165
+ expect(@response).to eq api_response
130
166
  end
131
167
  end
132
168
  end
@@ -4,84 +4,103 @@ require 'hello_sign/proxy/team'
4
4
  describe HelloSign::Proxy::Team do
5
5
  let(:client) { double('client') }
6
6
  let(:api_response) { double('API response') }
7
+
7
8
  subject(:team_proxy) { HelloSign::Proxy::Team.new(client) }
8
9
 
9
10
  before do
10
- client.stub(:get).and_return(api_response)
11
- client.stub(:post).and_return(api_response)
11
+ allow(client).to receive(:get).and_return(api_response)
12
+ allow(client).to receive(:post).and_return(api_response)
12
13
  end
13
14
 
14
15
  describe "#create" do
15
16
  let(:name) { 'The Browncoats' }
16
17
 
18
+ before { @response = team_proxy.create(name: name) }
19
+
17
20
  it "sends a request to create a team" do
18
- client.should_receive(:post).with('/team/create', body: {name: name})
19
- team_proxy.create(name: name)
21
+ expect(client).to have_received(:post).with(
22
+ '/team/create',
23
+ body: {name: name}
24
+ )
20
25
  end
21
26
 
22
27
  it "returns the API response" do
23
- expect(team_proxy.create(name: name)).to eq api_response
28
+ expect(@response).to eq api_response
24
29
  end
25
30
  end
26
31
 
27
32
  describe "#show" do
33
+ before { @response = team_proxy.show }
34
+
28
35
  it "sends a request to fetch the team information" do
29
- client.should_receive(:get).with('/team')
30
- team_proxy.show
36
+ expect(client).to have_received(:get).with('/team')
31
37
  end
32
38
 
33
39
  it "returns the API response" do
34
- expect(team_proxy.show).to eq api_response
40
+ expect(@response).to eq api_response
35
41
  end
36
42
  end
37
43
 
38
44
  describe "#update" do
39
45
  let(:new_name) { 'The Bluecoats' }
40
46
 
47
+ before { @response = team_proxy.update(name: new_name) }
48
+
41
49
  it "sends a request to update the team information" do
42
- client.should_receive(:post).with('/team', body: {name: new_name})
43
- team_proxy.update(name: new_name)
50
+ expect(client).to have_received(:post).with(
51
+ '/team',
52
+ body: {name: new_name}
53
+ )
44
54
  end
45
55
 
46
56
  it "returns the API response" do
47
- expect(team_proxy.update(name: new_name)).to eq api_response
57
+ expect(@response).to eq api_response
48
58
  end
49
59
  end
50
60
 
51
61
  describe "#destroy" do
62
+ before { @response = team_proxy.destroy }
63
+
52
64
  it "sends a request to destroy the team" do
53
- client.should_receive(:post).with('/team/destroy')
54
- team_proxy.destroy
65
+ expect(client).to have_received(:post).with('/team/destroy')
55
66
  end
56
67
 
57
68
  it "returns the API response" do
58
- expect(team_proxy.destroy).to eq api_response
69
+ expect(@response).to eq api_response
59
70
  end
60
71
  end
61
72
 
62
73
  describe "#add_member" do
63
74
  let(:email_address) { 'john@johnson.com' }
64
75
 
76
+ before { @response = team_proxy.add_member(email_address: email_address) }
77
+
65
78
  it "sends a request to add the member to the team" do
66
- client.should_receive(:post).with('/team/add_member', body: {email_address: email_address})
67
- team_proxy.add_member(email_address: email_address)
79
+ expect(client).to have_received(:post).with(
80
+ '/team/add_member',
81
+ body: {email_address: email_address}
82
+ )
68
83
  end
69
84
 
70
85
  it "returns the API response" do
71
- expect(team_proxy.add_member(email_address: email_address)).to eq api_response
86
+ expect(@response).to eq api_response
72
87
  end
73
88
  end
74
89
 
75
90
  describe "#remove_member" do
76
91
  let(:email_address) { 'john@johnson.com' }
77
92
 
93
+ before { @response = team_proxy.remove_member(email_address: email_address) }
94
+
78
95
  it "sends a request to remove the member from the team" do
79
- client.should_receive(:post).with('/team/remove_member', body: {email_address: email_address})
80
- team_proxy.remove_member(email_address: email_address)
96
+ expect(client).to have_received(:post).with(
97
+ '/team/remove_member',
98
+ body: {email_address: email_address}
99
+ )
81
100
  end
82
101
 
83
102
  it "returns the API response" do
84
- expect(team_proxy.remove_member(email_address: email_address)).to eq api_response
103
+ expect(@response).to eq api_response
85
104
  end
86
105
  end
87
106
  end
@@ -4,21 +4,40 @@ require 'hello_sign/proxy/unclaimed_draft'
4
4
  describe HelloSign::Proxy::UnclaimedDraft do
5
5
  let(:client) { double('client') }
6
6
  let(:api_response) { double('API response') }
7
+
7
8
  subject(:ud_proxy) { HelloSign::Proxy::UnclaimedDraft.new(client) }
8
9
 
10
+ before { allow(client).to receive(:post).and_return(api_response) }
11
+
9
12
  describe "#create" do
10
13
  let(:formatted_request_body) { double('formatted request body') }
11
14
  let(:draft_parameters) { double('draft parameters') }
12
15
 
13
16
  before do
14
- HelloSign::Parameters::UnclaimedDraft.stub(:new).and_return(draft_parameters)
15
- draft_parameters.stub(:formatted).and_return(formatted_request_body)
16
- draft_parameters.should_receive(:foo=).with('bar')
17
- client.should_receive(:post).with('/unclaimed_draft/create', body: formatted_request_body).and_return(api_response)
17
+ allow(HelloSign::Parameters::UnclaimedDraft).to(
18
+ receive(:new).and_return(draft_parameters)
19
+ )
20
+ allow(draft_parameters).to(
21
+ receive(:formatted).and_return(formatted_request_body)
22
+ )
23
+ allow(draft_parameters).to receive(:foo=)
24
+
25
+ @response = ud_proxy.create { |params| params.foo = 'bar' }
26
+ end
27
+
28
+ it "yields the request parameters to the block" do
29
+ expect(draft_parameters).to have_received(:foo=).with('bar')
30
+ end
31
+
32
+ it "sends an unclaimed draft creation request" do
33
+ expect(client).to have_received(:post).with(
34
+ '/unclaimed_draft/create',
35
+ body: formatted_request_body
36
+ )
18
37
  end
19
38
 
20
- it "sends a unclaimed draft creation request and returns the result" do
21
- expect(ud_proxy.create { |params| params.foo = 'bar' }).to eq api_response
39
+ it "returns the response" do
40
+ expect(@response).to eq api_response
22
41
  end
23
42
  end
24
43
  end
@@ -5,53 +5,95 @@ describe HelloSign::File do
5
5
  let(:attachment) { double('attachment') }
6
6
  let(:io_object) { double('IO object') }
7
7
 
8
- it "returns the attachment" do
9
- Faraday::UploadIO.stub(:new).and_return(attachment)
8
+ context "#attachment" do
9
+ before { allow(Faraday::UploadIO).to receive(:new).and_return(attachment) }
10
10
 
11
- expect(HelloSign::File.new(filename: 'test.txt').attachment).to eq attachment
12
- end
11
+ it "returns the attachment" do
12
+ expect(HelloSign::File.new(filename: 'test.txt').attachment).to(
13
+ eq attachment
14
+ )
15
+ end
13
16
 
14
- context "#upload" do
15
- specify do
16
- Faraday::UploadIO.should_receive(:new).with('test.txt', 'text/plain')
17
+ context "when called with a file with a .txt extension" do
18
+ before { HelloSign::File.new(filename: 'test.txt').attachment }
17
19
 
18
- HelloSign::File.new(filename: 'test.txt').attachment
20
+ it "creates an attachment with a text/plain MIME type" do
21
+ expect(Faraday::UploadIO).to(
22
+ have_received(:new).with('test.txt', 'text/plain')
23
+ )
24
+ end
19
25
  end
20
26
 
21
- specify do
22
- Faraday::UploadIO.should_receive(:new).with('test.foo', 'text/plain')
27
+ context "when called with a file with an unknown extension" do
28
+ before { HelloSign::File.new(filename: 'test.foo').attachment }
23
29
 
24
- HelloSign::File.new(filename: 'test.foo').attachment
30
+ it "creates an attachment with a text/plain MIME type" do
31
+ expect(Faraday::UploadIO).to(
32
+ have_received(:new).with('test.foo', 'text/plain')
33
+ )
34
+ end
25
35
  end
26
36
 
27
- specify do
28
- Faraday::UploadIO.should_receive(:new).with('test.baz', 'fake/mime')
37
+ context "when called with a specified MIME type" do
38
+ before do
39
+ HelloSign::File.new(filename: 'test.baz', mime: 'fake/mime').attachment
40
+ end
29
41
 
30
- HelloSign::File.new(filename: 'test.baz', mime: 'fake/mime').attachment
42
+ it "creates an attachment with the specified MIME type" do
43
+ expect(Faraday::UploadIO).to(
44
+ have_received(:new).with('test.baz', 'fake/mime')
45
+ )
46
+ end
31
47
  end
32
48
 
33
- specify do
34
- Faraday::UploadIO.should_receive(:new).with(io_object, 'text/plain')
49
+ context "when called with an IO object" do
50
+ before { HelloSign::File.new(io: io_object).attachment }
35
51
 
36
- HelloSign::File.new(io: io_object).attachment
52
+ it "creates an attachment with a text/plain MIME type" do
53
+ expect(Faraday::UploadIO).to(
54
+ have_received(:new).with(io_object, 'text/plain')
55
+ )
56
+ end
37
57
  end
38
58
 
39
- specify do
40
- Faraday::UploadIO.should_receive(:new).with(io_object, 'fake/mime')
59
+ context "when called with an IO and a specified MIME type" do
60
+ before do
61
+ HelloSign::File.new(io: io_object, mime: 'fake/mime').attachment
62
+ end
41
63
 
42
- HelloSign::File.new(io: io_object, mime: 'fake/mime').attachment
64
+ it "creates an attachment with the specified MIME type" do
65
+ expect(Faraday::UploadIO).to(
66
+ have_received(:new).with(io_object, 'fake/mime')
67
+ )
68
+ end
43
69
  end
44
70
 
45
- specify do
46
- Faraday::UploadIO.should_receive(:new).with(io_object, 'fake/mime', 'test.foo')
47
-
48
- HelloSign::File.new(filename: 'test.foo', io: io_object, mime: 'fake/mime').attachment
71
+ context "when called with a filename, IO object, and MIME type" do
72
+ before do
73
+ HelloSign::File.new(
74
+ filename: 'test.foo',
75
+ io: io_object,
76
+ mime: 'fake/mime'
77
+ ).attachment
78
+ end
79
+
80
+ it "creates an attachment with the specified information" do
81
+ expect(Faraday::UploadIO).to(
82
+ have_received(:new).with(io_object, 'fake/mime', 'test.foo')
83
+ )
84
+ end
49
85
  end
50
86
 
51
- specify do
52
- Faraday::UploadIO.should_receive(:new).with(io_object, 'text/plain', 'test.foo')
87
+ context "when called with a filename and IO object" do
88
+ before do
89
+ HelloSign::File.new(filename: 'test.foo', io: io_object).attachment
90
+ end
53
91
 
54
- HelloSign::File.new(filename: 'test.foo', io: io_object).attachment
92
+ it "creates an attachment with a text/plain MIME type" do
93
+ expect(Faraday::UploadIO).to(
94
+ have_received(:new).with(io_object, 'text/plain', 'test.foo')
95
+ )
96
+ end
55
97
  end
56
98
  end
57
99
  end