joost / phony_rails

This Gem adds useful methods to your Rails app to validate, display and save phone numbers. It uses the super awesome Phony gem (https://github.com/floere/phony).
MIT License
556 stars 111 forks source link

PhonyRails.default_country_code too intrusive in plausible_number? method #179

Closed sergioisidoro closed 6 years ago

sergioisidoro commented 6 years ago

With Finnish a valid phone number, while having a International code - Works as expected

(byebug) PhonyRails.default_country_code = :fi
:fi
(byebug) PhonyRails.plausible_number?("+358414955444")
true
(byebug) Phony.plausible?("+358414955444")
true

With default country code DE, the valid Finnish number with international code is deemed implausible by PhonyRails but not Phony.

(byebug) PhonyRails.default_country_code = :de
:de
(byebug) PhonyRails.plausible_number?("+358414955444")
false
(byebug) Phony.plausible?("+358414955444")
true

The name PhonyRails.default_country_code suggests that it is a fallback, not an enforcement (eg. like it would be if called PhonyRails.country_code)

Given a valid phone number, even if with a locale different from the default country_code, I would assume it is expected that plausible_number? would return true.

Edit: I just read about enforce_record_country: false, but I would ask you to consider the redesign of the interface of PhonyRails to make it more explicit on what validation it makes. plausible_number? is too broad and gives an erroneous idea of the validation logic it performs.