contactually-ruby 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +7 -0
- data/lib/contactually-ruby.rb +38 -0
- data/lib/contactually/accounts.rb +22 -0
- data/lib/contactually/api.rb +87 -0
- data/lib/contactually/buckets.rb +49 -0
- data/lib/contactually/contact_groupings.rb +16 -0
- data/lib/contactually/contacts.rb +54 -0
- data/lib/contactually/contents.rb +30 -0
- data/lib/contactually/errors.rb +21 -0
- data/lib/contactually/groupings.rb +36 -0
- data/lib/contactually/middleware/error_detector.rb +31 -0
- data/lib/contactually/notes.rb +31 -0
- data/lib/contactually/representer/account_representer.rb +15 -0
- data/lib/contactually/representer/bucket_representer.rb +16 -0
- data/lib/contactually/representer/contact_representer.rb +48 -0
- data/lib/contactually/representer/content_representer.rb +18 -0
- data/lib/contactually/representer/grouping_representer.rb +30 -0
- data/lib/contactually/representer/grouping_statistic_representer.rb +14 -0
- data/lib/contactually/representer/note_representer.rb +15 -0
- data/lib/contactually/representer/task_representer.rb +21 -0
- data/lib/contactually/tasks.rb +49 -0
- data/lib/contactually/utils.rb +44 -0
- data/lib/contactually/version.rb +3 -0
- data/spec/accounts_spec.rb +58 -0
- data/spec/api_spec.rb +125 -0
- data/spec/buckets_spec.rb +97 -0
- data/spec/contact_groupings_spec.rb +44 -0
- data/spec/contacts_spec.rb +133 -0
- data/spec/contents_spec.rb +80 -0
- data/spec/error_detector_spec.rb +24 -0
- data/spec/fixtures/account.json +10 -0
- data/spec/fixtures/accounts_index.json +19 -0
- data/spec/fixtures/bucket.json +8 -0
- data/spec/fixtures/buckets_index.json +41 -0
- data/spec/fixtures/contact.json +38 -0
- data/spec/fixtures/contacts_index.json +172 -0
- data/spec/fixtures/content.json +10 -0
- data/spec/fixtures/contents_index.json +29 -0
- data/spec/fixtures/grouping.json +19 -0
- data/spec/fixtures/groupings_index.json +28 -0
- data/spec/fixtures/note.json +7 -0
- data/spec/fixtures/note_destroy.json +4 -0
- data/spec/fixtures/notes_index.json +30 -0
- data/spec/fixtures/task.json +27 -0
- data/spec/fixtures/tasks_index.json +41 -0
- data/spec/groupings_spec.rb +85 -0
- data/spec/notes_spec.rb +85 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/tasks_spec.rb +127 -0
- metadata +205 -0
data/spec/api_spec.rb
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contactually::API do
|
4
|
+
|
5
|
+
describe 'missing configuration' do
|
6
|
+
before(:all) { Contactually.configure { |c| c.access_token = nil } }
|
7
|
+
specify do
|
8
|
+
expect{ subject }.to raise_error Contactually::ConfigMissingApiKeyError
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'allows to supply api key via initialize' do
|
12
|
+
expect{ described_class.new('asdf') }.not_to raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'sets access_token from parameters' do
|
16
|
+
expect(described_class.new('asdf').instance_variable_get(:@access_token)).to eq 'asdf'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'valid configuration' do
|
21
|
+
before(:all) { Contactually.configure { |c| c.access_token = 'VALID_ACCESS_TOKEN' } }
|
22
|
+
|
23
|
+
describe '#initialize' do
|
24
|
+
it 'initializes correctly' do
|
25
|
+
expect{ subject }.not_to raise_error
|
26
|
+
expect(subject).to be_kind_of Contactually::API
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'sets instance variables' do
|
30
|
+
expect(subject.instance_variable_get(:@access_token)).to eq 'VALID_ACCESS_TOKEN'
|
31
|
+
expect(subject.instance_variable_get(:@base_url)).to eq Contactually.contactually_url
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#call' do
|
36
|
+
it 'redirects get request to get' do
|
37
|
+
allow(subject).to receive(:get).and_return(Struct.new(:status, :body).new(200, {}))
|
38
|
+
subject.call('bla', :get, {})
|
39
|
+
expect(subject).to have_received(:get).with('bla', {})
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'redirects post request to post' do
|
43
|
+
allow(subject).to receive(:post).and_return(Struct.new(:status, :body).new(200, {}))
|
44
|
+
subject.call('bla', :post, {})
|
45
|
+
expect(subject).to have_received(:post).with('bla', {})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#call_params' do
|
50
|
+
specify do
|
51
|
+
expect(subject.send(:call_params, { foo: :bar })).to eql({ access_token: 'VALID_ACCESS_TOKEN', foo: :bar })
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#base_url' do
|
56
|
+
specify do
|
57
|
+
expect(subject.send(:base_url, 'foo/bar')).to eql("#{Contactually.contactually_url}foo/bar")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#accounts' do
|
62
|
+
specify do
|
63
|
+
expect(subject.accounts).to be_kind_of Contactually::Accounts
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#contact_groupings' do
|
68
|
+
specify do
|
69
|
+
expect(subject.contact_groupings).to be_kind_of Contactually::ContactGroupings
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#contacts' do
|
74
|
+
specify do
|
75
|
+
expect(subject.contacts).to be_kind_of Contactually::Contacts
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#contents' do
|
80
|
+
specify do
|
81
|
+
expect(subject.contents).to be_kind_of Contactually::Contents
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#groupings' do
|
86
|
+
specify do
|
87
|
+
expect(subject.groupings).to be_kind_of Contactually::Groupings
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#notes' do
|
92
|
+
specify do
|
93
|
+
expect(subject.notes).to be_kind_of Contactually::Notes
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#tasks' do
|
98
|
+
specify do
|
99
|
+
expect(subject.tasks).to be_kind_of Contactually::Tasks
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'endpoints' do
|
104
|
+
%w{ accounts contact_groupings contacts contents groupings notes tasks }.each do |endpoint|
|
105
|
+
specify { expect(subject.respond_to?(endpoint)).to eq true }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#get' do
|
110
|
+
it 'parses from json response' do
|
111
|
+
allow(subject.connection).to receive(:get).
|
112
|
+
with('https://api.contactually.com/v2/url', { foo: :bar, access_token: 'VALID_ACCESS_TOKEN' }).
|
113
|
+
and_return(Struct.new(:status, :body).new(200, "{ \"foo\": \"bar\" }"))
|
114
|
+
expect(subject.call('url', :get, { foo: :bar })).to be_kind_of Hash
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#post' do
|
119
|
+
it 'parses from json response' do
|
120
|
+
allow(subject.connection).to receive(:post).and_return(Struct.new(:status, :body).new(200, "{ \"foo\": \"bar\" }"))
|
121
|
+
expect(subject.call('url', :post, { foo: :bar })).to be_kind_of Hash
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contactually::Buckets do
|
4
|
+
|
5
|
+
let(:bucket_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/bucket.json")) }
|
6
|
+
let(:bucket_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/buckets_index.json")) }
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
Contactually.configure { |c| c.access_token = 'VALID_ACCESS_TOKEN' }
|
10
|
+
@master = Contactually::API.new
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { described_class.new @master }
|
14
|
+
describe '#initialize' do
|
15
|
+
specify do
|
16
|
+
expect(subject).to be_kind_of Contactually::Buckets
|
17
|
+
end
|
18
|
+
|
19
|
+
specify do
|
20
|
+
expect(subject.instance_variable_get(:@master)).to be_kind_of Contactually::API
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#create' do
|
25
|
+
it 'calls the api with correct params' do
|
26
|
+
allow(@master).to receive(:call).with('buckets.json', :post, { bucket: { foo: :bar }}).and_return(JSON.load(bucket_json))
|
27
|
+
subject.create({ bucket: { foo: :bar }})
|
28
|
+
expect(@master).to have_received(:call)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns a bucket' do
|
32
|
+
allow(@master).to receive(:call).with('buckets.json', :post, { bucket: { foo: :bar }}).and_return(JSON.load(bucket_json))
|
33
|
+
expect(subject.create({ bucket: { foo: :bar } })).to be_kind_of Contactually::Bucket
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#destroy' do
|
38
|
+
it 'calls the api with correct params' do
|
39
|
+
allow(@master).to receive(:call).with('buckets/1.json', :delete, {})
|
40
|
+
subject.destroy(1)
|
41
|
+
expect(@master).to have_received(:call)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#show' do
|
46
|
+
it 'calls the api with correct params' do
|
47
|
+
allow(@master).to receive(:call).with('buckets/1.json', :get, { foo: :bar }).and_return({ id: 1 })
|
48
|
+
subject.show(1, { foo: :bar })
|
49
|
+
expect(@master).to have_received(:call)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns a bucket' do
|
53
|
+
allow(@master).to receive(:call).with('buckets/1.json', :get, { foo: :bar }).and_return(JSON.load(bucket_json))
|
54
|
+
expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Bucket
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#update' do
|
59
|
+
it 'calls the api with correct params' do
|
60
|
+
allow(@master).to receive(:call).with('buckets/1.json', :put, { bucket: { foo: :bar }}).and_return(JSON.load(bucket_json))
|
61
|
+
subject.update(1, { bucket: { foo: :bar } })
|
62
|
+
expect(@master).to have_received(:call)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns a bucket from json response' do
|
66
|
+
allow(@master).to receive(:call).with('buckets/1.json', :put, { bucket: { foo: :bar }}).and_return(JSON.load(bucket_json))
|
67
|
+
expect(subject.update(1, bucket: { foo: :bar })).to be_kind_of Contactually::Bucket
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '#index' do
|
72
|
+
it 'calls the api with correct params' do
|
73
|
+
allow(@master).to receive(:call).with('buckets.json', :get, { foo: :bar }).and_return({ 'data' => [] })
|
74
|
+
subject.index({ foo: :bar })
|
75
|
+
expect(@master).to have_received(:call)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'returns buckets from json response' do
|
79
|
+
allow(@master).to receive(:call).with('buckets.json', :get, {}).and_return(JSON.load(bucket_index_json))
|
80
|
+
expect(subject.index({})).to be_kind_of Array
|
81
|
+
expect(subject.index({})[0]).to be_kind_of Contactually::Bucket
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#count' do
|
86
|
+
it 'calls the api with correct params' do
|
87
|
+
allow(@master).to receive(:call).with('buckets.json', :get, { limit: 1 }).and_return({ 'data' => [], 'meta' => {'total' => 120 }})
|
88
|
+
subject.count()
|
89
|
+
expect(@master).to have_received(:call)
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'returns total count' do
|
93
|
+
allow(@master).to receive(:call).with('buckets.json', :get, { limit: 1 }).and_return({ 'data' => [], 'meta' => {'total' => 120 }})
|
94
|
+
expect(subject.count).to be 120
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contactually::ContactGroupings do
|
4
|
+
|
5
|
+
let(:grouping_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/grouping.json")) }
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
Contactually.configure { |c| c.access_token = 'VALID_ACCESS_TOKEN' }
|
9
|
+
@master = Contactually::API.new
|
10
|
+
end
|
11
|
+
|
12
|
+
subject { described_class.new @master }
|
13
|
+
describe '#initialize' do
|
14
|
+
specify do
|
15
|
+
expect(subject).to be_kind_of Contactually::ContactGroupings
|
16
|
+
end
|
17
|
+
|
18
|
+
specify do
|
19
|
+
expect(subject.instance_variable_get(:@master)).to be_kind_of Contactually::API
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
describe '#create' do
|
25
|
+
it 'calls the api with correct params' do
|
26
|
+
allow(@master).to receive(:call).with('contacts/1/groupings.json', :post, { grouping_id: 512 }).and_return({ 'id' => 1234 })
|
27
|
+
subject.create(1, { grouping_id: 512 })
|
28
|
+
expect(@master).to have_received(:call)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns grouping from json response' do
|
32
|
+
allow(@master).to receive(:call).with('contacts/1/groupings.json', :post, { grouping_id: 512 }).and_return(JSON.load(grouping_json))
|
33
|
+
expect(subject.create(1, { grouping_id: 512 })).to be_kind_of Contactually::Grouping
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#destroy' do
|
38
|
+
it 'calls the api with correct params' do
|
39
|
+
allow(@master).to receive(:call).with('contacts/1/groupings/15.json', :delete, { foo: :bar }).and_return({ 'success' => true })
|
40
|
+
subject.destroy(1, 15, { foo: :bar })
|
41
|
+
expect(@master).to have_received(:call)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contactually::Contacts do
|
4
|
+
|
5
|
+
let(:contact_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contact.json")) }
|
6
|
+
let(:contacts_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contacts_index.json")) }
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
Contactually.configure { |c| c.access_token = 'VALID_ACCESS_TOKEN' }
|
10
|
+
@master = Contactually::API.new
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { described_class.new @master }
|
14
|
+
describe '#initialize' do
|
15
|
+
specify do
|
16
|
+
expect(subject).to be_kind_of Contactually::Contacts
|
17
|
+
end
|
18
|
+
|
19
|
+
specify do
|
20
|
+
expect(subject.instance_variable_get(:@master)).to be_kind_of Contactually::API
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#create' do
|
25
|
+
it 'calls the api with correct params' do
|
26
|
+
allow(@master).to receive(:call).with('contacts.json', :post, { contact: { foo: :bar }}).and_return(JSON.load(contact_json))
|
27
|
+
subject.create({ contact: { foo: :bar }})
|
28
|
+
expect(@master).to have_received(:call)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns a contact' do
|
32
|
+
allow(@master).to receive(:call).with('contacts.json', :post, { contact: { foo: :bar }}).and_return(JSON.load(contact_json))
|
33
|
+
expect(subject.create({ contact: { foo: :bar } })).to be_kind_of Contactually::Contact
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#destroy' do
|
38
|
+
it 'calls the api with correct params' do
|
39
|
+
allow(@master).to receive(:call).with('contacts/1.json', :delete, {})
|
40
|
+
subject.destroy(1)
|
41
|
+
expect(@master).to have_received(:call)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#destroy_multiple' do
|
46
|
+
it 'calls the api with correct params' do
|
47
|
+
allow(@master).to receive(:call).with('contacts.json', :delete, { ids: [ 1, 2, 3 ]})
|
48
|
+
subject.destroy_multiple({ ids: [ 1, 2, 3 ]})
|
49
|
+
expect(@master).to have_received(:call)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#show' do
|
54
|
+
it 'calls the api with correct params' do
|
55
|
+
allow(@master).to receive(:call).with('contacts/1.json', :get, { foo: :bar }).and_return({ id: 1 })
|
56
|
+
subject.show(1, { foo: :bar })
|
57
|
+
expect(@master).to have_received(:call)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns a contact' do
|
61
|
+
allow(@master).to receive(:call).with('contacts/1.json', :get, { foo: :bar }).and_return(JSON.load(contact_json))
|
62
|
+
expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Contact
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe '#tags' do
|
67
|
+
it 'calls the api with correct params - Array' do
|
68
|
+
allow(@master).to receive(:call).with('contacts/1/tags.json', :post, { tags: 'lol, haha' })
|
69
|
+
subject.tags(1, { tags: [ 'lol', 'haha' ]})
|
70
|
+
expect(@master).to have_received(:call)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'calls the api with correct params - String' do
|
74
|
+
allow(@master).to receive(:call).with('contacts/1/tags.json', :post, { tags: 'lol, haha' })
|
75
|
+
subject.tags(1, { tags: 'lol, haha' })
|
76
|
+
expect(@master).to have_received(:call)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#update' do
|
81
|
+
it 'calls the api with correct params' do
|
82
|
+
allow(@master).to receive(:call).with('contacts/1.json', :put, { contact: { foo: :bar }}).and_return(JSON.load(contact_json))
|
83
|
+
subject.update(1, { contact: { foo: :bar } })
|
84
|
+
expect(@master).to have_received(:call)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns a contact from json response' do
|
88
|
+
allow(@master).to receive(:call).with('contacts/1.json', :put, { contact: { foo: :bar }}).and_return(JSON.load(contact_json))
|
89
|
+
expect(subject.update(1, { contact: { foo: :bar }})).to be_kind_of Contactually::Contact
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#index' do
|
94
|
+
it 'calls the api with correct params' do
|
95
|
+
allow(@master).to receive(:call).with('contacts.json', :get, { foo: :bar }).and_return({ 'data' => [] })
|
96
|
+
subject.index({ foo: :bar })
|
97
|
+
expect(@master).to have_received(:call)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'returns contacts from json response' do
|
101
|
+
allow(@master).to receive(:call).with('contacts.json', :get, {}).and_return(JSON.load(contacts_index_json))
|
102
|
+
expect(subject.index({})).to be_kind_of Array
|
103
|
+
expect(subject.index({})[0]).to be_kind_of Contactually::Contact
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#search' do
|
108
|
+
it 'calls the api with correct params' do
|
109
|
+
allow(@master).to receive(:call).with('contacts/search.json', :get, { term: :foo_bar }).and_return({ 'data' => [] })
|
110
|
+
subject.search({ term: :foo_bar})
|
111
|
+
expect(@master).to have_received(:call)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'returns contacts from json response' do
|
115
|
+
allow(@master).to receive(:call).with('contacts/search.json', :get, { term: :foo_bar }).and_return(JSON.load(contacts_index_json))
|
116
|
+
expect(subject.search({ term: :foo_bar })).to be_kind_of Array
|
117
|
+
expect(subject.search({ term: :foo_bar })[0]).to be_kind_of Contactually::Contact
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe '#count' do
|
122
|
+
it 'calls the api with correct params' do
|
123
|
+
allow(@master).to receive(:call).with('contacts.json', :get, { limit: 1 }).and_return({ 'data' => [], 'total_count' => 120 })
|
124
|
+
subject.count()
|
125
|
+
expect(@master).to have_received(:call)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'returns total count' do
|
129
|
+
allow(@master).to receive(:call).with('contacts.json', :get, { limit: 1 }).and_return({ 'data' => [], 'total_count' => 120 })
|
130
|
+
expect(subject.count).to be 120
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Contactually::Contents do
|
4
|
+
|
5
|
+
let(:content_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/content.json")) }
|
6
|
+
let(:contents_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contents_index.json")) }
|
7
|
+
|
8
|
+
before(:all) do
|
9
|
+
Contactually.configure { |c| c.access_token = 'VALID_ACCESS_TOKEN' }
|
10
|
+
@master = Contactually::API.new
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { described_class.new @master }
|
14
|
+
describe '#initialize' do
|
15
|
+
specify do
|
16
|
+
expect(subject).to be_kind_of Contactually::Contents
|
17
|
+
end
|
18
|
+
|
19
|
+
specify do
|
20
|
+
expect(subject.instance_variable_get(:@master)).to be_kind_of Contactually::API
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#create' do
|
25
|
+
it 'calls the api with correct params' do
|
26
|
+
allow(@master).to receive(:call).with('contents.json', :post, { content: { foo: :bar }}).and_return(JSON.load(content_json))
|
27
|
+
subject.create({ content: { foo: :bar }})
|
28
|
+
expect(@master).to have_received(:call)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns a content' do
|
32
|
+
allow(@master).to receive(:call).with('contents.json', :post, { content: { foo: :bar }}).and_return(JSON.load(content_json))
|
33
|
+
expect(subject.create({ content: { foo: :bar }})).to be_kind_of Contactually::Content
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#index' do
|
38
|
+
it 'calls the api with correct params' do
|
39
|
+
allow(@master).to receive(:call).with('contents.json', :get, { foo: :bar }).and_return({ 'data' => [] })
|
40
|
+
subject.index({ foo: :bar })
|
41
|
+
expect(@master).to have_received(:call)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns contents from json response' do
|
45
|
+
allow(@master).to receive(:call).with('contents.json', :get, {}).and_return(JSON.load(contents_index_json))
|
46
|
+
expect(subject.index({})).to be_kind_of Array
|
47
|
+
expect(subject.index({})[0]).to be_kind_of Contactually::Content
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#destroy' do
|
52
|
+
it 'calls the api with correct params' do
|
53
|
+
allow(@master).to receive(:call).with('contents/115.json', :delete, { foo: :bar }).and_return({ 'success' => true })
|
54
|
+
subject.destroy(115, { foo: :bar })
|
55
|
+
expect(@master).to have_received(:call)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#show' do
|
60
|
+
it 'calls the api with correct params' do
|
61
|
+
allow(@master).to receive(:call).with('contents/1.json', :get, { foo: :bar }).and_return({ id: 1 })
|
62
|
+
subject.show(1, { foo: :bar })
|
63
|
+
expect(@master).to have_received(:call)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns a contact' do
|
67
|
+
allow(@master).to receive(:call).with('contents/1.json', :get, { foo: :bar }).and_return(JSON.load(content_json))
|
68
|
+
expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Content
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#update' do
|
73
|
+
it 'calls the api with correct params' do
|
74
|
+
allow(@master).to receive(:call).with('contents/1.json', :put, { content: { foo: :bar }})
|
75
|
+
subject.update(1, { content: { foo: :bar } })
|
76
|
+
expect(@master).to have_received(:call)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|