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

Add supporting classes for test helper generation #1034

Merged
merged 10 commits into from
Mar 28, 2022

Conversation

pakrym-stripe
Copy link
Contributor

@pakrym-stripe pakrym-stripe commented Feb 23, 2022

Test helper methods on a resource are placed inside a nested TestHelpers class:

        module Stripe
          class Foo < APIResource
            extend Stripe::APIOperations::Create

            OBJECT_NAME = 'foo'

            custom_method :pdf, http_verb: :get

            def pdf(params = {}, opts = {})
              request_stripe_object(
                method: :get,
                path: resource_url + '/pdf',
                params: params,
                opts: opts,
              )
            end

            def test_helpers
              TestHelpers.new(self)
            end

            class TestHelpers < APIResourceTestHelpers
              RESOURCE_CLASS = Foo

              custom_method :boop, http_verb: :post

              def boop(params = {}, opts = {})
                @resource.request_stripe_object(
                    method: :post,
                    path: resource_url + '/boop',
                    params: params,
                    opts: opts,
                  )
              end
            end
          end
        end

To support the generation we need:

  1. Add a base APIResourceTestHelpers with test-helper URL generation logic.
  2. Adjust custom_method to handle cases where static method in not on the resource class itself.

@richardm-stripe
Copy link
Contributor

CI is failing, one more file needs to be pushed?

@pakrym-stripe pakrym-stripe marked this pull request as ready for review February 24, 2022 18:42
Copy link
Contributor

@richardm-stripe richardm-stripe left a comment

Choose a reason for hiding this comment

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

This looks good, let's wait to merge until the first test_helper method is released.

Copy link
Contributor

@dcr-stripe dcr-stripe left a comment

Choose a reason for hiding this comment

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

Looks good, just one nit and then we'll be good to ship! Thanks!

lib/stripe/util.rb Show resolved Hide resolved
@pakrym-stripe
Copy link
Contributor Author

PTAL @dcr-stripe ?

Copy link
Contributor

@dcr-stripe dcr-stripe left a comment

Choose a reason for hiding this comment

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

LGTM!

@pakrym-stripe pakrym-stripe merged commit fc480cd into master Mar 28, 2022
@remi-stripe remi-stripe deleted the pakrym/test-helpers branch September 28, 2023 23:07
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.

3 participants