Skip to content

[bugfix] Missing client in the response of the object created #516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/intercom/api_operations/save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def save(object)
else
response = @client.post("/#{collection_name}", object.to_submittable_hash.merge(identity_hash(object)))
end
object.client = @client
object.from_response(response) if response # may be nil we received back a 202
end

Expand Down
55 changes: 55 additions & 0 deletions spec/unit/intercom/contact_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,5 +311,60 @@
client.expects(:delete).with("/contacts/1/companies/#{company.id}", "id": tag.id ).returns(test_company)
contact.remove_company({ "id": tag.id })
end

describe 'just after creating the contact' do
let(:contact) do
contact = Intercom::Contact.new('email' => 'jo@example.com', :external_id => 'i-1224242')
client.expects(:post).with('/contacts', 'email' => 'jo@example.com', 'external_id' => 'i-1224242', 'custom_attributes' => {})
.returns('id' => 1, 'email' => 'jo@example.com', 'external_id' => 'i-1224242')
client.contacts.save(contact)
end

it 'returns a collection proxy for listing notes' do
proxy = contact.notes
_(proxy.resource_name).must_equal 'notes'
_(proxy.url).must_equal '/contacts/1/notes'
_(proxy.resource_class).must_equal Intercom::Note
end

it 'returns a collection proxy for listing tags' do
proxy = contact.tags
_(proxy.resource_name).must_equal 'tags'
_(proxy.url).must_equal '/contacts/1/tags'
_(proxy.resource_class).must_equal Intercom::Tag
end

it 'returns a collection proxy for listing companies' do
proxy = contact.companies
_(proxy.resource_name).must_equal 'companies'
_(proxy.url).must_equal '/contacts/1/companies'
_(proxy.resource_class).must_equal Intercom::Company
end

it 'adds a note to a contact' do
client.expects(:post).with('/contacts/1/notes', {body: note.body}).returns(note.to_hash)
contact.create_note({body: note.body})
end

it 'adds a tag to a contact' do
client.expects(:post).with('/contacts/1/tags', "id": tag.id).returns(tag.to_hash)
contact.add_tag({ "id": tag.id })
end

it 'removes a tag from a contact' do
client.expects(:delete).with("/contacts/1/tags/#{tag.id}", "id": tag.id ).returns(tag.to_hash)
contact.remove_tag({ "id": tag.id })
end

it 'adds a contact to a company' do
client.expects(:post).with('/contacts/1/companies', "id": company.id).returns(test_company)
contact.add_company({ "id": tag.id })
end

it 'removes a contact from a company' do
client.expects(:delete).with("/contacts/1/companies/#{company.id}", "id": tag.id ).returns(test_company)
contact.remove_company({ "id": tag.id })
end
end
end
end