GitHub PullRequestReviewCommentEvent at 2014-12-08 11:24:53
Repository: spree
Actor: houndci
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/spree/spree/pulls/comments/21447097","id":21447097,"diff_hunk":"@@ -0,0 +1,281 @@\n+require 'spec_helper'\n+\n+describe Spree::PaymentMethod::StoreCredit do\n+  let(:order)           { create(:order) }\n+  let(:payment)         { create(:payment, order: order) }\n+  let(:gateway_options) { payment.gateway_options }\n+\n+  context \"#authorize\" do\n+    subject do\n+      Spree::PaymentMethod::StoreCredit.new.authorize(auth_amount, store_credit, gateway_options)\n+    end\n+\n+    let(:auth_amount) { store_credit.amount_remaining * 100 }\n+    let(:store_credit) { create(:store_credit) }\n+    let(:gateway_options) { super().merge(originator: originator) }\n+    let(:originator) { nil }\n+\n+    context 'without an invalid store credit' do\n+      let(:store_credit) { nil }\n+      let(:auth_amount) { 10 }\n+\n+      it \"declines an unknown store credit\" do\n+        expect(subject.success?).to be false\n+        subject.message.should include Spree.t('store_credit_payment_method.unable_to_find')\n+      end\n+    end\n+\n+    context 'with insuffient funds' do\n+      let(:auth_amount) { (store_credit.amount_remaining * 100) + 1 }\n+\n+      it \"declines a store credit\" do\n+        expect(subject.success?).to be false\n+        subject.message.should include Spree.t('store_credit_payment_method.insufficient_funds')\n+      end\n+    end\n+\n+    context 'when the currency does not match the order currency' do\n+      let(:store_credit) { create(:store_credit, currency: 'AUD') }\n+\n+      it \"declines the credit\" do\n+        expect(subject.success?).to be false\n+        subject.message.should include Spree.t('store_credit_payment_method.currency_mismatch')\n+      end\n+    end\n+\n+    context 'with a valid request' do\n+      it \"authorizes a valid store credit\" do\n+        expect(subject.success?).to be true\n+        subject.authorization.should_not be_nil\n+      end\n+\n+      context 'with an originator' do\n+        let(:originator) { double('originator') }\n+\n+        it 'passes the originator' do\n+          Spree::StoreCredit.any_instance.should_receive(:authorize)\n+            .with(anything, anything, action_originator: originator)\n+          subject\n+        end\n+      end\n+    end\n+  end\n+\n+  context \"#capture\" do\n+    subject do\n+      Spree::PaymentMethod::StoreCredit.new.capture(capture_amount, auth_code, gateway_options)\n+    end\n+\n+    let(:capture_amount) { 10_00 }\n+    let(:auth_code) { auth_event.authorization_code }\n+    let(:gateway_options) { super().merge(originator: originator) }\n+\n+    let(:authorized_amount) { capture_amount/100.0 }\n+    let(:auth_event) { create(:store_credit_auth_event, store_credit: store_credit, amount: authorized_amount) }\n+    let(:store_credit) { create(:store_credit, amount_authorized: authorized_amount) }\n+    let(:originator) { nil }\n+\n+    context 'with an invalid auth code' do\n+      let(:auth_code) { -1 }\n+\n+      it \"declines an unknown store credit\" do\n+        expect(subject.success?).to be false\n+        subject.message.should include Spree.t('store_credit_payment_method.unable_to_find')\n+      end\n+    end\n+\n+    context 'when unable to authorize the amount' do\n+      let(:authorized_amount) { (capture_amount-1)/100 }\n+\n+      before do\n+        Spree::StoreCredit.any_instance.stub(authorize: true)\n+      end\n+\n+      it \"declines a store credit\" do\n+        expect(subject.success?).to be false\n+        subject.message.should include Spree.t('store_credit_payment_method.insufficient_authorized_amount')\n+      end\n+    end\n+\n+    context 'when the currency does not match the order currency' do\n+      let(:store_credit) { create(:store_credit, currency: 'AUD', amount_authorized: authorized_amount) }\n+\n+      it \"declines the credit\" do\n+        expect(subject.success?).to be false\n+        subject.message.should include Spree.t('store_credit_payment_method.currency_mismatch')\n+      end\n+    end\n+\n+    context 'with a valid request' do\n+      it \"captures the store credit\" do\n+        subject.message.should include Spree.t('store_credit_payment_method.successful_action', action: Spree::StoreCredit::CAPTURE_ACTION)\n+        expect(subject.success?).to be true\n+      end\n+\n+      context 'with an originator' do\n+        let(:originator) { double('originator') }\n+\n+        it 'passes the originator' do\n+          Spree::StoreCredit.any_instance.should_receive(:capture)\n+            .with(anything, anything, anything, action_originator: originator)\n+          subject\n+        end\n+      end\n+    end\n+  end\n+\n+  context \"#void\" do\n+    subject do\n+      Spree::PaymentMethod::StoreCredit.new.void(auth_code, gateway_options)\n+    end\n+\n+    let(:auth_code) { auth_event.authorization_code }\n+    let(:gateway_options) { super().merge(originator: originator) }\n+    let(:auth_event) { create(:store_credit_auth_event) }\n+    let(:originator) { nil }\n+\n+    context 'with an invalid auth code' do\n+      let(:auth_code) { 1 }\n+\n+      it \"declines an unknown store credit\" do\n+        expect(subject.success?).to be false\n+        subject.message.should include Spree.t('store_credit_payment_method.unable_to_find')\n+      end\n+    end\n+\n+    context 'when the store credit is not voided successfully' do\n+      before { Spree::StoreCredit.any_instance.stub(void: false) }\n+\n+      it \"returns an error response\" do\n+        expect(subject.success?).to be false\n+      end\n+    end\n+\n+    it \"voids a valid store credit void request\" do\n+      expect(subject.success?).to be true\n+      subject.message.should include Spree.t('store_credit_payment_method.successful_action', action: Spree::StoreCredit::VOID_ACTION)\n+    end\n+\n+    context 'with an originator' do\n+      let(:originator) { double('originator') }\n+\n+      it 'passes the originator' do","path":"core/spec/models/spree/payment_method/store_credit_spec.rb","position":162,"original_position":162,"commit_id":"12cb7833e88fd7af1b0dce7a9287583782b3e234","original_commit_id":"12cb7833e88fd7af1b0dce7a9287583782b3e234","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":"Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.","created_at":"2014-12-08T11:24:53Z","updated_at":"2014-12-08T11:24:53Z","html_url":"https://github.com/spree/spree/pull/5625#discussion_r21447097","pull_request_url":"https://api.github.com/repos/spree/spree/pulls/5625","_links":{"self":{"href":"https://api.github.com/repos/spree/spree/pulls/comments/21447097"},"html":{"href":"https://github.com/spree/spree/pull/5625#discussion_r21447097"},"pull_request":{"href":"https://api.github.com/repos/spree/spree/pulls/5625"}}},"pull_request":{"url":"https://api.github.com/repos/spree/spree/pulls/5625","id":24589215,"html_url":"https://github.com/spree/spree/pull/5625","diff_url":"https://github.com/spree/spree/pull/5625.diff","patch_url":"https://github.com/spree/spree/pull/5625.patch","issue_url":"https://api.github.com/repos/spree/spree/issues/5625","number":5625,"state":"open","locked":false,"title":"Move store credits in core","user":{"login":"IrvinFan","id":5523239,"avatar_url":"https://avatars.githubusercontent.com/u/5523239?v=3","gravatar_id":"","url":"https://api.github.com/users/IrvinFan","html_url":"https://github.com/IrvinFan","followers_url":"https://api.github.com/users/IrvinFan/followers","following_url":"https://api.github.com/users/IrvinFan/following{/other_user}","gists_url":"https://api.github.com/users/IrvinFan/gists{/gist_id}","starred_url":"https://api.github.com/users/IrvinFan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IrvinFan/subscriptions","organizations_url":"https://api.github.com/users/IrvinFan/orgs","repos_url":"https://api.github.com/users/IrvinFan/repos","events_url":"https://api.github.com/users/IrvinFan/events{/privacy}","received_events_url":"https://api.github.com/users/IrvinFan/received_events","type":"User","site_admin":false},"body":"This is the starting point of merging store credits feature (but leave gift cards feature) from extension https://github.com/paulo-surfdome/spree_store_credit_payment_method/tree/move_credit_out into Spree.\r\n\r\nHere is the approach we took: go through codes in the directories in https://github.com/paulo-surfdome/spree_store_credit_payment_method/tree/move_credit_out and copy (new file) or merge (decorator) store credits related codes into Spree. And at the same time remove those codes from the extension (Related PR: https://github.com/spree-contrib/spree_store_credit_payment_method/pull/24).\r\n\r\nRight now the key components are done. Anyone can take from here.\r\n\r\n- [x] merge app directory\r\n- [x] merge bin directory\r\n- [x] merge db directory\r\n- [x] merge config directory\r\n- [x] merge lib directory\r\n- [ ] merge spec directory\r\n- [ ] implement store frontend UI \r\n","created_at":"2014-11-18T05:12:13Z","updated_at":"2014-12-08T11:24:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"90293200a73489eee4156eeef6ec91bc9288c923","assignee":null,"milestone":{"url":"https://api.github.com/repos/spree/spree/milestones/27","labels_url":"https://api.github.com/repos/spree/spree/milestones/27/labels","id":709927,"number":27,"title":"v3.0.0","description":"","creator":{"login":"JDutil","id":25104,"avatar_url":"https://avatars.githubusercontent.com/u/25104?v=3","gravatar_id":"","url":"https://api.github.com/users/JDutil","html_url":"https://github.com/JDutil","followers_url":"https://api.github.com/users/JDutil/followers","following_url":"https://api.github.com/users/JDutil/following{/other_user}","gists_url":"https://api.github.com/users/JDutil/gists{/gist_id}","starred_url":"https://api.github.com/users/JDutil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JDutil/subscriptions","organizations_url":"https://api.github.com/users/JDutil/orgs","repos_url":"https://api.github.com/users/JDutil/repos","events_url":"https://api.github.com/users/JDutil/events{/privacy}","received_events_url":"https://api.github.com/users/JDutil/received_events","type":"User","site_admin":false},"open_issues":31,"closed_issues":5,"state":"open","created_at":"2014-07-03T22:04:28Z","updated_at":"2014-12-05T22:21:48Z","due_on":"2025-07-31T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/spree/spree/pulls/5625/commits","review_comments_url":"https://api.github.com/repos/spree/spree/pulls/5625/comments","review_comment_url":"https://api.github.com/repos/spree/spree/pulls/comments/{number}","comments_url":"https://api.github.com/repos/spree/spree/issues/5625/comments","statuses_url":"https://api.github.com/repos/spree/spree/statuses/12cb7833e88fd7af1b0dce7a9287583782b3e234","head":{"label":"IrvinFan:move_store_credits_in_core","ref":"move_store_credits_in_core","sha":"12cb7833e88fd7af1b0dce7a9287583782b3e234","user":{"login":"IrvinFan","id":5523239,"avatar_url":"https://avatars.githubusercontent.com/u/5523239?v=3","gravatar_id":"","url":"https://api.github.com/users/IrvinFan","html_url":"https://github.com/IrvinFan","followers_url":"https://api.github.com/users/IrvinFan/followers","following_url":"https://api.github.com/users/IrvinFan/following{/other_user}","gists_url":"https://api.github.com/users/IrvinFan/gists{/gist_id}","starred_url":"https://api.github.com/users/IrvinFan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IrvinFan/subscriptions","organizations_url":"https://api.github.com/users/IrvinFan/orgs","repos_url":"https://api.github.com/users/IrvinFan/repos","events_url":"https://api.github.com/users/IrvinFan/events{/privacy}","received_events_url":"https://api.github.com/users/IrvinFan/received_events","type":"User","site_admin":false},"repo":{"id":22971723,"name":"spree","full_name":"IrvinFan/spree","owner":{"login":"IrvinFan","id":5523239,"avatar_url":"https://avatars.githubusercontent.com/u/5523239?v=3","gravatar_id":"","url":"https://api.github.com/users/IrvinFan","html_url":"https://github.com/IrvinFan","followers_url":"https://api.github.com/users/IrvinFan/followers","following_url":"https://api.github.com/users/IrvinFan/following{/other_user}","gists_url":"https://api.github.com/users/IrvinFan/gists{/gist_id}","starred_url":"https://api.github.com/users/IrvinFan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IrvinFan/subscriptions","organizations_url":"https://api.github.com/users/IrvinFan/orgs","repos_url":"https://api.github.com/users/IrvinFan/repos","events_url":"https://api.github.com/users/IrvinFan/events{/privacy}","received_events_url":"https://api.github.com/users/IrvinFan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/IrvinFan/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":true,"url":"https://api.github.com/repos/IrvinFan/spree","forks_url":"https://api.github.com/repos/IrvinFan/spree/forks","keys_url":"https://api.github.com/repos/IrvinFan/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IrvinFan/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IrvinFan/spree/teams","hooks_url":"https://api.github.com/repos/IrvinFan/spree/hooks","issue_events_url":"https://api.github.com/repos/IrvinFan/spree/issues/events{/number}","events_url":"https://api.github.com/repos/IrvinFan/spree/events","assignees_url":"https://api.github.com/repos/IrvinFan/spree/assignees{/user}","branches_url":"https://api.github.com/repos/IrvinFan/spree/branches{/branch}","tags_url":"https://api.github.com/repos/IrvinFan/spree/tags","blobs_url":"https://api.github.com/repos/IrvinFan/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IrvinFan/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IrvinFan/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/IrvinFan/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IrvinFan/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/IrvinFan/spree/languages","stargazers_url":"https://api.github.com/repos/IrvinFan/spree/stargazers","contributors_url":"https://api.github.com/repos/IrvinFan/spree/contributors","subscribers_url":"https://api.github.com/repos/IrvinFan/spree/subscribers","subscription_url":"https://api.github.com/repos/IrvinFan/spree/subscription","commits_url":"https://api.github.com/repos/IrvinFan/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/IrvinFan/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/IrvinFan/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/IrvinFan/spree/issues/comments/{number}","contents_url":"https://api.github.com/repos/IrvinFan/spree/contents/{+path}","compare_url":"https://api.github.com/repos/IrvinFan/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IrvinFan/spree/merges","archive_url":"https://api.github.com/repos/IrvinFan/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IrvinFan/spree/downloads","issues_url":"https://api.github.com/repos/IrvinFan/spree/issues{/number}","pulls_url":"https://api.github.com/repos/IrvinFan/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/IrvinFan/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/IrvinFan/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IrvinFan/spree/labels{/name}","releases_url":"https://api.github.com/repos/IrvinFan/spree/releases{/id}","created_at":"2014-08-14T23:19:53Z","updated_at":"2014-11-17T22:24:14Z","pushed_at":"2014-12-08T11:24:29Z","git_url":"git://github.com/IrvinFan/spree.git","ssh_url":"git@github.com:IrvinFan/spree.git","clone_url":"https://github.com/IrvinFan/spree.git","svn_url":"https://github.com/IrvinFan/spree","homepage":"http://spreecommerce.com","size":68277,"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":"1893133ee40742e6ace714f05fb5e6c11914f2b9","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":"2014-12-08T06:25:17Z","pushed_at":"2014-12-05T22:24:43Z","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":125944,"stargazers_count":5732,"watchers_count":5732,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2667,"mirror_url":null,"open_issues_count":121,"forks":2667,"open_issues":121,"watchers":5732,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spree/spree/pulls/5625"},"html":{"href":"https://github.com/spree/spree/pull/5625"},"issue":{"href":"https://api.github.com/repos/spree/spree/issues/5625"},"comments":{"href":"https://api.github.com/repos/spree/spree/issues/5625/comments"},"review_comments":{"href":"https://api.github.com/repos/spree/spree/pulls/5625/comments"},"review_comment":{"href":"https://api.github.com/repos/spree/spree/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/spree/spree/pulls/5625/commits"},"statuses":{"href":"https://api.github.com/repos/spree/spree/statuses/12cb7833e88fd7af1b0dce7a9287583782b3e234"}}}}