contextio 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,25 @@ describe ContextIO::API do
10
10
  end
11
11
  end
12
12
 
13
+ describe "#version" do
14
+ context "without version change" do
15
+ subject { ContextIO::API.new(nil, nil) }
16
+
17
+ it "uses API version 2.0" do
18
+ expect(subject.version).to eq('2.0')
19
+ end
20
+ end
21
+
22
+ context "with version change" do
23
+ subject { ContextIO::API.new(nil, nil) }
24
+
25
+ it "changes the API version used" do
26
+ subject.version = '1.1'
27
+ expect(subject.version).to eq('1.1')
28
+ end
29
+ end
30
+ end
31
+
13
32
  describe ".base_url" do
14
33
  subject { ContextIO::API }
15
34
 
@@ -18,6 +37,25 @@ describe ContextIO::API do
18
37
  end
19
38
  end
20
39
 
40
+ describe "#base_url" do
41
+ context "without base_url change" do
42
+ subject { ContextIO::API.new(nil, nil) }
43
+
44
+ it "is https://api.context.io" do
45
+ expect(subject.base_url).to eq('https://api.context.io')
46
+ end
47
+ end
48
+
49
+ context "with base_url change" do
50
+ subject { ContextIO::API.new(nil, nil) }
51
+
52
+ it "changes the base_url" do
53
+ subject.base_url = 'https://api.example.com'
54
+ expect(subject.base_url).to eq('https://api.example.com')
55
+ end
56
+ end
57
+ end
58
+
21
59
  describe ".new" do
22
60
  subject { ContextIO::API.new('test_key', 'test_secret', {a:'b'}) }
23
61
 
@@ -35,7 +73,7 @@ describe ContextIO::API do
35
73
  end
36
74
 
37
75
  describe "#path" do
38
- context "without params" do
76
+ context "without params and default version" do
39
77
  subject { ContextIO::API.new(nil, nil).path('test_command') }
40
78
 
41
79
  it "puts the command in the path" do
@@ -43,6 +81,15 @@ describe ContextIO::API do
43
81
  end
44
82
  end
45
83
 
84
+ context "without params and version change" do
85
+ subject { ContextIO::API.new(nil, nil) }
86
+
87
+ it "puts the command in the path" do
88
+ subject.version = '2.5'
89
+ expect(subject.path('test_command')).to eq('/2.5/test_command')
90
+ end
91
+ end
92
+
46
93
  context "with params" do
47
94
  subject { ContextIO::API.new(nil, nil).path('test_command', foo: 1, bar: %w(a b c)) }
48
95
 
@@ -58,6 +105,16 @@ describe ContextIO::API do
58
105
  expect(subject).to eq('/2.0/test_command')
59
106
  end
60
107
  end
108
+
109
+ context "with a full URL and version and base_url change" do
110
+ subject { ContextIO::API.new(nil, nil) }
111
+
112
+ it "strips out the command" do
113
+ subject.version = '2.5'
114
+ subject.base_url = 'https://api.example.com'
115
+ expect(subject.path('https://api.example.com/2.5/test_command')).to eq('/2.5/test_command')
116
+ end
117
+ end
61
118
  end
62
119
 
63
120
  describe "#request" do
@@ -109,7 +166,7 @@ describe ContextIO::API do
109
166
 
110
167
  describe ".url_for" do
111
168
  it "delegates to ContextIO::API::URLBuilder" do
112
- ContextIO::API::URLBuilder.should_receive(:url_for).with('foo')
169
+ expect(ContextIO::API::URLBuilder).to receive(:url_for).with('foo')
113
170
 
114
171
  ContextIO::API.url_for('foo')
115
172
  end
@@ -119,7 +176,7 @@ describe ContextIO::API do
119
176
  subject { ContextIO::API.new('test_key', 'test_secret') }
120
177
 
121
178
  it "delegates to the class" do
122
- ContextIO::API.should_receive(:url_for).with('foo')
179
+ expect(ContextIO::API).to receive(:url_for).with('foo')
123
180
 
124
181
  subject.url_for('foo')
125
182
  end
@@ -8,11 +8,11 @@ describe ContextIO::ConnectTokenCollection do
8
8
 
9
9
  describe "#create" do
10
10
  before do
11
- api.stub(:request).with(:post, anything, anything).and_return({ token: '1234' })
11
+ allow(api).to receive(:request).with(:post, anything, anything).and_return({ token: '1234' })
12
12
  end
13
13
 
14
14
  it "posts to the api" do
15
- api.should_receive(:request).with(
15
+ expect(api).to receive(:request).with(
16
16
  :post,
17
17
  'url from api',
18
18
  hash_including(callback_url: 'http://callback.com')
@@ -22,7 +22,7 @@ describe ContextIO::ConnectTokenCollection do
22
22
  end
23
23
 
24
24
  it "doesn't make any more API calls than it needs to" do
25
- api.should_not_receive(:request).with(:get, anything, anything)
25
+ expect(api).to_not receive(:request).with(:get, anything, anything)
26
26
 
27
27
  subject.create('http://callback.com')
28
28
  end
@@ -32,7 +32,7 @@ describe ContextIO::ConnectTokenCollection do
32
32
  end
33
33
 
34
34
  it "takes an optional service level" do
35
- api.should_receive(:request).with(
35
+ expect(api).to receive(:request).with(
36
36
  anything,
37
37
  anything,
38
38
  hash_including(service_level: 'PRO')
@@ -42,7 +42,7 @@ describe ContextIO::ConnectTokenCollection do
42
42
  end
43
43
 
44
44
  it "takes an optional email" do
45
- api.should_receive(:request).with(
45
+ expect(api).to receive(:request).with(
46
46
  anything,
47
47
  anything,
48
48
  hash_including(email: 'person@email.com')
@@ -52,7 +52,7 @@ describe ContextIO::ConnectTokenCollection do
52
52
  end
53
53
 
54
54
  it "takes an optional first name" do
55
- api.should_receive(:request).with(
55
+ expect(api).to receive(:request).with(
56
56
  anything,
57
57
  anything,
58
58
  hash_including(first_name: 'Bruno')
@@ -62,7 +62,7 @@ describe ContextIO::ConnectTokenCollection do
62
62
  end
63
63
 
64
64
  it "takes an optional last name" do
65
- api.should_receive(:request).with(
65
+ expect(api).to receive(:request).with(
66
66
  anything,
67
67
  anything,
68
68
  hash_including(last_name: 'Morency')
@@ -34,7 +34,7 @@ describe ContextIO::ConnectToken do
34
34
  subject { ContextIO::ConnectToken.new(api, token: '1234') }
35
35
 
36
36
  it "uses the input key" do
37
- api.should_not_receive(:request)
37
+ expect(api).to_not receive(:request)
38
38
 
39
39
  expect(subject.token).to eq('1234')
40
40
  end
@@ -44,7 +44,7 @@ describe ContextIO::ConnectToken do
44
44
  subject { ContextIO::ConnectToken.new(api, resource_url: 'http://example.com/hitme') }
45
45
 
46
46
  it "loads it from the API" do
47
- api.should_receive(:request).with(
47
+ expect(api).to receive(:request).with(
48
48
  :get,
49
49
  'http://example.com/hitme'
50
50
  ).and_return({
@@ -38,63 +38,63 @@ describe ContextIO::EmailSettings do
38
38
 
39
39
  describe "#documentation" do
40
40
  it "fetches it from the api" do
41
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'documentation' => ['foo', 'bar'] })
41
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'documentation' => ['foo', 'bar'] })
42
42
  expect(subject.documentation).to eq(['foo', 'bar'])
43
43
  end
44
44
  end
45
45
 
46
46
  describe "#found?" do
47
47
  it "fetches it from the api" do
48
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'found' => true })
48
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'found' => true })
49
49
  expect(subject).to be_found
50
50
  end
51
51
  end
52
52
 
53
53
  describe "#type" do
54
54
  it "fetches it from the api" do
55
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'type' => 'gmail' })
55
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'type' => 'gmail' })
56
56
  expect(subject.type).to eq('gmail')
57
57
  end
58
58
  end
59
59
 
60
60
  describe "#server" do
61
61
  it "fetches it from the api" do
62
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'server' => 'imap.gmail.com' }})
62
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'server' => 'imap.gmail.com' }})
63
63
  expect(subject.server).to eq('imap.gmail.com')
64
64
  end
65
65
  end
66
66
 
67
67
  describe "#username" do
68
68
  it "fetches it from the api" do
69
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'username' => 'ben' }})
69
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'username' => 'ben' }})
70
70
  expect(subject.username).to eq('ben')
71
71
  end
72
72
  end
73
73
 
74
74
  describe "#port" do
75
75
  it "fetches it from the api" do
76
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'port' => 993 }})
76
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'port' => 993 }})
77
77
  expect(subject.port).to eq(993)
78
78
  end
79
79
  end
80
80
 
81
81
  describe "#oauth?" do
82
82
  it "fetches it from the api" do
83
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'oauth' => false }})
83
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'oauth' => false }})
84
84
  expect(subject).to_not be_oauth
85
85
  end
86
86
  end
87
87
 
88
88
  describe "#use_ssl?" do
89
89
  it "fetches it from the api" do
90
- api.should_receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'use_ssl' => false }})
90
+ expect(api).to receive(:request).with(:get, anything, anything).and_return({ 'imap' => { 'use_ssl' => false }})
91
91
  expect(subject).to_not be_use_ssl
92
92
  end
93
93
  end
94
94
 
95
95
  describe "#fetch_attributes" do
96
96
  before do
97
- api.stub(:request).with(:get, anything, anything).and_return({ 'foo' => 'bar' })
97
+ allow(api).to receive(:request).with(:get, anything, anything).and_return({ 'foo' => 'bar' })
98
98
  end
99
99
 
100
100
  it "defines a getter if one doesn't already exist" do
@@ -104,7 +104,7 @@ describe ContextIO::EmailSettings do
104
104
  end
105
105
 
106
106
  it "hits the right URL" do
107
- api.should_receive(:request).with(:get, 'discovery', 'email' => 'email@email.com', 'source_type' => 'IMAP')
107
+ expect(api).to receive(:request).with(:get, 'discovery', 'email' => 'email@email.com', 'source_type' => 'IMAP')
108
108
 
109
109
  subject.send(:fetch_attributes)
110
110
  end
@@ -8,11 +8,11 @@ describe ContextIO::OAuthProviderCollection do
8
8
 
9
9
  describe "#create" do
10
10
  before do
11
- api.stub(:request).with(:post, anything, anything).and_return({ provider_consumer_key: 'test_key' })
11
+ allow(api).to receive(:request).with(:post, anything, anything).and_return({ provider_consumer_key: 'test_key' })
12
12
  end
13
13
 
14
14
  it "posts to the api" do
15
- api.should_receive(:request).with(
15
+ expect(api).to receive(:request).with(
16
16
  :post,
17
17
  'url from api',
18
18
  type: 'GMAIL',
@@ -24,7 +24,7 @@ describe ContextIO::OAuthProviderCollection do
24
24
  end
25
25
 
26
26
  it "doesn't make any more API requests than it needs to" do
27
- api.should_receive(:request).exactly(:once)
27
+ expect(api).to receive(:request).exactly(:once)
28
28
 
29
29
  subject.create('GMAIL', 'test_key', 'test_secret')
30
30
  end
@@ -42,7 +42,7 @@ describe ContextIO::OAuthProvider do
42
42
  subject { ContextIO::OAuthProvider.new(api, provider_consumer_key: '1234') }
43
43
 
44
44
  it "asks the api for a URL" do
45
- api.should_receive(:url_for).with(subject)
45
+ expect(api).to receive(:url_for).with(subject)
46
46
 
47
47
  subject.resource_url
48
48
  end
@@ -54,7 +54,7 @@ describe ContextIO::OAuthProvider do
54
54
  subject { ContextIO::OAuthProvider.new(api, provider_consumer_key: '1234') }
55
55
 
56
56
  it "uses the input key" do
57
- api.should_not_receive(:request)
57
+ expect(api).to_not receive(:request)
58
58
 
59
59
  expect(subject.provider_consumer_key).to eq('1234')
60
60
  end
@@ -64,7 +64,7 @@ describe ContextIO::OAuthProvider do
64
64
  subject { ContextIO::OAuthProvider.new(api, resource_url: 'http://example.com/hitme') }
65
65
 
66
66
  it "loads it from the API" do
67
- api.should_receive(:request).with(
67
+ expect(api).to receive(:request).with(
68
68
  :get,
69
69
  'http://example.com/hitme'
70
70
  ).and_return({
@@ -81,7 +81,7 @@ describe ContextIO::OAuthProvider do
81
81
  subject { ContextIO::OAuthProvider.new(api, provider_consumer_key: '1234', provider_consumer_secret: '0987') }
82
82
 
83
83
  it "uses the input provider_consumer_secret" do
84
- api.should_not_receive(:request)
84
+ expect(api).to_not receive(:request)
85
85
 
86
86
  expect(subject.provider_consumer_secret).to eq('0987')
87
87
  end
@@ -91,7 +91,7 @@ describe ContextIO::OAuthProvider do
91
91
  subject { ContextIO::OAuthProvider.new(api, provider_consumer_key: '1234') }
92
92
 
93
93
  it "loads it from the API" do
94
- api.should_receive(:request).with(:get, anything).and_return({ 'provider_consumer_secret' => '1029' })
94
+ expect(api).to receive(:request).with(:get, anything).and_return({ 'provider_consumer_secret' => '1029' })
95
95
  expect(subject.provider_consumer_secret).to eq('1029')
96
96
  end
97
97
  end
@@ -102,7 +102,7 @@ describe ContextIO::OAuthProvider do
102
102
  subject { ContextIO::OAuthProvider.new(api, provider_consumer_key: '1234', type: 'GMAIL') }
103
103
 
104
104
  it "uses the input type" do
105
- api.should_not_receive(:request)
105
+ expect(api).to_not receive(:request)
106
106
 
107
107
  expect(subject.type).to eq('GMAIL')
108
108
  end
@@ -112,7 +112,7 @@ describe ContextIO::OAuthProvider do
112
112
  subject { ContextIO::OAuthProvider.new(api, provider_consumer_key: '1234') }
113
113
 
114
114
  it "loads it from the API" do
115
- api.should_receive(:request).with(:get, anything).and_return({ 'type' => 'GOOGLEAPPSMARKETPLACE' })
115
+ expect(api).to receive(:request).with(:get, anything).and_return({ 'type' => 'GOOGLEAPPSMARKETPLACE' })
116
116
  expect(subject.type).to eq('GOOGLEAPPSMARKETPLACE')
117
117
  end
118
118
  end
@@ -8,14 +8,14 @@ describe ContextIO::SourceCollection 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
  'resource_url' => 'resource_url'
14
14
  )
15
15
  end
16
16
 
17
17
  it "posts to the api" do
18
- api.should_receive(:request).with(
18
+ expect(api).to receive(:request).with(
19
19
  :post,
20
20
  'url from api',
21
21
  anything
@@ -25,27 +25,27 @@ describe ContextIO::SourceCollection do
25
25
  end
26
26
 
27
27
  it "converts boolean to number string for ssl" do
28
- api.should_receive(:request).with(
28
+ expect(api).to receive(:request).with(
29
29
  anything,
30
30
  anything,
31
- hash_including('use_ssl' => '1')
31
+ hash_including(:use_ssl => '1')
32
32
  )
33
33
 
34
34
  subject.create('hello@gmail.com', 'imap.email.com', 'hello', true, 993, 'IMAP')
35
35
  end
36
36
 
37
37
  it "converts integer to number string for port" do
38
- api.should_receive(:request).with(
38
+ expect(api).to receive(:request).with(
39
39
  anything,
40
40
  anything,
41
- hash_including('port' => '993')
41
+ hash_including(:port => '993')
42
42
  )
43
43
 
44
44
  subject.create('hello@gmail.com', 'imap.email.com', 'hello', true, 993, 'IMAP')
45
45
  end
46
46
 
47
47
  it "doesn't make any more API calls than it needs to" do
48
- api.should_not_receive(:request).with(:get, anything, anything)
48
+ expect(api).to_not receive(:request).with(:get, anything, anything)
49
49
 
50
50
  subject.create('hello@gmail.com', 'imap.email.com', 'hello', true, 993, 'IMAP')
51
51
  end
@@ -22,13 +22,13 @@ describe ContextIO::Source 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::Source.new(api, resource_url: 'resource_url', sync_period: '1h') }
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
  'resource_url',
34
34
  sync_period: '4h'
@@ -44,21 +44,27 @@ describe ContextIO::Source 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(sync_period: '4h')
50
50
  end
51
+
52
+ it "allows you to send arbitrary arguments to the API" do
53
+ expect(api).to receive(:request).with(:post, anything, {foo: 'bar'})
54
+
55
+ subject.update(foo: 'bar')
56
+ end
51
57
  end
52
58
 
53
59
  describe ".sync!" do
54
60
  before do
55
- api.stub(:request).and_return({'success' => true})
61
+ allow(api).to receive(:request).and_return({'success' => true})
56
62
  end
57
63
 
58
64
  subject { ContextIO::Source.new(api, resource_url: 'resource_url', sync_period: '1h') }
59
65
 
60
66
  it "syncs to the api" do
61
- api.should_receive(:request).with(
67
+ expect(api).to receive(:request).with(
62
68
  :post,
63
69
  'resource_url/sync',
64
70
  {}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contextio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hamill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-10 00:00:00.000000000 Z
11
+ date: 2013-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '2.4'
61
+ version: '2.14'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '2.4'
68
+ version: '2.14'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement