{"action":"created","comment":{"url":"https://api.github.com/repos/spree/spree/pulls/comments/33062164","id":33062164,"diff_hunk":"@@ -1,69 +1,42 @@\n module Spree\n   module Adjustable\n     class AdjustmentsUpdater\n+\n       def self.update(adjustable)\n         new(adjustable).update\n       end\n \n       def initialize(adjustable)\n         @adjustable = adjustable\n-        adjustable.reload if shipment? && persisted?\n+        adjustable.reload if shipment? && adjustable.persisted?\n       end\n \n       def update\n-        return unless persisted?\n-        update_promo_adjustments\n-        update_tax_adjustments\n-        persist_totals\n-      end\n-\n-      private\n+        return unless @adjustable.persisted?\n \n-      attr_reader :adjustable\n-      delegate :adjustments, :persisted?, to: :adjustable\n+        totals = { adjustment_total: 0 }\n+        adjusters.each do |klass|\n+          klass.adjust(@adjustable, totals)\n+        end\n \n-      def update_promo_adjustments\n-        promo_adjustments = adjustments.competing_promos.reload.map { |a| a.update!(adjustable) }\n-        promos_total = promo_adjustments.compact.sum\n-        choose_best_promo_adjustment unless promos_total == 0\n-        @promo_total = best_promo_adjustment.try(:amount).to_f\n+        persist_totals totals\n       end\n \n-      def update_tax_adjustments\n-        tax = (adjustable.try(:all_adjustments) || adjustable.adjustments).tax\n-        @included_tax_total = tax.is_included.reload.map(&:update!).compact.sum\n-        @additional_tax_total = tax.additional.reload.map(&:update!).compact.sum\n-      end\n+      private\n \n-      def persist_totals\n-        adjustable.update_columns(\n-          promo_total: @promo_total,\n-          included_tax_total: @included_tax_total,\n-          additional_tax_total: @additional_tax_total,\n-          adjustment_total: @promo_total + @additional_tax_total,\n-          updated_at: Time.now\n-        )\n+      def persist_totals totals\n+        attributes = totals\n+        attributes[:updated_at] = Time.now\n+        @adjustable.update_columns(totals)\n       end\n \n       def shipment?\n-        adjustable.is_a?(Shipment)\n+        @adjustable.is_a?(Shipment)\n       end\n \n-      # Picks one (and only one) competing discount to be eligible for\n-      # this order. This adjustment provides the most discount, and if\n-      # two adjustments have the same amount, then it will pick the\n-      # latest one.\n-      def choose_best_promo_adjustment\n-        if best_promo_adjustment\n-          other_promotions = adjustments.competing_promos.where.not(id: best_promo_adjustment.id)\n-          other_promotions.update_all(eligible: false)\n-        end\n-      end\n-\n-      def best_promo_adjustment\n-        @best_promo_adjustment ||= begin\n-          adjustments.competing_promos.eligible.reorder(\"amount ASC, created_at DESC, id DESC\").first\n-        end\n+      def adjusters\n+        [Spree::Adjustable::Adjuster::Promo, Spree::Adjustable::Adjuster::Tax]\n+        #Rails.application.config.spree.adjustable_adjusters","path":"core/app/models/spree/adjustable/adjustments_updater.rb","position":83,"original_position":83,"commit_id":"eb76f10d14065e7b3f880ed5d940113c8e0df69f","original_commit_id":"eb76f10d14065e7b3f880ed5d940113c8e0df69f","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Missing space after #.","created_at":"2015-06-23T16:38:48Z","updated_at":"2015-06-23T16:38:48Z","html_url":"https://github.com/spree/spree/pull/6521#discussion_r33062164","pull_request_url":"https://api.github.com/repos/spree/spree/pulls/6521","_links":{"self":{"href":"https://api.github.com/repos/spree/spree/pulls/comments/33062164"},"html":{"href":"https://github.com/spree/spree/pull/6521#discussion_r33062164"},"pull_request":{"href":"https://api.github.com/repos/spree/spree/pulls/6521"}}},"pull_request":{"url":"https://api.github.com/repos/spree/spree/pulls/6521","id":38357066,"html_url":"https://github.com/spree/spree/pull/6521","diff_url":"https://github.com/spree/spree/pull/6521.diff","patch_url":"https://github.com/spree/spree/pull/6521.patch","issue_url":"https://api.github.com/repos/spree/spree/issues/6521","number":6521,"state":"open","locked":false,"title":"Add Adjusters to assist AdjustmentsUpdater","user":{"login":"adaddeo","id":1143517,"avatar_url":"https://avatars.githubusercontent.com/u/1143517?v=3","gravatar_id":"","url":"https://api.github.com/users/adaddeo","html_url":"https://github.com/adaddeo","followers_url":"https://api.github.com/users/adaddeo/followers","following_url":"https://api.github.com/users/adaddeo/following{/other_user}","gists_url":"https://api.github.com/users/adaddeo/gists{/gist_id}","starred_url":"https://api.github.com/users/adaddeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adaddeo/subscriptions","organizations_url":"https://api.github.com/users/adaddeo/orgs","repos_url":"https://api.github.com/users/adaddeo/repos","events_url":"https://api.github.com/users/adaddeo/events{/privacy}","received_events_url":"https://api.github.com/users/adaddeo/received_events","type":"User","site_admin":false},"body":"This commit removes all \"adjusting\" logic from the AdjustmentsUpdater and moves that logic into Adjuster classes. The AdjustmentsUpdater now has the single responsibility of sending the adjustable to all registered Adjusters for adjusting and performing the final update.\r\n\r\nThis will allow extensions to register their own custom Adjusters without have to patch any core code.\r\n\r\nAll tests are passing but this is just a proof of concept, additional tests should be written if the feedback is positive.","created_at":"2015-06-23T16:38:41Z","updated_at":"2015-06-23T16:38:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"684f34812b209b4fb04dc6deea39685b2810867b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/spree/spree/pulls/6521/commits","review_comments_url":"https://api.github.com/repos/spree/spree/pulls/6521/comments","review_comment_url":"https://api.github.com/repos/spree/spree/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spree/spree/issues/6521/comments","statuses_url":"https://api.github.com/repos/spree/spree/statuses/eb76f10d14065e7b3f880ed5d940113c8e0df69f","head":{"label":"pervino:adjustable_adjusters","ref":"adjustable_adjusters","sha":"eb76f10d14065e7b3f880ed5d940113c8e0df69f","user":{"login":"pervino","id":12450484,"avatar_url":"https://avatars.githubusercontent.com/u/12450484?v=3","gravatar_id":"","url":"https://api.github.com/users/pervino","html_url":"https://github.com/pervino","followers_url":"https://api.github.com/users/pervino/followers","following_url":"https://api.github.com/users/pervino/following{/other_user}","gists_url":"https://api.github.com/users/pervino/gists{/gist_id}","starred_url":"https://api.github.com/users/pervino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pervino/subscriptions","organizations_url":"https://api.github.com/users/pervino/orgs","repos_url":"https://api.github.com/users/pervino/repos","events_url":"https://api.github.com/users/pervino/events{/privacy}","received_events_url":"https://api.github.com/users/pervino/received_events","type":"Organization","site_admin":false},"repo":{"id":37550031,"name":"spree","full_name":"pervino/spree","owner":{"login":"pervino","id":12450484,"avatar_url":"https://avatars.githubusercontent.com/u/12450484?v=3","gravatar_id":"","url":"https://api.github.com/users/pervino","html_url":"https://github.com/pervino","followers_url":"https://api.github.com/users/pervino/followers","following_url":"https://api.github.com/users/pervino/following{/other_user}","gists_url":"https://api.github.com/users/pervino/gists{/gist_id}","starred_url":"https://api.github.com/users/pervino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pervino/subscriptions","organizations_url":"https://api.github.com/users/pervino/orgs","repos_url":"https://api.github.com/users/pervino/repos","events_url":"https://api.github.com/users/pervino/events{/privacy}","received_events_url":"https://api.github.com/users/pervino/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pervino/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":true,"url":"https://api.github.com/repos/pervino/spree","forks_url":"https://api.github.com/repos/pervino/spree/forks","keys_url":"https://api.github.com/repos/pervino/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pervino/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pervino/spree/teams","hooks_url":"https://api.github.com/repos/pervino/spree/hooks","issue_events_url":"https://api.github.com/repos/pervino/spree/issues/events{/number}","events_url":"https://api.github.com/repos/pervino/spree/events","assignees_url":"https://api.github.com/repos/pervino/spree/assignees{/user}","branches_url":"https://api.github.com/repos/pervino/spree/branches{/branch}","tags_url":"https://api.github.com/repos/pervino/spree/tags","blobs_url":"https://api.github.com/repos/pervino/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pervino/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pervino/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/pervino/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pervino/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/pervino/spree/languages","stargazers_url":"https://api.github.com/repos/pervino/spree/stargazers","contributors_url":"https://api.github.com/repos/pervino/spree/contributors","subscribers_url":"https://api.github.com/repos/pervino/spree/subscribers","subscription_url":"https://api.github.com/repos/pervino/spree/subscription","commits_url":"https://api.github.com/repos/pervino/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/pervino/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/pervino/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/pervino/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/pervino/spree/contents/{+path}","compare_url":"https://api.github.com/repos/pervino/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pervino/spree/merges","archive_url":"https://api.github.com/repos/pervino/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pervino/spree/downloads","issues_url":"https://api.github.com/repos/pervino/spree/issues{/number}","pulls_url":"https://api.github.com/repos/pervino/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/pervino/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/pervino/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pervino/spree/labels{/name}","releases_url":"https://api.github.com/repos/pervino/spree/releases{/id}","created_at":"2015-06-16T19:00:42Z","updated_at":"2015-06-16T19:00:49Z","pushed_at":"2015-06-23T16:31:32Z","git_url":"git://github.com/pervino/spree.git","ssh_url":"git@github.com:pervino/spree.git","clone_url":"https://github.com/pervino/spree.git","svn_url":"https://github.com/pervino/spree","homepage":"http://spreecommerce.com","size":74678,"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":"spree:master","ref":"master","sha":"b0faeb96fde984ca7e17ab249eaab88de9ea9617","user":{"login":"spree","id":56702,"avatar_url":"https://avatars.githubusercontent.com/u/56702?v=3","gravatar_id":"","url":"https://api.github.com/users/spree","html_url":"https://github.com/spree","followers_url":"https://api.github.com/users/spree/followers","following_url":"https://api.github.com/users/spree/following{/other_user}","gists_url":"https://api.github.com/users/spree/gists{/gist_id}","starred_url":"https://api.github.com/users/spree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spree/subscriptions","organizations_url":"https://api.github.com/users/spree/orgs","repos_url":"https://api.github.com/users/spree/repos","events_url":"https://api.github.com/users/spree/events{/privacy}","received_events_url":"https://api.github.com/users/spree/received_events","type":"Organization","site_admin":false},"repo":{"id":3314,"name":"spree","full_name":"spree/spree","owner":{"login":"spree","id":56702,"avatar_url":"https://avatars.githubusercontent.com/u/56702?v=3","gravatar_id":"","url":"https://api.github.com/users/spree","html_url":"https://github.com/spree","followers_url":"https://api.github.com/users/spree/followers","following_url":"https://api.github.com/users/spree/following{/other_user}","gists_url":"https://api.github.com/users/spree/gists{/gist_id}","starred_url":"https://api.github.com/users/spree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spree/subscriptions","organizations_url":"https://api.github.com/users/spree/orgs","repos_url":"https://api.github.com/users/spree/repos","events_url":"https://api.github.com/users/spree/events{/privacy}","received_events_url":"https://api.github.com/users/spree/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spree/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":false,"url":"https://api.github.com/repos/spree/spree","forks_url":"https://api.github.com/repos/spree/spree/forks","keys_url":"https://api.github.com/repos/spree/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spree/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spree/spree/teams","hooks_url":"https://api.github.com/repos/spree/spree/hooks","issue_events_url":"https://api.github.com/repos/spree/spree/issues/events{/number}","events_url":"https://api.github.com/repos/spree/spree/events","assignees_url":"https://api.github.com/repos/spree/spree/assignees{/user}","branches_url":"https://api.github.com/repos/spree/spree/branches{/branch}","tags_url":"https://api.github.com/repos/spree/spree/tags","blobs_url":"https://api.github.com/repos/spree/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spree/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spree/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/spree/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spree/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/spree/spree/languages","stargazers_url":"https://api.github.com/repos/spree/spree/stargazers","contributors_url":"https://api.github.com/repos/spree/spree/contributors","subscribers_url":"https://api.github.com/repos/spree/spree/subscribers","subscription_url":"https://api.github.com/repos/spree/spree/subscription","commits_url":"https://api.github.com/repos/spree/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/spree/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/spree/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/spree/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/spree/spree/contents/{+path}","compare_url":"https://api.github.com/repos/spree/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spree/spree/merges","archive_url":"https://api.github.com/repos/spree/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spree/spree/downloads","issues_url":"https://api.github.com/repos/spree/spree/issues{/number}","pulls_url":"https://api.github.com/repos/spree/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/spree/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/spree/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spree/spree/labels{/name}","releases_url":"https://api.github.com/repos/spree/spree/releases{/id}","created_at":"2008-03-10T14:45:35Z","updated_at":"2015-06-23T16:00:15Z","pushed_at":"2015-06-23T16:38:41Z","git_url":"git://github.com/spree/spree.git","ssh_url":"git@github.com:spree/spree.git","clone_url":"https://github.com/spree/spree.git","svn_url":"https://github.com/spree/spree","homepage":"http://spreecommerce.com","size":135882,"stargazers_count":6440,"watchers_count":6440,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3033,"mirror_url":null,"open_issues_count":136,"forks":3033,"open_issues":136,"watchers":6440,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spree/spree/pulls/6521"},"html":{"href":"https://github.com/spree/spree/pull/6521"},"issue":{"href":"https://api.github.com/repos/spree/spree/issues/6521"},"comments":{"href":"https://api.github.com/repos/spree/spree/issues/6521/comments"},"review_comments":{"href":"https://api.github.com/repos/spree/spree/pulls/6521/comments"},"review_comment":{"href":"https://api.github.com/repos/spree/spree/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spree/spree/pulls/6521/commits"},"statuses":{"href":"https://api.github.com/repos/spree/spree/statuses/eb76f10d14065e7b3f880ed5d940113c8e0df69f"}}}}