-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix locale setting #2734
Fix locale setting #2734
Conversation
I've been running behind on reviews, will check out this tomorrow. In the meantime, could you take a look at the rubocop failure? Thank you 🚀 |
@mateusdeap thank you for your contribution so far! Sorry for the late response. I think that having a configuration option which sets the default locale in a non-threadsafe way by having a:
can be worth introducing on faker. It seems like that's the easiest way to set that default locale initially. @thdaraujo thoughts? It would be a breaking change, and we can create a new release for it, no worries. Something I had in mind is to include this test from this branch, as it shows the desired behaviour of setting the locale globally with per-thread locales. It's just a start but it gives us a start 💭
About your question of where to place the tests, there is the faker test file. Another option is add the tests to the |
Sorry, I first missed the ! in These are now passing:
We'll need to update the docs as well to guide folks on how to use this as well. I confess I'm not super familiar with this, so hopefully @thdaraujo can chime in to give some ideas on the tests and docs 🙏 |
There was a problem hiding this 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 and being so helpful, @mateusdeap!
For testing, we can just add a new file called faker/test/test_default_locale.rb
and base it off of the specs that @stefannibrasil shared. That would be good enough.
See my comment about changing to default_locale
and let me know what you think.
Merging this and I will add the test and update the README in a follow up PR. Thank you @mateusdeap for your contribution! |
Summary
Better late than never.
This PR aims to make the locale setting work in threaded server environments.
It adds back the
@locale
class variable toFaker::Config
and adds a new thread unsafe method that sets that variable. That way we can still set the locale on a per thread basis withFaker::Config.locale
or we can set it in a global manner usingFaker::Config.locale!
As a final remark, not really sure this does what we want it to do, but tests still pass.
Also would like to give a shout out to @nateberkopec, @hlascelles, @stefannibrasil and @thdaraujo for all the help and patience.
P.S.: I might need some help with writing tests. I kind of know how to write the tests, just not sure in what file to add it.
Fixes Issue #2563