Hey, everyone! Does someone have knowledge how to...
# support
r
Hey, everyone! Does someone have knowledge how to get the currency symbol for specific currency? I dove into
solidus_core
code and had a look on
Spree::Price
and
Spree::Money
classes to see how it does formatting to html but stuck in
Spree::Money#format
method, since it looks like it's calling itself on object of the same class, so I'm not sure where it goes further. I'm trying to fix the specs for
solidus_starter_frontend
, since they have hardcoded strings with
$
in it, and when I change the default currency in
initializers/spree.rb
they start to fail. So I had the idea to make some helper method for specs, which will return the symbol for current default currency, and use it in the specs instead of hardcoded value. Or maybe rewriting the config to use USD as default currency in some spec initializer would be a better idea, so specs would be isolated from config changes? I would like to make a PR for that fix, but need someones help to point me in right direction. Thanks!
k
Hey @Roman Kapustynskyi! We should definitely solve this by allowing people to have the provided test suite passing even if they switch to another currency.
Did you consider removing the
$
sign all together in specs and write them using the
Spree::Money
format? Something like:
Copy code
expect(page).to have_content(Money.new(10.0).format)
r
Spree::Money.new(10.0).format
would definitely help in specs, because it takes into account currency from config file. But can we encourage everyone to use it in the specs? Also, there is a filter component for example, in which the id of filter checkboxes are different based on how currency show up on frontend (and from translations too). In the first screenshot you can see how specs starts to fail when I change the currency to UAH, because the id is formed from the look of price. For USD the price shows as
$10.00
which results in -
Price_Range_Under__10.00
where
_
is substituted instead of symbol. For UAH the price shows as
10.00 ₴
which results in -
Price_Range_Under_10.00__
Also I added translations to my site and changed default locale and a lot of specs started to fail too. The same filter component now have a lot of underscores instead in id's. And I see that labels are coming from
Spree::Core::ProductFilters.price_filter
already translated, and the component itself has no options to create id's from except from labels. And in general regarding to locale, should I change all wording inside specs to reflect my default locale in this situation? Or should I maintain english and default locale and check for I18n wordings with translation keys inside specs, not for the hardcoded translated string itself? So IMO it would be better not to make changes in specs for them to take into account the changes from config, but to override the config to some default value when we run specs. And if we need to create some spec that has a dependency on some config value, we should change or mock it for that spec only. But I think this is bigger problem to solve, so I probably need to open an issue on
solidus_starter_frontend
repo to continue discussion. What are your thoughts on this @kennyadsl?
k
Thanks for the detailed reply, it’s appreciated. I think your perspective as a user is super valuable, so if it’s acceptable to set those default configurations to always run specs, I think it’s a good initial solution with low effort.
We can definitely track this in a GH issue, feel free to open it.
👍 1