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 YARD docs to Faker::Stripe #1981

Merged
merged 3 commits into from May 17, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions lib/faker/default/stripe.rb
Expand Up @@ -3,6 +3,17 @@
module Faker
class Stripe < Base
class << self
##
# Produces a random valid card number.
#
# @param card_type [String] Specific valid card type.
# @return [String]
#
# @example
# Faker::Stripe.valid_card #=> "4242424242424242"
# Faker::Stripe.valid_card(card_type: "visa_debit") #=> "4000056655665556"
#
# @faker.version 1.9.0
def valid_card(legacy_card_type = NOT_GIVEN, card_type: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :card_type if legacy_card_type != NOT_GIVEN
Expand All @@ -22,6 +33,17 @@ def valid_card(legacy_card_type = NOT_GIVEN, card_type: nil)
fetch('stripe.valid_cards.' + card_type)
end

##
# Produces a random valid Stripe token.
#
# @param card_type [String] Specific valid card type.
# @return [String]
#
# @example
# Faker::Stripe.valid_token #=> "tok_visa"
# Faker::Stripe.valid_token(card_type: "mc_debit") #=> "tok_mastercard_debit"
#
# @faker.version 1.9.0
def valid_token(legacy_card_type = NOT_GIVEN, card_type: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :card_type if legacy_card_type != NOT_GIVEN
Expand All @@ -41,6 +63,16 @@ def valid_token(legacy_card_type = NOT_GIVEN, card_type: nil)
fetch('stripe.valid_tokens.' + card_type)
end

##
# Produces a random invalid card number.
#
# @return [String]
#
# @example
# Faker::Stripe.invalid_card #=> "4000000000000002"
# Faker::Stripe.invalid_card(card_error: "addressZipFail") #=> "4000000000000010"
#
# @faker.version 1.9.0
def invalid_card(legacy_card_error = NOT_GIVEN, card_error: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :card_error if legacy_card_error != NOT_GIVEN
Expand All @@ -60,15 +92,44 @@ def invalid_card(legacy_card_error = NOT_GIVEN, card_error: nil)
fetch('stripe.invalid_cards.' + card_error)
end

##
# Produces a random month in two digits format.
#
# @return [String]
#
# @example
# Faker::Stripe.month #=> "10"
#
# @faker.version 1.9.0
def month
format('%02d', rand_in_range(1, 12))
end

##
# Produces a random year that is always in the future.
#
# @return [Date]
danielTiringer marked this conversation as resolved.
Show resolved Hide resolved
#
# @example
# Faker::Stripe.year #=> "2018" # This will always be a year in the future
#
# @faker.version 1.9.0
def year
start_year = ::Time.new.year + 1
rand_in_range(start_year, start_year + 5).to_s
end

##
# Produces a random ccv number.
#
# @param card_type [String] Specific valid card type.
# @return [String]
#
# @example
# Faker::Stripe.ccv #=> "123"
# Faker::Stripe.ccv(card_type: "amex") #=> "1234"
#
# @faker.version 1.9.0
def ccv(legacy_card_type = NOT_GIVEN, card_type: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :card_type if legacy_card_type != NOT_GIVEN
Expand Down