contextio 1.5.0 → 1.6.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.
@@ -10,11 +10,12 @@ class ContextIO
10
10
  belongs_to :account
11
11
  has_many :sources
12
12
  has_many :body_parts
13
+ has_many :files
13
14
 
14
15
  lazy_attributes :date, :folders, :addresses, :subject, :list_help,
15
16
  :list_unsubscribe, :message_id, :email_message_id,
16
17
  :gmail_message_id, :gmail_thread_id, :person_info,
17
- :date_received, :date_indexed
18
+ :date_received, :date_indexed, :in_reply_to
18
19
  private :date_received, :date_indexed
19
20
 
20
21
  def received_at
@@ -27,16 +27,6 @@ class ContextIO
27
27
  # provider_token_secret, provider_consumer_key. See the Context.IO docs
28
28
  # for more details on these fields.
29
29
  def update(options={})
30
- updatable_attrs = %w(status sync_period service_level password
31
- provider_token provider_token_secret
32
- provider_consumer_key)
33
-
34
- options.keep_if do |key, value|
35
- updatable_attrs.include?(key.to_s)
36
- end
37
-
38
- return nil if options.empty?
39
-
40
30
  it_worked = api.request(:post, resource_url, options)['success']
41
31
 
42
32
  if it_worked
@@ -24,12 +24,12 @@ class ContextIO
24
24
  # required and what's optional.
25
25
  def create(email, server, username, use_ssl, port, type, options={})
26
26
  api_args = options.merge(
27
- 'email' => email,
28
- 'server' => server,
29
- 'username' => username,
30
- 'use_ssl' => use_ssl ? '1' : '0',
31
- 'port' => port.to_s,
32
- 'type' => type
27
+ :email => email,
28
+ :server => server,
29
+ :username => username,
30
+ :use_ssl => use_ssl ? '1' : '0',
31
+ :port => port.to_s,
32
+ :type => type
33
33
  )
34
34
 
35
35
  result_hash = api.request(:post, resource_url, api_args)
@@ -1,6 +1,6 @@
1
1
  class ContextIO
2
2
  # @private
3
- VERSION = "1.5.0"
3
+ VERSION = "1.6.0"
4
4
 
5
5
  # The gem version.
6
6
  #
@@ -12,6 +12,10 @@ RSpec.configure do |rspec|
12
12
  rspec.expect_with :rspec do |expectations|
13
13
  expectations.syntax = :expect
14
14
  end
15
+
16
+ rspec.mock_with :rspec do |mocks|
17
+ mocks.syntax = :expect
18
+ end
15
19
  end
16
20
 
17
21
  FakeWeb.allow_net_connect = false
@@ -8,7 +8,7 @@ describe ContextIO::AccountCollection do
8
8
 
9
9
  describe "#create" do
10
10
  before do
11
- api.stub(:request).with(:post, anything, anything).and_return(
11
+ allow(api).to receive(:request).with(:post, anything, anything).and_return(
12
12
  'success' => true,
13
13
  'id' => '1234',
14
14
  'resource_url' => 'resource_url'
@@ -21,7 +21,7 @@ describe ContextIO::AccountCollection do
21
21
  end
22
22
 
23
23
  it "posts to the api" do
24
- api.should_receive(:request).with(
24
+ expect(api).to receive(:request).with(
25
25
  :post,
26
26
  'url from api',
27
27
  hash_including(email: 'hello@email.com')
@@ -31,7 +31,7 @@ describe ContextIO::AccountCollection do
31
31
  end
32
32
 
33
33
  it "doesn't make any more API calls than it needs to" do
34
- api.should_not_receive(:request).with(:get, anything, anything)
34
+ expect(api).to_not receive(:request).with(:get, anything, anything)
35
35
 
36
36
  subject.create(email: 'hello@email.com')
37
37
  end
@@ -41,7 +41,7 @@ describe ContextIO::AccountCollection do
41
41
  end
42
42
 
43
43
  it "takes an optional first name" do
44
- api.should_receive(:request).with(
44
+ expect(api).to receive(:request).with(
45
45
  anything,
46
46
  anything,
47
47
  hash_including(first_name: 'Bruno')
@@ -51,7 +51,7 @@ describe ContextIO::AccountCollection do
51
51
  end
52
52
 
53
53
  it "takes an optional last name" do
54
- api.should_receive(:request).with(
54
+ expect(api).to receive(:request).with(
55
55
  anything,
56
56
  anything,
57
57
  hash_including(last_name: 'Morency')
@@ -65,11 +65,11 @@ describe ContextIO::AccountCollection do
65
65
  subject { ContextIO::AccountCollection.new(api).where(email: 'hello@email.com')}
66
66
 
67
67
  it "allows a missing email address" do
68
- expect { subject.create(first_name: 'Bruno') }.to_not raise_error(ArgumentError)
68
+ expect { subject.create(first_name: 'Bruno') }.to_not raise_error
69
69
  end
70
70
 
71
71
  it "uses the email address from the where constraints" do
72
- api.should_receive(:request).with(anything, anything, hash_including(email: 'hello@email.com'))
72
+ expect(api).to receive(:request).with(anything, anything, hash_including(email: 'hello@email.com'))
73
73
 
74
74
  subject.create(first_name: 'Bruno')
75
75
  end
@@ -22,13 +22,13 @@ describe ContextIO::Account do
22
22
 
23
23
  describe "#update" do
24
24
  before do
25
- api.stub(:request).and_return({'success' => true})
25
+ allow(api).to receive(:request).and_return({'success' => true})
26
26
  end
27
27
 
28
28
  subject { ContextIO::Account.new(api, id: '1234', first_name: 'old first name') }
29
29
 
30
30
  it "posts to the api" do
31
- api.should_receive(:request).with(
31
+ expect(api).to receive(:request).with(
32
32
  :post,
33
33
  'url from api',
34
34
  first_name: 'new first name'
@@ -44,7 +44,7 @@ describe ContextIO::Account do
44
44
  end
45
45
 
46
46
  it "doesn't make any more API calls than it needs to" do
47
- api.should_not_receive(:request).with(:get, anything, anything)
47
+ expect(api).to_not receive(:request).with(:get, anything, anything)
48
48
 
49
49
  subject.update(first_name: 'new first name')
50
50
  end
@@ -88,7 +88,7 @@ describe ContextIO::API::ResourceCollection do
88
88
  end
89
89
 
90
90
  it "limits the scope of subsequent #each calls" do
91
- api.should_receive(:request).with(anything, anything, foo: 'bar').and_return([])
91
+ expect(api).to receive(:request).with(anything, anything, foo: 'bar').and_return([])
92
92
 
93
93
  subject.where(foo: 'bar').each { }
94
94
  end
@@ -129,7 +129,7 @@ describe ContextIO::API::ResourceCollection do
129
129
  end
130
130
 
131
131
  before do
132
- api.stub(:request).and_return([{key: 'value 1'}, {key: 'value 2'}])
132
+ allow(api).to receive(:request).and_return([{key: 'value 1'}, {key: 'value 2'}])
133
133
  end
134
134
 
135
135
  it "yields instances of the singular resource class" do
@@ -139,20 +139,20 @@ describe ContextIO::API::ResourceCollection do
139
139
  end
140
140
 
141
141
  it "gets attributes for the resources from the api" do
142
- api.should_receive(:request).exactly(:once).with(:get, 'url from api', {})
142
+ expect(api).to receive(:request).exactly(:once).with(:get, 'url from api', {})
143
143
 
144
144
  subject.each { }
145
145
  end
146
146
 
147
147
  it "passes the api to the singular resource instances" do
148
- SingularHelper.should_receive(:new).exactly(:twice).with(api, anything)
148
+ expect(SingularHelper).to receive(:new).exactly(:twice).with(api, anything)
149
149
 
150
150
  subject.each { }
151
151
  end
152
152
 
153
153
  it "passes attributes to the singular resource instances" do
154
- SingularHelper.should_receive(:new).exactly(:once).with(anything, key: 'value 1')
155
- SingularHelper.should_receive(:new).exactly(:once).with(anything, key: 'value 2')
154
+ expect(SingularHelper).to receive(:new).exactly(:once).with(anything, key: 'value 1')
155
+ expect(SingularHelper).to receive(:new).exactly(:once).with(anything, key: 'value 2')
156
156
 
157
157
  subject.each { }
158
158
  end
@@ -175,7 +175,7 @@ describe ContextIO::API::ResourceCollection do
175
175
  end
176
176
 
177
177
  it "passes the belonged-to resource to the singular resource instances" do
178
- SingularHelper.should_receive(:new).exactly(:twice).with(
178
+ expect(SingularHelper).to receive(:new).exactly(:twice).with(
179
179
  anything,
180
180
  hash_including(owner: owner)
181
181
  )
@@ -197,20 +197,20 @@ describe ContextIO::API::ResourceCollection do
197
197
  end
198
198
 
199
199
  it "doesn't hit the API" do
200
- api.should_not_receive(:request)
200
+ expect(api).to_not receive(:request)
201
201
 
202
202
  subject.each { }
203
203
  end
204
204
 
205
205
  it "passes the api to the singular resource instances" do
206
- SingularHelper.should_receive(:new).exactly(:twice).with(api, anything)
206
+ expect(SingularHelper).to receive(:new).exactly(:twice).with(api, anything)
207
207
 
208
208
  subject.each { }
209
209
  end
210
210
 
211
211
  it "passes attributes to the singular resource instances" do
212
- SingularHelper.should_receive(:new).exactly(:once).with(anything, foo: 'bar')
213
- SingularHelper.should_receive(:new).exactly(:once).with(anything, foo: 'baz')
212
+ expect(SingularHelper).to receive(:new).exactly(:once).with(anything, foo: 'bar')
213
+ expect(SingularHelper).to receive(:new).exactly(:once).with(anything, foo: 'baz')
214
214
 
215
215
  subject.each { }
216
216
  end
@@ -237,7 +237,7 @@ describe ContextIO::API::ResourceCollection do
237
237
  end
238
238
 
239
239
  it "passes the belonged-to resource to the singular resource instances" do
240
- SingularHelper.should_receive(:new).exactly(:twice).with(
240
+ expect(SingularHelper).to receive(:new).exactly(:twice).with(
241
241
  anything,
242
242
  hash_including(owner: owner)
243
243
  )
@@ -266,19 +266,19 @@ describe ContextIO::API::ResourceCollection do
266
266
  end
267
267
 
268
268
  it "feeds the given key to the resource class" do
269
- SingularHelper.should_receive(:new).with(anything, 'token' => 1234)
269
+ expect(SingularHelper).to receive(:new).with(anything, 'token' => 1234)
270
270
 
271
271
  subject[1234]
272
272
  end
273
273
 
274
274
  it "feeds the api to the resource class" do
275
- SingularHelper.should_receive(:new).with(api, anything)
275
+ expect(SingularHelper).to receive(:new).with(api, anything)
276
276
 
277
277
  subject[1234]
278
278
  end
279
279
 
280
280
  it "doesn't hit the API" do
281
- api.should_not_receive(:request)
281
+ expect(api).to_not receive(:request)
282
282
 
283
283
  subject[1234]
284
284
  end
@@ -294,7 +294,7 @@ describe ContextIO::API::ResourceCollection do
294
294
  end
295
295
 
296
296
  it "doesn't pass a nil association to the resouce class" do
297
- SingularHelper.should_receive(:new).with(api, 'token' => 1234)
297
+ expect(SingularHelper).to receive(:new).with(api, 'token' => 1234)
298
298
 
299
299
  subject[1234]
300
300
  end
@@ -122,7 +122,7 @@ describe ContextIO::API::Resource do
122
122
  end
123
123
 
124
124
  it "doesn't try to fetch from the API" do
125
- subject.should_not_receive(:fetch_attributes)
125
+ expect(subject).to_not receive(:fetch_attributes)
126
126
 
127
127
  subject.foo
128
128
  end
@@ -134,7 +134,7 @@ describe ContextIO::API::Resource do
134
134
 
135
135
  context "when the attributes is not set at creation" do
136
136
  it "tries to fetch from the API" do
137
- api.should_receive(:request).with(:get, 'resource_url').
137
+ expect(api).to receive(:request).with(:get, 'resource_url').
138
138
  and_return({'foo' => 'set from API', 'longer-name' => 'bar'})
139
139
 
140
140
  subject.foo
@@ -164,7 +164,7 @@ describe ContextIO::API::Resource do
164
164
  subject { helper_class.new(api, resource_url: 'resource_url') }
165
165
 
166
166
  before do
167
- api.stub(:request).and_return(
167
+ allow(api).to receive(:request).and_return(
168
168
  {
169
169
  'resource' => {
170
170
  'resource_url' => 'relation_url'
@@ -178,7 +178,7 @@ describe ContextIO::API::Resource do
178
178
  end
179
179
 
180
180
  it "passes keys from the api response to the new object" do
181
- Resource.should_receive(:new).with(api, 'resource_url' => 'relation_url')
181
+ expect(Resource).to receive(:new).with(api, 'resource_url' => 'relation_url')
182
182
 
183
183
  subject.resource
184
184
  end
@@ -192,7 +192,7 @@ describe ContextIO::API::Resource do
192
192
  subject { helper_class.new(api, resource_url: 'resource_url') }
193
193
 
194
194
  before do
195
- api.stub(:request).and_return({ })
195
+ allow(api).to receive(:request).and_return({ })
196
196
  end
197
197
 
198
198
  it "makes the resource nil" do
@@ -204,7 +204,7 @@ describe ContextIO::API::Resource do
204
204
  subject { helper_class.new(api, resource_url: 'resource_url') }
205
205
 
206
206
  before do
207
- api.stub(:request).and_return(
207
+ allow(api).to receive(:request).and_return(
208
208
  {
209
209
  'resource' => { }
210
210
  }
@@ -220,7 +220,7 @@ describe ContextIO::API::Resource do
220
220
  subject { helper_class.new(api, resource_url: 'resource_url') }
221
221
 
222
222
  before do
223
- api.stub(:request).and_return(
223
+ allow(api).to receive(:request).and_return(
224
224
  {
225
225
  'resource' => [ ]
226
226
  }
@@ -243,7 +243,7 @@ describe ContextIO::API::Resource do
243
243
  end
244
244
 
245
245
  it "doesn't make any API calls" do
246
- api.should_not_receive(:request)
246
+ expect(api).to_not receive(:request)
247
247
 
248
248
  subject.resource
249
249
  end
@@ -265,7 +265,7 @@ describe ContextIO::API::Resource do
265
265
  subject { helper_class.new(api, resource_url: 'resource_url') }
266
266
 
267
267
  before do
268
- api.stub(:request).and_return(
268
+ allow(api).to receive(:request).and_return(
269
269
  {
270
270
  'resources' => [{
271
271
  'resource_url' => 'relation_url'
@@ -279,7 +279,7 @@ describe ContextIO::API::Resource do
279
279
  end
280
280
 
281
281
  it "passes keys from the api response to the new object" do
282
- ResourceCollection.should_receive(:new).with(api, hash_including(attribute_hashes: [{'resource_url' => 'relation_url'}]))
282
+ expect(ResourceCollection).to receive(:new).with(api, hash_including(attribute_hashes: [{'resource_url' => 'relation_url'}]))
283
283
 
284
284
  subject.resources
285
285
  end
@@ -289,7 +289,7 @@ describe ContextIO::API::Resource do
289
289
  end
290
290
 
291
291
  it "passes its self to the new collection" do
292
- ResourceCollection.should_receive(:new).with(anything, hash_including(:helper_class => subject))
292
+ expect(ResourceCollection).to receive(:new).with(anything, hash_including(:helper_class => subject))
293
293
 
294
294
  subject.resources
295
295
  end
@@ -299,11 +299,11 @@ describe ContextIO::API::Resource do
299
299
  subject { helper_class.new(api, resource_url: 'resource_url') }
300
300
 
301
301
  before do
302
- api.stub(:request).and_return({ 'foo' => 'bar' })
302
+ allow(api).to receive(:request).and_return({ 'foo' => 'bar' })
303
303
  end
304
304
 
305
305
  it "tries the API only once" do
306
- api.should_receive(:request).exactly(:once).and_return({ 'foo' => 'bar' })
306
+ expect(api).to receive(:request).exactly(:once).and_return({ 'foo' => 'bar' })
307
307
 
308
308
  subject.resources
309
309
  subject.resources
@@ -314,7 +314,7 @@ describe ContextIO::API::Resource do
314
314
  end
315
315
 
316
316
  it "passes its self to the new collection" do
317
- ResourceCollection.should_receive(:new).with(anything, hash_including(:helper_class => subject))
317
+ expect(ResourceCollection).to receive(:new).with(anything, hash_including(:helper_class => subject))
318
318
 
319
319
  subject.resources
320
320
  end
@@ -331,7 +331,7 @@ describe ContextIO::API::Resource do
331
331
  end
332
332
 
333
333
  it "doesn't make any API calls" do
334
- api.should_not_receive(:request)
334
+ expect(api).to_not receive(:request)
335
335
 
336
336
  subject.resources
337
337
  end
@@ -350,13 +350,13 @@ describe ContextIO::API::Resource do
350
350
  end
351
351
 
352
352
  it "makes a request to the API" do
353
- subject.api.should_receive(:request).with(:get, 'resource_url').and_return({})
353
+ expect(subject.api).to receive(:request).with(:get, 'resource_url').and_return({})
354
354
 
355
355
  subject.send(:fetch_attributes)
356
356
  end
357
357
 
358
358
  it "defines getter methods for new attributes returned" do
359
- subject.api.stub(:request).and_return(foo: 'bar')
359
+ allow(subject.api).to receive(:request).and_return(foo: 'bar')
360
360
 
361
361
  subject.send(:fetch_attributes)
362
362
 
@@ -368,7 +368,7 @@ describe ContextIO::API::Resource do
368
368
  'hard coded value'
369
369
  end
370
370
 
371
- subject.api.stub(:request).and_return(foo: 'bar')
371
+ allow(subject.api).to receive(:request).and_return(foo: 'bar')
372
372
 
373
373
  subject.send(:fetch_attributes)
374
374
 
@@ -376,7 +376,7 @@ describe ContextIO::API::Resource do
376
376
  end
377
377
 
378
378
  it "stores the response hash" do
379
- subject.api.stub(:request).and_return('foo' => 'bar')
379
+ allow(subject.api).to receive(:request).and_return('foo' => 'bar')
380
380
 
381
381
  subject.send(:fetch_attributes)
382
382
 
@@ -400,7 +400,7 @@ describe ContextIO::API::Resource do
400
400
  end
401
401
 
402
402
  it "hits the API only on first call" do
403
- api.should_receive(:request).exactly(:once)
403
+ expect(api).to receive(:request).exactly(:once)
404
404
 
405
405
  subject.api_attributes
406
406
  subject.api_attributes
@@ -436,7 +436,7 @@ describe ContextIO::API::Resource do
436
436
  end
437
437
 
438
438
  it "delegates URL construction to the api" do
439
- api.should_receive(:url_for).with(subject).and_return('helpers/33f1')
439
+ expect(api).to receive(:url_for).with(subject).and_return('helpers/33f1')
440
440
 
441
441
  expect(subject.resource_url).to eq('helpers/33f1')
442
442
  end
@@ -455,7 +455,7 @@ describe ContextIO::API::Resource do
455
455
  end
456
456
 
457
457
  it "makes a request to the API" do
458
- subject.api.should_receive(:request).with(:delete, 'resource_url')
458
+ expect(subject.api).to receive(:request).with(:delete, 'resource_url')
459
459
 
460
460
  subject.delete
461
461
  end