From d62908fd2d32b33872e0bae409a82e84696c9cb6 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 21 Mar 2019 10:06:15 +1100 Subject: [PATCH] Add spec for registration link on Spree pages The `registration_path` helper resolves to `/signup` in Spree controllers due to spree_auth_device > config > routes.rb. We worked around that in: https://github.com/openfoodfoundation/openfoodnetwork/pull/3174 Here we add a spec for this so that we can test more easily if we remove that workaround or detect it's accidental removal. --- .../spree/orders_controller_spec.rb | 39 ++++++++++++++++--- spec/features/consumer/shopping/cart_spec.rb | 11 ------ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index bf574a55bd..f8735a3290 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -116,7 +116,7 @@ describe Spree::OrdersController, type: :controller do expect(flash[:info]).to eq("The hub you have selected is temporarily closed for orders. Please try again later.") end - describe "when an item has insufficient stock" do + describe "when an item is in the cart" do let(:order) { subject.current_order(true) } let(:oc) { create(:simple_order_cycle, distributors: [d], variants: [variant]) } let(:d) { create(:distributor_enterprise, shipping_methods: [create(:shipping_method)], payment_methods: [create(:payment_method)]) } @@ -126,13 +126,40 @@ describe Spree::OrdersController, type: :controller do before do order.set_distribution! d, oc order.add_variant variant, 5 - variant.update_attributes! on_hand: 3 end - it "displays a flash message when we view the cart" do - spree_get :edit - expect(response.status).to eq 200 - expect(flash[:error]).to eq("An item in your cart has become unavailable.") + describe "the page" do + render_views + + pending "provides the right registration path" do + # We have an issue with the registration link within Spree controllers. + # The `registration_path` helper resolves to `/signup` due to + # spree_auth_device > config > routes.rb, but it should be `/register`. + # + # When this is true, we can use registration_path in views again. + expect(subject.registration_path).to eq registration_path + end + + it "shows the right registration link" do + # We fixed our view by hardcoding the link. + spree_registration_path = '/signup' + ofn_registration_path = '/register' + spree_get :edit + expect(response.body).to_not match spree_registration_path + expect(response.body).to match ofn_registration_path + end + end + + describe "when an item has insufficient stock" do + before do + variant.update_attributes! on_hand: 3 + end + + it "displays a flash message when we view the cart" do + spree_get :edit + expect(response.status).to eq 200 + expect(flash[:error]).to eq("An item in your cart has become unavailable.") + end end end end diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index fa1014b6af..09d4821f1c 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -20,17 +20,6 @@ feature "full-page cart", js: true do set_order order end - it "shows the right registration link" do - # We have an issue with the registration link within Spree controllers. - # The `registration_path` helper resolves to `/signup` due to - # spree_auth_device > config > routes.rb. This spec verifies that we have - # a solution to that problem. - add_product_to_cart order, product_with_fee - visit spree.cart_path - register_page = window_opened_by { click_link "Register here" } - within_window(register_page) { expect(page).to have_content "Welcome" } - end - describe "product description" do it "does not link to the product page" do add_product_to_cart order, product_with_fee, quantity: 2