Skip to content

Conversation

@WaKeMaTTa
Copy link
Contributor

@WaKeMaTTa WaKeMaTTa commented Mar 6, 2020

Issue

Missing client in the response of the object created.
Then you can not use the nested resources.

Example

contact = INTERCOM_CLIENT.contacts.new(email: "[email protected]")
INTERCOM_CLIENT.contacts.save(contact)
company = INTERCOM_CLIENT.contacts.new(company_id: "abc-company-example")
contact.add_company(id: company.id) # this fails!!

Before my fix, the specs that I created were broken:

be m spec/unit/intercom/contact_spec.rb 
Mocha deprecation warning at /github/intercom-ruby/spec/spec_helper.rb:5:in `require': Require 'mocha/test_unit', 'mocha/minitest' or 'mocha/api' instead of 'mocha/setup'.
Run options: -n "/^(test_0013_allows\\ setting\\ dates\\ to\\ nil\\ without\\ converting\\ them\\ to\\ 0|test_0015_will\\ allow\\ extra\\ attributes\\ in\\ response\\ from\\ api|test_0001_should\\ be\\ listable|test_0007_allows\\ easy\\ setting\\ of\\ custom\\ data|test_0008_rejects\\ nested\\ data\\ structures\\ in\\ custom_attributes|test_0009_saves\\ a\\ contact\\ \\(always\\ sends\\ custom_attributes\\)|test_0017_can\\ print\\ contacts\\ without\\ crashing|test_0005_is\\ throws\\ a\\ Intercom::AttributeNotSetError\\ on\\ trying\\ to\\ access\\ an\\ attribute\\ that\\ has\\ not\\ been\\ set|test_0003_to_hash'es\\ itself|test_0011_can\\ use\\ client\\.contacts\\.create\\ for\\ convenience|test_0006_presents\\ a\\ complete\\ contact\\ record\\ correctly|test_0020_deletes\\ a\\ contact|test_0002_should\\ throw\\ an\\ ArgumentError\\ when\\ there\\ are\\ no\\ parameters|test_0004_presents\\ created_at\\ and\\ last_impression_at\\ as\\ Date|test_0014_sets/gets\\ rw\\ keys|test_0019_can\\ update\\ a\\ contact\\ with\\ an\\ id|test_0016_returns\\ a\\ BaseCollectionProxy\\ for\\ all\\ without\\ making\\ any\\ requests|test_0012_updates\\ the\\ contact\\ with\\ attributes\\ as\\ set\\ by\\ the\\ server|test_0018_fetches\\ a\\ contact|test_0010_can\\ save\\ a\\ contact\\ with\\ a\\ nil\\ email|test_0001_increments\\ up\\ by\\ 1\\ with\\ no\\ args|test_0003_increments\\ down\\ by\\ given\\ value|test_0005_can\\ call\\ increment\\ on\\ the\\ same\\ key\\ twice\\ and\\ increment\\ by\\ 2|test_0002_increments\\ up\\ by\\ given\\ value|test_0004_can\\ increment\\ new\\ custom\\ data\\ fields|test_0001_decrements\\ down\\ by\\ 1\\ with\\ no\\ args|test_0002_decrements\\ down\\ by\\ given\\ value|test_0003_can\\ decrement\\ new\\ custom\\ data\\ fields|test_0004_can\\ call\\ decrement\\ on\\ the\\ same\\ key\\ twice\\ and\\ decrement\\ by\\ 2|test_0001_should\\ be\\ successful\\ with\\ a\\ lead\\ and\\ user|test_0001_returns\\ a\\ collection\\ proxy\\ for\\ listing\\ notes|test_0004_adds\\ a\\ note\\ to\\ a\\ contact|test_0007_adds\\ a\\ contact\\ to\\ a\\ company|test_0002_returns\\ a\\ collection\\ proxy\\ for\\ listing\\ tags|test_0003_returns\\ a\\ collection\\ proxy\\ for\\ listing\\ companies|test_0005_adds\\ a\\ tag\\ to\\ a\\ contact|test_0006_removes\\ a\\ tag\\ from\\ a\\ contact|test_0008_removes\\ a\\ contact\\ from\\ a\\ company|test_0001_returns\\ a\\ collection\\ proxy\\ for\\ listing\\ notes|test_0007_adds\\ a\\ contact\\ to\\ a\\ company|test_0006_removes\\ a\\ tag\\ from\\ a\\ contact|test_0002_returns\\ a\\ collection\\ proxy\\ for\\ listing\\ tags|test_0003_returns\\ a\\ collection\\ proxy\\ for\\ listing\\ companies|test_0008_removes\\ a\\ contact\\ from\\ a\\ company|test_0004_adds\\ a\\ note\\ to\\ a\\ contact|test_0005_adds\\ a\\ tag\\ to\\ a\\ contact)$/" --seed 7184

# Running:

....E.E.EEE...................................

Finished in 0.014731s, 3122.6858 runs/s, 7399.4076 assertions/s.

  1) Error:
Intercom::Contact::nested resources::just after creating the contact#test_0005_adds a tag to a contact:
NoMethodError: undefined method `post' for nil:NilClass
    /github/intercom-ruby/lib/intercom/api_operations/nested_resource.rb:37:in `block (2 levels) in nested_resource_methods'
    /github/intercom-ruby/spec/unit/intercom/contact_spec.rb:351:in `block (4 levels) in <top (required)>'

  2) Error:
Intercom::Contact::nested resources::just after creating the contact#test_0006_removes a tag from a contact:
NoMethodError: undefined method `delete' for nil:NilClass
    /github/intercom-ruby/lib/intercom/api_operations/nested_resource.rb:44:in `block (2 levels) in nested_resource_methods'
    /github/intercom-ruby/spec/unit/intercom/contact_spec.rb:356:in `block (4 levels) in <top (required)>'

  3) Error:
Intercom::Contact::nested resources::just after creating the contact#test_0004_adds a note to a contact:
NoMethodError: undefined method `post' for nil:NilClass
    /github/intercom-ruby/lib/intercom/api_operations/nested_resource.rb:30:in `block (2 levels) in nested_resource_methods'
    /github/intercom-ruby/spec/unit/intercom/contact_spec.rb:346:in `block (4 levels) in <top (required)>'

  4) Error:
Intercom::Contact::nested resources::just after creating the contact#test_0007_adds a contact to a company:
NoMethodError: undefined method `post' for nil:NilClass
    /github/intercom-ruby/lib/intercom/api_operations/nested_resource.rb:37:in `block (2 levels) in nested_resource_methods'
    /github/intercom-ruby/spec/unit/intercom/contact_spec.rb:361:in `block (4 levels) in <top (required)>'

  5) Error:
Intercom::Contact::nested resources::just after creating the contact#test_0008_removes a contact from a company:
NoMethodError: undefined method `delete' for nil:NilClass
    /github/intercom-ruby/lib/intercom/api_operations/nested_resource.rb:44:in `block (2 levels) in nested_resource_methods'
    /github/intercom-ruby/spec/unit/intercom/contact_spec.rb:366:in `block (4 levels) in <top (required)>'

46 runs, 109 assertions, 0 failures, 5 errors, 0 skips

Then you can not use the nested resources.

Example:

```ruby
contact = INTERCOM_CLIENT.contacts.new(email: "[email protected]")
INTERCOM_CLIENT.contacts.save(contact)
company = INTERCOM_CLIENT.contacts.new(company_id: "abc-company-example")
contact.add_company(id: company.id) # this fails!!
```
Copy link
Contributor

@murtron murtron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An oversight on our part, apologies 😞 Thanks a lot for this @WaKeMaTTa.

I'll try to get a new release out next week.

@murtron murtron merged commit fb84544 into intercom:master Mar 10, 2020
@murtron murtron mentioned this pull request Mar 10, 2020
@WaKeMaTTa WaKeMaTTa deleted the bug-contact-add-comapny branch March 10, 2020 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants