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 custom start date for Faker::Date.forward #2791

Merged

Conversation

luciagirasoles
Copy link
Contributor

@luciagirasoles luciagirasoles commented Jun 29, 2023

Motivation / Background

The goal of this PR is to make it possible to use a custom start date using the Faker::Date.forward function. Adding this will enable from param to be filled with 'Date.current' from Rails or a String like "Thu, 22 Jun 2023"
Fixes #2093.

Additional information

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug, refactor something, or add a feature.
  • Tests and Rubocop are passing before submitting your proposed changes.

If you're proposing a new generator:

  • Open an issue first for discussion before you write any code.
  • Double-check the existing generators documentation to make sure the new generator you want to add doesn't already exist.
  • You've reviewed and followed the Documentation guidelines.

Copy link
Contributor

@thdaraujo thdaraujo left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, I think this is a good solution that adds flexibility to this generator.

Left a comment about the test, as I don't think it's necessary to run it 100 times.

test/faker/default/test_faker_date.rb Outdated Show resolved Hide resolved
test/faker/default/test_faker_date.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@thdaraujo thdaraujo left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

Comment on lines +80 to +84
100.times do
random_date = @tester.forward(from: from, days: 5)

assert random_date > from_date, "Expected > \"#{from}\", but got #{random_date}"
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
100.times do
random_date = @tester.forward(from: from, days: 5)
assert random_date > from_date, "Expected > \"#{from}\", but got #{random_date}"
end
random_date = @tester.forward(from: from, days: 5)
assert random_date > from_date, "Expected > \"#{from}\", but got #{random_date}"

@thdaraujo thdaraujo changed the title Update faker date forward Add custom start date for Faker::Date.forward Jul 6, 2023
@thdaraujo thdaraujo merged commit e132ae9 into faker-ruby:main Jul 6, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Date.today causes timezone issues in Rails.
2 participants