Faker: Faker::Bank.iban yields NoMethodError when locale is not english

Created on 7 Feb 2017  路  12Comments  路  Source: faker-ruby/faker

Hi,

we're using Faker in a German app and so we have set our locale to German. Everything is working fine, except when I try to use Faker::Bank.iban. Since bank.iban_details is only implemented in en.yml this throws a NoMethodError in line 16 of bank.rb since there are no details available.

Since all those bank details are not really locale specific, would it make sense to cut those lines out and put them into a generic file that is always loaded? If so, let me know, I will create a PR.

BuFixes

Most helpful comment

Fixed via #1292 :)

All 12 comments

Shouldn't it work if you have en available as a fallback?

$ rails c test
Running via Spring preloader in process 2899
Loading test environment (Rails 5.0.1)

>> I18n.available_locales
=> [:de, :en]
>> I18n.locale
=> :de
>> Faker::Bank.iban
NoMethodError: undefined method `[]' for nil:NilClass

does not work for me. Even when I explicitly set Faker::Config.locale = :en it gives me the same error (that's really strange)

>> Faker::Config.locale = :en
=> :en
>> Faker::Bank.iban
NoMethodError: undefined method `[]' for nil:NilClass

I just experienced same thing as well, I dont think it has to do with locale. It's coming from details['bank_country_code'] in bank.rb file. I suspect details is nil at that point. I'll have a look at it and see if I can fix it

@andela-oosiname You should use a symbol for the key instead of a string to make it work.

details = iban_details.find { |country| country[:bank_country_code] == bank_country_code.upcase }

vs

details = iban_details.find { |country| country["bank_country_code"] == bank_country_code.upcase }

+1

I'm having this problem too, using the gem last version (1.8.4).

As said, the problems seems to be that calling I18n.translate with a locale key that has children keys returns a Hash with symbol keys. I didn't found any ruby or rails setup in my different projects where that call return a Hash with string keys. Here is the call that I'm talking about, that is called from here, that is called from here.

If I'm not missing something, accessing with strings to that Hash should therefore return nil. Also, this PR should solve the problem.

Please @stympy, check this issue again, since it seems that #916 doesn't solve the problem. :pray:

Sorry, wrong issue.

Fixed via #1292 :)

@vbrazo This one can be closed too!

@deivid-rodriguez thanks 馃憤

I've been trying to take a look in the issues to close the ones that should have been closed but I sometimes get lost. We still have several issues 馃槅 (which is good. Who doesn't like solving problems here?) At least the number of PRs have decreased substantially. We had more 100 in May.

It's also my fault for not adding "Fixes #" to the PR body :)

Thanks for the great work you've been doing!

Actually thanks for the community who loves the gem and keeps pushing new PRs.

Adding fixes would be pretty awesome.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gerryhd picture gerryhd  路  3Comments

elangovan-selvaraj picture elangovan-selvaraj  路  6Comments

kevgathuku picture kevgathuku  路  4Comments

mhutter picture mhutter  路  5Comments

tejasbubane picture tejasbubane  路  5Comments