Skip to content

Commit

Permalink
Do not normalize an implausible phone.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jell committed Feb 1, 2013
1 parent 19c68e7 commit 1f30058
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/phony_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def self.normalize_number(number, options = {})
# Add country_number if missing
number = "#{country_number}#{number}" if not number =~ /^(00|\+)?#{country_number}/
end
number = Phony.normalize(number)
number = Phony.normalize(number) if Phony.plausible?(number)
return number.to_s
rescue
number # If all goes wrong .. we still return the original input.
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/phony_rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
PhonyRails.normalize_number('+31-70-4157134', :country_code => 'NL').should eql('31704157134')
PhonyRails.normalize_number('0323-2269497', :country_code => 'BE').should eql('323232269497')
end

it "should not normalize an implausible number" do
PhonyRails.normalize_number('01').should eql('01')
end
end

describe 'defining ActiveRecord#phony_normalized_method' do
Expand Down

0 comments on commit 1f30058

Please sign in to comment.