rom-rb / rom-factory

Data generator with support for persistence backends
MIT License
83 stars 42 forks source link

Add possibility to use unique-ft of faker #75

Open wuarmin opened 2 years ago

wuarmin commented 2 years ago

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 commented 2 years ago

Yes this sounds good! 🙂

wuarmin commented 2 years ago

Great! I will prepare a PR.