{"action":"created","comment":{"url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/comments/28202526","id":28202526,"diff_hunk":"@@ -0,0 +1,31 @@\n+require 'spec_helper'\n+\n+module Spree\n+  describe Spree::Api::LineItemsController do\n+    render_views\n+\n+    before do\n+      stub_authentication!\n+      Spree.user_class.stub :find_by_spree_api_key => current_api_user\n+    end\n+\n+    def self.make_simple_data!\n+      let!(:order) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now) }\n+      let!(:line_item) { FactoryGirl.create(:line_item, order: order, unit_value: 500) }\n+    end\n+\n+    #test that when a line item is updated, an order's fees are updated too\n+    context \"as an admin user\" do\n+      sign_in_as_admin!\n+      make_simple_data!\n+\n+      context \"as a line item is updated\" do\n+        it \"apply enterprise fees on the item\" do\n+          line_item_params = { order_id: order.number, id: line_item.id, line_item: { id: line_item.id, unit_value: 520 }, format: :json}\n+          controller.should_receive(:apply_enterprise_fees).and_return(true)","path":"spec/controllers/spree/api/line_items_controller_spec.rb","position":25,"original_position":25,"commit_id":"ff935af18bd4a2a459e945dafa1e35642ac5d198","original_commit_id":"ff935af18bd4a2a459e945dafa1e35642ac5d198","user":{"login":"oeoeaio","id":2067859,"avatar_url":"https://avatars.githubusercontent.com/u/2067859?v=3","gravatar_id":"","url":"https://api.github.com/users/oeoeaio","html_url":"https://github.com/oeoeaio","followers_url":"https://api.github.com/users/oeoeaio/followers","following_url":"https://api.github.com/users/oeoeaio/following{/other_user}","gists_url":"https://api.github.com/users/oeoeaio/gists{/gist_id}","starred_url":"https://api.github.com/users/oeoeaio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oeoeaio/subscriptions","organizations_url":"https://api.github.com/users/oeoeaio/orgs","repos_url":"https://api.github.com/users/oeoeaio/repos","events_url":"https://api.github.com/users/oeoeaio/events{/privacy}","received_events_url":"https://api.github.com/users/oeoeaio/received_events","type":"User","site_admin":false},"body":"Hi @lin-d-hop,\r\n\r\nYep, basically as soon as you stub a method with should_receive, it gets replaced with a spy which listens for calls, and no code within the method is run. You can allow a pass through by adding .and_call_original to the stub. Of course you can't add a return value when you use .and_call_original.\r\n\r\nWhat I was trying to say in the original message is that I don't think we want to stub apply_enterprise_fees at all, because testing that it is just testing that rails is doing what rails should do. ie. calling a method specified in an after filter at the appropriate time. Testing that is not our responsibility. The behaviour we are actually interested in testing is that .update_distribution_charge! is called on the order after the update action.\r\n\r\nSo, I think you should remove the stub (should_receive) on the apply_enterprise_fees method on the controller, and instead stub the .update_distribution_charge! method on the order, and check that that method is called when you call the line_item update action.\r\n\r\nSomething like this:\r\norder.should_receive(:update_distribution_charge!)\r\n\r\nOr, if you wanted to use the newer RSpec syntax:\r\nexpect(order).to receive(:update_distribution_charge!)\r\n","created_at":"2015-04-12T10:57:16Z","updated_at":"2015-04-12T10:57:16Z","html_url":"https://github.com/openfoodfoundation/openfoodnetwork/pull/474#discussion_r28202526","pull_request_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474","_links":{"self":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/comments/28202526"},"html":{"href":"https://github.com/openfoodfoundation/openfoodnetwork/pull/474#discussion_r28202526"},"pull_request":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474"}}},"pull_request":{"url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474","id":32637603,"html_url":"https://github.com/openfoodfoundation/openfoodnetwork/pull/474","diff_url":"https://github.com/openfoodfoundation/openfoodnetwork/pull/474.diff","patch_url":"https://github.com/openfoodfoundation/openfoodnetwork/pull/474.patch","issue_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/474","number":474,"state":"open","locked":false,"title":"Variable weights on Line Items","user":{"login":"lin-d-hop","id":8669848,"avatar_url":"https://avatars.githubusercontent.com/u/8669848?v=3","gravatar_id":"","url":"https://api.github.com/users/lin-d-hop","html_url":"https://github.com/lin-d-hop","followers_url":"https://api.github.com/users/lin-d-hop/followers","following_url":"https://api.github.com/users/lin-d-hop/following{/other_user}","gists_url":"https://api.github.com/users/lin-d-hop/gists{/gist_id}","starred_url":"https://api.github.com/users/lin-d-hop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lin-d-hop/subscriptions","organizations_url":"https://api.github.com/users/lin-d-hop/orgs","repos_url":"https://api.github.com/users/lin-d-hop/repos","events_url":"https://api.github.com/users/lin-d-hop/events{/privacy}","received_events_url":"https://api.github.com/users/lin-d-hop/received_events","type":"User","site_admin":false},"body":"Hi guys!\r\n\r\nAssigning to Rob as I remember Kirsten saying that Rob can check this one over...\r\n\r\nI do have one or two questions on the specs:\r\n\r\n1) spec/controllers/spree/api/line_items_controller_spec.rb\r\nThe spec really only checks that the after filter is called. I found this link http://axonflux.com/rspecs-shouldreceive-doesnt-ac saying that should_receive only mocks and therefore can't itself be used to test order.update_distribution_charge! is received... which is probably more the behaviour I want.\r\nShould I now be writing a test to check that apply_enterprise_fees actually calls order.update_distribution_charge! ? As it is basically a one line method that seems a little OTT.\r\n\r\n2) Do I need to add specs testing that order.update_distribution_charge! performs the same function with when the cart is completed. Looking at the existing functionality and specs the state of the cart makes no difference to functionality so it feels like I would simply be repeating the existing specs, which seems a bit wasteful.\r\n\r\nBasically in thinking about this I was trading off between philosophies of 'specs for the sake of specs' and being super thorough. So some input into these questions would be appreciated.\r\n\r\nThanks for your input. Sorry it's taken me a while to get this up to this stage. I've had soooo much to catch up on after my time away... easy to underestimate these things :-)\r\n\r\nHope all is good in the hood xxx","created_at":"2015-04-04T18:31:45Z","updated_at":"2015-04-12T10:57:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e27fae0866f8b76fa4c95c92ab95ceaec8e95fd0","assignee":{"login":"oeoeaio","id":2067859,"avatar_url":"https://avatars.githubusercontent.com/u/2067859?v=3","gravatar_id":"","url":"https://api.github.com/users/oeoeaio","html_url":"https://github.com/oeoeaio","followers_url":"https://api.github.com/users/oeoeaio/followers","following_url":"https://api.github.com/users/oeoeaio/following{/other_user}","gists_url":"https://api.github.com/users/oeoeaio/gists{/gist_id}","starred_url":"https://api.github.com/users/oeoeaio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oeoeaio/subscriptions","organizations_url":"https://api.github.com/users/oeoeaio/orgs","repos_url":"https://api.github.com/users/oeoeaio/repos","events_url":"https://api.github.com/users/oeoeaio/events{/privacy}","received_events_url":"https://api.github.com/users/oeoeaio/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/milestones/6","html_url":"https://github.com/openfoodfoundation/openfoodnetwork/milestones/UK%20sprint%204","labels_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/milestones/6/labels","id":909776,"number":6,"title":"UK sprint 4","description":"","creator":{"login":"pmackay","id":115115,"avatar_url":"https://avatars.githubusercontent.com/u/115115?v=3","gravatar_id":"","url":"https://api.github.com/users/pmackay","html_url":"https://github.com/pmackay","followers_url":"https://api.github.com/users/pmackay/followers","following_url":"https://api.github.com/users/pmackay/following{/other_user}","gists_url":"https://api.github.com/users/pmackay/gists{/gist_id}","starred_url":"https://api.github.com/users/pmackay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmackay/subscriptions","organizations_url":"https://api.github.com/users/pmackay/orgs","repos_url":"https://api.github.com/users/pmackay/repos","events_url":"https://api.github.com/users/pmackay/events{/privacy}","received_events_url":"https://api.github.com/users/pmackay/received_events","type":"User","site_admin":false},"open_issues":15,"closed_issues":7,"state":"open","created_at":"2014-12-19T08:32:31Z","updated_at":"2015-04-04T18:32:51Z","due_on":"2015-04-08T23:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474/commits","review_comments_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474/comments","review_comment_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/474/comments","statuses_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/statuses/ff935af18bd4a2a459e945dafa1e35642ac5d198","head":{"label":"lin-d-hop:variable_weights","ref":"variable_weights","sha":"ff935af18bd4a2a459e945dafa1e35642ac5d198","user":{"login":"lin-d-hop","id":8669848,"avatar_url":"https://avatars.githubusercontent.com/u/8669848?v=3","gravatar_id":"","url":"https://api.github.com/users/lin-d-hop","html_url":"https://github.com/lin-d-hop","followers_url":"https://api.github.com/users/lin-d-hop/followers","following_url":"https://api.github.com/users/lin-d-hop/following{/other_user}","gists_url":"https://api.github.com/users/lin-d-hop/gists{/gist_id}","starred_url":"https://api.github.com/users/lin-d-hop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lin-d-hop/subscriptions","organizations_url":"https://api.github.com/users/lin-d-hop/orgs","repos_url":"https://api.github.com/users/lin-d-hop/repos","events_url":"https://api.github.com/users/lin-d-hop/events{/privacy}","received_events_url":"https://api.github.com/users/lin-d-hop/received_events","type":"User","site_admin":false},"repo":{"id":31240124,"name":"openfoodnetwork","full_name":"lin-d-hop/openfoodnetwork","owner":{"login":"lin-d-hop","id":8669848,"avatar_url":"https://avatars.githubusercontent.com/u/8669848?v=3","gravatar_id":"","url":"https://api.github.com/users/lin-d-hop","html_url":"https://github.com/lin-d-hop","followers_url":"https://api.github.com/users/lin-d-hop/followers","following_url":"https://api.github.com/users/lin-d-hop/following{/other_user}","gists_url":"https://api.github.com/users/lin-d-hop/gists{/gist_id}","starred_url":"https://api.github.com/users/lin-d-hop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lin-d-hop/subscriptions","organizations_url":"https://api.github.com/users/lin-d-hop/orgs","repos_url":"https://api.github.com/users/lin-d-hop/repos","events_url":"https://api.github.com/users/lin-d-hop/events{/privacy}","received_events_url":"https://api.github.com/users/lin-d-hop/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lin-d-hop/openfoodnetwork","description":"Connect suppliers, distributors and consumers for the sale and purchase of local produce","fork":true,"url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork","forks_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/forks","keys_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/teams","hooks_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/hooks","issue_events_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/issues/events{/number}","events_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/events","assignees_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/assignees{/user}","branches_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/branches{/branch}","tags_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/tags","blobs_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/git/refs{/sha}","trees_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/statuses/{sha}","languages_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/languages","stargazers_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/stargazers","contributors_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/contributors","subscribers_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/subscribers","subscription_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/subscription","commits_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/commits{/sha}","git_commits_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/git/commits{/sha}","comments_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/comments{/number}","issue_comment_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/issues/comments{/number}","contents_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/contents/{+path}","compare_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/merges","archive_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/downloads","issues_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/issues{/number}","pulls_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/pulls{/number}","milestones_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/milestones{/number}","notifications_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/labels{/name}","releases_url":"https://api.github.com/repos/lin-d-hop/openfoodnetwork/releases{/id}","created_at":"2015-02-24T01:49:05Z","updated_at":"2015-04-04T17:35:57Z","pushed_at":"2015-04-04T18:21:19Z","git_url":"git://github.com/lin-d-hop/openfoodnetwork.git","ssh_url":"git@github.com:lin-d-hop/openfoodnetwork.git","clone_url":"https://github.com/lin-d-hop/openfoodnetwork.git","svn_url":"https://github.com/lin-d-hop/openfoodnetwork","homepage":"http://openfoodnetwork.org/","size":18297,"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":"openfoodfoundation:master","ref":"master","sha":"5d7659aa3ce8629c14f014954a0a32e5e95fb8bc","user":{"login":"openfoodfoundation","id":2578987,"avatar_url":"https://avatars.githubusercontent.com/u/2578987?v=3","gravatar_id":"","url":"https://api.github.com/users/openfoodfoundation","html_url":"https://github.com/openfoodfoundation","followers_url":"https://api.github.com/users/openfoodfoundation/followers","following_url":"https://api.github.com/users/openfoodfoundation/following{/other_user}","gists_url":"https://api.github.com/users/openfoodfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/openfoodfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openfoodfoundation/subscriptions","organizations_url":"https://api.github.com/users/openfoodfoundation/orgs","repos_url":"https://api.github.com/users/openfoodfoundation/repos","events_url":"https://api.github.com/users/openfoodfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/openfoodfoundation/received_events","type":"Organization","site_admin":false},"repo":{"id":6257856,"name":"openfoodnetwork","full_name":"openfoodfoundation/openfoodnetwork","owner":{"login":"openfoodfoundation","id":2578987,"avatar_url":"https://avatars.githubusercontent.com/u/2578987?v=3","gravatar_id":"","url":"https://api.github.com/users/openfoodfoundation","html_url":"https://github.com/openfoodfoundation","followers_url":"https://api.github.com/users/openfoodfoundation/followers","following_url":"https://api.github.com/users/openfoodfoundation/following{/other_user}","gists_url":"https://api.github.com/users/openfoodfoundation/gists{/gist_id}","starred_url":"https://api.github.com/users/openfoodfoundation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openfoodfoundation/subscriptions","organizations_url":"https://api.github.com/users/openfoodfoundation/orgs","repos_url":"https://api.github.com/users/openfoodfoundation/repos","events_url":"https://api.github.com/users/openfoodfoundation/events{/privacy}","received_events_url":"https://api.github.com/users/openfoodfoundation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openfoodfoundation/openfoodnetwork","description":"Connect suppliers, distributors and consumers for the sale and purchase of local produce","fork":false,"url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork","forks_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/forks","keys_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/teams","hooks_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/hooks","issue_events_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/events{/number}","events_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/events","assignees_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/assignees{/user}","branches_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/branches{/branch}","tags_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/tags","blobs_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/git/refs{/sha}","trees_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/statuses/{sha}","languages_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/languages","stargazers_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/stargazers","contributors_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/contributors","subscribers_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/subscribers","subscription_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/subscription","commits_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/commits{/sha}","git_commits_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/git/commits{/sha}","comments_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/comments{/number}","issue_comment_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/comments{/number}","contents_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/contents/{+path}","compare_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/merges","archive_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/downloads","issues_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues{/number}","pulls_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls{/number}","milestones_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/milestones{/number}","notifications_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/labels{/name}","releases_url":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/releases{/id}","created_at":"2012-10-17T07:56:23Z","updated_at":"2015-04-12T01:39:35Z","pushed_at":"2015-04-12T01:39:34Z","git_url":"git://github.com/openfoodfoundation/openfoodnetwork.git","ssh_url":"git@github.com:openfoodfoundation/openfoodnetwork.git","clone_url":"https://github.com/openfoodfoundation/openfoodnetwork.git","svn_url":"https://github.com/openfoodfoundation/openfoodnetwork","homepage":"http://openfoodnetwork.org/","size":26078,"stargazers_count":76,"watchers_count":76,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":31,"mirror_url":null,"open_issues_count":126,"forks":31,"open_issues":126,"watchers":76,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474"},"html":{"href":"https://github.com/openfoodfoundation/openfoodnetwork/pull/474"},"issue":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/474"},"comments":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/issues/474/comments"},"review_comments":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474/comments"},"review_comment":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/pulls/474/commits"},"statuses":{"href":"https://api.github.com/repos/openfoodfoundation/openfoodnetwork/statuses/ff935af18bd4a2a459e945dafa1e35642ac5d198"}}}}