Skip to content
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

Models say they don't respond_to :object #82

Open
jaynetics opened this issue Sep 2, 2024 · 0 comments
Open

Models say they don't respond_to :object #82

jaynetics opened this issue Sep 2, 2024 · 0 comments

Comments

@jaynetics
Copy link

jaynetics commented Sep 2, 2024

Many (all?) Chargebee models respond to the "object" method. E.g.

session = ChargeBee::PortalSession.create(...).portal_session
session.object # => 'portal_session'

however, they say that they don't:

session.respond_to?(:object) # => false

presumably this is because the return value is fetched via method_missing here.

this is not ideal for code with type checks.

also respond_to_missing? has not been implemented, though there is a PR for it.

similarly, this:

ChargeBee::PortalSession.public_method_defined?(:object) # => false

prevents the usage of verified doubles with rspec:

instance_double(ChargeBee::PortalSession, object: 'portal_session')
# => error: the ChargeBee::PortalSession class does not implement the instance method: object

i hacked around this in my code with:

ChargeBee::Model.class_eval { attr_reader :object }

but i don't know if this is correct and whether all models include the "object" information.

ideally, each model that has the "object" information would have an attr_reader/accessor for it (or it could be added to Model if its all of them).

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

No branches or pull requests

1 participant