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 Faker::UniqueGenerator - exclude method #1307

Merged
merged 1 commit into from
Jul 14, 2018
Merged

Add Faker::UniqueGenerator - exclude method #1307

merged 1 commit into from
Jul 14, 2018

Conversation

mtancoigne
Copy link
Contributor

@mtancoigne mtancoigne commented Jul 10, 2018

This adds an "add_to_previous_results" method to UniqueGenerator, allowing to manually specify already used values, or excluded ones.

On a Rails app, I had collisions in the tests with manually defined values and the ones created by faker. I guess there are other use cases where having this feature could be useful.

I think the test speaks for itself:

def test_unique_with_already_set_values
  values = ('a'..'z').to_a + ('0'..'9').to_a
  @tester.unique.add_to_previous_results(:character, [], values)
  assert_raise(Faker::UniqueGenerator::RetryLimitExceeded) { @tester.unique.character }
end
  • Rubocop
  • Documentation
  • New test
  • Tests passing

I can change the method name if it's not understandable.

@stympy
Copy link
Contributor

stympy commented Jul 11, 2018

Perhaps this method could be renamed to exclude... that would more clearly indicate what the method does, I think.

@mtancoigne
Copy link
Contributor Author

I changed the method name and reworded the commit...

README.md Outdated
# Faker::<generator>.unique.add_to_previous_results(method, arguments, list)

# Add 'azerty' and 'wxcvbn' to the string generator with 6 char length
Faker::Lorem.unique.add_to_previous_results :string, [6], %w[azerty wxcvbn]
Copy link
Member

Choose a reason for hiding this comment

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

@mtancoigne please update the docs as well. Thanks :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, my bad :/

@vbrazo vbrazo changed the title Add "add_to_previous_results" method to UniqueGenerator Faker::UniqueGenerator - exclude method Jul 12, 2018
@vbrazo vbrazo changed the title Faker::UniqueGenerator - exclude method Add Faker::UniqueGenerator - exclude method Jul 12, 2018
@stympy stympy merged commit ecf0c19 into faker-ruby:master Jul 14, 2018
davidmorton0 pushed a commit to davidmorton0/faker that referenced this pull request Jul 12, 2021
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.

3 participants