{"action":"created","comment":{"url":"https://api.github.com/repos/bonobos/spree/pulls/comments/26344647","id":26344647,"diff_hunk":"@@ -0,0 +1,172 @@\n+require 'spec_helper'\n+\n+describe Spree::OrderShipping do\n+  let(:order) { create(:order_ready_to_ship, line_items_count: 1) }\n+\n+  describe \"#ship\" do\n+    subject do\n+      order.shipping.ship(\n+        inventory_units: inventory_units,\n+        stock_location: stock_location,\n+        address: address,\n+        shipping_method: shipping_method,\n+      )\n+    end\n+\n+    let(:shipment) { order.shipments.to_a.first }\n+    let(:inventory_units) { shipment.inventory_units }\n+    let(:stock_location) { shipment.stock_location }\n+    let(:address) { shipment.address }\n+    let(:shipping_method) { shipment.shipping_method }\n+\n+    it \"creates a carton with the supplied inventory units\" do\n+      expect { subject }.to change { order.cartons.count }.by(1)\n+      expect(order.cartons.first.inventory_units).to match_array(inventory_units)\n+    end\n+\n+    it \"marks the inventory units as shipped\" do\n+      expect { subject }.to change { inventory_units.reload.map(&:state) }.from(['on_hand']).to(['shipped'])\n+    end\n+\n+    describe \"shipment email\" do\n+      before { with_test_mail { subject } }\n+\n+      def emails\n+        ActionMailer::Base.deliveries\n+      end\n+\n+      it \"should send a shipment email\" do\n+        expect(emails.size).to eq(1)\n+        expect(emails.first.subject).to eq(\"Spree Demo Site Shipment Notification ##{order.number}\")\n+      end\n+    end\n+\n+    it \"updates the order shipment state\" do\n+      expect { subject }.to change { order.reload.shipment_state }.from('ready').to('shipped')\n+    end\n+\n+    it \"updates shipment.shipped_at\" do\n+      future = Timecop.freeze\n+      expect { subject }.to change { shipment.shipped_at }.from(nil).to(future)\n+    end\n+\n+    it \"updates order.updated_at\" do\n+      future = 1.minute.from_now\n+      expect do\n+        Timecop.freeze(future) do\n+          subject\n+        end\n+      end.to change { order.updated_at }.from(order.updated_at).to(future)\n+    end\n+\n+    context \"with an external_number\" do\n+      subject do\n+        order.shipping.ship(\n+          inventory_units: inventory_units,\n+          stock_location: stock_location,\n+          address: address,\n+          shipping_method: shipping_method,\n+          external_number: 'some-external-number',\n+        )\n+      end\n+\n+      it \"sets the external_number\" do\n+        expect { subject }.to change { order.cartons.count }.by(1)\n+        expect(order.cartons.last.external_number).to eq 'some-external-number'\n+      end\n+    end\n+\n+    context \"with a tracking number\" do\n+      subject do\n+        order.shipping.ship(\n+          inventory_units: inventory_units,\n+          stock_location: stock_location,\n+          address: address,\n+          shipping_method: shipping_method,\n+          tracking_number: 'tracking-number',\n+        )\n+      end\n+\n+      it \"sets the external_number\" do\n+        expect { subject }.to change { order.cartons.count }.by(1)\n+        expect(order.cartons.last.tracking).to eq 'tracking-number'\n+      end\n+    end\n+\n+  end\n+\n+  describe \"#ship_shipment\" do\n+    subject { order.shipping.ship_shipment(shipment) }\n+\n+    let(:shipment) { order.shipments.to_a.first }\n+\n+    it \"creates a carton with the shipment's inventory units\" do\n+      expect { subject }.to change { order.cartons.count }.by(1)\n+      expect(order.cartons.first.inventory_units).to match_array(shipment.inventory_units)\n+    end\n+\n+    it \"marks the inventory units as shipped\" do\n+      expect { subject }.to change { order.inventory_units.reload.map(&:state) }.from(['on_hand']).to(['shipped'])\n+    end\n+\n+    describe \"shipment email\" do\n+      before { with_test_mail { subject } }\n+\n+      def emails\n+        ActionMailer::Base.deliveries\n+      end\n+\n+      it \"should send a shipment email\" do\n+        expect(emails.size).to eq(1)\n+        expect(emails.first.subject).to eq(\"Spree Demo Site Shipment Notification ##{order.number}\")\n+      end\n+    end\n+\n+    it \"updates the order shipment state\" do\n+      expect { subject }.to change { order.reload.shipment_state }.from('ready').to('shipped')\n+    end\n+\n+    it \"updates shipment.shipped_at\" do\n+      future = Timecop.freeze\n+      expect { subject }.to change { shipment.shipped_at }.from(nil).to(future)\n+    end\n+\n+    it \"updates order.updated_at\" do\n+      future = 1.minute.from_now\n+      expect do\n+        Timecop.freeze(future) do\n+          subject\n+        end\n+      end.to change { order.updated_at }.from(order.updated_at).to(future)\n+    end\n+\n+    context \"with an external_number\" do\n+      subject do\n+        order.shipping.ship_shipment(\n+          shipment,\n+          external_number: 'some-external-number',\n+        )\n+      end\n+\n+      it \"sets the external_number\" do\n+        expect { subject }.to change { order.cartons.count }.by(1)","path":"core/spec/models/spree/order_shipping_spec.rb","position":152,"original_position":152,"commit_id":"e4d689a76346bcce208a2482bb388c6420dd6457","original_commit_id":"e4d689a76346bcce208a2482bb388c6420dd6457","user":{"login":"jordan-brough","id":23050,"avatar_url":"https://avatars.githubusercontent.com/u/23050?v=3","gravatar_id":"","url":"https://api.github.com/users/jordan-brough","html_url":"https://github.com/jordan-brough","followers_url":"https://api.github.com/users/jordan-brough/followers","following_url":"https://api.github.com/users/jordan-brough/following{/other_user}","gists_url":"https://api.github.com/users/jordan-brough/gists{/gist_id}","starred_url":"https://api.github.com/users/jordan-brough/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jordan-brough/subscriptions","organizations_url":"https://api.github.com/users/jordan-brough/orgs","repos_url":"https://api.github.com/users/jordan-brough/repos","events_url":"https://api.github.com/users/jordan-brough/events{/privacy}","received_events_url":"https://api.github.com/users/jordan-brough/received_events","type":"User","site_admin":false},"body":"I guess i'm not a huge fan of the shared context stuff. Maybe I just haven't wrapped my brain around it but for some reason it's always hard for me to parse.  How about we look at extracting it out once we have three things using it?","created_at":"2015-03-12T21:07:59Z","updated_at":"2015-03-12T21:07:59Z","html_url":"https://github.com/bonobos/spree/pull/276#discussion_r26344647","pull_request_url":"https://api.github.com/repos/bonobos/spree/pulls/276","_links":{"self":{"href":"https://api.github.com/repos/bonobos/spree/pulls/comments/26344647"},"html":{"href":"https://github.com/bonobos/spree/pull/276#discussion_r26344647"},"pull_request":{"href":"https://api.github.com/repos/bonobos/spree/pulls/276"}}},"pull_request":{"url":"https://api.github.com/repos/bonobos/spree/pulls/276","id":30790701,"html_url":"https://github.com/bonobos/spree/pull/276","diff_url":"https://github.com/bonobos/spree/pull/276.diff","patch_url":"https://github.com/bonobos/spree/pull/276.patch","issue_url":"https://api.github.com/repos/bonobos/spree/issues/276","number":276,"state":"open","locked":false,"title":"Shipped Shipments represented as Spree::Carton - Step 1","user":{"login":"philbirt","id":208828,"avatar_url":"https://avatars.githubusercontent.com/u/208828?v=3","gravatar_id":"","url":"https://api.github.com/users/philbirt","html_url":"https://github.com/philbirt","followers_url":"https://api.github.com/users/philbirt/followers","following_url":"https://api.github.com/users/philbirt/following{/other_user}","gists_url":"https://api.github.com/users/philbirt/gists{/gist_id}","starred_url":"https://api.github.com/users/philbirt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philbirt/subscriptions","organizations_url":"https://api.github.com/users/philbirt/orgs","repos_url":"https://api.github.com/users/philbirt/repos","events_url":"https://api.github.com/users/philbirt/events{/privacy}","received_events_url":"https://api.github.com/users/philbirt/received_events","type":"User","site_admin":false},"body":"We are going to split the shipped shipments represented at `Spree::Cartons` work into several roll-back-able chunks like we did for bulk promotions. This represents step 1, full plan outlined below:\r\n\r\nStep 1:\r\n- schema changes\r\n- mirrored data (do both: ship Shipments and create Cartons when `Shipment.ship!` is called)\r\n- move after_ship into OrderContents#ship_shipment\r\n\r\nStep 2:\r\n- Backfill old shipped shipments to have an associated Carton\r\n\r\nStep 3:\r\n- Wombat changes to support getting Cartons data to the correct places / Turn off associated shipment flows\r\n\r\nStep 4:\r\n- Admin UI pulls from Carton data instead of Shipment data\r\n- All other reads from shipped shipments should read from Cartons\r\n\r\nStep 5:\r\n- Stop writing data to Shipments for anything during or after `ship!`","created_at":"2015-03-09T19:16:24Z","updated_at":"2015-03-12T21:07:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f6f66d421dba1a2858adc16325f3bfe020ec6dfc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bonobos/spree/pulls/276/commits","review_comments_url":"https://api.github.com/repos/bonobos/spree/pulls/276/comments","review_comment_url":"https://api.github.com/repos/bonobos/spree/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bonobos/spree/issues/276/comments","statuses_url":"https://api.github.com/repos/bonobos/spree/statuses/e4d689a76346bcce208a2482bb388c6420dd6457","head":{"label":"bonobos:cartons-step-1","ref":"cartons-step-1","sha":"e4d689a76346bcce208a2482bb388c6420dd6457","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":12625383,"name":"spree","full_name":"bonobos/spree","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/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":true,"url":"https://api.github.com/repos/bonobos/spree","forks_url":"https://api.github.com/repos/bonobos/spree/forks","keys_url":"https://api.github.com/repos/bonobos/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bonobos/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bonobos/spree/teams","hooks_url":"https://api.github.com/repos/bonobos/spree/hooks","issue_events_url":"https://api.github.com/repos/bonobos/spree/issues/events{/number}","events_url":"https://api.github.com/repos/bonobos/spree/events","assignees_url":"https://api.github.com/repos/bonobos/spree/assignees{/user}","branches_url":"https://api.github.com/repos/bonobos/spree/branches{/branch}","tags_url":"https://api.github.com/repos/bonobos/spree/tags","blobs_url":"https://api.github.com/repos/bonobos/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bonobos/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bonobos/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/bonobos/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bonobos/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/bonobos/spree/languages","stargazers_url":"https://api.github.com/repos/bonobos/spree/stargazers","contributors_url":"https://api.github.com/repos/bonobos/spree/contributors","subscribers_url":"https://api.github.com/repos/bonobos/spree/subscribers","subscription_url":"https://api.github.com/repos/bonobos/spree/subscription","commits_url":"https://api.github.com/repos/bonobos/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/bonobos/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/bonobos/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/bonobos/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/bonobos/spree/contents/{+path}","compare_url":"https://api.github.com/repos/bonobos/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bonobos/spree/merges","archive_url":"https://api.github.com/repos/bonobos/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bonobos/spree/downloads","issues_url":"https://api.github.com/repos/bonobos/spree/issues{/number}","pulls_url":"https://api.github.com/repos/bonobos/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/bonobos/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/bonobos/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bonobos/spree/labels{/name}","releases_url":"https://api.github.com/repos/bonobos/spree/releases{/id}","created_at":"2013-09-05T18:28:25Z","updated_at":"2015-03-11T20:27:10Z","pushed_at":"2015-03-12T19:31:54Z","git_url":"git://github.com/bonobos/spree.git","ssh_url":"git@github.com:bonobos/spree.git","clone_url":"https://github.com/bonobos/spree.git","svn_url":"https://github.com/bonobos/spree","homepage":"http://spreecommerce.com","size":77446,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":9,"forks":1,"open_issues":9,"watchers":1,"default_branch":"2-2-dev"}},"base":{"label":"bonobos:2-2-dev","ref":"2-2-dev","sha":"40b0efacde35e44555e1cbfb4da5296b8a3f03ab","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":12625383,"name":"spree","full_name":"bonobos/spree","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/spree","description":"Spree is a complete open source e-commerce solution for Ruby on Rails.","fork":true,"url":"https://api.github.com/repos/bonobos/spree","forks_url":"https://api.github.com/repos/bonobos/spree/forks","keys_url":"https://api.github.com/repos/bonobos/spree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bonobos/spree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bonobos/spree/teams","hooks_url":"https://api.github.com/repos/bonobos/spree/hooks","issue_events_url":"https://api.github.com/repos/bonobos/spree/issues/events{/number}","events_url":"https://api.github.com/repos/bonobos/spree/events","assignees_url":"https://api.github.com/repos/bonobos/spree/assignees{/user}","branches_url":"https://api.github.com/repos/bonobos/spree/branches{/branch}","tags_url":"https://api.github.com/repos/bonobos/spree/tags","blobs_url":"https://api.github.com/repos/bonobos/spree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bonobos/spree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bonobos/spree/git/refs{/sha}","trees_url":"https://api.github.com/repos/bonobos/spree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bonobos/spree/statuses/{sha}","languages_url":"https://api.github.com/repos/bonobos/spree/languages","stargazers_url":"https://api.github.com/repos/bonobos/spree/stargazers","contributors_url":"https://api.github.com/repos/bonobos/spree/contributors","subscribers_url":"https://api.github.com/repos/bonobos/spree/subscribers","subscription_url":"https://api.github.com/repos/bonobos/spree/subscription","commits_url":"https://api.github.com/repos/bonobos/spree/commits{/sha}","git_commits_url":"https://api.github.com/repos/bonobos/spree/git/commits{/sha}","comments_url":"https://api.github.com/repos/bonobos/spree/comments{/number}","issue_comment_url":"https://api.github.com/repos/bonobos/spree/issues/comments{/number}","contents_url":"https://api.github.com/repos/bonobos/spree/contents/{+path}","compare_url":"https://api.github.com/repos/bonobos/spree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bonobos/spree/merges","archive_url":"https://api.github.com/repos/bonobos/spree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bonobos/spree/downloads","issues_url":"https://api.github.com/repos/bonobos/spree/issues{/number}","pulls_url":"https://api.github.com/repos/bonobos/spree/pulls{/number}","milestones_url":"https://api.github.com/repos/bonobos/spree/milestones{/number}","notifications_url":"https://api.github.com/repos/bonobos/spree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bonobos/spree/labels{/name}","releases_url":"https://api.github.com/repos/bonobos/spree/releases{/id}","created_at":"2013-09-05T18:28:25Z","updated_at":"2015-03-11T20:27:10Z","pushed_at":"2015-03-12T19:31:54Z","git_url":"git://github.com/bonobos/spree.git","ssh_url":"git@github.com:bonobos/spree.git","clone_url":"https://github.com/bonobos/spree.git","svn_url":"https://github.com/bonobos/spree","homepage":"http://spreecommerce.com","size":77446,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":9,"forks":1,"open_issues":9,"watchers":1,"default_branch":"2-2-dev"}},"_links":{"self":{"href":"https://api.github.com/repos/bonobos/spree/pulls/276"},"html":{"href":"https://github.com/bonobos/spree/pull/276"},"issue":{"href":"https://api.github.com/repos/bonobos/spree/issues/276"},"comments":{"href":"https://api.github.com/repos/bonobos/spree/issues/276/comments"},"review_comments":{"href":"https://api.github.com/repos/bonobos/spree/pulls/276/comments"},"review_comment":{"href":"https://api.github.com/repos/bonobos/spree/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bonobos/spree/pulls/276/commits"},"statuses":{"href":"https://api.github.com/repos/bonobos/spree/statuses/e4d689a76346bcce208a2482bb388c6420dd6457"}}}}