From fd21d35aeebcd7375a2d6fb591282c0e38057adc Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 19 Jul 2019 14:27:11 +0100 Subject: [PATCH] Transpec and fix rubocop issues in spree/api/shipments_controller_spec --- .../spree/api/shipments_controller_spec.rb | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/spec/controllers/spree/api/shipments_controller_spec.rb b/spec/controllers/spree/api/shipments_controller_spec.rb index 9f5dd63d5f..2b02eb8534 100644 --- a/spec/controllers/spree/api/shipments_controller_spec.rb +++ b/spec/controllers/spree/api/shipments_controller_spec.rb @@ -5,7 +5,7 @@ describe Spree::Api::ShipmentsController, type: :controller do let!(:shipment) { create(:shipment) } let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_method, :inventory_units] } - let!(:resource_scoping) { { :order_id => shipment.order.to_param, :id => shipment.to_param } } + let!(:resource_scoping) { { order_id: shipment.order.to_param, id: shipment.to_param } } let(:current_api_user) { build(:user) } before do @@ -91,58 +91,58 @@ describe Spree::Api::ShipmentsController, type: :controller do end it "can make a shipment ready" do - Spree::Order.any_instance.stub(:paid? => true, :complete? => true) + allow_any_instance_of(Spree::Order).to receive_messages(paid?: true, complete?: true) api_put :ready expect(attributes.all?{ |attr| json_response.key? attr.to_s }).to be_truthy - json_response["state"].should == "ready" - shipment.reload.state.should == "ready" + expect(json_response["state"]).to eq("ready") + expect(shipment.reload.state).to eq("ready") end it "cannot make a shipment ready if the order is unpaid" do - Spree::Order.any_instance.stub(:paid? => false) + allow_any_instance_of(Spree::Order).to receive_messages(paid?: false) api_put :ready - json_response["error"].should == "Cannot ready shipment." - response.status.should == 422 + expect(json_response["error"]).to eq("Cannot ready shipment.") + expect(response.status).to eq(422) end context 'for completed shipments' do let(:order) { create :completed_order_with_totals } - let!(:resource_scoping) { { :order_id => order.to_param, :id => order.shipments.first.to_param } } + let!(:resource_scoping) { { order_id: order.to_param, id: order.shipments.first.to_param } } it 'adds a variant to a shipment' do - api_put :add, { variant_id: variant.to_param, quantity: 2 } - response.status.should == 200 - json_response['inventory_units'].select { |h| h['variant_id'] == variant.id }.size.should == 2 + api_put :add, variant_id: variant.to_param, quantity: 2 + expect(response.status).to eq(200) + expect(json_response['inventory_units'].select { |h| h['variant_id'] == variant.id }.size).to eq(2) end it 'removes a variant from a shipment' do order.contents.add(variant, 2) - api_put :remove, { variant_id: variant.to_param, quantity: 1 } - response.status.should == 200 - json_response['inventory_units'].select { |h| h['variant_id'] == variant.id }.size.should == 1 + api_put :remove, variant_id: variant.to_param, quantity: 1 + expect(response.status).to eq(200) + expect(json_response['inventory_units'].select { |h| h['variant_id'] == variant.id }.size).to eq(1) end end context "can transition a shipment from ready to ship" do before do - Spree::Order.any_instance.stub(:paid? => true, :complete? => true) + allow_any_instance_of(Spree::Order).to receive_messages(paid?: true, complete?: true) # For the shipment notification email Spree::Config[:mails_from] = "spree@example.com" shipment.update!(shipment.order) - shipment.state.should == "ready" - Spree::ShippingRate.any_instance.stub(:cost => 5) + expect(shipment.state).to eq("ready") + allow_any_instance_of(Spree::ShippingRate).to receive_messages(cost: 5) end it "can transition a shipment from ready to ship" do - pending "[Spree build] Failing spec (with postgres)" shipment.reload - api_put :ship, :order_id => shipment.order.to_param, :id => shipment.to_param, :shipment => { :tracking => "123123" } - json_response.should have_attributes(attributes) - json_response["state"].should == "shipped" + api_put :ship, order_id: shipment.order.to_param, id: shipment.to_param, shipment: { tracking: "123123" } + + expect(attributes.all?{ |attr| json_response.key? attr.to_s }).to be_truthy + expect(json_response["state"]).to eq("shipped") end end