From 99de74dede5dff272c0dce3b5e8d113fb5e56b42 Mon Sep 17 00:00:00 2001 From: SamuelMartini Date: Fri, 11 Dec 2020 17:09:15 +0100 Subject: [PATCH] Fix rubocop --- .../spree/checkout_controller_spec.rb | 77 +++++++++---------- .../spree/current_order_tracking_spec.rb | 7 +- .../spree/orders_controller_ability_spec.rb | 24 +++--- spec/requests/spree/orders_controller_spec.rb | 11 +-- .../orders_controller_transitions_spec.rb | 4 +- .../spree/products_controller_spec.rb | 2 +- 6 files changed, 62 insertions(+), 63 deletions(-) diff --git a/spec/requests/spree/checkout_controller_spec.rb b/spec/requests/spree/checkout_controller_spec.rb index 4b54c0ded..e57ce8e91 100644 --- a/spec/requests/spree/checkout_controller_spec.rb +++ b/spec/requests/spree/checkout_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Spree::CheckoutController, type: :request, with_signed_in_user: true do @@ -9,7 +10,7 @@ address.attributes.except("created_at", "updated_at") end let(:order) { create(:order_with_line_items) } - + context "#edit" do let!(:order) { create(:order_with_line_items) } @@ -28,7 +29,7 @@ end it "redirects to the cart path if current_order is nil" do - order.destroy + order.destroy get spree.checkout_path, params: { state: "delivery" } expect(response).to redirect_to(spree.cart_path) @@ -37,14 +38,14 @@ it "redirects to cart if order is completed" do order.touch(:completed_at) get spree.checkout_path, params: { state: "address" } - + expect(response).to redirect_to(spree.cart_path) end # Regression test for https://github.com/spree/spree/issues/2280 it "redirects to current step trying to access a future step" do order.update_column(:state, "address") - + get spree.checkout_path, params: { state: "delivery" } expect(response).to redirect_to spree.checkout_state_path("address") end @@ -81,16 +82,15 @@ context "save successful" do def post_address patch spree.update_checkout_path(state: "address", - order: { - bill_address_attributes: address_params, - use_billing: true - } - ) + order: { + bill_address_attributes: address_params, + use_billing: true + }) end let!(:payment_method) { create(:payment_method) } - context "with the order in the cart state", partial_double_verification: false do + context "when the order in the cart state", partial_double_verification: false do let!(:order) { create(:order_with_line_items, state: 'cart') } it "assigns order" do @@ -103,7 +103,7 @@ def post_address expect(order.reload.state).to eq("delivery") end - it "should redirect the next state" do + it "redirects the next state" do post_address expect(response).to redirect_to spree.checkout_state_path("delivery") end @@ -113,25 +113,24 @@ def post_address def post_persist_address patch spree.update_checkout_path(state: "address", - order: { - bill_address_attributes: address_params, - use_billing: true - }, - save_user_address: "1" - ) + order: { + bill_address_attributes: address_params, + use_billing: true + }, + save_user_address: "1") end - + it "calls persist order address on user" do user.user_addresses.destroy - expect { post_persist_address }.to change { user.user_addresses.count }.from(0).to(1) + expect { post_persist_address }.to change { user.user_addresses.count }.from(0).to(1) end end end context "when the order in the address state" do context 'when landing to address page' do - let!(:order) do + let!(:order) do create(:order_with_line_items, state: 'address', user_id: user.id, bill_address: nil, ship_address: nil) end let(:user) { create(:user_with_addresses) } @@ -144,7 +143,7 @@ def post_persist_address end end - context "with a billing and shipping address" do + context "when a billing and shipping address" do subject do patch spree.update_checkout_path( state: 'address', @@ -157,15 +156,15 @@ def post_persist_address end it "doesn't change bill address" do - expect { + expect do subject - }.not_to change { order.reload.ship_address.id } + end.not_to(change { order.reload.ship_address.id }) end it "doesn't change ship address" do - expect { + expect do subject - }.not_to change { order.reload.bill_address.id } + end.not_to(change { order.reload.bill_address.id }) end end end @@ -232,7 +231,7 @@ def post_persist_address } end - context 'with a permitted payment method' do + context 'when a permitted payment method' do it 'sets the payment amount' do patch spree.update_checkout_path(params) order.reload @@ -242,13 +241,13 @@ def post_persist_address end end - context 'with an unpermitted payment method' do + context 'when an unpermitted payment method' do before { payment_method.update!(available_to_users: false) } it 'sets the payment amount' do - expect { + expect do patch spree.update_checkout_path(params) - }.to raise_error(ActiveRecord::RecordNotFound) + end.to raise_error(ActiveRecord::RecordNotFound) expect(order.state).to eq('payment') expect(order.payments).to be_empty @@ -282,7 +281,7 @@ def post_persist_address context "when in the confirm state" do let(:order) { create(:order_with_line_items, state: 'confirm') } - + before do # An order requires a payment to reach the complete state # This is because payment_required? is true on the order @@ -306,20 +305,20 @@ def post_persist_address it "removes completed order from current_order" do patch spree.update_checkout_path(state: "confirm") expect(assigns(:current_order)).to be_nil - expect(assigns(:order)).to eql order + expect(assigns(:order)).to eql order end end end context "save unsuccessful" do it "does not assign order" do - patch spree.update_checkout_path(state: "address", order: { bill_address_attributes: address_params } ) + patch spree.update_checkout_path(state: "address", order: { bill_address_attributes: address_params }) expect(assigns[:order]).not_to be_nil end it "renders the edit template" do order.line_items.destroy_all - patch spree.update_checkout_path(state: "address", order: { bill_address_attributes: address_params } ) + patch spree.update_checkout_path(state: "address", order: { bill_address_attributes: address_params }) expect(response).to redirect_to(spree.cart_path) end end @@ -418,7 +417,7 @@ def post_persist_address before do allow(Spree::OrderUpdateAttributes).to receive(:new).and_raise(Spree::Order::InsufficientStock) allow(Spree::Stock::AvailabilityValidator).to receive(:new) { availability_validator } - allow(availability_validator).to receive(:validate).and_return(false) + allow(availability_validator).to receive(:validate).and_return(false) end it "redirects the customer to the address checkout page with an error message" do @@ -451,7 +450,7 @@ def post_persist_address expect(response).to redirect_to spree.cart_path end - it "should set flash message for no inventory" do + it "redirects set flash message for no inventory" do expect(flash[:error]).to eq("#{order.line_items.first.name} became unavailable.") end end @@ -477,9 +476,9 @@ def post_persist_address end it "doesn't remove unshippable items before payment" do - expect { + expect do patch spree.update_checkout_path(state: "payment") - }.to_not change { order.line_items } + end.to_not(change { order.line_items }) end end @@ -492,9 +491,9 @@ def post_persist_address end it "removes unshippable items before payment" do - expect { + expect do patch spree.update_checkout_path(state: "payment", order: { email: "johndoe@example.com" }) - }.to change { order.line_items.reload.to_a.size }.from(1).to(0) + end.to change { order.line_items.reload.to_a.size }.from(1).to(0) end end end diff --git a/spec/requests/spree/current_order_tracking_spec.rb b/spec/requests/spree/current_order_tracking_spec.rb index 6ff9656c9..9f5012a36 100644 --- a/spec/requests/spree/current_order_tracking_spec.rb +++ b/spec/requests/spree/current_order_tracking_spec.rb @@ -16,7 +16,7 @@ def not_create_order head :ok end end - + before do Rails.application.routes.draw do get '/test', to: 'test#create_order' @@ -27,7 +27,6 @@ def not_create_order Rails.application.reload_routes! end - it 'automatically tracks who the order was created by & IP address' do get '/test' @@ -37,9 +36,9 @@ def not_create_order context "current order creation" do it "doesn't create a new order out of the blue" do - expect { + expect do get '/test2' - }.not_to change { Spree::Order.count } + end.not_to(change { Spree::Order.count }) end end end diff --git a/spec/requests/spree/orders_controller_ability_spec.rb b/spec/requests/spree/orders_controller_ability_spec.rb index 2ef490264..fb2e8aa50 100644 --- a/spec/requests/spree/orders_controller_ability_spec.rb +++ b/spec/requests/spree/orders_controller_ability_spec.rb @@ -8,7 +8,7 @@ module Spree let!(:store) { create(:store) } let(:variant) { create(:variant) } - it 'should understand order routes with token' do + it 'understands order routes with token' do expect(spree.token_order_path('R123456', 'ABCDEF')).to eq('/orders/R123456/token/ABCDEF') end @@ -16,35 +16,35 @@ module Spree before { order.update(guest_token: nil) } context '#populate' do - it 'should check if user is authorized for :update' do + it 'checks if user is authorized for :update' do post spree.populate_orders_path, params: { variant_id: variant.id } expect(response).to redirect_to :unauthorized end end context '#edit' do - it 'should check if user is authorized for :read' do + it 'checks if user is authorized for :read' do get spree.cart_path expect(response).to redirect_to :unauthorized end end context '#update' do - it 'should check if user is authorized for :update' do + it 'checks if user is authorized for :update' do put spree.order_path(order.number), params: { order: { email: "foo@bar.com" } } expect(response).to redirect_to :unauthorized end end context '#empty' do - it 'should check if user is authorized for :update' do + it 'checks if user is authorized for :update' do put spree.empty_cart_path expect(response).to redirect_to :unauthorized end end context "#show" do - it "should check against the specified order" do + it "checks against the specified order" do get spree.order_path(id: order.number) expect(response).to redirect_to :unauthorized end @@ -54,7 +54,7 @@ module Spree context 'when no authenticated user' do let(:order) { create(:order, number: 'R123') } let(:another_order) { create(:order) } - + context '#show' do context 'when token parameter present' do it 'always ooverride existing token when passing a new one' do @@ -62,9 +62,9 @@ module Spree get spree.order_path(id: another_order.number, token: another_order.guest_token) jar = ActionDispatch::Cookies::CookieJar.build(request, cookies.to_hash) expect(jar.signed[:guest_token]).to eq another_order.guest_token - end + end - it 'should store as guest_token in session' do + it 'stores as guest_token in session' do get spree.order_path(id: order.number, token: order.guest_token) jar = ActionDispatch::Cookies::CookieJar.build(request, cookies.to_hash) expect(jar.signed[:guest_token]).to eq order.guest_token @@ -72,10 +72,10 @@ module Spree end context 'when no token present' do - it 'should respond with 404' do - expect { + it 'responds with 404' do + expect do get spree.order_path(id: 'R123') - }.to raise_error(ActiveRecord::RecordNotFound) + end.to raise_error(ActiveRecord::RecordNotFound) end end end diff --git a/spec/requests/spree/orders_controller_spec.rb b/spec/requests/spree/orders_controller_spec.rb index e2e94bb49..d39f85ec3 100644 --- a/spec/requests/spree/orders_controller_spec.rb +++ b/spec/requests/spree/orders_controller_spec.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'spec_helper' describe Spree::OrdersController, type: :request do @@ -65,7 +66,7 @@ end context "when quantity is nil" do - it "should populate order with 1 of given variant" do + it "populates order with 1 of given variant" do expect do post spree.populate_orders_path, params: { variant_id: variant.id, quantity: nil } end.to change { Spree::Order.count }.by(1) @@ -82,7 +83,7 @@ context '#edit', with_guest_session: true do let(:order) { create(:order, user: nil, store: store) } - + it 'renders the cart' do get spree.edit_order_path(order.number) @@ -90,7 +91,7 @@ expect(response).to be_ok end - context 'with another order number than the current_order' do + context 'when another order number than the current_order' do let(:other_order) { create(:completed_order_with_totals, email: 'test@email.com', user: nil, store: store) } it 'displays error message' do @@ -105,7 +106,7 @@ context "#update", with_guest_session: true do let(:order) { create(:order_with_line_items, user: nil, store: store) } - context "with authorization" do + context "when authorization" do it "renders the edit view (on failure)" do # email validation is only after address state order.update_column(:state, "delivery") @@ -131,7 +132,7 @@ context "#empty", with_guest_session: true do let(:order) { create(:order_with_line_items, user: nil, store: store) } - it "it destroys line items in the current order" do + it "destroys line items in the current order" do put spree.empty_cart_path expect(response).to redirect_to(spree.cart_path) diff --git a/spec/requests/spree/orders_controller_transitions_spec.rb b/spec/requests/spree/orders_controller_transitions_spec.rb index 35178674e..24c6eafbc 100644 --- a/spec/requests/spree/orders_controller_transitions_spec.rb +++ b/spec/requests/spree/orders_controller_transitions_spec.rb @@ -9,7 +9,7 @@ module Spree describe OrdersController, type: :request, with_guest_session: true do # Regression test for https://github.com/spree/spree/issues/2004 - context "with a transition callback on first state" do + context "when a transition callback on first state" do let(:order) { create(:order, user: nil, store: store) } let!(:store) { create(:store) } @@ -20,7 +20,7 @@ module Spree end end - it "correctly calls the transition callback" do + it "calls the transition callback" do expect(order.number).not_to eq 'test' order.line_items << create(:line_item) put spree.order_path(order.number), params: { checkout: "checkout" } diff --git a/spec/requests/spree/products_controller_spec.rb b/spec/requests/spree/products_controller_spec.rb index 635914613..23c005bf3 100644 --- a/spec/requests/spree/products_controller_spec.rb +++ b/spec/requests/spree/products_controller_spec.rb @@ -36,7 +36,7 @@ end.to raise_error(ActiveRecord::RecordNotFound) end - it "should provide the current user to the searcher class" do + it "provides the current user to the searcher class" do get spree.products_path expect(searcher_class).to have_received(:current_user=).with(user)