{"action":"created","comment":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/comments/36562222","id":36562222,"diff_hunk":"@@ -18,19 +18,48 @@ class Address < Spree::Base\n     alias_attribute :first_name, :firstname\n     alias_attribute :last_name, :lastname\n \n+    DB_ONLY_ATTRS = %w(id updated_at created_at)\n+\n+    scope :with_values, ->(attributes) do\n+      where(value_attributes(attributes))\n+    end\n+\n     def self.build_default\n-      country = Spree::Country.find(Spree::Config[:default_country_id]) rescue Spree::Country.first\n-      new(country: country)\n+      new(country: Spree::Country.default)\n     end\n \n     def self.default(user = nil, kind = \"bill\")\n-      if user && user_address = user.send(:\"#{kind}_address\")\n-        user_address.dup\n+      ActiveSupport::Deprecation.warn(\"Address.default is deprecated. Use User.default_address or Address.build_default\", caller)\n+      if user\n+        user.send(:\"#{kind}_address\") || build_default\n       else\n         build_default\n       end\n     end\n \n+    # @return [Address] address from existing address plus new_attributes as diff\n+    # @note, this may return existing_address if there are no changes to value equality\n+    def self.immutable_merge(existing_address, new_attributes)\n+      return self.new(value_attributes(new_attributes)) unless existing_address\n+\n+      new_attributes ||= {}\n+      merged_attributes = existing_address.attributes.merge(new_attributes.stringify_keys).except(*DB_ONLY_ATTRS)\n+      new_address = self.new(merged_attributes)\n+      if existing_address == new_address\n+        existing_address\n+      else\n+        new_address\n+      end\n+    end\n+\n+    def self.value_attributes(attributes_hash)\n+      (attributes_hash || {}).stringify_keys.except(*DB_ONLY_ATTRS)","path":"core/app/models/spree/address.rb","position":52,"original_position":52,"commit_id":"b531e70924e6912a5dcc9a9cf24f2ed3db4686e8","original_commit_id":"b531e70924e6912a5dcc9a9cf24f2ed3db4686e8","user":{"login":"gvaughn","id":10173,"avatar_url":"https://avatars.githubusercontent.com/u/10173?v=3","gravatar_id":"","url":"https://api.github.com/users/gvaughn","html_url":"https://github.com/gvaughn","followers_url":"https://api.github.com/users/gvaughn/followers","following_url":"https://api.github.com/users/gvaughn/following{/other_user}","gists_url":"https://api.github.com/users/gvaughn/gists{/gist_id}","starred_url":"https://api.github.com/users/gvaughn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gvaughn/subscriptions","organizations_url":"https://api.github.com/users/gvaughn/orgs","repos_url":"https://api.github.com/users/gvaughn/repos","events_url":"https://api.github.com/users/gvaughn/events{/privacy}","received_events_url":"https://api.github.com/users/gvaughn/received_events","type":"User","site_admin":false},"body":"`dup` works great when we have an Address instance, but not so much when we have a Hash of attributes.","created_at":"2015-08-07T21:19:43Z","updated_at":"2015-08-07T21:19:43Z","html_url":"https://github.com/solidusio/solidus/pull/257#discussion_r36562222","pull_request_url":"https://api.github.com/repos/solidusio/solidus/pulls/257","_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments/36562222"},"html":{"href":"https://github.com/solidusio/solidus/pull/257#discussion_r36562222"},"pull_request":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/257"}}},"pull_request":{"url":"https://api.github.com/repos/solidusio/solidus/pulls/257","id":41736448,"html_url":"https://github.com/solidusio/solidus/pull/257","diff_url":"https://github.com/solidusio/solidus/pull/257.diff","patch_url":"https://github.com/solidusio/solidus/pull/257.patch","issue_url":"https://api.github.com/repos/solidusio/solidus/issues/257","number":257,"state":"open","locked":false,"title":"Implementing a user's address book functionality","user":{"login":"gvaughn","id":10173,"avatar_url":"https://avatars.githubusercontent.com/u/10173?v=3","gravatar_id":"","url":"https://api.github.com/users/gvaughn","html_url":"https://github.com/gvaughn","followers_url":"https://api.github.com/users/gvaughn/followers","following_url":"https://api.github.com/users/gvaughn/following{/other_user}","gists_url":"https://api.github.com/users/gvaughn/gists{/gist_id}","starred_url":"https://api.github.com/users/gvaughn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gvaughn/subscriptions","organizations_url":"https://api.github.com/users/gvaughn/orgs","repos_url":"https://api.github.com/users/gvaughn/repos","events_url":"https://api.github.com/users/gvaughn/events{/privacy}","received_events_url":"https://api.github.com/users/gvaughn/received_events","type":"User","site_admin":false},"body":"Consists of:\r\n* a UserAddressBook module for inclusion into User model\r\n* a UserAddress join model to include default flag\r\n* making Address readonly with copy-on-write behavior\r\n* removing defensive cloning of Address\r\n* improving Address clone/default/copy behavior\r\n* backwards compatibility with existing Order address behavior, but adding a User reference to the address\r\n* backwards compatability for frontend, backend behavior relying on accepts_nested_attributes_for\r\n* a rake task/migration to backfill data into new model\r\n* bill_address sticks around with minor use in code, plus it gets added to address book\r\n* SearchController updates to handle addresses association\r\n\r\nThis is setup work to allow us to surface new behavior in My Account and\r\nCheckout, but as is, you should not see anything new. That also means it\r\nshould not break anything.","created_at":"2015-08-05T23:06:02Z","updated_at":"2015-08-07T21:19:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"df518f6939455d00676f11f650809ce856f57523","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/solidusio/solidus/pulls/257/commits","review_comments_url":"https://api.github.com/repos/solidusio/solidus/pulls/257/comments","review_comment_url":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/solidusio/solidus/issues/257/comments","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/b531e70924e6912a5dcc9a9cf24f2ed3db4686e8","head":{"label":"bonobos:user-address-book","ref":"user-address-book","sha":"b531e70924e6912a5dcc9a9cf24f2ed3db4686e8","user":{"login":"bonobos","id":78914,"avatar_url":"https://avatars.githubusercontent.com/u/78914?v=3","gravatar_id":"","url":"https://api.github.com/users/bonobos","html_url":"https://github.com/bonobos","followers_url":"https://api.github.com/users/bonobos/followers","following_url":"https://api.github.com/users/bonobos/following{/other_user}","gists_url":"https://api.github.com/users/bonobos/gists{/gist_id}","starred_url":"https://api.github.com/users/bonobos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bonobos/subscriptions","organizations_url":"https://api.github.com/users/bonobos/orgs","repos_url":"https://api.github.com/users/bonobos/repos","events_url":"https://api.github.com/users/bonobos/events{/privacy}","received_events_url":"https://api.github.com/users/bonobos/received_events","type":"Organization","site_admin":false},"repo":{"id":37876553,"name":"solidus","full_name":"bonobos/solidus","owner":{"login":"bonobos","id":78914,"avatar_url":"https://avatars.githubusercontent.com/u/78914?v=3","gravatar_id":"","url":"https://api.github.com/users/bonobos","html_url":"https://github.com/bonobos","followers_url":"https://api.github.com/users/bonobos/followers","following_url":"https://api.github.com/users/bonobos/following{/other_user}","gists_url":"https://api.github.com/users/bonobos/gists{/gist_id}","starred_url":"https://api.github.com/users/bonobos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bonobos/subscriptions","organizations_url":"https://api.github.com/users/bonobos/orgs","repos_url":"https://api.github.com/users/bonobos/repos","events_url":"https://api.github.com/users/bonobos/events{/privacy}","received_events_url":"https://api.github.com/users/bonobos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bonobos/solidus","description":"Solidus e-commerce system","fork":true,"url":"https://api.github.com/repos/bonobos/solidus","forks_url":"https://api.github.com/repos/bonobos/solidus/forks","keys_url":"https://api.github.com/repos/bonobos/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bonobos/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bonobos/solidus/teams","hooks_url":"https://api.github.com/repos/bonobos/solidus/hooks","issue_events_url":"https://api.github.com/repos/bonobos/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/bonobos/solidus/events","assignees_url":"https://api.github.com/repos/bonobos/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/bonobos/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/bonobos/solidus/tags","blobs_url":"https://api.github.com/repos/bonobos/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bonobos/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bonobos/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/bonobos/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bonobos/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/bonobos/solidus/languages","stargazers_url":"https://api.github.com/repos/bonobos/solidus/stargazers","contributors_url":"https://api.github.com/repos/bonobos/solidus/contributors","subscribers_url":"https://api.github.com/repos/bonobos/solidus/subscribers","subscription_url":"https://api.github.com/repos/bonobos/solidus/subscription","commits_url":"https://api.github.com/repos/bonobos/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/bonobos/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/bonobos/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/bonobos/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/bonobos/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/bonobos/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bonobos/solidus/merges","archive_url":"https://api.github.com/repos/bonobos/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bonobos/solidus/downloads","issues_url":"https://api.github.com/repos/bonobos/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/bonobos/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/bonobos/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/bonobos/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bonobos/solidus/labels{/name}","releases_url":"https://api.github.com/repos/bonobos/solidus/releases{/id}","created_at":"2015-06-22T19:37:20Z","updated_at":"2015-06-22T19:37:24Z","pushed_at":"2015-08-07T19:51:28Z","git_url":"git://github.com/bonobos/solidus.git","ssh_url":"git@github.com:bonobos/solidus.git","clone_url":"https://github.com/bonobos/solidus.git","svn_url":"https://github.com/bonobos/solidus","homepage":"","size":63317,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"solidusio:master","ref":"master","sha":"7fa0d79d12880f720648d0b29a85ca090d06652f","user":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"repo":{"id":30985840,"name":"solidus","full_name":"solidusio/solidus","owner":{"login":"solidusio","id":11045486,"avatar_url":"https://avatars.githubusercontent.com/u/11045486?v=3","gravatar_id":"","url":"https://api.github.com/users/solidusio","html_url":"https://github.com/solidusio","followers_url":"https://api.github.com/users/solidusio/followers","following_url":"https://api.github.com/users/solidusio/following{/other_user}","gists_url":"https://api.github.com/users/solidusio/gists{/gist_id}","starred_url":"https://api.github.com/users/solidusio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/solidusio/subscriptions","organizations_url":"https://api.github.com/users/solidusio/orgs","repos_url":"https://api.github.com/users/solidusio/repos","events_url":"https://api.github.com/users/solidusio/events{/privacy}","received_events_url":"https://api.github.com/users/solidusio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/solidusio/solidus","description":"Solidus e-commerce system","fork":false,"url":"https://api.github.com/repos/solidusio/solidus","forks_url":"https://api.github.com/repos/solidusio/solidus/forks","keys_url":"https://api.github.com/repos/solidusio/solidus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/solidusio/solidus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/solidusio/solidus/teams","hooks_url":"https://api.github.com/repos/solidusio/solidus/hooks","issue_events_url":"https://api.github.com/repos/solidusio/solidus/issues/events{/number}","events_url":"https://api.github.com/repos/solidusio/solidus/events","assignees_url":"https://api.github.com/repos/solidusio/solidus/assignees{/user}","branches_url":"https://api.github.com/repos/solidusio/solidus/branches{/branch}","tags_url":"https://api.github.com/repos/solidusio/solidus/tags","blobs_url":"https://api.github.com/repos/solidusio/solidus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/solidusio/solidus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/solidusio/solidus/git/refs{/sha}","trees_url":"https://api.github.com/repos/solidusio/solidus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/solidusio/solidus/statuses/{sha}","languages_url":"https://api.github.com/repos/solidusio/solidus/languages","stargazers_url":"https://api.github.com/repos/solidusio/solidus/stargazers","contributors_url":"https://api.github.com/repos/solidusio/solidus/contributors","subscribers_url":"https://api.github.com/repos/solidusio/solidus/subscribers","subscription_url":"https://api.github.com/repos/solidusio/solidus/subscription","commits_url":"https://api.github.com/repos/solidusio/solidus/commits{/sha}","git_commits_url":"https://api.github.com/repos/solidusio/solidus/git/commits{/sha}","comments_url":"https://api.github.com/repos/solidusio/solidus/comments{/number}","issue_comment_url":"https://api.github.com/repos/solidusio/solidus/issues/comments{/number}","contents_url":"https://api.github.com/repos/solidusio/solidus/contents/{+path}","compare_url":"https://api.github.com/repos/solidusio/solidus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/solidusio/solidus/merges","archive_url":"https://api.github.com/repos/solidusio/solidus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/solidusio/solidus/downloads","issues_url":"https://api.github.com/repos/solidusio/solidus/issues{/number}","pulls_url":"https://api.github.com/repos/solidusio/solidus/pulls{/number}","milestones_url":"https://api.github.com/repos/solidusio/solidus/milestones{/number}","notifications_url":"https://api.github.com/repos/solidusio/solidus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/solidusio/solidus/labels{/name}","releases_url":"https://api.github.com/repos/solidusio/solidus/releases{/id}","created_at":"2015-02-18T20:41:58Z","updated_at":"2015-08-07T13:34:57Z","pushed_at":"2015-08-07T19:44:25Z","git_url":"git://github.com/solidusio/solidus.git","ssh_url":"git@github.com:solidusio/solidus.git","clone_url":"https://github.com/solidusio/solidus.git","svn_url":"https://github.com/solidusio/solidus","homepage":"","size":65242,"stargazers_count":22,"watchers_count":22,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":34,"forks":16,"open_issues":34,"watchers":22,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/257"},"html":{"href":"https://github.com/solidusio/solidus/pull/257"},"issue":{"href":"https://api.github.com/repos/solidusio/solidus/issues/257"},"comments":{"href":"https://api.github.com/repos/solidusio/solidus/issues/257/comments"},"review_comments":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/257/comments"},"review_comment":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/solidusio/solidus/pulls/257/commits"},"statuses":{"href":"https://api.github.com/repos/solidusio/solidus/statuses/b531e70924e6912a5dcc9a9cf24f2ed3db4686e8"}}}}