From b7876ebfbf44321d714b2550a67a2757b80e8c57 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 2 Feb 2018 16:45:06 +1100 Subject: [PATCH] Replace references to 'standing order' with 'subscription' (spec) --- .../admin/proxy_orders_controller_spec.rb | 8 +- .../admin/subscriptions_controller_spec.rb | 200 +++++++++--------- spec/factories.rb | 24 +-- spec/features/admin/enterprises_spec.rb | 2 +- spec/features/admin/order_cycles_spec.rb | 4 +- spec/features/admin/schedules_spec.rb | 6 +- spec/features/admin/subscriptions_spec.rb | 134 ++++++------ .../admin/subscriptions_helper_spec.rb | 16 +- spec/jobs/subscription_confirm_job_spec.rb | 30 +-- spec/jobs/subscription_placement_job_spec.rb | 32 +-- .../lib/open_food_network/permissions_spec.rb | 10 +- .../proxy_order_syncer_spec.rb | 56 ++--- .../subscription_payment_updater_spec.rb | 18 +- .../subscription_summarizer_spec.rb | 10 +- .../subscription_summary_spec.rb | 6 +- spec/mailers/subscription_mailer_spec.rb | 88 ++++---- spec/models/column_preference_spec.rb | 4 +- spec/models/proxy_order_spec.rb | 34 +-- spec/models/spree/order_spec.rb | 6 +- spec/models/standing_line_item_spec.rb | 4 +- spec/models/subscription_spec.rb | 78 +++---- spec/performance/proxy_order_syncer_spec.rb | 20 +- spec/services/order_syncer_spec.rb | 152 ++++++------- spec/services/subscription_form_spec.rb | 20 +- spec/services/subscription_validator_spec.rb | 86 ++++---- 25 files changed, 524 insertions(+), 524 deletions(-) diff --git a/spec/controllers/admin/proxy_orders_controller_spec.rb b/spec/controllers/admin/proxy_orders_controller_spec.rb index ff7bf3c3dd..35b200db57 100644 --- a/spec/controllers/admin/proxy_orders_controller_spec.rb +++ b/spec/controllers/admin/proxy_orders_controller_spec.rb @@ -7,8 +7,8 @@ describe Admin::ProxyOrdersController, type: :controller do let!(:user) { create(:user, enterprise_limit: 10) } let!(:shop) { create(:distributor_enterprise) } let!(:order_cycle) { create(:simple_order_cycle, orders_close_at: 1.day.from_now) } - let!(:standing_order) { create(:standing_order, shop: shop, with_items: true) } - let!(:proxy_order) { create(:proxy_order, standing_order: standing_order, order_cycle: order_cycle) } + let!(:subscription) { create(:subscription, shop: shop, with_items: true) } + let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) } before do allow(controller).to receive(:spree_current_user) { user } @@ -68,8 +68,8 @@ describe Admin::ProxyOrdersController, type: :controller do let!(:order_cycle) { create(:simple_order_cycle, orders_close_at: 1.day.from_now) } let!(:payment_method) { create(:payment_method) } let!(:shipping_method) { create(:shipping_method) } - let!(:standing_order) { create(:standing_order, shop: shop, with_items: true) } - let!(:proxy_order) { create(:proxy_order, standing_order: standing_order, order_cycle: order_cycle) } + let!(:subscription) { create(:subscription, shop: shop, with_items: true) } + let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) } let(:order) { proxy_order.initialise_order! } before do diff --git a/spec/controllers/admin/subscriptions_controller_spec.rb b/spec/controllers/admin/subscriptions_controller_spec.rb index a9c2075419..73a5a60179 100644 --- a/spec/controllers/admin/subscriptions_controller_spec.rb +++ b/spec/controllers/admin/subscriptions_controller_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe Admin::StandingOrdersController, type: :controller do +describe Admin::SubscriptionsController, type: :controller do include AuthenticationWorkflow describe 'index' do let!(:user) { create(:user, enterprise_limit: 10) } - let!(:shop) { create(:distributor_enterprise, enable_standing_orders: true) } + let!(:shop) { create(:distributor_enterprise, enable_subscriptions: true) } before do allow(controller).to receive(:spree_current_user) { user } @@ -25,8 +25,8 @@ describe Admin::StandingOrdersController, type: :controller do before { shop.update_attributes(owner: user) } let!(:not_enabled_shop) { create(:distributor_enterprise, owner: user) } - context "where I manage a shop that is set up for standing orders" do - let!(:standing_order) { create(:standing_order, shop: shop) } + context "where I manage a shop that is set up for subscriptions" do + let!(:subscription) { create(:subscription, shop: shop) } it 'renders the index page with appropriate data' do spree_get :index, params @@ -36,7 +36,7 @@ describe Admin::StandingOrdersController, type: :controller do end end - context "where I don't manage a shop that is set up for standing orders" do + context "where I don't manage a shop that is set up for subscriptions" do it 'renders the setup_explanation page' do spree_get :index, params expect(response).to render_template 'setup_explanation' @@ -49,7 +49,7 @@ describe Admin::StandingOrdersController, type: :controller do context 'json' do let(:params) { { format: :json } } - let!(:standing_order) { create(:standing_order, shop: shop) } + let!(:subscription) { create(:subscription, shop: shop) } context 'as a regular user' do it 'redirects to unauthorized' do @@ -61,25 +61,25 @@ describe Admin::StandingOrdersController, type: :controller do context 'as an enterprise user' do before { shop.update_attributes(owner: user) } let!(:shop2) { create(:distributor_enterprise, owner: user) } - let!(:standing_order2) { create(:standing_order, shop: shop2) } + let!(:subscription2) { create(:subscription, shop: shop2) } it 'renders the collection as json' do spree_get :index, params json_response = JSON.parse(response.body) expect(json_response.count).to be 2 - expect(json_response.map{ |so| so['id'] }).to include standing_order.id, standing_order2.id + expect(json_response.map{ |so| so['id'] }).to include subscription.id, subscription2.id end context "when ransack predicates are submitted" do before { params.merge!(q: { shop_id_eq: shop2.id }) } - it "restricts the list of standing orders" do + it "restricts the list of subscriptions" do spree_get :index, params json_response = JSON.parse(response.body) expect(json_response.count).to be 1 ids = json_response.map{ |so| so['id'] } - expect(ids).to include standing_order2.id - expect(ids).to_not include standing_order.id + expect(ids).to include subscription2.id + expect(ids).to_not include subscription.id end end end @@ -96,9 +96,9 @@ describe Admin::StandingOrdersController, type: :controller do it 'loads the preloads the necessary data' do expect(controller).to receive(:load_form_data) - spree_get :new, standing_order: { shop_id: shop.id } - expect(assigns(:standing_order)).to be_a_new StandingOrder - expect(assigns(:standing_order).shop).to eq shop + spree_get :new, subscription: { shop_id: shop.id } + expect(assigns(:subscription)).to be_a_new Subscription + expect(assigns(:subscription).shop).to eq shop end end @@ -110,7 +110,7 @@ describe Admin::StandingOrdersController, type: :controller do let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } let!(:payment_method) { create(:payment_method, distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } - let(:params) { { format: :json, standing_order: { shop_id: shop.id } } } + let(:params) { { format: :json, subscription: { shop_id: shop.id } } } context 'as an non-manager of the specified shop' do before do @@ -130,14 +130,14 @@ describe Admin::StandingOrdersController, type: :controller do context 'when I submit insufficient params' do it 'returns errors' do - expect{ spree_post :create, params }.to_not change{ StandingOrder.count } + expect{ spree_post :create, params }.to_not change{ Subscription.count } json_response = JSON.parse(response.body) expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'begins_at' end end context 'when I submit params containing ids of inaccessible objects' do - # As 'user' I shouldnt be able to associate a standing_order with any of these. + # As 'user' I shouldnt be able to associate a subscription with any of these. let(:unmanaged_enterprise) { create(:enterprise) } let(:unmanaged_schedule) { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: unmanaged_enterprise)]) } let(:unmanaged_customer) { create(:customer, enterprise: unmanaged_enterprise) } @@ -145,7 +145,7 @@ describe Admin::StandingOrdersController, type: :controller do let(:unmanaged_shipping_method) { create(:shipping_method, distributors: [unmanaged_enterprise]) } before do - params[:standing_order].merge!( + params[:subscription].merge!( schedule_id: unmanaged_schedule.id, customer_id: unmanaged_customer.id, payment_method_id: unmanaged_payment_method.id, @@ -156,7 +156,7 @@ describe Admin::StandingOrdersController, type: :controller do end it 'returns errors' do - expect{ spree_post :create, params }.to_not change{ StandingOrder.count } + expect{ spree_post :create, params }.to_not change{ Subscription.count } json_response = JSON.parse(response.body) expect(json_response['errors'].keys).to include 'schedule', 'customer', 'payment_method', 'shipping_method', 'ends_at' end @@ -167,7 +167,7 @@ describe Admin::StandingOrdersController, type: :controller do let(:variant) { create(:variant) } before do - params[:standing_order].merge!( + params[:subscription].merge!( schedule_id: schedule.id, customer_id: customer.id, payment_method_id: payment_method.id, @@ -184,7 +184,7 @@ describe Admin::StandingOrdersController, type: :controller do context 'where the specified variants are not available from the shop' do it 'returns an error' do - expect{ spree_post :create, params }.to_not change{ StandingOrder.count } + expect{ spree_post :create, params }.to_not change{ Subscription.count } json_response = JSON.parse(response.body) expect(json_response['errors']['standing_line_items']).to eq ["#{variant.product.name} - #{variant.full_name} is not available from the selected schedule"] end @@ -193,17 +193,17 @@ describe Admin::StandingOrdersController, type: :controller do context 'where the specified variants are available from the shop' do let!(:exchange) { create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop, variants: [variant]) } - it 'creates standing line items for the standing order' do - expect{ spree_post :create, params }.to change{ StandingOrder.count }.by(1) - standing_order = StandingOrder.last - expect(standing_order.schedule).to eq schedule - expect(standing_order.customer).to eq customer - expect(standing_order.payment_method).to eq payment_method - expect(standing_order.shipping_method).to eq shipping_method - expect(standing_order.bill_address.firstname).to eq address.firstname - expect(standing_order.ship_address.firstname).to eq address.firstname - expect(standing_order.standing_line_items.count).to be 1 - standing_line_item = standing_order.standing_line_items.first + it 'creates standing line items for the subscription' do + expect{ spree_post :create, params }.to change{ Subscription.count }.by(1) + subscription = Subscription.last + expect(subscription.schedule).to eq schedule + expect(subscription.customer).to eq customer + expect(subscription.payment_method).to eq payment_method + expect(subscription.shipping_method).to eq shipping_method + expect(subscription.bill_address.firstname).to eq address.firstname + expect(subscription.ship_address.firstname).to eq address.firstname + expect(subscription.standing_line_items.count).to be 1 + standing_line_item = subscription.standing_line_items.first expect(standing_line_item.quantity).to be 2 expect(standing_line_item.variant).to eq variant end @@ -220,8 +220,8 @@ describe Admin::StandingOrdersController, type: :controller do let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } let!(:payment_method) { create(:payment_method, distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } - let!(:standing_order) { - create(:standing_order, + let!(:subscription) { + create(:subscription, shop: shop, customer: customer1, schedule: schedule, @@ -235,8 +235,8 @@ describe Admin::StandingOrdersController, type: :controller do it 'loads the preloads the necessary data' do expect(controller).to receive(:load_form_data) - spree_get :edit, id: standing_order.id - expect(assigns(:standing_order)).to eq standing_order + spree_get :edit, id: subscription.id + expect(assigns(:subscription)).to eq subscription end end @@ -252,8 +252,8 @@ describe Admin::StandingOrdersController, type: :controller do let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) } let!(:payment_method) { create(:payment_method, distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } - let!(:standing_order) { - create(:standing_order, + let!(:subscription) { + create(:subscription, shop: shop, customer: customer, schedule: schedule, @@ -261,10 +261,10 @@ describe Admin::StandingOrdersController, type: :controller do shipping_method: shipping_method, standing_line_items: [create(:standing_line_item, variant: variant1, quantity: 2)]) } - let(:standing_line_item1) { standing_order.standing_line_items.first } - let(:params) { { format: :json, id: standing_order.id, standing_order: {} } } + let(:standing_line_item1) { subscription.standing_line_items.first } + let(:params) { { format: :json, id: subscription.id, subscription: {} } } - context 'as an non-manager of the standing order shop' do + context 'as an non-manager of the subscription shop' do before do allow(controller).to receive(:spree_current_user) { create(:user, enterprises: [create(:enterprise)]) } end @@ -275,7 +275,7 @@ describe Admin::StandingOrdersController, type: :controller do end end - context 'as a manager of the standing_order shop' do + context 'as a manager of the subscription shop' do before do allow(controller).to receive(:spree_current_user) { user } end @@ -285,37 +285,37 @@ describe Admin::StandingOrdersController, type: :controller do let!(:new_schedule) { create(:schedule, order_cycles: [order_cycle]) } before do - params[:standing_order].merge!(schedule_id: new_schedule.id, customer_id: new_customer.id) + params[:subscription].merge!(schedule_id: new_schedule.id, customer_id: new_customer.id) end it 'does not alter customer_id or schedule_id' do spree_post :update, params - standing_order.reload - expect(standing_order.customer).to eq customer - expect(standing_order.schedule).to eq schedule + subscription.reload + expect(subscription.customer).to eq customer + expect(subscription.schedule).to eq schedule end end context 'when I submit params containing ids of inaccessible objects' do - # As 'user' I shouldnt be able to associate a standing_order with any of these. + # As 'user' I shouldnt be able to associate a subscription with any of these. let(:unmanaged_enterprise) { create(:enterprise) } let(:unmanaged_payment_method) { create(:payment_method, distributors: [unmanaged_enterprise]) } let(:unmanaged_shipping_method) { create(:shipping_method, distributors: [unmanaged_enterprise]) } before do - params[:standing_order].merge!( + params[:subscription].merge!( payment_method_id: unmanaged_payment_method.id, shipping_method_id: unmanaged_shipping_method.id ) end it 'returns errors' do - expect{ spree_post :update, params }.to_not change{ StandingOrder.count } + expect{ spree_post :update, params }.to_not change{ Subscription.count } json_response = JSON.parse(response.body) expect(json_response['errors'].keys).to include 'payment_method', 'shipping_method' - standing_order.reload - expect(standing_order.payment_method).to eq payment_method - expect(standing_order.shipping_method).to eq shipping_method + subscription.reload + expect(subscription.payment_method).to eq payment_method + expect(subscription.shipping_method).to eq shipping_method end end @@ -324,19 +324,19 @@ describe Admin::StandingOrdersController, type: :controller do let!(:new_shipping_method) { create(:shipping_method, distributors: [shop]) } before do - params[:standing_order].merge!( + params[:subscription].merge!( payment_method_id: new_payment_method.id, shipping_method_id: new_shipping_method.id ) end - it 'updates the standing order' do + it 'updates the subscription' do spree_post :update, params - standing_order.reload - expect(standing_order.schedule).to eq schedule - expect(standing_order.customer).to eq customer - expect(standing_order.payment_method).to eq new_payment_method - expect(standing_order.shipping_method).to eq new_shipping_method + subscription.reload + expect(subscription.schedule).to eq schedule + expect(subscription.customer).to eq customer + expect(subscription.payment_method).to eq new_payment_method + expect(subscription.shipping_method).to eq new_shipping_method end context 'with standing_line_items params' do @@ -349,7 +349,7 @@ describe Admin::StandingOrdersController, type: :controller do context 'where the specified variants are not available from the shop' do it 'returns an error' do - expect{ spree_post :update, params }.to_not change{ standing_order.standing_line_items.count } + expect{ spree_post :update, params }.to_not change{ subscription.standing_line_items.count } json_response = JSON.parse(response.body) expect(json_response['errors']['standing_line_items']).to eq ["#{product2.name} - #{variant2.full_name} is not available from the selected schedule"] end @@ -358,11 +358,11 @@ describe Admin::StandingOrdersController, type: :controller do context 'where the specified variants are available from the shop' do before { outgoing_exchange.update_attributes(variants: [variant1, variant2]) } - it 'creates standing line items for the standing order' do - expect{ spree_post :update, params }.to change{ standing_order.standing_line_items.count }.by(1) - standing_order.reload - expect(standing_order.standing_line_items.count).to be 2 - standing_line_item = standing_order.standing_line_items.last + it 'creates standing line items for the subscription' do + expect{ spree_post :update, params }.to change{ subscription.standing_line_items.count }.by(1) + subscription.reload + expect(subscription.standing_line_items.count).to be 2 + standing_line_item = subscription.standing_line_items.last expect(standing_line_item.quantity).to be 2 expect(standing_line_item.variant).to eq variant2 end @@ -376,15 +376,15 @@ describe Admin::StandingOrdersController, type: :controller do let!(:user) { create(:user, enterprise_limit: 10) } let!(:shop) { create(:distributor_enterprise) } let!(:order_cycle) { create(:simple_order_cycle, orders_close_at: 1.day.from_now) } - let!(:standing_order) { create(:standing_order, shop: shop, with_items: true) } - let!(:proxy_order) { create(:proxy_order, standing_order: standing_order, order_cycle: order_cycle) } + let!(:subscription) { create(:subscription, shop: shop, with_items: true) } + let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) } before do allow(controller).to receive(:spree_current_user) { user } end context 'json' do - let(:params) { { format: :json, id: standing_order.id } } + let(:params) { { format: :json, id: subscription.id } } context 'as a regular user' do it 'redirects to unauthorized' do @@ -408,8 +408,8 @@ describe Admin::StandingOrdersController, type: :controller do before { shop.update_attributes(owner: user) } context "when at least one associated order is still 'open'" do - let(:order_cycle) { standing_order.order_cycles.first } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order, order_cycle: order_cycle) } + let(:order_cycle) { subscription.order_cycles.first } + let(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) } let!(:order) { proxy_order.initialise_order! } before { while !order.completed? do break unless order.next! end } @@ -419,19 +419,19 @@ describe Admin::StandingOrdersController, type: :controller do spree_put :cancel, params expect(response.status).to be 409 json_response = JSON.parse(response.body) - expect(json_response['errors']['open_orders']).to eq I18n.t('admin.standing_orders.confirm_cancel_open_orders_msg') + expect(json_response['errors']['open_orders']).to eq I18n.t('admin.subscriptions.confirm_cancel_open_orders_msg') end end context "when 'keep' has been provided as the 'open_orders' directive" do before { params.merge!(open_orders: 'keep') } - it 'renders the cancelled standing_order as json, and does not cancel the open order' do + it 'renders the cancelled subscription as json, and does not cancel the open order' do spree_put :cancel, params json_response = JSON.parse(response.body) expect(json_response['canceled_at']).to_not be nil - expect(json_response['id']).to eq standing_order.id - expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now + expect(json_response['id']).to eq subscription.id + expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now expect(order.reload.state).to eq 'complete' expect(proxy_order.reload.canceled_at).to be nil end @@ -446,12 +446,12 @@ describe Admin::StandingOrdersController, type: :controller do allow(mail_mock).to receive(:deliver) end - it 'renders the cancelled standing_order as json, and cancels the open order' do + it 'renders the cancelled subscription as json, and cancels the open order' do spree_put :cancel, params json_response = JSON.parse(response.body) expect(json_response['canceled_at']).to_not be nil - expect(json_response['id']).to eq standing_order.id - expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now + expect(json_response['id']).to eq subscription.id + expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now expect(order.reload.state).to eq 'canceled' expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now expect(mail_mock).to have_received(:deliver) @@ -460,12 +460,12 @@ describe Admin::StandingOrdersController, type: :controller do end context "when no associated orders are still 'open'" do - it 'renders the cancelled standing_order as json' do + it 'renders the cancelled subscription as json' do spree_put :cancel, params json_response = JSON.parse(response.body) expect(json_response['canceled_at']).to_not be nil - expect(json_response['id']).to eq standing_order.id - expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now + expect(json_response['id']).to eq subscription.id + expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now end end end @@ -476,14 +476,14 @@ describe Admin::StandingOrdersController, type: :controller do describe 'pause' do let!(:user) { create(:user, enterprise_limit: 10) } let!(:shop) { create(:distributor_enterprise) } - let!(:standing_order) { create(:standing_order, shop: shop, with_items: true) } + let!(:subscription) { create(:subscription, shop: shop, with_items: true) } before do allow(controller).to receive(:spree_current_user) { user } end context 'json' do - let(:params) { { format: :json, id: standing_order.id } } + let(:params) { { format: :json, id: subscription.id } } context 'as a regular user' do it 'redirects to unauthorized' do @@ -507,8 +507,8 @@ describe Admin::StandingOrdersController, type: :controller do before { shop.update_attributes(owner: user) } context "when at least one associated order is still 'open'" do - let(:order_cycle) { standing_order.order_cycles.first } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order, order_cycle: order_cycle) } + let(:order_cycle) { subscription.order_cycles.first } + let(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle) } let!(:order) { proxy_order.initialise_order! } before { while !order.completed? do break unless order.next! end } @@ -518,19 +518,19 @@ describe Admin::StandingOrdersController, type: :controller do spree_put :pause, params expect(response.status).to be 409 json_response = JSON.parse(response.body) - expect(json_response['errors']['open_orders']).to eq I18n.t('admin.standing_orders.confirm_cancel_open_orders_msg') + expect(json_response['errors']['open_orders']).to eq I18n.t('admin.subscriptions.confirm_cancel_open_orders_msg') end end context "when 'keep' has been provided as the 'open_orders' directive" do before { params.merge!(open_orders: 'keep') } - it 'renders the paused standing_order as json, and does not cancel the open order' do + it 'renders the paused subscription as json, and does not cancel the open order' do spree_put :pause, params json_response = JSON.parse(response.body) expect(json_response['paused_at']).to_not be nil - expect(json_response['id']).to eq standing_order.id - expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.zone.now + expect(json_response['id']).to eq subscription.id + expect(subscription.reload.paused_at).to be_within(5.seconds).of Time.zone.now expect(order.reload.state).to eq 'complete' expect(proxy_order.reload.canceled_at).to be nil end @@ -545,12 +545,12 @@ describe Admin::StandingOrdersController, type: :controller do allow(mail_mock).to receive(:deliver) end - it 'renders the paused standing_order as json, and cancels the open order' do + it 'renders the paused subscription as json, and cancels the open order' do spree_put :pause, params json_response = JSON.parse(response.body) expect(json_response['paused_at']).to_not be nil - expect(json_response['id']).to eq standing_order.id - expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.zone.now + expect(json_response['id']).to eq subscription.id + expect(subscription.reload.paused_at).to be_within(5.seconds).of Time.zone.now expect(order.reload.state).to eq 'canceled' expect(proxy_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now expect(mail_mock).to have_received(:deliver) @@ -559,12 +559,12 @@ describe Admin::StandingOrdersController, type: :controller do end context "when no associated orders are still 'open'" do - it 'renders the paused standing_order as json' do + it 'renders the paused subscription as json' do spree_put :pause, params json_response = JSON.parse(response.body) expect(json_response['paused_at']).to_not be nil - expect(json_response['id']).to eq standing_order.id - expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.zone.now + expect(json_response['id']).to eq subscription.id + expect(subscription.reload.paused_at).to be_within(5.seconds).of Time.zone.now end end end @@ -575,14 +575,14 @@ describe Admin::StandingOrdersController, type: :controller do describe 'unpause' do let!(:user) { create(:user, enterprise_limit: 10) } let!(:shop) { create(:distributor_enterprise) } - let!(:standing_order) { create(:standing_order, shop: shop, paused_at: Time.zone.now, with_items: true) } + let!(:subscription) { create(:subscription, shop: shop, paused_at: Time.zone.now, with_items: true) } before do allow(controller).to receive(:spree_current_user) { user } end context 'json' do - let(:params) { { format: :json, id: standing_order.id } } + let(:params) { { format: :json, id: subscription.id } } context 'as a regular user' do it 'redirects to unauthorized' do @@ -605,12 +605,12 @@ describe Admin::StandingOrdersController, type: :controller do context "with authorisation" do before { shop.update_attributes(owner: user) } - it 'renders the paused standing_order as json' do + it 'renders the paused subscription as json' do spree_put :unpause, params json_response = JSON.parse(response.body) expect(json_response['paused_at']).to be nil - expect(json_response['id']).to eq standing_order.id - expect(standing_order.reload.paused_at).to be nil + expect(json_response['id']).to eq subscription.id + expect(subscription.reload.paused_at).to be nil end end end @@ -629,7 +629,7 @@ describe Admin::StandingOrdersController, type: :controller do before do allow(controller).to receive(:spree_current_user) { user } - controller.instance_variable_set(:@standing_order, StandingOrder.new(shop: shop)) + controller.instance_variable_set(:@subscription, Subscription.new(shop: shop)) end it "assigns data to instance variables" do diff --git a/spec/factories.rb b/spec/factories.rb index c5ad8a25e6..2378be4d39 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -138,7 +138,7 @@ FactoryGirl.define do order_cycles { [OrderCycle.first || FactoryGirl.create(:simple_order_cycle)] } end - factory :standing_order, :class => StandingOrder do + factory :subscription, :class => Subscription do shop { create :enterprise } schedule { create(:schedule, order_cycles: [create(:simple_order_cycle, coordinator: shop)]) } customer { create(:customer, enterprise: shop) } @@ -153,33 +153,33 @@ FactoryGirl.define do with_proxy_orders false end - after(:create) do |standing_order, proxy| + after(:create) do |subscription, proxy| if proxy.with_items - standing_order.standing_line_items = build_list(:standing_line_item, 3, standing_order: standing_order) - standing_order.order_cycles.each do |oc| - ex = oc.exchanges.outgoing.find_by_sender_id_and_receiver_id(standing_order.shop_id, standing_order.shop_id) || - create(:exchange, :order_cycle => oc, :sender => standing_order.shop, :receiver => standing_order.shop, :incoming => false, :pickup_time => 'time', :pickup_instructions => 'instructions') - standing_order.standing_line_items.each { |sli| ex.variants << sli.variant } + subscription.standing_line_items = build_list(:standing_line_item, 3, subscription: subscription) + subscription.order_cycles.each do |oc| + ex = oc.exchanges.outgoing.find_by_sender_id_and_receiver_id(subscription.shop_id, subscription.shop_id) || + create(:exchange, :order_cycle => oc, :sender => subscription.shop, :receiver => subscription.shop, :incoming => false, :pickup_time => 'time', :pickup_instructions => 'instructions') + subscription.standing_line_items.each { |sli| ex.variants << sli.variant } end end if proxy.with_proxy_orders - standing_order.order_cycles.each do |oc| - standing_order.proxy_orders << create(:proxy_order, standing_order: standing_order, order_cycle: oc) + subscription.order_cycles.each do |oc| + subscription.proxy_orders << create(:proxy_order, subscription: subscription, order_cycle: oc) end end end end factory :standing_line_item, :class => StandingLineItem do - standing_order + subscription variant quantity 1 end factory :proxy_order, :class => ProxyOrder do - standing_order - order_cycle { standing_order.order_cycles.first } + subscription + order_cycle { subscription.order_cycles.first } before(:create) do |proxy_order, proxy| if proxy_order.order proxy_order.order.update_attribute(:order_cycle_id, proxy_order.order_cycle_id) diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 506292e17f..228cce3b1e 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -91,7 +91,7 @@ feature %q{ expect(page).to have_checked_field "enterprise_allow_guest_orders_true" choose "Visible to registered customers only" expect(page).to have_no_checked_field "enterprise_require_login_false" - # expect(page).to have_checked_field "enterprise_enable_standing_orders_false" + # expect(page).to have_checked_field "enterprise_enable_subscriptions_false" within(".side_menu") { click_link "Users" } select2_search user.email, from: 'Owner' diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index a3d8233ede..78df24c5bb 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -702,7 +702,7 @@ feature %q{ end scenario "creating a new order cycle" do - distributor_managed.update_attribute(:enable_standing_orders, true) + distributor_managed.update_attribute(:enable_subscriptions, true) # Make the page long enough to avoid the save bar overlaying the form page.driver.resize(1280, 2000) @@ -796,7 +796,7 @@ feature %q{ scenario "editing an order cycle" do oc = create(:simple_order_cycle, { suppliers: [supplier_managed, supplier_permitted, supplier_unmanaged], coordinator: distributor_managed, distributors: [distributor_managed, distributor_permitted, distributor_unmanaged], name: 'Order Cycle 1' } ) - distributor_managed.update_attribute(:enable_standing_orders, true) + distributor_managed.update_attribute(:enable_subscriptions, true) visit edit_admin_order_cycle_path(oc) diff --git a/spec/features/admin/schedules_spec.rb b/spec/features/admin/schedules_spec.rb index b842942612..d400d5f087 100644 --- a/spec/features/admin/schedules_spec.rb +++ b/spec/features/admin/schedules_spec.rb @@ -6,9 +6,9 @@ feature 'Schedules', js: true do context "as an enterprise user" do let(:user) { create(:user, enterprise_limit: 10) } - let(:managed_enterprise) { create(:distributor_enterprise, owner: user, enable_standing_orders: true) } - let(:unmanaged_enterprise) { create(:distributor_enterprise, enable_standing_orders: true) } - let(:managed_enterprise2) { create(:distributor_enterprise, owner: user, enable_standing_orders: true) } + let(:managed_enterprise) { create(:distributor_enterprise, owner: user, enable_subscriptions: true) } + let(:unmanaged_enterprise) { create(:distributor_enterprise, enable_subscriptions: true) } + let(:managed_enterprise2) { create(:distributor_enterprise, owner: user, enable_subscriptions: true) } let!(:oc1) { create(:simple_order_cycle, coordinator: managed_enterprise, name: 'oc1') } let!(:oc2) { create(:simple_order_cycle, coordinator: managed_enterprise, name: 'oc2') } let!(:oc3) { create(:simple_order_cycle, coordinator: managed_enterprise, name: 'oc3') } diff --git a/spec/features/admin/subscriptions_spec.rb b/spec/features/admin/subscriptions_spec.rb index 3ce7e703e0..c65e1ce166 100644 --- a/spec/features/admin/subscriptions_spec.rb +++ b/spec/features/admin/subscriptions_spec.rb @@ -6,16 +6,16 @@ feature 'Standing Orders' do context "as an enterprise user", js: true do let!(:user) { create_enterprise_user(enterprise_limit: 10) } - let!(:shop) { create(:distributor_enterprise, owner: user, enable_standing_orders: true) } - let!(:shop2) { create(:distributor_enterprise, owner: user, enable_standing_orders: true) } - let!(:shop_unmanaged) { create(:distributor_enterprise, enable_standing_orders: true) } + let!(:shop) { create(:distributor_enterprise, owner: user, enable_subscriptions: true) } + let!(:shop2) { create(:distributor_enterprise, owner: user, enable_subscriptions: true) } + let!(:shop_unmanaged) { create(:distributor_enterprise, enable_subscriptions: true) } before { quick_login_as user } - context 'listing standing orders' do - let!(:standing_order) { create(:standing_order, shop: shop, with_items: true, with_proxy_orders: true) } - let!(:standing_order2) { create(:standing_order, shop: shop2, with_items: true, with_proxy_orders: true) } - let!(:standing_order_unmanaged) { create(:standing_order, shop: shop_unmanaged, with_items: true, with_proxy_orders: true) } + context 'listing subscriptions' do + let!(:subscription) { create(:subscription, shop: shop, with_items: true, with_proxy_orders: true) } + let!(:subscription2) { create(:subscription, shop: shop2, with_items: true, with_proxy_orders: true) } + let!(:subscription_unmanaged) { create(:subscription, shop: shop_unmanaged, with_items: true, with_proxy_orders: true) } it "passes the smoke test" do visit spree.admin_path @@ -26,42 +26,42 @@ feature 'Standing Orders' do select2_select shop2.name, from: "shop_id" - # Loads the right standing orders - expect(page).to have_selector "tr#so_#{standing_order2.id}" - expect(page).to have_no_selector "tr#so_#{standing_order.id}" - expect(page).to have_no_selector "tr#so_#{standing_order_unmanaged.id}" - within "tr#so_#{standing_order2.id}" do - expect(page).to have_selector "td.customer", text: standing_order2.customer.email + # Loads the right subscriptions + expect(page).to have_selector "tr#so_#{subscription2.id}" + expect(page).to have_no_selector "tr#so_#{subscription.id}" + expect(page).to have_no_selector "tr#so_#{subscription_unmanaged.id}" + within "tr#so_#{subscription2.id}" do + expect(page).to have_selector "td.customer", text: subscription2.customer.email end # Changing Shops select2_select shop.name, from: "shop_id" - # Loads the right standing orders - expect(page).to have_selector "tr#so_#{standing_order.id}" - expect(page).to have_no_selector "tr#so_#{standing_order2.id}" - expect(page).to have_no_selector "tr#so_#{standing_order_unmanaged.id}" - within "tr#so_#{standing_order.id}" do - expect(page).to have_selector "td.customer", text: standing_order.customer.email + # Loads the right subscriptions + expect(page).to have_selector "tr#so_#{subscription.id}" + expect(page).to have_no_selector "tr#so_#{subscription2.id}" + expect(page).to have_no_selector "tr#so_#{subscription_unmanaged.id}" + within "tr#so_#{subscription.id}" do + expect(page).to have_selector "td.customer", text: subscription.customer.email end # Using the Quick Search - expect(page).to have_selector "tr#so_#{standing_order.id}" + expect(page).to have_selector "tr#so_#{subscription.id}" fill_in 'query', with: 'blah blah blah' - expect(page).to have_no_selector "tr#so_#{standing_order.id}" + expect(page).to have_no_selector "tr#so_#{subscription.id}" fill_in 'query', with: '' - expect(page).to have_selector "tr#so_#{standing_order.id}" + expect(page).to have_selector "tr#so_#{subscription.id}" # Toggling columns expect(page).to have_selector "th.customer" - expect(page).to have_content standing_order.customer.email + expect(page).to have_content subscription.customer.email first("div#columns-dropdown", :text => "COLUMNS").click first("div#columns-dropdown div.menu div.menu_item", text: "Customer").click expect(page).to_not have_selector "th.customer" - expect(page).to_not have_content standing_order.customer.email + expect(page).to_not have_content subscription.customer.email # Viewing Orders - within "tr#so_#{standing_order.id}" do + within "tr#so_#{subscription.id}" do expect(page).to have_selector "td.orders.panel-toggle", text: 1 page.find("td.orders.panel-toggle").trigger('click') end @@ -69,7 +69,7 @@ feature 'Standing Orders' do within ".standing-order-orders" do expect(page).to have_selector "tr.proxy_order", count: 1 - proxy_order = standing_order.proxy_orders.first + proxy_order = subscription.proxy_orders.first within "tr#po_#{proxy_order.id}" do expect(page).to_not have_content 'CANCELLED' accept_alert 'Are you sure?' do @@ -88,39 +88,39 @@ feature 'Standing Orders' do end end - # Pausing a standing order - within "tr#so_#{standing_order.id}" do + # Pausing a subscription + within "tr#so_#{subscription.id}" do find("a.pause-standing-order").click end click_button "Yes, I'm sure" - within "tr#so_#{standing_order.id}" do + within "tr#so_#{subscription.id}" do expect(page).to have_selector ".state.paused", text: "PAUSED" - expect(standing_order.reload.paused_at).to be_within(5.seconds).of Time.zone.now + expect(subscription.reload.paused_at).to be_within(5.seconds).of Time.zone.now end - # Unpausing a standing order - within "tr#so_#{standing_order.id}" do + # Unpausing a subscription + within "tr#so_#{subscription.id}" do find("a.unpause-standing-order").click end click_button "Yes, I'm sure" - within "tr#so_#{standing_order.id}" do + within "tr#so_#{subscription.id}" do expect(page).to have_selector ".state.active", text: "ACTIVE" - expect(standing_order.reload.paused_at).to be nil + expect(subscription.reload.paused_at).to be nil end - # Cancelling a standing order - within "tr#so_#{standing_order.id}" do + # Cancelling a subscription + within "tr#so_#{subscription.id}" do find("a.cancel-standing-order").click end click_button "Yes, I'm sure" - within "tr#so_#{standing_order.id}" do + within "tr#so_#{subscription.id}" do expect(page).to have_selector ".state.canceled", text: "CANCELLED" - expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now + expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now end end end - context 'creating a new standing order' do + context 'creating a new subscription' do let(:address) { create(:address) } let!(:customer_user) { create(:user) } let!(:credit_card1) { create(:credit_card, user: customer_user, cc_type: 'visa', last_digits: 1111, month: 10, year: 2030) } @@ -139,9 +139,9 @@ feature 'Standing Orders' do let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } it "passes the smoke test" do - visit admin_standing_orders_path + visit admin_subscriptions_path click_link 'New Standing Order' - select2_select shop.name, from: 'new_standing_order_shop_id' + select2_select shop.name, from: 'new_subscription_shop_id' click_button 'Continue' select2_select customer.email, from: 'customer_id' @@ -222,7 +222,7 @@ feature 'Standing Orders' do expect{ click_button('Create Standing Order') expect(page).to have_content 'Please add at least one product' - }.to_not change(StandingOrder, :count) + }.to_not change(Subscription, :count) # Adding a new product targetted_select2_search product2.name, from: '#add_variant_id', dropdown_css: '.select2-drop' @@ -238,7 +238,7 @@ feature 'Standing Orders' do expect{ click_button('Create Standing Order') expect(page).to have_content 'Saved' - }.to change(StandingOrder, :count).by(1) + }.to change(Subscription, :count).by(1) # Prices are shown within 'table#standing-line-items tr.item', match: :first do @@ -248,24 +248,24 @@ feature 'Standing Orders' do expect(page).to have_selector 'td.total', text: "$23.25" end - # Basic properties of standing order are set - standing_order = StandingOrder.last - expect(standing_order.customer).to eq customer - expect(standing_order.schedule).to eq schedule - expect(standing_order.payment_method).to eq payment_method - expect(standing_order.shipping_method).to eq shipping_method - expect(standing_order.bill_address.firstname).to eq 'Freda' - expect(standing_order.ship_address.firstname).to eq 'Freda' - expect(standing_order.credit_card_id).to eq credit_card2.id + # Basic properties of subscription are set + subscription = Subscription.last + expect(subscription.customer).to eq customer + expect(subscription.schedule).to eq schedule + expect(subscription.payment_method).to eq payment_method + expect(subscription.shipping_method).to eq shipping_method + expect(subscription.bill_address.firstname).to eq 'Freda' + expect(subscription.ship_address.firstname).to eq 'Freda' + expect(subscription.credit_card_id).to eq credit_card2.id # Standing Line Items are created - expect(standing_order.standing_line_items.count).to eq 1 - standing_line_item = standing_order.standing_line_items.first + expect(subscription.standing_line_items.count).to eq 1 + standing_line_item = subscription.standing_line_items.first expect(standing_line_item.variant).to eq variant2 expect(standing_line_item.quantity).to eq 3 end - context 'editing an existing standing order' do + context 'editing an existing subscription' do let!(:customer) { create(:customer, enterprise: shop) } let!(:product1) { create(:product, supplier: shop) } let!(:product2) { create(:product, supplier: shop) } @@ -281,8 +281,8 @@ feature 'Standing Orders' do let!(:variant3_ex) { variant3_oc.exchanges.create(sender: shop, receiver: shop, variants: [variant3]) } let!(:payment_method) { create(:payment_method, distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } - let!(:standing_order) { - create(:standing_order, + let!(:subscription) { + create(:subscription, shop: shop, customer: customer, schedule: schedule, @@ -293,7 +293,7 @@ feature 'Standing Orders' do } it "passes the smoke test" do - visit edit_admin_standing_order_path(standing_order) + visit edit_admin_subscription_path(subscription) # Customer and Schedule cannot be edited expect(page).to have_selector '#s2id_customer_id.select2-container-disabled' @@ -306,7 +306,7 @@ feature 'Standing Orders' do expect(page).to have_input 'quantity', with: "2" expect(page).to have_selector 'td.total', text: "$27.50" - # Remove variant1 from the standing order + # Remove variant1 from the subscription find("a.delete-item").click end @@ -314,7 +314,7 @@ feature 'Standing Orders' do click_button 'Save Changes' expect(page).to have_content 'Please add at least one product' - # Add variant2 to the standing order + # Add variant2 to the subscription targetted_select2_search product2.name, from: '#add_variant_id', dropdown_css: '.select2-drop' fill_in 'add_quantity', with: 1 click_link 'Add' @@ -328,7 +328,7 @@ feature 'Standing Orders' do # Total should be $7.75 expect(page).to have_selector '#order_form_total', text: "$7.75" - # Add variant3 to the standing order (even though it is not available) + # Add variant3 to the subscription (even though it is not available) targetted_select2_search product3.name, from: '#add_variant_id', dropdown_css: '.select2-drop' fill_in 'add_quantity', with: 1 click_link 'Add' @@ -345,7 +345,7 @@ feature 'Standing Orders' do click_button 'Save Changes' expect(page).to have_content "#{product3.name} - #{variant3.full_name} is not available from the selected schedule" - # Remove variant3 from the standing order + # Remove variant3 from the subscription within '#sli_1' do find("a.delete-item").click end @@ -356,19 +356,19 @@ feature 'Standing Orders' do # Total should be $7.75 expect(page).to have_selector '#order_form_total', text: "$7.75" expect(page).to have_selector 'tr.item', count: 1 - expect(standing_order.reload.standing_line_items.length).to eq 1 - expect(standing_order.standing_line_items.first.variant).to eq variant2 + expect(subscription.reload.standing_line_items.length).to eq 1 + expect(subscription.standing_line_items.first.variant).to eq variant2 end context "with initialised order that has been changed" do - let(:proxy_order) { standing_order.proxy_orders.first } + let(:proxy_order) { subscription.proxy_orders.first } let(:order) { proxy_order.initialise_order! } let(:line_item) { order.line_items.first } before { line_item.update_attributes(quantity: 3) } it "reports issues encountered during the update" do - visit edit_admin_standing_order_path(standing_order) + visit edit_admin_subscription_path(subscription) within "#sli_0" do fill_in 'quantity', with: "1" @@ -377,7 +377,7 @@ feature 'Standing Orders' do click_button 'Save Changes' expect(page).to have_content 'Saved' - expect(page).to have_selector "#order_update_issues_dialog .message", text: I18n.t("admin.standing_orders.order_update_issues_msg") + expect(page).to have_selector "#order_update_issues_dialog .message", text: I18n.t("admin.subscriptions.order_update_issues_msg") end end end diff --git a/spec/helpers/admin/subscriptions_helper_spec.rb b/spec/helpers/admin/subscriptions_helper_spec.rb index 0e2607d6e0..db8866488a 100644 --- a/spec/helpers/admin/subscriptions_helper_spec.rb +++ b/spec/helpers/admin/subscriptions_helper_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Admin::StandingOrdersHelper, type: :helper do +describe Admin::SubscriptionsHelper, type: :helper do describe "checking if setup is complete for any [shop]" do let(:shop) { create(:distributor_enterprise) } let(:customer) { create(:customer, enterprise: shop) } @@ -10,23 +10,23 @@ describe Admin::StandingOrdersHelper, type: :helper do context "when a shop has no shipping methods present" do before { customer; payment_method; schedule } - it { expect(helper.standing_orders_setup_complete?([shop])).to be false } + it { expect(helper.subscriptions_setup_complete?([shop])).to be false } end context "when a shop has no Cash or Stripe payment methods present" do let!(:paypal) { Spree::Gateway::PayPalExpress.create!(name: "PayPalExpress", distributor_ids: [shop.id]) } before { customer; shipping_method; schedule } - it { expect(helper.standing_orders_setup_complete?([shop])).to be false } + it { expect(helper.subscriptions_setup_complete?([shop])).to be false } end context "when a shop has no customers present" do before { shipping_method; payment_method; schedule } - it { expect(helper.standing_orders_setup_complete?([shop])).to be false } + it { expect(helper.subscriptions_setup_complete?([shop])).to be false } end context "when a shop does not coordinate any schedules" do before { customer; shipping_method; payment_method; } - it { expect(helper.standing_orders_setup_complete?([shop])).to be false } + it { expect(helper.subscriptions_setup_complete?([shop])).to be false } end context "when a shop meets all requirements" do @@ -34,15 +34,15 @@ describe Admin::StandingOrdersHelper, type: :helper do let(:some_other_shop) { create(:distributor_enterprise) } context "but it is not passed in" do - it { expect(helper.standing_orders_setup_complete?([some_other_shop])).to be false } + it { expect(helper.subscriptions_setup_complete?([some_other_shop])).to be false } end context "and it is passed in" do - it { expect(helper.standing_orders_setup_complete?([shop])).to be true } + it { expect(helper.subscriptions_setup_complete?([shop])).to be true } end context "and it is passed in with other shops that do not meet the requirements" do - it { expect(helper.standing_orders_setup_complete?([shop, some_other_shop])).to be true } + it { expect(helper.subscriptions_setup_complete?([shop, some_other_shop])).to be true } end end end diff --git a/spec/jobs/subscription_confirm_job_spec.rb b/spec/jobs/subscription_confirm_job_spec.rb index 58933a4163..8dc425c087 100644 --- a/spec/jobs/subscription_confirm_job_spec.rb +++ b/spec/jobs/subscription_confirm_job_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe StandingOrderConfirmJob do - let(:job) { StandingOrderConfirmJob.new } +describe SubscriptionConfirmJob do + let(:job) { SubscriptionConfirmJob.new } describe "finding proxy_orders that are ready to be confirmed" do let(:shop) { create(:distributor_enterprise) } let(:order_cycle1) { create(:simple_order_cycle, coordinator: shop, orders_close_at: 59.minutes.ago, updated_at: 1.day.ago) } let(:order_cycle2) { create(:simple_order_cycle, coordinator: shop, orders_close_at: 61.minutes.ago, updated_at: 1.day.ago) } let(:schedule) { create(:schedule, order_cycles: [order_cycle1, order_cycle2]) } - let(:standing_order) { create(:standing_order, shop: shop, schedule: schedule) } - let!(:proxy_order) { create(:proxy_order, standing_order: standing_order, order_cycle: order_cycle1, placed_at: 5.minutes.ago, order: create(:order, completed_at: 1.minute.ago)) } + let(:subscription) { create(:subscription, shop: shop, schedule: schedule) } + let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle1, placed_at: 5.minutes.ago, order: create(:order, completed_at: 1.minute.ago)) } let(:proxy_orders) { job.send(:proxy_orders) } it "returns proxy orders that meet all of the criteria" do @@ -21,13 +21,13 @@ describe StandingOrderConfirmJob do expect(proxy_orders).to_not include proxy_order end - it "ignores proxy orders for paused standing orders" do - standing_order.update_attributes!(paused_at: 1.minute.ago) + it "ignores proxy orders for paused subscriptions" do + subscription.update_attributes!(paused_at: 1.minute.ago) expect(proxy_orders).to_not include proxy_order end - it "ignores proxy orders for cancelled standing orders" do - standing_order.update_attributes!(canceled_at: 1.minute.ago) + it "ignores proxy orders for cancelled subscriptions" do + subscription.update_attributes!(canceled_at: 1.minute.ago) expect(proxy_orders).to_not include proxy_order end @@ -106,8 +106,8 @@ describe StandingOrderConfirmJob do let(:order_cycle1) { create(:simple_order_cycle, coordinator: shop) } let(:order_cycle2) { create(:simple_order_cycle, coordinator: shop) } let(:schedule1) { create(:schedule, order_cycles: [order_cycle1, order_cycle2]) } - let(:standing_order1) { create(:standing_order, shop: shop, schedule: schedule1, with_items: true) } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order1) } + let(:subscription1) { create(:subscription, shop: shop, schedule: schedule1, with_items: true) } + let(:proxy_order) { create(:proxy_order, subscription: subscription1) } let(:order) { proxy_order.initialise_order! } before do @@ -162,7 +162,7 @@ describe StandingOrderConfirmJob do expect(payment).to receive(:completed?) { true } end - it "sends only a standing order confirm email, no regular confirmation emails" do + it "sends only a subscription confirm email, no regular confirmation emails" do ActionMailer::Base.deliveries.clear expect{ job.send(:process!) }.to_not enqueue_job ConfirmOrderJob expect(job).to have_received(:send_confirm_email).once @@ -179,13 +179,13 @@ describe StandingOrderConfirmJob do before do job.instance_variable_set(:@order, order) - allow(StandingOrderMailer).to receive(:confirmation_email) { mail_mock } + allow(SubscriptionMailer).to receive(:confirmation_email) { mail_mock } end it "records a success and sends the email" do expect(job).to receive(:record_success).with(order).once job.send(:send_confirm_email) - expect(StandingOrderMailer).to have_received(:confirmation_email).with(order) + expect(SubscriptionMailer).to have_received(:confirmation_email).with(order) expect(mail_mock).to have_received(:deliver) end end @@ -196,13 +196,13 @@ describe StandingOrderConfirmJob do before do job.instance_variable_set(:@order, order) - allow(StandingOrderMailer).to receive(:failed_payment_email) { mail_mock } + allow(SubscriptionMailer).to receive(:failed_payment_email) { mail_mock } end it "records and logs an error and sends the email" do expect(job).to receive(:record_and_log_error).with(:failed_payment, order).once job.send(:send_failed_payment_email) - expect(StandingOrderMailer).to have_received(:failed_payment_email).with(order) + expect(SubscriptionMailer).to have_received(:failed_payment_email).with(order) expect(mail_mock).to have_received(:deliver) end end diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb index be0bac3a18..d1f6e1dfd9 100644 --- a/spec/jobs/subscription_placement_job_spec.rb +++ b/spec/jobs/subscription_placement_job_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe StandingOrderPlacementJob do - let(:job) { StandingOrderPlacementJob.new } +describe SubscriptionPlacementJob do + let(:job) { SubscriptionPlacementJob.new } describe "finding proxy_orders that are ready to be placed" do let(:shop) { create(:distributor_enterprise) } let(:order_cycle1) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 1.minute.ago, orders_close_at: 10.minutes.from_now) } let(:order_cycle2) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 10.minutes.ago, orders_close_at: 1.minute.ago) } let(:schedule) { create(:schedule, order_cycles: [order_cycle1, order_cycle2]) } - let(:standing_order) { create(:standing_order, shop: shop, schedule: schedule) } - let!(:proxy_order) { create(:proxy_order, standing_order: standing_order, order_cycle: order_cycle1) } # OK + let(:subscription) { create(:subscription, shop: shop, schedule: schedule) } + let!(:proxy_order) { create(:proxy_order, subscription: subscription, order_cycle: order_cycle1) } # OK it "ignores proxy orders where the OC has closed" do expect(job.send(:proxy_orders)).to include proxy_order @@ -17,13 +17,13 @@ describe StandingOrderPlacementJob do expect(job.send(:proxy_orders)).to_not include proxy_order end - it "ignores proxy orders for paused or cancelled standing orders" do + it "ignores proxy orders for paused or cancelled subscriptions" do expect(job.send(:proxy_orders)).to include proxy_order - standing_order.update_attributes!(paused_at: 1.minute.ago) + subscription.update_attributes!(paused_at: 1.minute.ago) expect(job.send(:proxy_orders)).to_not include proxy_order - standing_order.update_attributes!(paused_at: nil) + subscription.update_attributes!(paused_at: nil) expect(job.send(:proxy_orders)).to include proxy_order - standing_order.update_attributes!(canceled_at: 1.minute.ago) + subscription.update_attributes!(canceled_at: 1.minute.ago) expect(job.send(:proxy_orders)).to_not include proxy_order end @@ -118,9 +118,9 @@ describe StandingOrderPlacementJob do end end - describe "processing a standing order order" do - let(:standing_order) { create(:standing_order, with_items: true) } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order) } + describe "processing a subscription order" do + let(:subscription) { create(:subscription, with_items: true) } + let(:proxy_order) { create(:proxy_order, subscription: subscription) } let!(:order) { proxy_order.initialise_order! } before do @@ -186,7 +186,7 @@ describe StandingOrderPlacementJob do let(:mail_mock) { double(:mailer_mock, deliver: true) } before do - allow(StandingOrderMailer).to receive(:placement_email) { mail_mock } + allow(SubscriptionMailer).to receive(:placement_email) { mail_mock } end context "when changes are present" do @@ -195,7 +195,7 @@ describe StandingOrderPlacementJob do it "logs an issue and sends the email" do expect(job).to receive(:record_issue).with(:changes, order).once job.send(:send_placement_email, order, changes) - expect(StandingOrderMailer).to have_received(:placement_email).with(order, changes) + expect(SubscriptionMailer).to have_received(:placement_email).with(order, changes) expect(mail_mock).to have_received(:deliver) end end @@ -206,7 +206,7 @@ describe StandingOrderPlacementJob do it "logs a success and sends the email" do expect(job).to receive(:record_success).with(order).once job.send(:send_placement_email, order, changes) - expect(StandingOrderMailer).to have_received(:placement_email) + expect(SubscriptionMailer).to have_received(:placement_email) expect(mail_mock).to have_received(:deliver) end end @@ -218,13 +218,13 @@ describe StandingOrderPlacementJob do let(:mail_mock) { double(:mailer_mock, deliver: true) } before do - allow(StandingOrderMailer).to receive(:empty_email) { mail_mock } + allow(SubscriptionMailer).to receive(:empty_email) { mail_mock } end it "logs an issue and sends the email" do expect(job).to receive(:record_issue).with(:empty, order).once job.send(:send_empty_email, order, changes) - expect(StandingOrderMailer).to have_received(:empty_email).with(order, changes) + expect(SubscriptionMailer).to have_received(:empty_email).with(order, changes) expect(mail_mock).to have_received(:deliver) end end diff --git a/spec/lib/open_food_network/permissions_spec.rb b/spec/lib/open_food_network/permissions_spec.rb index 08865033dc..90480acf44 100644 --- a/spec/lib/open_food_network/permissions_spec.rb +++ b/spec/lib/open_food_network/permissions_spec.rb @@ -395,14 +395,14 @@ module OpenFoodNetwork end end - describe "finding visible standing orders" do - let!(:so1) { create(:standing_order) } - let!(:so2) { create(:standing_order) } + describe "finding visible subscriptions" do + let!(:so1) { create(:subscription) } + let!(:so2) { create(:subscription) } - it "returns standing orders placed with managed shops" do + it "returns subscriptions placed with managed shops" do expect(permissions).to receive(:managed_enterprises) { [so1.shop] } - expect(permissions.visible_standing_orders).to eq [so1] + expect(permissions.visible_subscriptions).to eq [so1] end end end diff --git a/spec/lib/open_food_network/proxy_order_syncer_spec.rb b/spec/lib/open_food_network/proxy_order_syncer_spec.rb index fadae8bb28..eb7684ad28 100644 --- a/spec/lib/open_food_network/proxy_order_syncer_spec.rb +++ b/spec/lib/open_food_network/proxy_order_syncer_spec.rb @@ -3,75 +3,75 @@ require 'open_food_network/proxy_order_syncer' module OpenFoodNetwork describe ProxyOrderSyncer do describe "initialization" do - let!(:standing_order) { create(:standing_order) } + let!(:subscription) { create(:subscription) } - it "raises an error when initialized with an object that is not a StandingOrder or an ActiveRecord::Relation" do - expect{ ProxyOrderSyncer.new(standing_order) }.to_not raise_error - expect{ ProxyOrderSyncer.new(StandingOrder.where(id: standing_order.id)) }.to_not raise_error + it "raises an error when initialized with an object that is not a Subscription or an ActiveRecord::Relation" do + expect{ ProxyOrderSyncer.new(subscription) }.to_not raise_error + expect{ ProxyOrderSyncer.new(Subscription.where(id: subscription.id)) }.to_not raise_error expect{ ProxyOrderSyncer.new("something") }.to raise_error RuntimeError end end - describe "updating proxy_orders on a standing orders" do + describe "updating proxy_orders on a subscriptions" do let(:now) { Time.zone.now } let!(:schedule) { create(:schedule) } - let!(:standing_order) { create(:standing_order, schedule: schedule, begins_at: now + 1.minute, ends_at: now + 2.minutes) } + let!(:subscription) { create(:subscription, schedule: schedule, begins_at: now + 1.minute, ends_at: now + 2.minutes) } let!(:oc1) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now) } # Closed let!(:oc2) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now + 59.seconds) } # Open, but closes before begins at let!(:oc3) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now + 1.minute) } # Open + closes on begins at let!(:oc4) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now + 2.minutes) } # Open + closes on ends at let!(:oc5) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now + 121.seconds) } # Open + closes after ends at - let(:syncer) { ProxyOrderSyncer.new(standing_order) } + let(:syncer) { ProxyOrderSyncer.new(subscription) } describe "#sync!" do let!(:oc6) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now + 59.seconds) } # Open, but closes before begins at let!(:oc7) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now + 61.seconds) } # Open + closes on begins at let!(:oc8) { create(:simple_order_cycle, schedules: [schedule], orders_open_at: now - 1.minute, orders_close_at: now + 121.seconds) } # Open + closes after ends at - let!(:po1) { create(:proxy_order, standing_order: standing_order, order_cycle: oc6) } - let!(:po2) { create(:proxy_order, standing_order: standing_order, order_cycle: oc7) } - let!(:po3) { create(:proxy_order, standing_order: standing_order, order_cycle: oc8) } + let!(:po1) { create(:proxy_order, subscription: subscription, order_cycle: oc6) } + let!(:po2) { create(:proxy_order, subscription: subscription, order_cycle: oc7) } + let!(:po3) { create(:proxy_order, subscription: subscription, order_cycle: oc8) } it "performs both create and remove actions to rectify proxy orders" do expect(syncer).to receive(:create_proxy_orders!).and_call_original expect(syncer).to receive(:remove_obsolete_proxy_orders!).and_call_original syncer.sync! - standing_order.reload - expect(standing_order.proxy_orders).to include po2 - expect(standing_order.proxy_orders).to_not include po1, po3 - expect(standing_order.proxy_orders.map(&:order_cycle)).to include oc3, oc4, oc7 - expect(standing_order.proxy_orders.map(&:order_cycle)).to_not include oc1, oc2, oc5, oc6, oc8 + subscription.reload + expect(subscription.proxy_orders).to include po2 + expect(subscription.proxy_orders).to_not include po1, po3 + expect(subscription.proxy_orders.map(&:order_cycle)).to include oc3, oc4, oc7 + expect(subscription.proxy_orders.map(&:order_cycle)).to_not include oc1, oc2, oc5, oc6, oc8 end end describe "#initialise_proxy_orders!" do - let(:new_standing_order) { build(:standing_order, schedule: schedule, begins_at: now + 1.minute, ends_at: now + 2.minutes) } + let(:new_subscription) { build(:subscription, schedule: schedule, begins_at: now + 1.minute, ends_at: now + 2.minutes) } it "builds proxy orders for in-range order cycles that are not already closed" do - allow(syncer).to receive(:standing_order) { new_standing_order } + allow(syncer).to receive(:subscription) { new_subscription } expect{ syncer.send(:initialise_proxy_orders!) }.to_not change(ProxyOrder, :count).from(0) - expect{ new_standing_order.save! }.to change(ProxyOrder, :count).from(0).to(2) - expect(new_standing_order.proxy_orders.map(&:order_cycle_id)).to include oc3.id, oc4.id + expect{ new_subscription.save! }.to change(ProxyOrder, :count).from(0).to(2) + expect(new_subscription.proxy_orders.map(&:order_cycle_id)).to include oc3.id, oc4.id end end describe "#create_proxy_orders!" do it "creates proxy orders for in-range order cycles that are not already closed" do - allow(syncer).to receive(:standing_order) { standing_order } + allow(syncer).to receive(:subscription) { subscription } expect{ syncer.send(:create_proxy_orders!) }.to change(ProxyOrder, :count).from(0).to(2) - expect(standing_order.proxy_orders.map(&:order_cycle)).to include oc3, oc4 + expect(subscription.proxy_orders.map(&:order_cycle)).to include oc3, oc4 end end describe "#remove_obsolete_proxy_orders!" do - let!(:po1) { create(:proxy_order, standing_order: standing_order, order_cycle: oc1) } - let!(:po2) { create(:proxy_order, standing_order: standing_order, order_cycle: oc2) } - let!(:po3) { create(:proxy_order, standing_order: standing_order, order_cycle: oc3) } - let!(:po4) { create(:proxy_order, standing_order: standing_order, order_cycle: oc4) } - let!(:po5) { create(:proxy_order, standing_order: standing_order, order_cycle: oc5) } + let!(:po1) { create(:proxy_order, subscription: subscription, order_cycle: oc1) } + let!(:po2) { create(:proxy_order, subscription: subscription, order_cycle: oc2) } + let!(:po3) { create(:proxy_order, subscription: subscription, order_cycle: oc3) } + let!(:po4) { create(:proxy_order, subscription: subscription, order_cycle: oc4) } + let!(:po5) { create(:proxy_order, subscription: subscription, order_cycle: oc5) } it "destroys proxy orders that are closed or out of range" do - allow(syncer).to receive(:standing_order) { standing_order } + allow(syncer).to receive(:subscription) { subscription } expect{ syncer.send(:remove_obsolete_proxy_orders!) }.to change(ProxyOrder, :count).from(5).to(2) - expect(standing_order.proxy_orders.map(&:order_cycle)).to include oc3, oc4 + expect(subscription.proxy_orders.map(&:order_cycle)).to include oc3, oc4 end end end diff --git a/spec/lib/open_food_network/subscription_payment_updater_spec.rb b/spec/lib/open_food_network/subscription_payment_updater_spec.rb index e932e4e682..726a4ec9cf 100644 --- a/spec/lib/open_food_network/subscription_payment_updater_spec.rb +++ b/spec/lib/open_food_network/subscription_payment_updater_spec.rb @@ -1,9 +1,9 @@ -require 'open_food_network/standing_order_payment_updater' +require 'open_food_network/subscription_payment_updater' module OpenFoodNetwork - describe StandingOrderPaymentUpdater do + describe SubscriptionPaymentUpdater do let(:order) { create(:order) } - let(:updater) { OpenFoodNetwork::StandingOrderPaymentUpdater.new(order) } + let(:updater) { OpenFoodNetwork::SubscriptionPaymentUpdater.new(order) } describe "#payment" do context "when only one payment exists on the order" do @@ -48,12 +48,12 @@ module OpenFoodNetwork context "when no pending payments are present" do let(:payment_method) { create(:payment_method) } - let(:standing_order) { double(:standing_order, payment_method_id: payment_method.id) } + let(:subscription) { double(:subscription, payment_method_id: payment_method.id) } before do allow(order).to receive(:pending_payments).once { [] } allow(order).to receive(:outstanding_balance) { 5 } - allow(order).to receive(:standing_order) { standing_order } + allow(order).to receive(:subscription) { subscription } end it "creates a new payment on the order" do @@ -96,7 +96,7 @@ module OpenFoodNetwork context "and the payment source is not a credit card" do before { expect(updater).to receive(:card_set?) { false } } - context "and no credit card is available on the standing order" do + context "and no credit card is available on the subscription" do before { expect(updater).to receive(:ensure_credit_card) { false } } it "adds an error to the order and does not update the payment" do @@ -105,7 +105,7 @@ module OpenFoodNetwork end end - context "but a credit card is available on the standing order" do + context "but a credit card is available on the subscription" do before { expect(updater).to receive(:ensure_credit_card) { true } } context "when the payment total doesn't match the outstanding balance on the order" do @@ -151,7 +151,7 @@ module OpenFoodNetwork let!(:payment) { create(:payment, source: nil) } before { allow(updater).to receive(:payment) { payment } } - context "when no credit card is specified by the standing order" do + context "when no credit card is specified by the subscription" do before { allow(updater).to receive(:saved_credit_card) { nil } } it "returns false and down not update the payment source" do @@ -161,7 +161,7 @@ module OpenFoodNetwork end end - context "when a credit card is specified by the standing order" do + context "when a credit card is specified by the subscription" do let(:credit_card) { create(:credit_card) } before { allow(updater).to receive(:saved_credit_card) { credit_card } } diff --git a/spec/lib/open_food_network/subscription_summarizer_spec.rb b/spec/lib/open_food_network/subscription_summarizer_spec.rb index 96fe616134..973ec7620c 100644 --- a/spec/lib/open_food_network/subscription_summarizer_spec.rb +++ b/spec/lib/open_food_network/subscription_summarizer_spec.rb @@ -1,9 +1,9 @@ -require 'open_food_network/standing_order_summarizer' +require 'open_food_network/subscription_summarizer' module OpenFoodNetwork - describe StandingOrderSummarizer do + describe SubscriptionSummarizer do let(:order) { create(:order) } - let(:summarizer) { OpenFoodNetwork::StandingOrderSummarizer.new } + let(:summarizer) { OpenFoodNetwork::SubscriptionSummarizer.new } describe "#summary_for" do let(:order) { double(:order, distributor_id: 123) } @@ -100,7 +100,7 @@ module OpenFoodNetwork end it "sends a placement summary email for each summary" do - expect(StandingOrderMailer).to receive(:placement_summary_email).twice { mail_mock } + expect(SubscriptionMailer).to receive(:placement_summary_email).twice { mail_mock } summarizer.send_placement_summary_emails end end @@ -116,7 +116,7 @@ module OpenFoodNetwork end it "sends a placement summary email for each summary" do - expect(StandingOrderMailer).to receive(:confirmation_summary_email).twice { mail_mock } + expect(SubscriptionMailer).to receive(:confirmation_summary_email).twice { mail_mock } summarizer.send_confirmation_summary_emails end end diff --git a/spec/lib/open_food_network/subscription_summary_spec.rb b/spec/lib/open_food_network/subscription_summary_spec.rb index cdca0553c8..7d72e4f4ba 100644 --- a/spec/lib/open_food_network/subscription_summary_spec.rb +++ b/spec/lib/open_food_network/subscription_summary_spec.rb @@ -1,8 +1,8 @@ -require 'open_food_network/standing_order_summary' +require 'open_food_network/subscription_summary' module OpenFoodNetwork - describe StandingOrderSummary do - let(:summary) { OpenFoodNetwork::StandingOrderSummary.new(123) } + describe SubscriptionSummary do + let(:summary) { OpenFoodNetwork::SubscriptionSummary.new(123) } describe "#initialize" do it "initializes instance variables: shop_id, order_count, success_count and issues" do diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb index 95bae3845d..cca7e5258d 100644 --- a/spec/mailers/subscription_mailer_spec.rb +++ b/spec/mailers/subscription_mailer_spec.rb @@ -1,13 +1,13 @@ require 'spec_helper' -describe StandingOrderMailer do +describe SubscriptionMailer do include ActionView::Helpers::SanitizeHelper let!(:mail_method) { create(:mail_method, preferred_mails_from: 'spree@example.com') } describe "order placement" do - let(:standing_order) { create(:standing_order, with_items: true) } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order) } + let(:subscription) { create(:subscription, with_items: true) } + let(:proxy_order) { create(:proxy_order, subscription: subscription) } let!(:order) { proxy_order.initialise_order! } context "when changes have been made to the order" do @@ -16,12 +16,12 @@ describe StandingOrderMailer do before do changes[order.line_items.first.id] = 2 expect do - StandingOrderMailer.placement_email(order, changes).deliver - end.to change{ StandingOrderMailer.deliveries.count }.by(1) + SubscriptionMailer.placement_email(order, changes).deliver + end.to change{ SubscriptionMailer.deliveries.count }.by(1) end it "sends the email, which notifies the customer of changes made" do - body = StandingOrderMailer.deliveries.last.body.encoded + body = SubscriptionMailer.deliveries.last.body.encoded expect(body).to include "This order was automatically created for you." expect(body).to include "Unfortunately, not all products that you requested were available." expect(body).to include "href=\"#{spree.order_url(order)}\"" @@ -31,12 +31,12 @@ describe StandingOrderMailer do context "and changes have not been made to the order" do before do expect do - StandingOrderMailer.placement_email(order, {}).deliver - end.to change{ StandingOrderMailer.deliveries.count }.by(1) + SubscriptionMailer.placement_email(order, {}).deliver + end.to change{ SubscriptionMailer.deliveries.count }.by(1) end it "sends the email" do - body = StandingOrderMailer.deliveries.last.body.encoded + body = SubscriptionMailer.deliveries.last.body.encoded expect(body).to include "This order was automatically created for you." expect(body).to_not include "Unfortunately, not all products that you requested were available." expect(body).to include "href=\"#{spree.order_url(order)}\"" @@ -45,60 +45,60 @@ describe StandingOrderMailer do end describe "order confirmation" do - let(:standing_order) { create(:standing_order, with_items: true) } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order) } + let(:subscription) { create(:subscription, with_items: true) } + let(:proxy_order) { create(:proxy_order, subscription: subscription) } let!(:order) { proxy_order.initialise_order! } before do expect do - StandingOrderMailer.confirmation_email(order).deliver - end.to change{ StandingOrderMailer.deliveries.count }.by(1) + SubscriptionMailer.confirmation_email(order).deliver + end.to change{ SubscriptionMailer.deliveries.count }.by(1) end it "sends the email" do - body = StandingOrderMailer.deliveries.last.body.encoded + body = SubscriptionMailer.deliveries.last.body.encoded expect(body).to include "This order was automatically placed for you" expect(body).to include "href=\"#{spree.order_url(order)}\"" end end describe "empty order notification" do - let(:standing_order) { create(:standing_order, with_items: true) } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order) } + let(:subscription) { create(:subscription, with_items: true) } + let(:proxy_order) { create(:proxy_order, subscription: subscription) } let!(:order) { proxy_order.initialise_order! } before do expect do - StandingOrderMailer.empty_email(order, {}).deliver - end.to change{ StandingOrderMailer.deliveries.count }.by(1) + SubscriptionMailer.empty_email(order, {}).deliver + end.to change{ SubscriptionMailer.deliveries.count }.by(1) end it "sends the email" do - body = StandingOrderMailer.deliveries.last.body.encoded + body = SubscriptionMailer.deliveries.last.body.encoded expect(body).to include "We tried to place a new order with" expect(body).to include "Unfortunately, none of products that you ordered were available" end end describe "failed payment notification" do - let(:standing_order) { create(:standing_order, with_items: true) } - let(:proxy_order) { create(:proxy_order, standing_order: standing_order) } + let(:subscription) { create(:subscription, with_items: true) } + let(:proxy_order) { create(:proxy_order, subscription: subscription) } let!(:order) { proxy_order.initialise_order! } before do order.errors.add(:base, "This is a payment failure error") expect do - StandingOrderMailer.failed_payment_email(order).deliver - end.to change{ StandingOrderMailer.deliveries.count }.by(1) + SubscriptionMailer.failed_payment_email(order).deliver + end.to change{ SubscriptionMailer.deliveries.count }.by(1) end it "sends the email" do - body = strip_tags(StandingOrderMailer.deliveries.last.body.encoded) + body = strip_tags(SubscriptionMailer.deliveries.last.body.encoded) expect(body).to include I18n.t("email_so_failed_payment_intro_html") - explainer = I18n.t("email_so_failed_payment_explainer_html", distributor: standing_order.shop.name) + explainer = I18n.t("email_so_failed_payment_explainer_html", distributor: subscription.shop.name) expect(body).to include strip_tags(explainer) - details = I18n.t("email_so_failed_payment_details_html", distributor: standing_order.shop.name) + details = I18n.t("email_so_failed_payment_details_html", distributor: subscription.shop.name) expect(body).to include strip_tags(details) expect(body).to include "This is a payment failure error" end @@ -107,17 +107,17 @@ describe StandingOrderMailer do describe "order placement summary" do let!(:shop) { create(:enterprise) } let!(:summary) { double(:summary, shop_id: shop.id) } - let(:body) { strip_tags(StandingOrderMailer.deliveries.last.body.encoded) } - let(:scope) { "standing_order_mailer" } + let(:body) { strip_tags(SubscriptionMailer.deliveries.last.body.encoded) } + let(:scope) { "subscription_mailer" } before { allow(summary).to receive(:unrecorded_ids) { [] } } - context "when no issues were encountered while processing standing orders" do + context "when no issues were encountered while processing subscriptions" do before do allow(summary).to receive(:order_count) { 37 } allow(summary).to receive(:issue_count) { 0 } allow(summary).to receive(:issues) { {} } - StandingOrderMailer.placement_summary_email(summary).deliver + SubscriptionMailer.placement_summary_email(summary).deliver end it "sends the email, which notifies the enterprise that all orders were successfully processed" do @@ -128,7 +128,7 @@ describe StandingOrderMailer do end end - context "when some issues were encountered while processing standing orders" do + context "when some issues were encountered while processing subscriptions" do let(:order1) { double(:order, id: 1, number: "R123456", to_s: "R123456") } let(:order2) { double(:order, id: 2, number: "R654321", to_s: "R654321") } @@ -142,7 +142,7 @@ describe StandingOrderMailer do context "when no unrecorded issues are present" do it "sends the email, which notifies the enterprise that some issues were encountered" do - StandingOrderMailer.placement_summary_email(summary).deliver + SubscriptionMailer.placement_summary_email(summary).deliver expect(body).to include I18n.t("#{scope}.placement_summary_email.intro", shop: shop.name) expect(body).to include I18n.t("#{scope}.summary_overview.total", count: 37) expect(body).to include I18n.t("#{scope}.summary_overview.success_some", count: 35) @@ -170,7 +170,7 @@ describe StandingOrderMailer do it "sends the email, which notifies the enterprise that some issues were encountered" do expect(summary).to receive(:orders_affected_by).with(:other) { [order3, order4] } - StandingOrderMailer.placement_summary_email(summary).deliver + SubscriptionMailer.placement_summary_email(summary).deliver expect(body).to include I18n.t("#{scope}.summary_detail.processing.title", count: 2) expect(body).to include I18n.t("#{scope}.summary_detail.processing.explainer") expect(body).to include I18n.t("#{scope}.summary_detail.other.title", count: 2) @@ -183,7 +183,7 @@ describe StandingOrderMailer do end end - context "when no standing orders were processed successfully" do + context "when no subscriptions were processed successfully" do let(:order1) { double(:order, id: 1, number: "R123456", to_s: "R123456") } let(:order2) { double(:order, id: 2, number: "R654321", to_s: "R654321") } @@ -193,7 +193,7 @@ describe StandingOrderMailer do allow(summary).to receive(:issue_count) { 2 } allow(summary).to receive(:issues) { { changes: { 1 => nil, 2 => nil } } } allow(summary).to receive(:orders_affected_by) { [order1, order2] } - StandingOrderMailer.placement_summary_email(summary).deliver + SubscriptionMailer.placement_summary_email(summary).deliver end it "sends the email, which notifies the enterprise that some issues were encountered" do @@ -217,17 +217,17 @@ describe StandingOrderMailer do describe "order confirmation summary" do let!(:shop) { create(:enterprise) } let!(:summary) { double(:summary, shop_id: shop.id) } - let(:body) { strip_tags(StandingOrderMailer.deliveries.last.body.encoded) } - let(:scope) { "standing_order_mailer" } + let(:body) { strip_tags(SubscriptionMailer.deliveries.last.body.encoded) } + let(:scope) { "subscription_mailer" } before { allow(summary).to receive(:unrecorded_ids) { [] } } - context "when no issues were encountered while processing standing orders" do + context "when no issues were encountered while processing subscriptions" do before do allow(summary).to receive(:order_count) { 37 } allow(summary).to receive(:issue_count) { 0 } allow(summary).to receive(:issues) { {} } - StandingOrderMailer.confirmation_summary_email(summary).deliver + SubscriptionMailer.confirmation_summary_email(summary).deliver end it "sends the email, which notifies the enterprise that all orders were successfully processed" do @@ -238,7 +238,7 @@ describe StandingOrderMailer do end end - context "when some issues were encountered while processing standing orders" do + context "when some issues were encountered while processing subscriptions" do let(:order1) { double(:order, id: 1, number: "R123456", to_s: "R123456") } let(:order2) { double(:order, id: 2, number: "R654321", to_s: "R654321") } @@ -252,7 +252,7 @@ describe StandingOrderMailer do context "when no unrecorded issues are present" do it "sends the email, which notifies the enterprise that some issues were encountered" do - StandingOrderMailer.confirmation_summary_email(summary).deliver + SubscriptionMailer.confirmation_summary_email(summary).deliver expect(body).to include I18n.t("#{scope}.confirmation_summary_email.intro", shop: shop.name) expect(body).to include I18n.t("#{scope}.summary_overview.total", count: 37) expect(body).to include I18n.t("#{scope}.summary_overview.success_some", count: 35) @@ -280,7 +280,7 @@ describe StandingOrderMailer do it "sends the email, which notifies the enterprise that some issues were encountered" do expect(summary).to receive(:orders_affected_by).with(:other) { [order3, order4] } - StandingOrderMailer.confirmation_summary_email(summary).deliver + SubscriptionMailer.confirmation_summary_email(summary).deliver expect(body).to include I18n.t("#{scope}.summary_detail.failed_payment.title", count: 2) expect(body).to include I18n.t("#{scope}.summary_detail.failed_payment.explainer") expect(body).to include I18n.t("#{scope}.summary_detail.other.title", count: 2) @@ -293,7 +293,7 @@ describe StandingOrderMailer do end end - context "when no standing orders were processed successfully" do + context "when no subscriptions were processed successfully" do let(:order1) { double(:order, id: 1, number: "R123456", to_s: "R123456") } let(:order2) { double(:order, id: 2, number: "R654321", to_s: "R654321") } @@ -303,7 +303,7 @@ describe StandingOrderMailer do allow(summary).to receive(:issue_count) { 2 } allow(summary).to receive(:issues) { { changes: { 1 => nil, 2 => nil } } } allow(summary).to receive(:orders_affected_by) { [order1, order2] } - StandingOrderMailer.confirmation_summary_email(summary).deliver + SubscriptionMailer.confirmation_summary_email(summary).deliver end it "sends the email, which notifies the enterprise that some issues were encountered" do diff --git a/spec/models/column_preference_spec.rb b/spec/models/column_preference_spec.rb index b565d827c8..983d86185b 100644 --- a/spec/models/column_preference_spec.rb +++ b/spec/models/column_preference_spec.rb @@ -65,7 +65,7 @@ describe ColumnPreference, type: :model do let(:action_name) { "order_cycles_index" } context "and the user owns a standing-orders-enabled enterprise" do - let!(:enterprise) { create(:distributor_enterprise, enable_standing_orders: true) } + let!(:enterprise) { create(:distributor_enterprise, enable_subscriptions: true) } it "removes the schedules column from the defaults" do ColumnPreference.filter(default_preferences, enterprise.owner, action_name) @@ -74,7 +74,7 @@ describe ColumnPreference, type: :model do end context "and the user does not own a standing-orders-enabled enterprise" do - let!(:enterprise) { create(:distributor_enterprise, enable_standing_orders: false) } + let!(:enterprise) { create(:distributor_enterprise, enable_subscriptions: false) } it "removes the schedules column from the defaults" do ColumnPreference.filter(default_preferences, enterprise.owner, action_name) diff --git a/spec/models/proxy_order_spec.rb b/spec/models/proxy_order_spec.rb index 10512432a2..7ef3ad977a 100644 --- a/spec/models/proxy_order_spec.rb +++ b/spec/models/proxy_order_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' describe ProxyOrder, type: :model do describe "cancel" do let(:order_cycle) { create(:simple_order_cycle) } - let(:standing_order) { create(:standing_order) } + let(:subscription) { create(:subscription) } context "when the order cycle is not yet closed" do - let(:proxy_order) { create(:proxy_order, standing_order: standing_order, order: order, order_cycle: order_cycle) } + let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) } before { order_cycle.update_attributes(orders_open_at: 1.day.ago, orders_close_at: 3.days.from_now) } context "and an order has not been initialised" do @@ -44,7 +44,7 @@ describe ProxyOrder, type: :model do end context "when the order cycle is already closed" do - let(:proxy_order) { create(:proxy_order, standing_order: standing_order, order: order, order_cycle: order_cycle) } + let(:proxy_order) { create(:proxy_order, subscription: subscription, order: order, order_cycle: order_cycle) } before { order_cycle.update_attributes(orders_open_at: 3.days.ago, orders_close_at: 1.minute.ago) } context "and an order has not been initialised" do @@ -159,28 +159,28 @@ describe ProxyOrder, type: :model do describe "initialise_order!" do context "when the order has not already been initialised" do - let(:standing_order) { create(:standing_order, with_items: true) } - let!(:proxy_order) { create(:proxy_order, standing_order: standing_order) } + let(:subscription) { create(:subscription, with_items: true) } + let!(:proxy_order) { create(:proxy_order, subscription: subscription) } - it "builds a new order based the standing order" do + it "builds a new order based the subscription" do expect{ proxy_order.initialise_order! }.to change{ Spree::Order.count }.by(1) expect(proxy_order.reload.order).to be_a Spree::Order order = proxy_order.order - expect(order.line_items.count).to eq standing_order.standing_line_items.count - expect(order.customer).to eq standing_order.customer - expect(order.user).to eq standing_order.customer.user - expect(order.distributor).to eq standing_order.shop + expect(order.line_items.count).to eq subscription.standing_line_items.count + expect(order.customer).to eq subscription.customer + expect(order.user).to eq subscription.customer.user + expect(order.distributor).to eq subscription.shop expect(order.order_cycle).to eq proxy_order.order_cycle - expect(order.shipping_method).to eq standing_order.shipping_method - expect(order.shipments.first.shipping_method).to eq standing_order.shipping_method - expect(order.payments.first.payment_method).to eq standing_order.payment_method - expect(order.bill_address).to eq standing_order.bill_address - expect(order.ship_address).to eq standing_order.ship_address + expect(order.shipping_method).to eq subscription.shipping_method + expect(order.shipments.first.shipping_method).to eq subscription.shipping_method + expect(order.payments.first.payment_method).to eq subscription.payment_method + expect(order.bill_address).to eq subscription.bill_address + expect(order.ship_address).to eq subscription.ship_address expect(order.complete?).to be false end context "when a requested quantity is greater than available stock" do - let(:sli) { standing_order.standing_line_items.first } + let(:sli) { subscription.standing_line_items.first } let(:variant) { sli.variant } before do @@ -198,7 +198,7 @@ describe ProxyOrder, type: :model do context "when the customer does not have a user associated with it" do before do - standing_order.customer.update_attribute(:user_id, nil) + subscription.customer.update_attribute(:user_id, nil) end it "initialises the order without a user_id" do diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 8e7180313b..cfd7f0bba0 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -573,7 +573,7 @@ describe Spree::Order do end.to_not enqueue_job ConfirmOrderJob end - it "does not send confirmation emails when the order belongs to a standing order" do + it "does not send confirmation emails when the order belongs to a subscription" do create(:proxy_order, order: order) expect do @@ -794,13 +794,13 @@ describe Spree::Order do let!(:order) { create(:order ) } let!(:payment) { create(:payment, order: order, state: 'checkout') } - context "when the order is not a standing order" do + context "when the order is not a subscription" do it "returns the payments on the order" do expect(order.reload.pending_payments).to eq [payment] end end - context "when the order is a standing order" do + context "when the order is a subscription" do let!(:proxy_order) { create(:proxy_order, order: order) } let!(:order_cycle) { proxy_order.order_cycle } diff --git a/spec/models/standing_line_item_spec.rb b/spec/models/standing_line_item_spec.rb index 767a7c6a5f..7edc9e57a3 100644 --- a/spec/models/standing_line_item_spec.rb +++ b/spec/models/standing_line_item_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' describe StandingLineItem, model: true do describe "validations" do - it "requires a standing_order" do - expect(subject).to validate_presence_of :standing_order + it "requires a subscription" do + expect(subject).to validate_presence_of :subscription end it "requires a variant" do diff --git a/spec/models/subscription_spec.rb b/spec/models/subscription_spec.rb index 44ce77d2fd..015b6840f4 100644 --- a/spec/models/subscription_spec.rb +++ b/spec/models/subscription_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe StandingOrder, type: :model do +describe Subscription, type: :model do describe "associations" do it { expect(subject).to belong_to(:shop) } it { expect(subject).to belong_to(:customer) } @@ -17,34 +17,34 @@ describe StandingOrder, type: :model do end describe "cancel" do - let!(:standing_order) { create(:standing_order) } + let!(:subscription) { create(:subscription) } let!(:proxy_order1) { create(:proxy_order, order_cycle: create(:simple_order_cycle)) } let!(:proxy_order2) { create(:proxy_order, order_cycle: create(:simple_order_cycle)) } before do - allow(standing_order).to receive(:proxy_orders) { [proxy_order1, proxy_order2] } + allow(subscription).to receive(:proxy_orders) { [proxy_order1, proxy_order2] } end - context "when all standing order orders can be cancelled" do + context "when all subscription orders can be cancelled" do before { allow(proxy_order1).to receive(:cancel) { true } } before { allow(proxy_order2).to receive(:cancel) { true } } - it "marks the standing order as cancelled and calls #cancel on all proxy_orders" do - standing_order.cancel - expect(standing_order.reload.canceled_at).to be_within(5.seconds).of Time.zone.now + it "marks the subscription as cancelled and calls #cancel on all proxy_orders" do + subscription.cancel + expect(subscription.reload.canceled_at).to be_within(5.seconds).of Time.zone.now expect(proxy_order1).to have_received(:cancel) expect(proxy_order2).to have_received(:cancel) end end - context "when a standing order order cannot be cancelled" do + context "when a subscription order cannot be cancelled" do before { allow(proxy_order1).to receive(:cancel).and_raise("Some error") } before { allow(proxy_order2).to receive(:cancel) { true } } it "aborts the transaction" do - # ie. canceled_at remains as nil, #cancel not called on second standing order order - expect{ standing_order.cancel }.to raise_error "Some error" - expect(standing_order.reload.canceled_at).to be nil + # ie. canceled_at remains as nil, #cancel not called on second subscription order + expect{ subscription.cancel }.to raise_error "Some error" + expect(subscription.reload.canceled_at).to be nil expect(proxy_order1).to have_received(:cancel) expect(proxy_order2).to_not have_received(:cancel) end @@ -52,70 +52,70 @@ describe StandingOrder, type: :model do end describe "state" do - let(:standing_order) { StandingOrder.new } + let(:subscription) { Subscription.new } - context "when the standing order has been cancelled" do - before { allow(standing_order).to receive(:canceled_at) { Time.zone.now } } + context "when the subscription has been cancelled" do + before { allow(subscription).to receive(:canceled_at) { Time.zone.now } } it "returns 'canceled'" do - expect(standing_order.state).to eq 'canceled' + expect(subscription.state).to eq 'canceled' end end - context "when the standing order has not been cancelled" do - before { allow(standing_order).to receive(:canceled_at) { nil } } + context "when the subscription has not been cancelled" do + before { allow(subscription).to receive(:canceled_at) { nil } } - context "and the standing order has been paused" do - before { allow(standing_order).to receive(:paused_at) { Time.zone.now } } + context "and the subscription has been paused" do + before { allow(subscription).to receive(:paused_at) { Time.zone.now } } it "returns 'paused'" do - expect(standing_order.state).to eq 'paused' + expect(subscription.state).to eq 'paused' end end - context "and the standing order has not been paused" do - before { allow(standing_order).to receive(:paused_at) { nil } } + context "and the subscription has not been paused" do + before { allow(subscription).to receive(:paused_at) { nil } } - context "and the standing order has no begins_at date" do - before { allow(standing_order).to receive(:begins_at) { nil } } + context "and the subscription has no begins_at date" do + before { allow(subscription).to receive(:begins_at) { nil } } it "returns 'pending'" do - expect(standing_order.state).to eq 'pending' + expect(subscription.state).to eq 'pending' end end - context "and the standing order has a begins_at date in the future" do - before { allow(standing_order).to receive(:begins_at) { 1.minute.from_now } } + context "and the subscription has a begins_at date in the future" do + before { allow(subscription).to receive(:begins_at) { 1.minute.from_now } } it "returns 'pending'" do - expect(standing_order.state).to eq 'pending' + expect(subscription.state).to eq 'pending' end end - context "and the standing order has a begins_at date in the past" do - before { allow(standing_order).to receive(:begins_at) { 1.minute.ago } } + context "and the subscription has a begins_at date in the past" do + before { allow(subscription).to receive(:begins_at) { 1.minute.ago } } - context "and the standing order has no ends_at date set" do - before { allow(standing_order).to receive(:ends_at) { nil } } + context "and the subscription has no ends_at date set" do + before { allow(subscription).to receive(:ends_at) { nil } } it "returns 'active'" do - expect(standing_order.state).to eq 'active' + expect(subscription.state).to eq 'active' end end - context "and the standing order has an ends_at date in the future" do - before { allow(standing_order).to receive(:ends_at) { 1.minute.from_now } } + context "and the subscription has an ends_at date in the future" do + before { allow(subscription).to receive(:ends_at) { 1.minute.from_now } } it "returns 'active'" do - expect(standing_order.state).to eq 'active' + expect(subscription.state).to eq 'active' end end - context "and the standing order has an ends_at date in the past" do - before { allow(standing_order).to receive(:ends_at) { 1.minute.ago } } + context "and the subscription has an ends_at date in the past" do + before { allow(subscription).to receive(:ends_at) { 1.minute.ago } } it "returns 'ended'" do - expect(standing_order.state).to eq 'ended' + expect(subscription.state).to eq 'ended' end end end diff --git a/spec/performance/proxy_order_syncer_spec.rb b/spec/performance/proxy_order_syncer_spec.rb index 3ec5962054..a466ca6c56 100644 --- a/spec/performance/proxy_order_syncer_spec.rb +++ b/spec/performance/proxy_order_syncer_spec.rb @@ -11,19 +11,19 @@ module OpenFoodNetwork end end - let!(:standing_orders) do + let!(:subscriptions) do Array.new(150) do |_i| - create(:standing_order, schedule: schedule, begins_at: start, ends_at: start + 10.days) + create(:subscription, schedule: schedule, begins_at: start, ends_at: start + 10.days) end - StandingOrder.where(schedule_id: schedule) + Subscription.where(schedule_id: schedule) end context "measuring performance for initialisation" do - it "reports the average run time for adding 10 OCs to 150 standing orders" do + it "reports the average run time for adding 10 OCs to 150 subscriptions" do expect(ProxyOrder.count).to be 0 times = [] 10.times do - syncer = ProxyOrderSyncer.new(standing_orders.reload) + syncer = ProxyOrderSyncer.new(subscriptions.reload) t1 = Time.zone.now syncer.sync! @@ -40,14 +40,14 @@ module OpenFoodNetwork end context "measuring performance for removal" do - it "reports the average run time for removing 8 OCs from 150 standing orders" do + it "reports the average run time for removing 8 OCs from 150 subscriptions" do times = [] 10.times do - syncer = ProxyOrderSyncer.new(standing_orders.reload) + syncer = ProxyOrderSyncer.new(subscriptions.reload) syncer.sync! expect(ProxyOrder.count).to be 1500 - standing_orders.update_all(begins_at: start + 8.days + 1.minute) - syncer = ProxyOrderSyncer.new(standing_orders.reload) + subscriptions.update_all(begins_at: start + 8.days + 1.minute) + syncer = ProxyOrderSyncer.new(subscriptions.reload) t1 = Time.zone.now syncer.sync! @@ -57,7 +57,7 @@ module OpenFoodNetwork puts diff.round(2) expect(ProxyOrder.count).to be 300 - standing_orders.update_all(begins_at: start) + subscriptions.update_all(begins_at: start) end puts "AVG: #{(times.sum / times.count).round(2)}" end diff --git a/spec/services/order_syncer_spec.rb b/spec/services/order_syncer_spec.rb index a495377954..51eaeb2508 100644 --- a/spec/services/order_syncer_spec.rb +++ b/spec/services/order_syncer_spec.rb @@ -1,45 +1,45 @@ describe OrderSyncer do describe "updating the shipping method" do - let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) } - let(:order) { standing_order.proxy_orders.first.initialise_order! } - let(:shipping_method) { standing_order.shipping_method } - let(:new_shipping_method) { create(:shipping_method, distributors: [standing_order.shop]) } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) } + let(:order) { subscription.proxy_orders.first.initialise_order! } + let(:shipping_method) { subscription.shipping_method } + let(:new_shipping_method) { create(:shipping_method, distributors: [subscription.shop]) } + let(:syncer) { OrderSyncer.new(subscription) } - context "when the shipping method on an order is the same as the standing order" do + context "when the shipping method on an order is the same as the subscription" do let(:params) { { shipping_method_id: new_shipping_method.id } } it "updates the shipping_method on the order and on shipments" do expect(order.shipments.first.shipping_method_id_was).to eq shipping_method.id - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(order.reload.shipping_method).to eq new_shipping_method expect(order.shipments.first.shipping_method).to eq new_shipping_method end end - context "when the shipping method on a shipment is not the same as the original shipping method on the standing order" do + context "when the shipping method on a shipment is not the same as the original shipping method on the subscription" do let(:params) { { shipping_method_id: new_shipping_method.id } } - context "when the shipping method on a shipment is the same as the new shipping method on the standing order" do + context "when the shipping method on a shipment is the same as the new shipping method on the subscription" do before do # Updating the shipping method on a shipment updates the shipping method on the order, # and vice-versa via logic in Spree's shipments controller. So updating both here mimics that # behaviour. order.shipments.first.update_attributes(shipping_method_id: new_shipping_method.id) order.update_attributes(shipping_method_id: new_shipping_method.id) - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true end - it "does not update the shipping_method on the standing order or on the pre-altered shipment" do + it "does not update the shipping_method on the subscription or on the pre-altered shipment" do expect(order.reload.shipping_method).to eq new_shipping_method expect(order.reload.shipments.first.shipping_method).to eq new_shipping_method expect(syncer.order_update_issues[order.id]).to be nil end end - context "when the shipping method on a shipment is not the same as the new shipping method on the standing order" do + context "when the shipping method on a shipment is not the same as the new shipping method on the subscription" do let(:changed_shipping_method) { create(:shipping_method) } before do @@ -48,11 +48,11 @@ describe OrderSyncer do # behaviour. order.shipments.first.update_attributes(shipping_method_id: changed_shipping_method.id) order.update_attributes(shipping_method_id: changed_shipping_method.id) - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true end - it "does not update the shipping_method on the standing order or on the pre-altered shipment" do + it "does not update the shipping_method on the subscription or on the pre-altered shipment" do expect(order.reload.shipping_method).to eq changed_shipping_method expect(order.reload.shipments.first.shipping_method).to eq changed_shipping_method expect(syncer.order_update_issues[order.id]).to include "Shipping Method" @@ -62,20 +62,20 @@ describe OrderSyncer do end describe "changing the payment method" do - let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) } - let(:order) { standing_order.proxy_orders.first.initialise_order! } - let(:payment_method) { standing_order.payment_method } - let(:new_payment_method) { create(:payment_method, distributors: [standing_order.shop]) } + let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) } + let(:order) { subscription.proxy_orders.first.initialise_order! } + let(:payment_method) { subscription.payment_method } + let(:new_payment_method) { create(:payment_method, distributors: [subscription.shop]) } let(:invalid_payment_method) { create(:payment_method, distributors: [create(:enterprise)]) } - let(:bogus_payment_method) { create(:bogus_payment_method, distributors: [standing_order.shop]) } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:bogus_payment_method) { create(:bogus_payment_method, distributors: [subscription.shop]) } + let(:syncer) { OrderSyncer.new(subscription) } - context "when the payment method on an order is the same as the standing order" do + context "when the payment method on an order is the same as the subscription" do let(:params) { { payment_method_id: new_payment_method.id } } it "voids existing payments and creates a new payment with the relevant payment method" do expect(order.payments.reload.first.payment_method).to eq payment_method - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true payments = order.reload.payments expect(payments.count).to be 2 @@ -86,13 +86,13 @@ describe OrderSyncer do end end - context "when the payment method on a payment is not the same as the standing order" do + context "when the payment method on a payment is not the same as the subscription" do let(:params) { { payment_method_id: new_payment_method.id } } - context "when the payment method on a payment is the same as the original payment method on the standing order" do + context "when the payment method on a payment is the same as the original payment method on the subscription" do before do order.payments.first.update_attribute(:payment_method_id, new_payment_method.id) - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true end @@ -104,12 +104,12 @@ describe OrderSyncer do end end - context "when the payment method on a shipment is not the same as the original payment method on the standing order" do + context "when the payment method on a shipment is not the same as the original payment method on the subscription" do let(:changed_payment_method) { create(:payment_method) } before do order.payments.first.update_attribute(:payment_method_id, changed_payment_method.id) - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true end @@ -124,20 +124,20 @@ describe OrderSyncer do end describe "changing the billing address" do - let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) } - let(:shipping_method) { standing_order.shipping_method } - let!(:order) { standing_order.proxy_orders.first.initialise_order! } - let!(:bill_address_attrs) { standing_order.bill_address.attributes } - let!(:ship_address_attrs) { standing_order.ship_address.attributes } + let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) } + let(:shipping_method) { subscription.shipping_method } + let!(:order) { subscription.proxy_orders.first.initialise_order! } + let!(:bill_address_attrs) { subscription.bill_address.attributes } + let!(:ship_address_attrs) { subscription.ship_address.attributes } let(:params) { { bill_address_attributes: { id: bill_address_attrs["id"], firstname: "Bill", address1: "123 abc st", phone: "1123581321" } } } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:syncer) { OrderSyncer.new(subscription) } context "when a ship address is not required" do before { shipping_method.update_attributes(require_ship_address: false) } - context "when the bill_address on the order matches that on the standing order" do + context "when the bill_address on the order matches that on the subscription" do it "updates all bill_address attrs and ship_address names + phone" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to_not include order.id order.reload; @@ -152,10 +152,10 @@ describe OrderSyncer do end end - context "when the bill_address on the order doesn't match that on the standing order" do + context "when the bill_address on the order doesn't match that on the subscription" do before { order.bill_address.update_attributes(firstname: "Jane") } it "does not update bill_address or ship_address on the order" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to include order.id order.reload; @@ -174,9 +174,9 @@ describe OrderSyncer do context "when a ship address is required" do before { shipping_method.update_attributes(require_ship_address: true) } - context "when the bill_address on the order matches that on the standing order" do + context "when the bill_address on the order matches that on the subscription" do it "only updates bill_address attrs" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to_not include order.id order.reload; @@ -191,11 +191,11 @@ describe OrderSyncer do end end - context "when the bill_address on the order doesn't match that on the standing order" do + context "when the bill_address on the order doesn't match that on the subscription" do before { order.bill_address.update_attributes(firstname: "Jane") } it "does not update bill_address or ship_address on the order" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to include order.id order.reload; @@ -213,19 +213,19 @@ describe OrderSyncer do end describe "changing the ship address" do - let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) } - let(:shipping_method) { standing_order.shipping_method } - let!(:order) { standing_order.proxy_orders.first.initialise_order! } - let!(:bill_address_attrs) { standing_order.bill_address.attributes } - let!(:ship_address_attrs) { standing_order.ship_address.attributes } + let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) } + let(:shipping_method) { subscription.shipping_method } + let!(:order) { subscription.proxy_orders.first.initialise_order! } + let!(:bill_address_attrs) { subscription.bill_address.attributes } + let!(:ship_address_attrs) { subscription.ship_address.attributes } let(:params) { { ship_address_attributes: { id: ship_address_attrs["id"], firstname: "Ship", address1: "123 abc st", phone: "1123581321" } } } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:syncer) { OrderSyncer.new(subscription) } context "when a ship address is not required" do before { shipping_method.update_attributes(require_ship_address: false) } it "does not change the ship address" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to_not include order.id order.reload; @@ -240,7 +240,7 @@ describe OrderSyncer do before { params.merge!(shipping_method_id: new_shipping_method.id) } it "updates ship_address attrs" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to_not include order.id order.reload; @@ -255,9 +255,9 @@ describe OrderSyncer do context "when a ship address is required" do before { shipping_method.update_attributes(require_ship_address: true) } - context "when the ship address on the order matches that on the standing order" do + context "when the ship address on the order matches that on the subscription" do it "updates ship_address attrs" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to_not include order.id order.reload; @@ -268,10 +268,10 @@ describe OrderSyncer do end end - context "when the ship address on the order doesn't match that on the standing order" do + context "when the ship address on the order doesn't match that on the subscription" do before { order.ship_address.update_attributes(firstname: "Jane") } it "does not update ship_address on the order" do - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(syncer.order_update_issues.keys).to include order.id order.reload; @@ -285,22 +285,22 @@ describe OrderSyncer do end describe "changing the quantity of a line item" do - let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) } - let(:order) { standing_order.proxy_orders.first.initialise_order! } - let(:sli) { standing_order.standing_line_items.first } + let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) } + let(:order) { subscription.proxy_orders.first.initialise_order! } + let(:sli) { subscription.standing_line_items.first } let(:variant) { sli.variant } before { variant.update_attribute(:count_on_hand, 2) } context "when quantity is within available stock" do let(:params) { { standing_line_items_attributes: [{ id: sli.id, quantity: 2}] } } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:syncer) { OrderSyncer.new(subscription) } it "updates the line_item quantities and totals on all orders" do expect(order.reload.total.to_f).to eq 59.97 - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true - line_items = Spree::LineItem.where(order_id: standing_order.orders, variant_id: sli.variant_id) + line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: sli.variant_id) expect(line_items.map(&:quantity)).to eq [2] expect(order.reload.total.to_f).to eq 79.96 end @@ -308,13 +308,13 @@ describe OrderSyncer do context "when quantity is greater than available stock" do let(:params) { { standing_line_items_attributes: [{ id: sli.id, quantity: 3}] } } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:syncer) { OrderSyncer.new(subscription) } it "updates the line_item quantities and totals on all orders" do expect(order.reload.total.to_f).to eq 59.97 - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true - line_items = Spree::LineItem.where(order_id: standing_order.orders, variant_id: sli.variant_id) + line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: sli.variant_id) expect(line_items.map(&:quantity)).to eq [3] expect(order.reload.total.to_f).to eq 99.95 end @@ -322,7 +322,7 @@ describe OrderSyncer do context "where the quantity of the item on an initialised order has already been changed" do let(:params) { { standing_line_items_attributes: [{ id: sli.id, quantity: 3}] } } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:syncer) { OrderSyncer.new(subscription) } let(:changed_line_item) { order.line_items.find_by_variant_id(sli.variant_id) } before { variant.update_attribute(:count_on_hand, 3) } @@ -332,7 +332,7 @@ describe OrderSyncer do it "does not change the quantity, and doesn't add the order to order_update_issues" do expect(order.reload.total.to_f).to eq 99.95 - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(changed_line_item.reload.quantity).to eq 3 expect(order.reload.total.to_f).to eq 99.95 @@ -345,7 +345,7 @@ describe OrderSyncer do it "does not change the quantity, and adds the order to order_update_issues" do expect(order.reload.total.to_f).to eq 79.96 - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true expect(changed_line_item.reload.quantity).to eq 2 expect(order.reload.total.to_f).to eq 79.96 @@ -356,35 +356,35 @@ describe OrderSyncer do end describe "adding a new line item" do - let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) } - let(:order) { standing_order.proxy_orders.first.initialise_order! } + let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) } + let(:order) { subscription.proxy_orders.first.initialise_order! } let(:variant) { create(:variant) } let(:params) { { standing_line_items_attributes: [{ id: nil, variant_id: variant.id, quantity: 1}] } } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:syncer) { OrderSyncer.new(subscription) } it "adds the line item and updates the total on all orders" do expect(order.reload.total.to_f).to eq 59.97 - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true - line_items = Spree::LineItem.where(order_id: standing_order.orders, variant_id: variant.id) + line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: variant.id) expect(line_items.map(&:quantity)).to eq [1] expect(order.reload.total.to_f).to eq 79.96 end end describe "removing an existing line item" do - let(:standing_order) { create(:standing_order, with_items: true, with_proxy_orders: true) } - let(:order) { standing_order.proxy_orders.first.initialise_order! } - let(:sli) { standing_order.standing_line_items.first } + let(:subscription) { create(:subscription, with_items: true, with_proxy_orders: true) } + let(:order) { subscription.proxy_orders.first.initialise_order! } + let(:sli) { subscription.standing_line_items.first } let(:variant) { sli.variant } let(:params) { { standing_line_items_attributes: [{ id: sli.id, _destroy: true }] } } - let(:syncer) { OrderSyncer.new(standing_order) } + let(:syncer) { OrderSyncer.new(subscription) } it "removes the line item and updates totals on all orders" do expect(order.reload.total.to_f).to eq 59.97 - standing_order.assign_attributes(params) + subscription.assign_attributes(params) expect(syncer.sync!).to be true - line_items = Spree::LineItem.where(order_id: standing_order.orders, variant_id: variant.id) + line_items = Spree::LineItem.where(order_id: subscription.orders, variant_id: variant.id) expect(line_items.count).to be 0 expect(order.reload.total.to_f).to eq 39.98 end diff --git a/spec/services/subscription_form_spec.rb b/spec/services/subscription_form_spec.rb index 47ca2ae879..2434c43c52 100644 --- a/spec/services/subscription_form_spec.rb +++ b/spec/services/subscription_form_spec.rb @@ -1,5 +1,5 @@ -describe StandingOrderForm do - describe "creating a new standing order" do +describe SubscriptionForm do + describe "creating a new subscription" do let!(:shop) { create(:distributor_enterprise) } let!(:customer) { create(:customer, enterprise: shop) } let!(:product1) { create(:product, supplier: shop) } @@ -21,7 +21,7 @@ describe StandingOrderForm do let!(:payment_method) { create(:payment_method, distributors: [shop]) } let!(:shipping_method) { create(:shipping_method, distributors: [shop]) } let!(:address) { create(:address) } - let(:standing_order) { StandingOrder.new } + let(:subscription) { Subscription.new } let!(:params) { { @@ -41,20 +41,20 @@ describe StandingOrderForm do ] } } - let(:form) { StandingOrderForm.new(standing_order, params) } + let(:form) { SubscriptionForm.new(subscription, params) } it "creates orders for each order cycle in the schedule" do Spree::Config.set allow_backorders: false expect(form.save).to be true - expect(standing_order.proxy_orders.count).to be 2 + expect(subscription.proxy_orders.count).to be 2 # This order cycle has already closed, so no order is initialized - proxy_order1 = standing_order.proxy_orders.find_by_order_cycle_id(order_cycle1.id) + proxy_order1 = subscription.proxy_orders.find_by_order_cycle_id(order_cycle1.id) expect(proxy_order1).to be nil # Currently open order cycle, closing after begins_at and before ends_at - proxy_order2 = standing_order.proxy_orders.find_by_order_cycle_id(order_cycle2.id) + proxy_order2 = subscription.proxy_orders.find_by_order_cycle_id(order_cycle2.id) expect(proxy_order2).to be_a ProxyOrder order2 = proxy_order2.initialise_order! expect(order2.line_items.count).to be 3 @@ -69,7 +69,7 @@ describe StandingOrderForm do # Future order cycle, closing after begins_at and before ends_at # Adds line items for variants that aren't yet available from the order cycle - proxy_order3 = standing_order.proxy_orders.find_by_order_cycle_id(order_cycle3.id) + proxy_order3 = subscription.proxy_orders.find_by_order_cycle_id(order_cycle3.id) expect(proxy_order3).to be_a ProxyOrder order3 = proxy_order3.initialise_order! expect(order3).to be_a Spree::Order @@ -84,14 +84,14 @@ describe StandingOrderForm do expect(order3.completed?).to be false # Future order cycle closing after ends_at - proxy_order4 = standing_order.proxy_orders.find_by_order_cycle_id(order_cycle4.id) + proxy_order4 = subscription.proxy_orders.find_by_order_cycle_id(order_cycle4.id) expect(proxy_order4).to be nil end end describe "validating price_estimates on standing line items" do let(:params) { { } } - let(:form) { StandingOrderForm.new(nil, params) } + let(:form) { SubscriptionForm.new(nil, params) } context "when line_item params are present" do before { allow(form).to receive(:price_estimate_for) } diff --git a/spec/services/subscription_validator_spec.rb b/spec/services/subscription_validator_spec.rb index b648daf719..1f48eb2b01 100644 --- a/spec/services/subscription_validator_spec.rb +++ b/spec/services/subscription_validator_spec.rb @@ -1,25 +1,25 @@ -describe StandingOrderValidator do +describe SubscriptionValidator do let(:shop) { instance_double(Enterprise, name: "Shop") } describe "delegation" do - let(:standing_order) { create(:standing_order) } - let(:validator) { StandingOrderValidator.new(standing_order) } + let(:subscription) { create(:subscription) } + let(:validator) { SubscriptionValidator.new(subscription) } - it "delegates to standing_order" do - expect(validator.shop).to eq standing_order.shop - expect(validator.customer).to eq standing_order.customer - expect(validator.schedule).to eq standing_order.schedule - expect(validator.shipping_method).to eq standing_order.shipping_method - expect(validator.payment_method).to eq standing_order.payment_method - expect(validator.bill_address).to eq standing_order.bill_address - expect(validator.ship_address).to eq standing_order.ship_address - expect(validator.begins_at).to eq standing_order.begins_at - expect(validator.ends_at).to eq standing_order.ends_at + it "delegates to subscription" do + expect(validator.shop).to eq subscription.shop + expect(validator.customer).to eq subscription.customer + expect(validator.schedule).to eq subscription.schedule + expect(validator.shipping_method).to eq subscription.shipping_method + expect(validator.payment_method).to eq subscription.payment_method + expect(validator.bill_address).to eq subscription.bill_address + expect(validator.ship_address).to eq subscription.ship_address + expect(validator.begins_at).to eq subscription.begins_at + expect(validator.ends_at).to eq subscription.ends_at end end describe "validations" do - let(:standing_order_stubs) do + let(:subscription_stubs) do { shop: shop, customer: true, @@ -48,8 +48,8 @@ describe StandingOrderValidator do } end - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs) } - let(:validator) { StandingOrderValidator.new(standing_order) } + let(:subscription) { instance_double(Subscription, subscription_stubs) } + let(:validator) { SubscriptionValidator.new(subscription) } def stub_validations(validator, methods) methods.each do |name, value| @@ -58,11 +58,11 @@ describe StandingOrderValidator do end describe "shipping method validation" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:shipping_method)) } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:shipping_method)) } before { stub_validations(validator, validation_stubs.except(:shipping_method_allowed?)) } context "when no shipping method is present" do - before { expect(standing_order).to receive(:shipping_method).at_least(:once) { nil } } + before { expect(subscription).to receive(:shipping_method).at_least(:once) { nil } } it "adds an error and returns false" do expect(validator.valid?).to be false @@ -72,7 +72,7 @@ describe StandingOrderValidator do context "when a shipping method is present" do let(:shipping_method) { instance_double(Spree::ShippingMethod, distributors: [shop]) } - before { expect(standing_order).to receive(:shipping_method).at_least(:once) { shipping_method } } + before { expect(subscription).to receive(:shipping_method).at_least(:once) { shipping_method } } context "and the shipping method is not associated with the shop" do before { allow(shipping_method).to receive(:distributors) { [double(:enterprise)] } } @@ -95,11 +95,11 @@ describe StandingOrderValidator do end describe "payment method validation" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:payment_method)) } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:payment_method)) } before { stub_validations(validator, validation_stubs.except(:payment_method_allowed?)) } context "when no payment method is present" do - before { expect(standing_order).to receive(:payment_method).at_least(:once) { nil } } + before { expect(subscription).to receive(:payment_method).at_least(:once) { nil } } it "adds an error and returns false" do expect(validator.valid?).to be false @@ -109,7 +109,7 @@ describe StandingOrderValidator do context "when a payment method is present" do let(:payment_method) { instance_double(Spree::PaymentMethod, distributors: [shop]) } - before { expect(standing_order).to receive(:payment_method).at_least(:once) { payment_method } } + before { expect(subscription).to receive(:payment_method).at_least(:once) { payment_method } } context "and the payment method is not associated with the shop" do before { allow(payment_method).to receive(:distributors) { [double(:enterprise)] } } @@ -132,12 +132,12 @@ describe StandingOrderValidator do end describe "payment method type validation" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:payment_method)) } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:payment_method)) } before { stub_validations(validator, validation_stubs.except(:payment_method_type_allowed?)) } context "when a payment method is present" do let(:payment_method) { instance_double(Spree::PaymentMethod, distributors: [shop]) } - before { expect(standing_order).to receive(:payment_method).at_least(:once) { payment_method } } + before { expect(subscription).to receive(:payment_method).at_least(:once) { payment_method } } context "and the payment method type is not in the approved list" do before { allow(payment_method).to receive(:type) { "Blah" } } @@ -149,7 +149,7 @@ describe StandingOrderValidator do end context "and the payment method is in the approved list" do - let(:approved_type) { StandingOrder::ALLOWED_PAYMENT_METHOD_TYPES.first } + let(:approved_type) { Subscription::ALLOWED_PAYMENT_METHOD_TYPES.first } before { allow(payment_method).to receive(:type) { approved_type } } it "returns true" do @@ -161,9 +161,9 @@ describe StandingOrderValidator do end describe "dates" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:begins_at, :ends_at)) } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:begins_at, :ends_at)) } before { stub_validations(validator, validation_stubs.except(:ends_at_after_begins_at?)) } - before { expect(standing_order).to receive(:begins_at).at_least(:once) { begins_at } } + before { expect(subscription).to receive(:begins_at).at_least(:once) { begins_at } } context "when no begins_at is present" do let(:begins_at) { nil } @@ -176,7 +176,7 @@ describe StandingOrderValidator do context "when a start date is present" do let(:begins_at) { Time.zone.today } - before { expect(standing_order).to receive(:ends_at).at_least(:once) { ends_at } } + before { expect(subscription).to receive(:ends_at).at_least(:once) { ends_at } } context "when no ends_at is present" do let(:ends_at) { nil } @@ -215,9 +215,9 @@ describe StandingOrderValidator do describe "addresses" do before { stub_validations(validator, validation_stubs) } - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:bill_address, :ship_address)) } - before { expect(standing_order).to receive(:bill_address).at_least(:once) { bill_address } } - before { expect(standing_order).to receive(:ship_address).at_least(:once) { ship_address } } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:bill_address, :ship_address)) } + before { expect(subscription).to receive(:bill_address).at_least(:once) { bill_address } } + before { expect(subscription).to receive(:ship_address).at_least(:once) { ship_address } } context "when bill_address and ship_address are not present" do let(:bill_address) { nil } @@ -243,9 +243,9 @@ describe StandingOrderValidator do end describe "customer" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:customer)) } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:customer)) } before { stub_validations(validator, validation_stubs.except(:customer_allowed?)) } - before { expect(standing_order).to receive(:customer).at_least(:once) { customer } } + before { expect(subscription).to receive(:customer).at_least(:once) { customer } } context "when no customer is present" do let(:customer) { nil } @@ -280,9 +280,9 @@ describe StandingOrderValidator do end describe "schedule" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:schedule)) } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:schedule)) } before { stub_validations(validator, validation_stubs.except(:schedule_allowed?)) } - before { expect(standing_order).to receive(:schedule).at_least(:once) { schedule } } + before { expect(subscription).to receive(:schedule).at_least(:once) { schedule } } context "when no schedule is present" do let(:schedule) { nil } @@ -317,9 +317,9 @@ describe StandingOrderValidator do end describe "credit card" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs.except(:payment_method)) } + let(:subscription) { instance_double(Subscription, subscription_stubs.except(:payment_method)) } before { stub_validations(validator, validation_stubs.except(:credit_card_ok?)) } - before { expect(standing_order).to receive(:payment_method).at_least(:once) { payment_method } } + before { expect(subscription).to receive(:payment_method).at_least(:once) { payment_method } } context "when using a Check payment method" do let(:payment_method) { instance_double(Spree::PaymentMethod, type: "Spree::PaymentMethod::Check") } @@ -332,7 +332,7 @@ describe StandingOrderValidator do context "when using the StripeConnect payment gateway" do let(:payment_method) { instance_double(Spree::PaymentMethod, type: "Spree::Gateway::StripeConnect") } - before { expect(standing_order).to receive(:credit_card_id).at_least(:once) { credit_card_id } } + before { expect(subscription).to receive(:credit_card_id).at_least(:once) { credit_card_id } } context "when a credit card is not present" do let(:credit_card_id) { nil } @@ -345,7 +345,7 @@ describe StandingOrderValidator do context "when a credit card is present" do let(:credit_card_id) { 12 } - before { expect(standing_order).to receive(:customer).at_least(:once) { customer } } + before { expect(subscription).to receive(:customer).at_least(:once) { customer } } context "and the customer is not associated with a user" do let(:customer) { instance_double(Customer, user: nil) } @@ -382,9 +382,9 @@ describe StandingOrderValidator do end describe "standing line items" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs) } + let(:subscription) { instance_double(Subscription, subscription_stubs) } before { stub_validations(validator, validation_stubs.except(:standing_line_items_present?)) } - before { expect(standing_order).to receive(:standing_line_items).at_least(:once) { standing_line_items } } + before { expect(subscription).to receive(:standing_line_items).at_least(:once) { standing_line_items } } context "when no standing line items are present" do let(:standing_line_items) { [] } @@ -418,9 +418,9 @@ describe StandingOrderValidator do end describe "variant availability" do - let(:standing_order) { instance_double(StandingOrder, standing_order_stubs) } + let(:subscription) { instance_double(Subscription, subscription_stubs) } before { stub_validations(validator, validation_stubs.except(:requested_variants_available?)) } - before { expect(standing_order).to receive(:standing_line_items).at_least(:once) { standing_line_items } } + before { expect(subscription).to receive(:standing_line_items).at_least(:once) { standing_line_items } } context "when no standing line items are present" do let(:standing_line_items) { [] }