sendgrid4r 0.3.0 → 0.4.0

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +4 -1
  3. data/.travis.yml +1 -1
  4. data/lib/client.rb +0 -2
  5. data/lib/sendgrid4r/rest/api.rb +4 -0
  6. data/lib/sendgrid4r/rest/api_keys/api_keys.rb +4 -10
  7. data/lib/sendgrid4r/rest/asm/global_suppressions.rb +9 -16
  8. data/lib/sendgrid4r/rest/asm/groups.rb +3 -7
  9. data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -18
  10. data/lib/sendgrid4r/rest/categories/categories.rb +1 -3
  11. data/lib/sendgrid4r/rest/contacts/custom_fields.rb +1 -1
  12. data/lib/sendgrid4r/rest/contacts/lists.rb +15 -37
  13. data/lib/sendgrid4r/rest/contacts/recipients.rb +19 -44
  14. data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +1 -5
  15. data/lib/sendgrid4r/rest/contacts/segments.rb +9 -16
  16. data/lib/sendgrid4r/rest/email_activity/email_activity.rb +84 -0
  17. data/lib/sendgrid4r/rest/ips/addresses.rb +9 -18
  18. data/lib/sendgrid4r/rest/ips/pools.rb +7 -12
  19. data/lib/sendgrid4r/rest/ips/warmup.rb +7 -17
  20. data/lib/sendgrid4r/rest/request.rb +7 -1
  21. data/lib/sendgrid4r/rest/settings/enforced_tls.rb +5 -12
  22. data/lib/sendgrid4r/rest/stats/advanced.rb +10 -32
  23. data/lib/sendgrid4r/rest/stats/category.rb +4 -11
  24. data/lib/sendgrid4r/rest/stats/global.rb +3 -2
  25. data/lib/sendgrid4r/rest/stats/parse.rb +4 -6
  26. data/lib/sendgrid4r/rest/stats/subuser.rb +4 -11
  27. data/lib/sendgrid4r/rest/subusers/subusers.rb +83 -0
  28. data/lib/sendgrid4r/rest/templates/templates.rb +1 -1
  29. data/lib/sendgrid4r/rest/templates/versions.rb +3 -2
  30. data/lib/sendgrid4r/version.rb +1 -1
  31. data/spec/client_spec.rb +17 -4
  32. data/spec/factory/condition_factory_spec.rb +1 -1
  33. data/spec/factory/segment_factory_spec.rb +1 -1
  34. data/spec/factory/version_factory_spec.rb +1 -1
  35. data/spec/{api_keys → rest/api_keys}/api_keys_spec.rb +52 -18
  36. data/spec/{asm → rest/asm}/asm_spec.rb +23 -17
  37. data/spec/{asm → rest/asm}/global_suppressions_spec.rb +45 -2
  38. data/spec/{asm → rest/asm}/groups_spec.rb +76 -7
  39. data/spec/{asm → rest/asm}/suppressions_spec.rb +95 -20
  40. data/spec/{categories → rest/categories}/categories_spec.rb +27 -7
  41. data/spec/{contacts → rest/contacts}/custom_fields_spec.rb +49 -15
  42. data/spec/{contacts → rest/contacts}/lists_spec.rb +138 -15
  43. data/spec/{contacts → rest/contacts}/recipients_spec.rb +141 -26
  44. data/spec/{contacts → rest/contacts}/reserved_fields_spec.rb +29 -13
  45. data/spec/{contacts → rest/contacts}/segments_spec.rb +108 -31
  46. data/spec/rest/email_activity/email_activity_spec.rb +192 -0
  47. data/spec/{ips → rest/ips}/addresses_spec.rb +58 -18
  48. data/spec/{ips → rest/ips}/pools_spec.rb +80 -45
  49. data/spec/{ips → rest/ips}/warmup_spec.rb +50 -7
  50. data/spec/{settings → rest/settings}/enforced_tls_spec.rb +32 -7
  51. data/spec/{stats → rest/stats}/advanced_spec.rb +2 -2
  52. data/spec/{stats → rest/stats}/category_spec.rb +2 -2
  53. data/spec/{stats → rest/stats}/global_spec.rb +2 -2
  54. data/spec/{stats → rest/stats}/parse_spec.rb +2 -2
  55. data/spec/{stats → rest/stats}/stats_spec.rb +2 -2
  56. data/spec/{stats → rest/stats}/subuser_spec.rb +2 -2
  57. data/spec/rest/subusers/subusers_spec.rb +246 -0
  58. data/spec/{templates → rest/templates}/templates_spec.rb +55 -15
  59. data/spec/{templates → rest/templates}/versions_spec.rb +44 -7
  60. metadata +54 -48
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::ApiKeys do
5
- describe 'integration test' do
5
+ describe 'integration test', :it do
6
6
  before do
7
7
  begin
8
8
  Dotenv.load
@@ -115,22 +115,13 @@ describe SendGrid4r::REST::ApiKeys do
115
115
  end
116
116
  end
117
117
 
118
- describe 'unit test' do
119
- it 'creates api_key instance' do
120
- json =
121
- '{'\
122
- '"api_key_id": "qfTQ6KG0QBiwWdJ0-pCLCA",'\
123
- '"name": "A New Hope"'\
124
- '}'
125
- hash = JSON.parse(json)
126
- actual = SendGrid4r::REST::ApiKeys.create_api_key(hash)
127
- expect(actual).to be_a(SendGrid4r::REST::ApiKeys::ApiKey)
128
- expect(actual.api_key_id).to eq('qfTQ6KG0QBiwWdJ0-pCLCA')
129
- expect(actual.name).to eq('A New Hope')
118
+ describe 'unit test', :ut do
119
+ let(:client) do
120
+ SendGrid4r::Client.new(api_key: '')
130
121
  end
131
122
 
132
- it 'creates api_keys instance' do
133
- json =
123
+ let(:api_keys) do
124
+ JSON.parse(
134
125
  '{'\
135
126
  '"result": ['\
136
127
  '{'\
@@ -139,8 +130,51 @@ describe SendGrid4r::REST::ApiKeys do
139
130
  '}'\
140
131
  ']'\
141
132
  '}'
142
- hash = JSON.parse(json)
143
- actual = SendGrid4r::REST::ApiKeys.create_api_keys(hash)
133
+ )
134
+ end
135
+
136
+ let(:api_key) do
137
+ JSON.parse(
138
+ '{'\
139
+ '"api_key_id": "qfTQ6KG0QBiwWdJ0-pCLCA",'\
140
+ '"name": "A New Hope"'\
141
+ '}'
142
+ )
143
+ end
144
+
145
+ it '#get_api_keys' do
146
+ allow(client).to receive(:execute).and_return(api_keys)
147
+ actual = client.get_api_keys
148
+ expect(actual).to be_a(SendGrid4r::REST::ApiKeys::ApiKeys)
149
+ end
150
+
151
+ it '#post_api_key' do
152
+ allow(client).to receive(:execute).and_return(api_key)
153
+ actual = client.post_api_key('')
154
+ expect(actual).to be_a(SendGrid4r::REST::ApiKeys::ApiKey)
155
+ end
156
+
157
+ it '#delete_api_key' do
158
+ allow(client).to receive(:execute).and_return('')
159
+ actual = client.delete_api_key('')
160
+ expect(actual).to eq('')
161
+ end
162
+
163
+ it '#patch_api_key' do
164
+ allow(client).to receive(:execute).and_return(api_key)
165
+ actual = client.patch_api_key('', '')
166
+ expect(actual).to be_a(SendGrid4r::REST::ApiKeys::ApiKey)
167
+ end
168
+
169
+ it 'creates api_key instance' do
170
+ actual = SendGrid4r::REST::ApiKeys.create_api_key(api_key)
171
+ expect(actual).to be_a(SendGrid4r::REST::ApiKeys::ApiKey)
172
+ expect(actual.api_key_id).to eq('qfTQ6KG0QBiwWdJ0-pCLCA')
173
+ expect(actual.name).to eq('A New Hope')
174
+ end
175
+
176
+ it 'creates api_keys instance' do
177
+ actual = SendGrid4r::REST::ApiKeys.create_api_keys(api_keys)
144
178
  expect(actual).to be_a(SendGrid4r::REST::ApiKeys::ApiKeys)
145
179
  expect(actual.result).to be_a(Array)
146
180
  actual.result.each do |api_key|
@@ -1,18 +1,29 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Asm do
5
- describe 'unit test' do
5
+ let(:recipient_email) do
6
+ JSON.parse(
7
+ '{'\
8
+ '"recipient_email": "test1@example.com"'\
9
+ '}'
10
+ )
11
+ end
12
+
13
+ let(:recipient_emails) do
14
+ JSON.parse(
15
+ '{'\
16
+ '"recipient_emails": ['\
17
+ '"test1@example.com",'\
18
+ '"test2@example.com"'\
19
+ ']'\
20
+ '}'
21
+ )
22
+ end
23
+
24
+ describe 'unit test', :ut do
6
25
  it 'creates recipient_emails instance' do
7
- json =
8
- '{'\
9
- '"recipient_emails": ['\
10
- '"test1@example.com",'\
11
- '"test2@example.com"'\
12
- ']'\
13
- '}'
14
- hash = JSON.parse(json)
15
- actual = SendGrid4r::REST::Asm.create_recipient_emails(hash)
26
+ actual = SendGrid4r::REST::Asm.create_recipient_emails(recipient_emails)
16
27
  expect(actual).to be_a(SendGrid4r::REST::Asm::RecipientEmails)
17
28
  expect(actual.recipient_emails).to be_a(Array)
18
29
  expect(actual.recipient_emails).to include('test1@example.com')
@@ -20,12 +31,7 @@ describe SendGrid4r::REST::Asm do
20
31
  end
21
32
 
22
33
  it 'creates recipient_email instance' do
23
- json =
24
- '{'\
25
- '"recipient_email": "test1@example.com"'\
26
- '}'
27
- hash = JSON.parse(json)
28
- actual = SendGrid4r::REST::Asm.create_recipient_email(hash)
34
+ actual = SendGrid4r::REST::Asm.create_recipient_email(recipient_email)
29
35
  expect(actual).to be_a(SendGrid4r::REST::Asm::RecipientEmail)
30
36
  expect(actual.recipient_email).to eq('test1@example.com')
31
37
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Asm::GlobalSuppressions do
5
- describe 'integration test' do
5
+ describe 'integration test', :it do
6
6
  before do
7
7
  begin
8
8
  Dotenv.load
@@ -115,4 +115,47 @@ describe SendGrid4r::REST::Asm::GlobalSuppressions do
115
115
  end
116
116
  end
117
117
  end
118
+
119
+ describe 'unit test', :ut do
120
+ let(:client) do
121
+ SendGrid4r::Client.new(api_key: '')
122
+ end
123
+
124
+ let(:recipient_emails) do
125
+ JSON.parse(
126
+ '{'\
127
+ '"recipient_emails": ['\
128
+ '"test1@example.com",'\
129
+ '"test2@example.com"'\
130
+ ']'\
131
+ '}'
132
+ )
133
+ end
134
+
135
+ let(:recipient_email) do
136
+ JSON.parse(
137
+ '{'\
138
+ '"recipient_email": "test1@example.com"'\
139
+ '}'
140
+ )
141
+ end
142
+
143
+ it '#post_global_suppressed_emails' do
144
+ allow(client).to receive(:execute).and_return(recipient_emails)
145
+ emails = client.post_global_suppressed_emails([])
146
+ expect(emails).to be_a(SendGrid4r::REST::Asm::RecipientEmails)
147
+ end
148
+
149
+ it '#get_global_suppressed_email' do
150
+ allow(client).to receive(:execute).and_return(recipient_email)
151
+ actual = client.get_global_suppressed_email('')
152
+ expect(actual).to be_a(SendGrid4r::REST::Asm::RecipientEmail)
153
+ end
154
+
155
+ it '#delete_global_suppressed_email' do
156
+ allow(client).to receive(:execute).and_return('')
157
+ actual = client.delete_global_suppressed_email('')
158
+ expect(actual).to eq('')
159
+ end
160
+ end
118
161
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Asm::Groups do
5
- describe 'integration test' do
5
+ describe 'integration test', :it do
6
6
  before do
7
7
  begin
8
8
  Dotenv.load
@@ -157,9 +157,13 @@ describe SendGrid4r::REST::Asm::Groups do
157
157
  end
158
158
  end
159
159
 
160
- describe 'unit test' do
161
- it 'creates group instance' do
162
- json =
160
+ describe 'unit test', :ut do
161
+ let(:client) do
162
+ SendGrid4r::Client.new(api_key: '')
163
+ end
164
+
165
+ let(:group) do
166
+ JSON.parse(
163
167
  '{'\
164
168
  '"id": 100,'\
165
169
  '"name": "Newsletters",'\
@@ -167,8 +171,65 @@ describe SendGrid4r::REST::Asm::Groups do
167
171
  '"last_email_sent_at": "2014-09-04 01:34:43",'\
168
172
  '"unsubscribes": 400'\
169
173
  '}'
170
- hash = JSON.parse(json)
171
- actual = SendGrid4r::REST::Asm::Groups.create_group(hash)
174
+ )
175
+ end
176
+
177
+ let(:groups) do
178
+ JSON.parse(
179
+ '['\
180
+ '{'\
181
+ '"id": 100,'\
182
+ '"name": "Newsletters",'\
183
+ '"description": "Our monthly newsletter.",'\
184
+ '"last_email_sent_at": "2014-09-04 01:34:43",'\
185
+ '"unsubscribes": 400'\
186
+ '},'\
187
+ '{'\
188
+ '"id": 101,'\
189
+ '"name": "Alerts",'\
190
+ '"description": "Emails triggered by user-defined rules.",'\
191
+ '"last_email_sent_at": "2012-11-06 09:37:33",'\
192
+ '"unsubscribes": 1'\
193
+ '}'\
194
+ ']'
195
+ )
196
+ end
197
+
198
+ it '#post_group' do
199
+ allow(client).to receive(:execute).and_return(group)
200
+ actual = client.post_group('', '')
201
+ expect(actual).to be_a(SendGrid4r::REST::Asm::Groups::Group)
202
+ end
203
+
204
+ it '#patch_group' do
205
+ allow(client).to receive(:execute).and_return(group)
206
+ actual = client.patch_group(0, nil)
207
+ expect(actual).to be_a(SendGrid4r::REST::Asm::Groups::Group)
208
+ end
209
+
210
+ it '#get_groups' do
211
+ allow(client).to receive(:execute).and_return(groups)
212
+ actual = client.get_groups
213
+ expect(actual).to be_a(Array)
214
+ actual.each do |group|
215
+ expect(group).to be_a(SendGrid4r::REST::Asm::Groups::Group)
216
+ end
217
+ end
218
+
219
+ it '#get_group' do
220
+ allow(client).to receive(:execute).and_return(group)
221
+ actual = client.get_group(0)
222
+ expect(actual).to be_a(SendGrid4r::REST::Asm::Groups::Group)
223
+ end
224
+
225
+ it '#delete_group' do
226
+ allow(client).to receive(:execute).and_return('')
227
+ actual = client.delete_group(0)
228
+ expect(actual).to eq('')
229
+ end
230
+
231
+ it 'creates group instance' do
232
+ actual = SendGrid4r::REST::Asm::Groups.create_group(group)
172
233
  expect(actual).to be_a(
173
234
  SendGrid4r::REST::Asm::Groups::Group
174
235
  )
@@ -178,5 +239,13 @@ describe SendGrid4r::REST::Asm::Groups do
178
239
  expect(actual.last_email_sent_at).to eq('2014-09-04 01:34:43')
179
240
  expect(actual.unsubscribes).to eq(400)
180
241
  end
242
+
243
+ it 'creates groups instance' do
244
+ actual = SendGrid4r::REST::Asm::Groups.create_groups(groups)
245
+ expect(actual).to be_a(Array)
246
+ actual.each do |group|
247
+ expect(group).to be_a(SendGrid4r::REST::Asm::Groups::Group)
248
+ end
249
+ end
181
250
  end
182
251
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Asm::Suppressions do
5
- describe 'integration test' do
5
+ describe 'integration test', :it do
6
6
  before do
7
7
  begin
8
8
  Dotenv.load
@@ -89,7 +89,7 @@ describe SendGrid4r::REST::Asm::Suppressions do
89
89
  end
90
90
  end
91
91
 
92
- context 'wthout block call' do
92
+ context 'with block call' do
93
93
  it '#post_suppressed_emails' do
94
94
  @client.post_suppressed_emails(
95
95
  @group.id, [@email2, @email3]
@@ -108,7 +108,12 @@ describe SendGrid4r::REST::Asm::Suppressions do
108
108
 
109
109
  it '#get_suppressed_emails' do
110
110
  @client.get_suppressed_emails(@group.id) do |resp, req, res|
111
+ resp =
112
+ SendGrid4r::REST::Asm::Suppressions.create_emails(JSON.parse(resp))
111
113
  expect(resp).to be_a(Array)
114
+ resp.each do |email|
115
+ expect(email).to be_a(String)
116
+ end
112
117
  expect(req).to be_a(RestClient::Request)
113
118
  expect(res).to be_a(Net::HTTPOK)
114
119
  end
@@ -117,7 +122,9 @@ describe SendGrid4r::REST::Asm::Suppressions do
117
122
  it '#get_suppressions' do
118
123
  @client.get_suppressions(@email1) do |resp, req, res|
119
124
  resp =
120
- SendGrid4r::REST::Asm::Suppressions.create_suppressions(resp)
125
+ SendGrid4r::REST::Asm::Suppressions.create_suppressions(
126
+ JSON.parse(resp)
127
+ )
121
128
  expect(resp).to be_a(
122
129
  SendGrid4r::REST::Asm::Suppressions::Suppressions
123
130
  )
@@ -136,9 +143,49 @@ describe SendGrid4r::REST::Asm::Suppressions do
136
143
  end
137
144
  end
138
145
 
139
- describe 'unit test' do
140
- it 'creates suppressions instance' do
141
- json =
146
+ describe 'unit test', :ut do
147
+ let(:client) do
148
+ SendGrid4r::Client.new(api_key: '')
149
+ end
150
+
151
+ let(:recipient_emails) do
152
+ JSON.parse(
153
+ '{'\
154
+ '"recipient_emails": ['\
155
+ '"test1@example.com",'\
156
+ '"test2@example.com"'\
157
+ ']'\
158
+ '}'
159
+ )
160
+ end
161
+
162
+ let(:recipient_email) do
163
+ JSON.parse(
164
+ '{'\
165
+ '"recipient_email": "test1@example.com"'\
166
+ '}'
167
+ )
168
+ end
169
+
170
+ let(:emails) do
171
+ JSON.parse(
172
+ '["test1@example.com","test2@example.com"]'
173
+ )
174
+ end
175
+
176
+ let(:suppression) do
177
+ JSON.parse(
178
+ '{'\
179
+ '"id": 4,'\
180
+ '"name": "Special Offers",'\
181
+ '"description": "Special offers and coupons",'\
182
+ '"suppressed": false'\
183
+ '}'
184
+ )
185
+ end
186
+
187
+ let(:suppressions) do
188
+ JSON.parse(
142
189
  '{'\
143
190
  '"suppressions": ['\
144
191
  '{'\
@@ -155,11 +202,24 @@ describe SendGrid4r::REST::Asm::Suppressions do
155
202
  '}'\
156
203
  ']'\
157
204
  '}'
158
- hash = JSON.parse(json)
159
- actual = SendGrid4r::REST::Asm::Suppressions.create_suppressions(hash)
160
- expect(actual).to be_a(
161
- SendGrid4r::REST::Asm::Suppressions::Suppressions
162
205
  )
206
+ end
207
+
208
+ it '#post_suppressed_emails' do
209
+ allow(client).to receive(:execute).and_return(recipient_emails)
210
+ actual = client.post_suppressed_emails(0, ['', ''])
211
+ expect(actual).to be_a(SendGrid4r::REST::Asm::RecipientEmails)
212
+ end
213
+
214
+ it '#get_suppressed_emails' do
215
+ allow(client).to receive(:execute).and_return(emails)
216
+ actual = client.get_suppressed_emails(0)
217
+ expect(actual).to be_a(Array)
218
+ end
219
+
220
+ it '#get_suppressions' do
221
+ allow(client).to receive(:execute).and_return(suppressions)
222
+ actual = client.get_suppressions('')
163
223
  expect(actual.suppressions).to be_a(Array)
164
224
  actual.suppressions.each do |suppression|
165
225
  expect(suppression).to be_a(
@@ -168,16 +228,16 @@ describe SendGrid4r::REST::Asm::Suppressions do
168
228
  end
169
229
  end
170
230
 
231
+ it '#delete_suppressed_email' do
232
+ allow(client).to receive(:execute).and_return('')
233
+ actual = client.delete_suppressed_email(0, '')
234
+ expect(actual).to eq('')
235
+ end
236
+
171
237
  it 'creates suppression instance' do
172
- json =
173
- '{'\
174
- '"id": 4,'\
175
- '"name": "Special Offers",'\
176
- '"description": "Special offers and coupons",'\
177
- '"suppressed": false'\
178
- '}'
179
- hash = JSON.parse(json)
180
- actual = SendGrid4r::REST::Asm::Suppressions.create_suppression(hash)
238
+ actual = SendGrid4r::REST::Asm::Suppressions.create_suppression(
239
+ suppression
240
+ )
181
241
  expect(actual).to be_a(
182
242
  SendGrid4r::REST::Asm::Suppressions::Suppression
183
243
  )
@@ -186,5 +246,20 @@ describe SendGrid4r::REST::Asm::Suppressions do
186
246
  expect(actual.description).to eq('Special offers and coupons')
187
247
  expect(actual.suppressed).to eq(false)
188
248
  end
249
+
250
+ it 'creates suppressions instance' do
251
+ actual = SendGrid4r::REST::Asm::Suppressions.create_suppressions(
252
+ suppressions
253
+ )
254
+ expect(actual).to be_a(
255
+ SendGrid4r::REST::Asm::Suppressions::Suppressions
256
+ )
257
+ expect(actual.suppressions).to be_a(Array)
258
+ actual.suppressions.each do |suppression|
259
+ expect(suppression).to be_a(
260
+ SendGrid4r::REST::Asm::Suppressions::Suppression
261
+ )
262
+ end
263
+ end
189
264
  end
190
265
  end
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Categories do
5
- describe 'integration test' do
5
+ describe 'integration test', :it do
6
6
  before do
7
7
  Dotenv.load
8
8
  @client = SendGrid4r::Client.new(
@@ -71,9 +71,13 @@ describe SendGrid4r::REST::Categories do
71
71
  end
72
72
  end
73
73
 
74
- describe 'unit test' do
75
- it 'creates categories instance' do
76
- json =
74
+ describe 'unit test', :ut do
75
+ let(:client) do
76
+ SendGrid4r::Client.new(api_key: '')
77
+ end
78
+
79
+ let(:categories) do
80
+ JSON.parse(
77
81
  '['\
78
82
  '{"category": "cat1"},'\
79
83
  '{"category": "cat2"},'\
@@ -81,8 +85,24 @@ describe SendGrid4r::REST::Categories do
81
85
  '{"category": "cat4"},'\
82
86
  '{"category": "cat5"}'\
83
87
  ']'
84
- hash = JSON.parse(json)
85
- actual = SendGrid4r::REST::Categories::Categories.create_categories(hash)
88
+ )
89
+ end
90
+
91
+ it '#get_categories' do
92
+ allow(client).to receive(:execute).and_return(categories)
93
+ actual = client.get_categories
94
+ expect(actual).to be_a(Array)
95
+ actual.each do |category|
96
+ expect(category).to be_a(
97
+ SendGrid4r::REST::Categories::Categories::Category
98
+ )
99
+ end
100
+ end
101
+
102
+ it 'creates categories instance' do
103
+ actual = SendGrid4r::REST::Categories::Categories.create_categories(
104
+ categories
105
+ )
86
106
  expect(actual).to be_a(Array)
87
107
  actual.each do |category|
88
108
  expect(category).to be_a(
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + '/../spec_helper'
2
+ require File.dirname(__FILE__) + '/../../spec_helper'
3
3
 
4
4
  describe SendGrid4r::REST::Contacts::CustomFields do
5
- describe 'integration test' do
5
+ describe 'integration test', :it do
6
6
  before do
7
7
  begin
8
8
  Dotenv.load
@@ -144,24 +144,23 @@ describe SendGrid4r::REST::Contacts::CustomFields do
144
144
  end
145
145
  end
146
146
 
147
- describe 'unit test' do
148
- it 'creates field instance' do
149
- json =
147
+ describe 'unit test', :ut do
148
+ let(:client) do
149
+ SendGrid4r::Client.new(api_key: '')
150
+ end
151
+
152
+ let(:field) do
153
+ JSON.parse(
150
154
  '{'\
151
155
  '"id": 1,'\
152
156
  '"name": "pet",'\
153
157
  '"type": "text"'\
154
158
  '}'
155
- hash = JSON.parse(json)
156
- actual = SendGrid4r::REST::Contacts::CustomFields.create_field(hash)
157
- expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
158
- expect(actual.id).to eq(1)
159
- expect(actual.name).to eq('pet')
160
- expect(actual.type).to eq('text')
159
+ )
161
160
  end
162
161
 
163
- it 'creates fields instance' do
164
- json =
162
+ let(:fields) do
163
+ JSON.parse(
165
164
  '{'\
166
165
  '"custom_fields": ['\
167
166
  '{'\
@@ -181,8 +180,43 @@ describe SendGrid4r::REST::Contacts::CustomFields do
181
180
  '}'\
182
181
  ']'\
183
182
  '}'
184
- hash = JSON.parse(json)
185
- actual = SendGrid4r::REST::Contacts::CustomFields.create_fields(hash)
183
+ )
184
+ end
185
+
186
+ it '#post_custom_field' do
187
+ allow(client).to receive(:execute).and_return(field)
188
+ actual = client.post_custom_field('', '')
189
+ expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
190
+ end
191
+
192
+ it '#get_custom_fields' do
193
+ allow(client).to receive(:execute).and_return(fields)
194
+ actual = client.get_custom_fields
195
+ expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Fields)
196
+ end
197
+
198
+ it '#get_custom_field' do
199
+ allow(client).to receive(:execute).and_return(field)
200
+ actual = client.get_custom_field(0)
201
+ expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
202
+ end
203
+
204
+ it '#delete_custom_field' do
205
+ allow(client).to receive(:execute).and_return('')
206
+ actual = client.delete_custom_field(0)
207
+ expect(actual).to eq('')
208
+ end
209
+
210
+ it 'creates field instance' do
211
+ actual = SendGrid4r::REST::Contacts::CustomFields.create_field(field)
212
+ expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Field)
213
+ expect(actual.id).to eq(1)
214
+ expect(actual.name).to eq('pet')
215
+ expect(actual.type).to eq('text')
216
+ end
217
+
218
+ it 'creates fields instance' do
219
+ actual = SendGrid4r::REST::Contacts::CustomFields.create_fields(fields)
186
220
  expect(actual).to be_a(SendGrid4r::REST::Contacts::CustomFields::Fields)
187
221
  expect(actual.custom_fields).to be_a(Array)
188
222
  actual.custom_fields.each do |field|