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 possibility to use unique-ft of faker #75

Open
wuarmin opened this issue Sep 5, 2022 · 2 comments
Open

Add possibility to use unique-ft of faker #75

wuarmin opened this issue Sep 5, 2022 · 2 comments

Comments

@wuarmin
Copy link
Contributor

wuarmin commented Sep 5, 2022

Describe the bug

At the moment it's not possible to use unique-feature of faker.

To Reproduce

Factory.define(:company) do |f|
  f.id { fake(:alphanumeric, :unique, :alpha, number: 3).upcase } # will fail
  f.name { fake(:name, :name) }
end

Expected behavior

id should be unique

Proposal

What do you think about following solution:
We could allow a unique-option at our DSL and if unique is set to true, the method unique is called in front of the specified method (alpha in this case)

Factory.define(:company) do |f|
  f.id { fake(:alphanumeric, :alpha, number: 3, unique: true).upcase }
  # resulting call will be Faker::Alphanumeric.unique.alpha(number: 3)
end

WDYT?

Thanks and best regards

@solnic
Copy link
Member

solnic commented Sep 6, 2022

Yes this sounds good! 🙂

@wuarmin
Copy link
Contributor Author

wuarmin commented Sep 6, 2022

Great! I will prepare a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants