Skip to content

Commit 5e25a20

Browse files
authored
Merge branch 'master' into conversation-add-remove-nested-contact
2 parents 0be174a + fb84544 commit 5e25a20

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

Diff for: lib/intercom/api_operations/save.rb

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def save(object)
2727
else
2828
response = @client.post("/#{collection_name}", object.to_submittable_hash.merge(identity_hash(object)))
2929
end
30+
object.client = @client
3031
object.from_response(response) if response # may be nil we received back a 202
3132
end
3233

Diff for: spec/unit/intercom/contact_spec.rb

+55
Original file line numberDiff line numberDiff line change
@@ -311,5 +311,60 @@
311311
client.expects(:delete).with("/contacts/1/companies/#{company.id}", "id": tag.id ).returns(test_company)
312312
contact.remove_company({ "id": tag.id })
313313
end
314+
315+
describe 'just after creating the contact' do
316+
let(:contact) do
317+
contact = Intercom::Contact.new('email' => '[email protected]', :external_id => 'i-1224242')
318+
client.expects(:post).with('/contacts', 'email' => '[email protected]', 'external_id' => 'i-1224242', 'custom_attributes' => {})
319+
.returns('id' => 1, 'email' => '[email protected]', 'external_id' => 'i-1224242')
320+
client.contacts.save(contact)
321+
end
322+
323+
it 'returns a collection proxy for listing notes' do
324+
proxy = contact.notes
325+
_(proxy.resource_name).must_equal 'notes'
326+
_(proxy.url).must_equal '/contacts/1/notes'
327+
_(proxy.resource_class).must_equal Intercom::Note
328+
end
329+
330+
it 'returns a collection proxy for listing tags' do
331+
proxy = contact.tags
332+
_(proxy.resource_name).must_equal 'tags'
333+
_(proxy.url).must_equal '/contacts/1/tags'
334+
_(proxy.resource_class).must_equal Intercom::Tag
335+
end
336+
337+
it 'returns a collection proxy for listing companies' do
338+
proxy = contact.companies
339+
_(proxy.resource_name).must_equal 'companies'
340+
_(proxy.url).must_equal '/contacts/1/companies'
341+
_(proxy.resource_class).must_equal Intercom::Company
342+
end
343+
344+
it 'adds a note to a contact' do
345+
client.expects(:post).with('/contacts/1/notes', {body: note.body}).returns(note.to_hash)
346+
contact.create_note({body: note.body})
347+
end
348+
349+
it 'adds a tag to a contact' do
350+
client.expects(:post).with('/contacts/1/tags', "id": tag.id).returns(tag.to_hash)
351+
contact.add_tag({ "id": tag.id })
352+
end
353+
354+
it 'removes a tag from a contact' do
355+
client.expects(:delete).with("/contacts/1/tags/#{tag.id}", "id": tag.id ).returns(tag.to_hash)
356+
contact.remove_tag({ "id": tag.id })
357+
end
358+
359+
it 'adds a contact to a company' do
360+
client.expects(:post).with('/contacts/1/companies', "id": company.id).returns(test_company)
361+
contact.add_company({ "id": tag.id })
362+
end
363+
364+
it 'removes a contact from a company' do
365+
client.expects(:delete).with("/contacts/1/companies/#{company.id}", "id": tag.id ).returns(test_company)
366+
contact.remove_company({ "id": tag.id })
367+
end
368+
end
314369
end
315370
end

0 commit comments

Comments
 (0)