{"action":"opened","issue":{"url":"https://api.github.com/repos/joost/phony_rails/issues/76","labels_url":"https://api.github.com/repos/joost/phony_rails/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/joost/phony_rails/issues/76/comments","events_url":"https://api.github.com/repos/joost/phony_rails/issues/76/events","html_url":"https://github.com/joost/phony_rails/issues/76","id":54723514,"number":76,"title":"Already normalized numbers have default country code prepended","user":{"login":"mroach","id":79006,"avatar_url":"https://avatars.githubusercontent.com/u/79006?v=3","gravatar_id":"","url":"https://api.github.com/users/mroach","html_url":"https://github.com/mroach","followers_url":"https://api.github.com/users/mroach/followers","following_url":"https://api.github.com/users/mroach/following{/other_user}","gists_url":"https://api.github.com/users/mroach/gists{/gist_id}","starred_url":"https://api.github.com/users/mroach/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mroach/subscriptions","organizations_url":"https://api.github.com/users/mroach/orgs","repos_url":"https://api.github.com/users/mroach/repos","events_url":"https://api.github.com/users/mroach/events{/privacy}","received_events_url":"https://api.github.com/users/mroach/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-19T03:41:39Z","updated_at":"2015-01-19T03:41:39Z","closed_at":null,"body":"Scenario: A model has 3 phone number fields all with a `default_country_code: 'AU'`. Setting one of them to explicitly be a foreign number using a + in the number correctly normalises the value as expected. However, after modifying the model and saving it again, the number stored in the database will have the default country code prepended to the phone number that was already perfectly valid. Here's code to illustrate the problem:\r\n\r\n```ruby\r\nclass Person < ActiveRecord::Base\r\n  phony_normalize :phone_home,   default_country_code: 'AU'\r\n  phony_normalize :phone_mobile, default_country_code: 'AU'\r\n  phony_normalize :phone_work,   default_country_code: 'AU'\r\nend\r\n````\r\n\r\nNow, I'll create a person with an Australian mobile number and American home number.\r\n\r\nWhen the model is saved, the numbers are correctly normalised. The Australian number is prefixed with 61 and the American number is prefixed with 1. Everything is perfect.\r\n\r\nThen, I set the work phone number to another perfectly valid Australian number. When saving, the number is again correctly normalised with a leading 61. However, you'll notice that the home number, the American one, got 61 tacked onto the front of it! This is the problem.\r\n\r\nIf the assumption is that the numbers stored in the database are already normalised and start with the country code, why is the country code being added again?\r\n\r\n```\r\nirb(main):001:0> p = Person.new(phone_mobile: '0450 764 000', phone_home: '+1 978 555 0000')\r\n=> #<Person id: nil, phone_home: \"+1 978 555 0000\", phone_mobile: \"0450 764 000\", phone_work: nil, created_at: nil, updated_at: nil>\r\nirb(main):002:0> p.save!\r\n   (0.2ms)  begin transaction\r\n  SQL (0.5ms)  INSERT INTO \"people\" (\"phone_mobile\", \"phone_home\", \"created_at\", \"updated_at\") VALUES (?, ?, ?, ?)  [[\"phone_mobile\", \"61450764000\"], [\"phone_home\", \"19785550000\"], [\"created_at\", \"2015-01-19 03:34:06.119993\"], [\"updated_at\", \"2015-01-19 03:34:06.119993\"]]\r\n   (2.0ms)  commit transaction\r\n=> true\r\nirb(main):003:0> p.phone_work = '0200 777 000'\r\n=> \"0200 777 000\"\r\nirb(main):004:0> p\r\n=> #<Person id: 1, phone_home: \"19785550000\", phone_mobile: \"61450764000\", phone_work: \"0200 777 000\", created_at: \"2015-01-19 03:34:06\", updated_at: \"2015-01-19 03:34:06\">\r\nirb(main):005:0> p.save\r\n   (0.1ms)  begin transaction\r\n  SQL (0.5ms)  UPDATE \"people\" SET \"phone_work\" = ?, \"phone_home\" = ?, \"updated_at\" = ? WHERE \"people\".\"id\" = ?  [[\"phone_work\", \"61200777000\"], [\"phone_home\", \"6119785550000\"], [\"updated_at\", \"2015-01-19 03:34:28.677510\"], [\"id\", 1]]\r\n   (1.1ms)  commit transaction\r\n=> true\r\n```"}}