Search code examples
ruby-on-railsrubymethods

Ruby: ArgumentError (wrong number of arguments (given 1, expected 0))


I'm clearly fundamentally not understanding how to pass arguments and call methods in Rails.

I'm trying to make a test call to stripe with dummy information and I'm getting the subject error when I try and run this command from the console:

Stripe::CustomerApi.new(30).create_stripe_customer

My class where the method is located is as follows:

require 'stripe'
module Stripe
    class CustomerApi

        def initialize(id)
          @user = User.find(id)
          @company_profile = @user.company_profile
          Stripe.api_key = 'my test key info'
        end


        def create_stripe_customer
          request = Stripe::Customer.create({
              email: '[email protected]',
              name: 'john doe',
              address: {
                city: 'Brothers',
                country: 'US',
                line1: '27 Any Street',
                postal_code: '90210',
                state: 'CA',
              }
            })

          Rails.logger.info request

        end
    end
end

The idea here is once I get the test working I would pass actual user information through the id value.

Adding stack trace from rails console.

irb(main):001:0> Stripe::CustomerApi.new(30).create_stripe_customer
  User Load (7.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 30], ["LIMIT", 1]]
  CompanyProfile Load (2.7ms)  SELECT  "company_profiles".* FROM "company_profiles" WHERE "company_profiles"."user_id" = $1 LIMIT $2  [["user_id", 30], ["LIMIT", 1]]
Traceback (most recent call last):
        3: from (irb):1
        2: from app/services/stripe/customer_api.rb:15:in `create_stripe_customer'
        1: from app/services/stripe/stripe_client.rb:11:in `initialize'
ArgumentError (wrong number of arguments (given 1, expected 0))

The trace references the stripe_client file, which I'm not sure why. It's a separate file where I tried to make this same API call using REST API. It doesn't have the same methods.


Solution

  • Whelp. I'm a moron. The stack trace shows here:

    from app/services/stripe/stripe_client.rb:11:in `initialize' 
    

    that I'm calling both initialize methods across two different files in the same folder area. I'm guessing that's a no-no. I deleted the method I'm not using and it tested SAT.