From d2f29b7d731eafbd93a4dd4eab964fdf57b35cea Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 14 Mar 2023 16:40:52 +0100 Subject: [PATCH 1/9] Some refactoring to avoid rubocop class too long warning --- app/helpers/admin/enterprises_helper.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index 25dae316f8..80aad564dd 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -23,6 +23,14 @@ module Admin show_enterprise_fees = can?(:manage_enterprise_fees, enterprise) && (is_shop || enterprise.is_primary_producer) + build_enterprise_side_menu_items(is_shop, show_properties, show_shipping_methods, + show_payment_methods, show_enterprise_fees) + end + + private + + def build_enterprise_side_menu_items(is_shop, show_properties, show_shipping_methods, + show_payment_methods, show_enterprise_fees) [ { name: 'primary_details', icon_class: "icon-home", show: true, selected: 'selected' }, { name: 'address', icon_class: "icon-map-marker", show: true }, From 3452864503731f9e471322af6976becc2dd78afb Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 14 Mar 2023 18:15:53 +0100 Subject: [PATCH 2/9] Add "white label" panel in enterprise settings page --- app/helpers/admin/enterprises_helper.rb | 3 ++- app/views/admin/enterprises/form/_white_label.html.haml | 0 config/locales/en.yml | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/enterprises/form/_white_label.html.haml diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index 80aad564dd..8e273a810f 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -49,7 +49,8 @@ module Admin { name: 'inventory_settings', icon_class: "icon-list-ol", show: is_shop }, { name: 'tag_rules', icon_class: "icon-random", show: is_shop }, { name: 'shop_preferences', icon_class: "icon-shopping-cart", show: is_shop }, - { name: 'users', icon_class: "icon-user", show: true } + { name: 'users', icon_class: "icon-user", show: true }, + { name: 'white_label', icon_class: "icon-leaf", show: true } ] end # rubocop:enable Metrics/MethodLength diff --git a/app/views/admin/enterprises/form/_white_label.html.haml b/app/views/admin/enterprises/form/_white_label.html.haml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/config/locales/en.yml b/config/locales/en.yml index 50b456fd18..aa0a45addf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1155,6 +1155,8 @@ en: net_value: Net Value add_new: Add New no_voucher_yet: No Vouchers yet + white_label: + legend: "White Label" actions: edit_profile: Settings properties: Properties @@ -1394,6 +1396,7 @@ en: shop_preferences: "Shop Preferences" users: "Users" vouchers: Vouchers + white_label: "White Label" enterprise_group: primary_details: "Primary Details" users: "Users" From c20ae0de1e284af9d126f788cc9d67be2474c6e3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 14 Mar 2023 18:16:21 +0100 Subject: [PATCH 3/9] Edit `hide_ofn_navigation` in 'white label' panel for an enterprise --- app/models/enterprise.rb | 1 + .../api/admin/enterprise_serializer.rb | 2 +- .../api/enterprise_shopfront_serializer.rb | 3 ++- .../permitted_attributes/enterprise.rb | 3 ++- .../enterprises/form/_white_label.html.haml | 6 +++++ config/locales/en.yml | 1 + spec/system/admin/enterprises_spec.rb | 27 +++++++++++++++++++ 7 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index a5d4fe6ff6..9a692dcc4d 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -30,6 +30,7 @@ class Enterprise < ApplicationRecord preference :shopfront_product_sorting_method, :string, default: "by_category" preference :invoice_order_by_supplier, :boolean, default: false preference :product_low_stock_display, :boolean, default: false + preference :hide_ofn_navigation, :boolean, default: false # Allow hubs to restrict visible variants to only those in their inventory preference :product_selection_from_inventory_only, :boolean, default: false diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index 2071024f3e..1e8a184910 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -14,7 +14,7 @@ module Api :logo, :promo_image, :terms_and_conditions, :terms_and_conditions_file_name, :terms_and_conditions_updated_at, :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, - :visible + :visible, :preferred_hide_ofn_navigation has_one :owner, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index ac0fed09f2..ab8b26bc67 100644 --- a/app/serializers/api/enterprise_shopfront_serializer.rb +++ b/app/serializers/api/enterprise_shopfront_serializer.rb @@ -9,7 +9,8 @@ module Api :instagram, :linkedin, :twitter, :facebook, :is_primary_producer, :is_distributor, :phone, :whatsapp_phone, :whatsapp_url, :visible, :email_address, :hash, :logo, :promo_image, :path, :category, :active, :producers, :orders_close_at, :hubs, - :taxons, :supplied_taxons, :pickup, :delivery, :preferred_product_low_stock_display + :taxons, :supplied_taxons, :pickup, :delivery, :preferred_product_low_stock_display, + :preferred_hide_ofn_navigation has_one :address, serializer: Api::AddressSerializer has_many :supplied_properties, serializer: Api::PropertySerializer diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index 5aff8fbb76..9904e88b23 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -34,7 +34,8 @@ module PermittedAttributes :preferred_shopfront_producer_order, :preferred_shopfront_order_cycle_order, :show_customer_names_to_suppliers, :preferred_shopfront_product_sorting_method, :preferred_invoice_order_by_supplier, - :preferred_product_low_stock_display + :preferred_product_low_stock_display, + :preferred_hide_ofn_navigation ] end end diff --git a/app/views/admin/enterprises/form/_white_label.html.haml b/app/views/admin/enterprises/form/_white_label.html.haml index e69de29bb2..892c91a34e 100644 --- a/app/views/admin/enterprises/form/_white_label.html.haml +++ b/app/views/admin/enterprises/form/_white_label.html.haml @@ -0,0 +1,6 @@ +.row + .three.columns.alpha + = f.label :preferred_hide_ofn_navigation, t('.hide_ofn_navigation') + .three.columns + = f.check_box :preferred_hide_ofn_navigation + diff --git a/config/locales/en.yml b/config/locales/en.yml index aa0a45addf..eb520908a0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1157,6 +1157,7 @@ en: no_voucher_yet: No Vouchers yet white_label: legend: "White Label" + hide_ofn_navigation: "Hide OFN navigation" actions: edit_profile: Settings properties: Properties diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index d377f51635..0265a1f32d 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -584,5 +584,32 @@ describe ' end end end + + context "white label settings" do + before do + visit edit_admin_enterprise_path(distributor1) + + within(".side_menu") do + click_link "White Label" + end + end + + it "set the hide_ofn_navigation preference for the current shop" do + check "Hide OFN navigation" + click_button 'Update' + expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.preferred_hide_ofn_navigation).to be true + + visit edit_admin_enterprise_path(distributor1) + within(".side_menu") do + click_link "White Label" + end + + uncheck "Hide OFN navigation" + click_button 'Update' + expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.preferred_hide_ofn_navigation).to be false + end + end end end From 348c1ff7da1972b84af3e0a29e01860e6a285721 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 15 Mar 2023 09:23:59 +0100 Subject: [PATCH 4/9] Hide the OFN navigation menu when distributor as set its preference Hide, when preference is true, for page: - shop - cart - checkout - order confirmation --- app/helpers/enterprises_helper.rb | 22 ++++ app/views/shared/menu/_large_menu.html.haml | 17 +-- spec/system/consumer/white_label_spec.rb | 134 ++++++++++++++++++++ 3 files changed, 165 insertions(+), 8 deletions(-) create mode 100644 spec/system/consumer/white_label_spec.rb diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 2f60c848b4..38c0aff325 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -87,4 +87,26 @@ module EnterprisesHelper main_app.producers_url end end + + def hide_ofn_navigation? + # if we are not on a shopfront, a cart page, checkout page or the order confirmation page + # then we should show the OFN navigation + # whatever the current distributor has set for the hide_ofn_navigation preference + return false unless current_distributor && current_page?(main_app.enterprise_shop_path(current_distributor)) || # shopfront + request.path.start_with?(main_app.checkout_path) || # checkout + current_page?(main_app.cart_path) || # cart + request.path.start_with?("/orders/") # order confirmation + + distributor = if request.path.start_with?("/orders/") + # if we are on an order confirmation page, + # we need to get the distributor from the order, not the current one + Spree::Order.find_by(number: params[:id]).distributor + else + current_distributor + end + + # if the current distributor has the hide_ofn_navigation preference set to true + # then we should hide the OFN navigation + distributor.preferred_hide_ofn_navigation + end end diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index d8cb828ca6..f9c36f4803 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -10,14 +10,15 @@ = t 'powered_by' %a{href: '/'} = t 'title' - %ul.nav-main-menu - - [*1..7].each do |menu_number| - - menu_name = "menu_#{menu_number}" - - if ContentConfig[menu_name].present? - %li - %a{href: t("#{menu_name}_url") } - %span.nav-primary - = t "#{menu_name}_title" + - unless hide_ofn_navigation? + %ul.nav-main-menu + - [*1..7].each do |menu_number| + - menu_name = "menu_#{menu_number}" + - if ContentConfig[menu_name].present? + %li + %a{href: t("#{menu_name}_url") } + %span.nav-primary + = t "#{menu_name}_title" %ul.nav-icons-menu - if OpenFoodNetwork::I18nConfig.selectable_locales.count > 1 = render 'shared/menu/language_selector' diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb new file mode 100644 index 0000000000..0b6c10a6b8 --- /dev/null +++ b/spec/system/consumer/white_label_spec.rb @@ -0,0 +1,134 @@ +# frozen_string_literal: true + +require 'system_helper' + +describe 'White label setting' do + include AuthenticationHelper + include ShopWorkflow + + let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } + let!(:shipping_method) { create(:shipping_method, distributors: [distributor]) } + let(:product) { + create(:taxed_product, supplier: create(:supplier_enterprise), price: 10, + zone: create(:zone_with_member), tax_rate_amount: 0.1) + } + let!(:order_cycle) { + create(:simple_order_cycle, distributors: [distributor], + coordinator: create(:distributor_enterprise), + variants: [product.variants.first]) + } + let!(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) } + + let(:ofn_navigation) { 'ul.nav-main-menu' } + + context "manage the hide_ofn_navigation preference" do + context "when the preference is set to true" do + before do + distributor.update_attribute(:preferred_hide_ofn_navigation, true) + end + + shared_examples "hides the OFN navigation when needed only" do + it "hides the OFN navigation when visiting the shop" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_no_selector ofn_navigation + end + + it "does not hide the OFN navigation when visiting root path" do + visit main_app.root_path + expect(page).to have_selector ofn_navigation + end + end + + context "without order or current distributor" do + it_behaves_like "hides the OFN navigation when needed only" + end + + context "when the user has an order ready to checkout" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + end + + shared_examples "hides the OFN navigation when needed only for the checkout" do + it_behaves_like "hides the OFN navigation when needed only" + + it "hides the OFN navigation when visiting cart path" do + visit main_app.cart_path + expect(page).to have_no_selector ofn_navigation + end + + it "hides the OFN navigation when visiting checkout path" do + visit checkout_path + expect(page).to have_content "Checkout now" + expect(page).to have_content "Order ready for " + expect(page).to have_no_selector ofn_navigation + end + end + + context "when the split checkout is disabled" do + it_behaves_like "hides the OFN navigation when needed only for the checkout" + end + + context "when the split checkout is enabled" do + before do + Flipper.enable(:split_checkout) + end + + it_behaves_like "hides the OFN navigation when needed only for the checkout" + end + end + + context "when the user has a complete order" do + let(:complete_order) { + create(:order_with_credit_payment, + user: nil, + email: "guest@user.com", + distributor: distributor, + order_cycle: order_cycle) + } + before do + set_order(complete_order) + end + + it "hides the OFN navigation when visiting the order confirmation page" do + visit order_path(complete_order, order_token: complete_order.token) + expect(page).to have_no_selector ofn_navigation + end + end + + context "when the user has a current distributor" do + before do + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(distributor) + end + + it_behaves_like "hides the OFN navigation when needed only" + end + end + + context "when the preference is set to false" do + before do + distributor.update_attribute(:preferred_hide_ofn_navigation, false) + set_order(order) + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(distributor) + end + + it "does not hide the OFN navigation when visiting the shop" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_selector ofn_navigation + end + + it "does not hide the OFN navigation when visiting root path" do + visit main_app.root_path + expect(page).to have_selector ofn_navigation + end + + it "does not hide the OFN navigation when visiting cart path" do + visit main_app.cart_path + expect(page).to have_selector ofn_navigation + end + end + end +end From 5279be4dc6b9ee59e5bc1fc14724c87ff73f57b8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 17 Mar 2023 10:09:33 +0100 Subject: [PATCH 5/9] Improve spec: visiting order confirmation with distributor Two cases: - the current distributor is the same than the order of the order confirmation page - the current distributor *is not* the same than the order of the order confirmation page (and has not set `hide_ofn_navigation` preference to `true`) --- spec/system/consumer/white_label_spec.rb | 28 +++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 0b6c10a6b8..ce1d52ab13 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -91,9 +91,31 @@ describe 'White label setting' do set_order(complete_order) end - it "hides the OFN navigation when visiting the order confirmation page" do - visit order_path(complete_order, order_token: complete_order.token) - expect(page).to have_no_selector ofn_navigation + shared_examples "hides the OFN navigation when needed only for the order confirmation" do + it "hides" do + visit order_path(complete_order, order_token: complete_order.token) + expect(page).to have_no_selector ofn_navigation + end + end + + context "when the current distributor is the distributor of the order" do + before do + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(distributor) + end + + it_behaves_like "hides the OFN navigation when needed only for the order confirmation" + end + + context "when the user has a current distributor that is not the distributor's order" do + let!(:another_distributor) { create(:distributor_enterprise) } + before do + another_distributor.update_attribute(:preferred_hide_ofn_navigation, false) + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(another_distributor) + end + + it_behaves_like "hides the OFN navigation when needed only for the order confirmation" end end From 4ad2a1a723cdca3d3754c8b605b17a36ec0618dc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 17 Mar 2023 10:58:56 +0100 Subject: [PATCH 6/9] Prefer a concern that set a variable instead of a global helper Therefor, for the right controllers, simply implements: ``` include WhiteLabel before_action :hide_ofn_navigation, only: [:show, :edit] ``` This is mort robust, since we're working in a controller level, not parsing URLs... --- app/controllers/checkout_controller.rb | 3 +++ app/controllers/concerns/white_label.rb | 22 +++++++++++++++++++ app/controllers/enterprises_controller.rb | 2 ++ app/controllers/split_checkout_controller.rb | 2 ++ app/controllers/spree/orders_controller.rb | 2 ++ app/helpers/enterprises_helper.rb | 22 ------------------- app/views/shared/menu/_large_menu.html.haml | 2 +- .../spree/orders_controller_spec.rb | 1 + 8 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 app/controllers/concerns/white_label.rb diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 48d5cf060a..2c8b7f7cfe 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -5,6 +5,7 @@ require 'open_food_network/address_finder' class CheckoutController < ::BaseController include OrderStockCheck include OrderCompletion + include WhiteLabel layout 'darkswarm' @@ -27,6 +28,8 @@ class CheckoutController < ::BaseController before_action :associate_user before_action :check_authorization + before_action :hide_ofn_navigation, only: :edit + helper 'spree/orders' def edit; end diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb new file mode 100644 index 0000000000..19c54741f8 --- /dev/null +++ b/app/controllers/concerns/white_label.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module WhiteLabel + extend ActiveSupport::Concern + include EnterprisesHelper + + def hide_ofn_navigation + # if the distributor has the hide_ofn_navigation preference set to true + # then we should hide the OFN navigation + @hide_ofn_navigation = distributor.preferred_hide_ofn_navigation + end + + private + + def distributor + return current_distributor unless request.path.start_with?("/orders/") + + # if we are on an order confirmation page, + # we need to get the distributor from the order, not the current one + Spree::Order.find_by(number: params[:id]).distributor + end +end diff --git a/app/controllers/enterprises_controller.rb b/app/controllers/enterprises_controller.rb index 2fc7f43b44..058c6528ed 100644 --- a/app/controllers/enterprises_controller.rb +++ b/app/controllers/enterprises_controller.rb @@ -7,6 +7,7 @@ class EnterprisesController < BaseController helper Spree::ProductsHelper include OrderCyclesHelper include SerializerHelper + include WhiteLabel protect_from_forgery except: :check_permalink @@ -14,6 +15,7 @@ class EnterprisesController < BaseController prepend_before_action :set_order_cycles, :require_distributor_chosen, :reset_order, only: :shop before_action :clean_permalink, only: :check_permalink + before_action :hide_ofn_navigation, only: :shop respond_to :js, only: :permalink_checker diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index e33bd0038b..c1a63c2c44 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -10,6 +10,7 @@ class SplitCheckoutController < ::BaseController include CheckoutCallbacks include OrderCompletion include CablecarResponses + include WhiteLabel helper 'terms_and_conditions' helper 'checkout' @@ -18,6 +19,7 @@ class SplitCheckoutController < ::BaseController helper OrderHelper before_action :set_checkout_redirect + before_action :hide_ofn_navigation, only: [:edit, :update] def edit redirect_to_step_based_on_order unless params[:step] diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 95e9390f9b..07d8fbb895 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -5,6 +5,7 @@ module Spree include OrderCyclesHelper include Rails.application.routes.url_helpers include CablecarResponses + include WhiteLabel layout 'darkswarm' @@ -22,6 +23,7 @@ module Spree prepend_before_action :require_distributor_chosen, only: :edit before_action :check_hub_ready_for_checkout, only: :edit before_action :check_at_least_one_line_item, only: :update + before_action :hide_ofn_navigation, only: [:show, :edit] def show @order = Spree::Order.find_by!(number: params[:id]) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 38c0aff325..2f60c848b4 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -87,26 +87,4 @@ module EnterprisesHelper main_app.producers_url end end - - def hide_ofn_navigation? - # if we are not on a shopfront, a cart page, checkout page or the order confirmation page - # then we should show the OFN navigation - # whatever the current distributor has set for the hide_ofn_navigation preference - return false unless current_distributor && current_page?(main_app.enterprise_shop_path(current_distributor)) || # shopfront - request.path.start_with?(main_app.checkout_path) || # checkout - current_page?(main_app.cart_path) || # cart - request.path.start_with?("/orders/") # order confirmation - - distributor = if request.path.start_with?("/orders/") - # if we are on an order confirmation page, - # we need to get the distributor from the order, not the current one - Spree::Order.find_by(number: params[:id]).distributor - else - current_distributor - end - - # if the current distributor has the hide_ofn_navigation preference set to true - # then we should hide the OFN navigation - distributor.preferred_hide_ofn_navigation - end end diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index f9c36f4803..ec64ecdcf5 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -10,7 +10,7 @@ = t 'powered_by' %a{href: '/'} = t 'title' - - unless hide_ofn_navigation? + - unless @hide_ofn_navigation %ul.nav-main-menu - [*1..7].each do |menu_number| - menu_name = "menu_#{menu_number}" diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index c6ce2a43e6..41da37c00f 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -91,6 +91,7 @@ describe Spree::OrdersController, type: :controller do it "redirects to shop when order is empty" do allow(controller).to receive(:current_distributor).and_return(distributor) + allow(distributor).to receive(:preferred_hide_ofn_navigation).and_return false allow(controller).to receive(:current_order_cycle).and_return(order_cycle) allow(controller).to receive(:current_order).and_return order allow(order).to receive_message_chain(:line_items, :empty?).and_return true From 4fa44e6c646978a4b4a668514bdd76efccdfc64f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 17 Mar 2023 11:38:13 +0100 Subject: [PATCH 7/9] Put the white label behind a feature toggle `white_label` + update specs as well + for admin section also --- app/controllers/concerns/white_label.rb | 2 + app/helpers/admin/enterprises_helper.rb | 9 +- lib/open_food_network/feature_toggle.rb | 3 + spec/system/admin/enterprises_spec.rb | 48 +++-- spec/system/consumer/white_label_spec.rb | 214 ++++++++++++----------- 5 files changed, 159 insertions(+), 117 deletions(-) diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 19c54741f8..5b9d23b96b 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -5,6 +5,8 @@ module WhiteLabel include EnterprisesHelper def hide_ofn_navigation + return false unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label) + # if the distributor has the hide_ofn_navigation preference set to true # then we should hide the OFN navigation @hide_ofn_navigation = distributor.preferred_hide_ofn_navigation diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index 8e273a810f..f36661544a 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -50,8 +50,13 @@ module Admin { name: 'tag_rules', icon_class: "icon-random", show: is_shop }, { name: 'shop_preferences', icon_class: "icon-shopping-cart", show: is_shop }, { name: 'users', icon_class: "icon-user", show: true }, - { name: 'white_label', icon_class: "icon-leaf", show: true } - ] + ] + [add_white_label_if_feature_activated].compact + end + + def add_white_label_if_feature_activated + return nil unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label) + + { name: 'white_label', icon_class: "icon-leaf", show: true } end # rubocop:enable Metrics/MethodLength end diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index ebebffb1de..b6a3048209 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -40,6 +40,9 @@ module OpenFoodNetwork "vouchers" => <<~DESC, Add voucher functionality. Voucher can be managed via Enterprise settings. DESC + "white_label" => <<~DESC, + Customize shopfront (shop, cart, checkout) and emails without OFN branding. + DESC }.freeze # Move your feature entry from CURRENT_FEATURES to RETIRED_FEATURES when diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 0265a1f32d..1ba51c6a65 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -586,29 +586,43 @@ describe ' end context "white label settings" do - before do - visit edit_admin_enterprise_path(distributor1) + context "when the feature is enabled" do + before do + Flipper.enable(:white_label) + visit edit_admin_enterprise_path(distributor1) - within(".side_menu") do - click_link "White Label" + within(".side_menu") do + click_link "White Label" + end + end + + it "set the hide_ofn_navigation preference for the current shop" do + check "Hide OFN navigation" + click_button 'Update' + expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.preferred_hide_ofn_navigation).to be true + + visit edit_admin_enterprise_path(distributor1) + within(".side_menu") do + click_link "White Label" + end + + uncheck "Hide OFN navigation" + click_button 'Update' + expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.preferred_hide_ofn_navigation).to be false end end - it "set the hide_ofn_navigation preference for the current shop" do - check "Hide OFN navigation" - click_button 'Update' - expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be true - - visit edit_admin_enterprise_path(distributor1) - within(".side_menu") do - click_link "White Label" + context "when the feature is disabled" do + before do + Flipper.disable(:white_label) + visit edit_admin_enterprise_path(distributor1) end - uncheck "Hide OFN navigation" - click_button 'Update' - expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be false + it "does not show the white label settings" do + expect(page).not_to have_link "White Label" + end end end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index ce1d52ab13..58aa0ff5af 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -21,136 +21,154 @@ describe 'White label setting' do let(:ofn_navigation) { 'ul.nav-main-menu' } - context "manage the hide_ofn_navigation preference" do - context "when the preference is set to true" do - before do - distributor.update_attribute(:preferred_hide_ofn_navigation, true) - end + shared_examples "does not hide the OFN navigation" do + it "does not hide the OFN navigation when visiting the shop" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_selector ofn_navigation + end - shared_examples "hides the OFN navigation when needed only" do - it "hides the OFN navigation when visiting the shop" do - visit main_app.enterprise_shop_path(distributor) - expect(page).to have_no_selector ofn_navigation - end + it "does not hide the OFN navigation when visiting root path" do + visit main_app.root_path + expect(page).to have_selector ofn_navigation + end - it "does not hide the OFN navigation when visiting root path" do - visit main_app.root_path - expect(page).to have_selector ofn_navigation - end - end + it "does not hide the OFN navigation when visiting cart path" do + visit main_app.cart_path + expect(page).to have_selector ofn_navigation + end + end - context "without order or current distributor" do - it_behaves_like "hides the OFN navigation when needed only" - end + context "when the white label feature is activated" do + before do + Flipper.enable(:white_label) + end - context "when the user has an order ready to checkout" do + context "manage the hide_ofn_navigation preference" do + context "when the preference is set to true" do before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) + distributor.update_attribute(:preferred_hide_ofn_navigation, true) end - shared_examples "hides the OFN navigation when needed only for the checkout" do + shared_examples "hides the OFN navigation when needed only" do + it "hides the OFN navigation when visiting the shop" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_no_selector ofn_navigation + end + + it "does not hide the OFN navigation when visiting root path" do + visit main_app.root_path + expect(page).to have_selector ofn_navigation + end + end + + context "without order or current distributor" do it_behaves_like "hides the OFN navigation when needed only" - - it "hides the OFN navigation when visiting cart path" do - visit main_app.cart_path - expect(page).to have_no_selector ofn_navigation - end - - it "hides the OFN navigation when visiting checkout path" do - visit checkout_path - expect(page).to have_content "Checkout now" - expect(page).to have_content "Order ready for " - expect(page).to have_no_selector ofn_navigation - end end - context "when the split checkout is disabled" do - it_behaves_like "hides the OFN navigation when needed only for the checkout" - end - - context "when the split checkout is enabled" do + context "when the user has an order ready to checkout" do before do - Flipper.enable(:split_checkout) + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) end - it_behaves_like "hides the OFN navigation when needed only for the checkout" - end - end + shared_examples "hides the OFN navigation when needed only for the checkout" do + it_behaves_like "hides the OFN navigation when needed only" - context "when the user has a complete order" do - let(:complete_order) { - create(:order_with_credit_payment, - user: nil, - email: "guest@user.com", - distributor: distributor, - order_cycle: order_cycle) - } - before do - set_order(complete_order) - end + it "hides the OFN navigation when visiting cart path" do + visit main_app.cart_path + expect(page).to have_no_selector ofn_navigation + end - shared_examples "hides the OFN navigation when needed only for the order confirmation" do - it "hides" do - visit order_path(complete_order, order_token: complete_order.token) - expect(page).to have_no_selector ofn_navigation + it "hides the OFN navigation when visiting checkout path" do + visit checkout_path + expect(page).to have_content "Checkout now" + expect(page).to have_content "Order ready for " + expect(page).to have_no_selector ofn_navigation + end + end + + context "when the split checkout is disabled" do + it_behaves_like "hides the OFN navigation when needed only for the checkout" + end + + context "when the split checkout is enabled" do + before do + Flipper.enable(:split_checkout) + end + + it_behaves_like "hides the OFN navigation when needed only for the checkout" end end - context "when the current distributor is the distributor of the order" do + context "when the user has a complete order" do + let(:complete_order) { + create(:order_with_credit_payment, + user: nil, + email: "guest@user.com", + distributor: distributor, + order_cycle: order_cycle) + } + before do + set_order(complete_order) + end + + shared_examples "hides the OFN navigation when needed only for the order confirmation" do + it "hides" do + visit order_path(complete_order, order_token: complete_order.token) + expect(page).to have_no_selector ofn_navigation + end + end + + context "when the current distributor is the distributor of the order" do + before do + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(distributor) + end + + it_behaves_like "hides the OFN navigation when needed only for the order confirmation" + end + + context "when the user has a current distributor that is not the distributor's order" do + let!(:another_distributor) { create(:distributor_enterprise) } + before do + another_distributor.update_attribute(:preferred_hide_ofn_navigation, false) + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(another_distributor) + end + + it_behaves_like "hides the OFN navigation when needed only for the order confirmation" + end + end + + context "when the user has a current distributor" do before do allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(distributor) end - it_behaves_like "hides the OFN navigation when needed only for the order confirmation" - end - - context "when the user has a current distributor that is not the distributor's order" do - let!(:another_distributor) { create(:distributor_enterprise) } - before do - another_distributor.update_attribute(:preferred_hide_ofn_navigation, false) - allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). - and_return(another_distributor) - end - - it_behaves_like "hides the OFN navigation when needed only for the order confirmation" + it_behaves_like "hides the OFN navigation when needed only" end end - context "when the user has a current distributor" do + context "when the preference is set to false" do before do + distributor.update_attribute(:preferred_hide_ofn_navigation, false) + set_order(order) allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(distributor) end - it_behaves_like "hides the OFN navigation when needed only" - end - end - - context "when the preference is set to false" do - before do - distributor.update_attribute(:preferred_hide_ofn_navigation, false) - set_order(order) - allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). - and_return(distributor) - end - - it "does not hide the OFN navigation when visiting the shop" do - visit main_app.enterprise_shop_path(distributor) - expect(page).to have_selector ofn_navigation - end - - it "does not hide the OFN navigation when visiting root path" do - visit main_app.root_path - expect(page).to have_selector ofn_navigation - end - - it "does not hide the OFN navigation when visiting cart path" do - visit main_app.cart_path - expect(page).to have_selector ofn_navigation + it_behaves_like "does not hide the OFN navigation" end end end + + context "when the white label feature is deactivated" do + before do + Flipper.disable(:white_label) + end + + it_behaves_like "does not hide the OFN navigation" + end end From dd9fec58a46d8db5e32ae701cc3af83599330d33 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 20 Mar 2023 09:07:42 +0100 Subject: [PATCH 8/9] Instead of parsing URLs pass order through method for Orders Ctrl Use methods for before_actions Maybe we should for hide_of_navigation too, but a name 'hide_ofn_navigation_for_order_distributor' seemed unhelpful.. --- app/controllers/concerns/white_label.rb | 12 +----------- app/controllers/spree/orders_controller.rb | 15 ++++++++++----- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 5b9d23b96b..575fa68d25 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -4,21 +4,11 @@ module WhiteLabel extend ActiveSupport::Concern include EnterprisesHelper - def hide_ofn_navigation + def hide_ofn_navigation(distributor = current_distributor) return false unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label) # if the distributor has the hide_ofn_navigation preference set to true # then we should hide the OFN navigation @hide_ofn_navigation = distributor.preferred_hide_ofn_navigation end - - private - - def distributor - return current_distributor unless request.path.start_with?("/orders/") - - # if we are on an order confirmation page, - # we need to get the distributor from the order, not the current one - Spree::Order.find_by(number: params[:id]).distributor - end end diff --git a/app/controllers/spree/orders_controller.rb b/app/controllers/spree/orders_controller.rb index 07d8fbb895..e0a8d2281b 100644 --- a/app/controllers/spree/orders_controller.rb +++ b/app/controllers/spree/orders_controller.rb @@ -15,7 +15,8 @@ module Spree respond_to :html, :json before_action :check_authorization - before_action :set_current_order, only: :update + before_action :set_order_from_params, only: :show + before_action :set_current_order, only: [:edit, :update] before_action :filter_order_params, only: :update prepend_before_action :require_order_authentication, only: :show @@ -23,12 +24,13 @@ module Spree prepend_before_action :require_distributor_chosen, only: :edit before_action :check_hub_ready_for_checkout, only: :edit before_action :check_at_least_one_line_item, only: :update - before_action :hide_ofn_navigation, only: [:show, :edit] - def show - @order = Spree::Order.find_by!(number: params[:id]) + before_action only: [:show, :edit] do + hide_ofn_navigation(@order.distributor) end + def show; end + def empty if @order = current_order @order.empty! @@ -39,7 +41,6 @@ module Spree # Patching to redirect to shop if order is empty def edit - @order = current_order(true) @insufficient_stock_lines = @order.insufficient_stock_lines @unavailable_order_variants = OrderCycleDistributedVariants. new(current_order_cycle, current_distributor).unavailable_order_variants(@order) @@ -108,6 +109,10 @@ module Spree private + def set_order_from_params + @order = Spree::Order.find_by!(number: params[:id]) + end + def set_current_order @order = current_order(true) end From 89036db666d37cc40f876d5534470f9dbb08bea9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 29 Mar 2023 11:20:56 +0200 Subject: [PATCH 9/9] Do not use a preference, but create a new column for hide_ofn_navigation --- app/controllers/concerns/white_label.rb | 2 +- app/models/enterprise.rb | 1 - app/serializers/api/admin/enterprise_serializer.rb | 2 +- app/serializers/api/enterprise_shopfront_serializer.rb | 2 +- app/services/permitted_attributes/enterprise.rb | 2 +- app/views/admin/enterprises/form/_white_label.html.haml | 4 ++-- ...20230329080357_add_hide_ofn_navigation_to_enterprises.rb | 5 +++++ db/schema.rb | 3 ++- spec/controllers/spree/orders_controller_spec.rb | 2 +- spec/system/admin/enterprises_spec.rb | 4 ++-- spec/system/consumer/white_label_spec.rb | 6 +++--- 11 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 575fa68d25..180d138237 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -9,6 +9,6 @@ module WhiteLabel # if the distributor has the hide_ofn_navigation preference set to true # then we should hide the OFN navigation - @hide_ofn_navigation = distributor.preferred_hide_ofn_navigation + @hide_ofn_navigation = distributor.hide_ofn_navigation end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 9a692dcc4d..a5d4fe6ff6 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -30,7 +30,6 @@ class Enterprise < ApplicationRecord preference :shopfront_product_sorting_method, :string, default: "by_category" preference :invoice_order_by_supplier, :boolean, default: false preference :product_low_stock_display, :boolean, default: false - preference :hide_ofn_navigation, :boolean, default: false # Allow hubs to restrict visible variants to only those in their inventory preference :product_selection_from_inventory_only, :boolean, default: false diff --git a/app/serializers/api/admin/enterprise_serializer.rb b/app/serializers/api/admin/enterprise_serializer.rb index 1e8a184910..9afed8e532 100644 --- a/app/serializers/api/admin/enterprise_serializer.rb +++ b/app/serializers/api/admin/enterprise_serializer.rb @@ -14,7 +14,7 @@ module Api :logo, :promo_image, :terms_and_conditions, :terms_and_conditions_file_name, :terms_and_conditions_updated_at, :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, - :visible, :preferred_hide_ofn_navigation + :visible, :hide_ofn_navigation has_one :owner, serializer: Api::Admin::UserSerializer has_many :users, serializer: Api::Admin::UserSerializer diff --git a/app/serializers/api/enterprise_shopfront_serializer.rb b/app/serializers/api/enterprise_shopfront_serializer.rb index ab8b26bc67..12ca4d1b79 100644 --- a/app/serializers/api/enterprise_shopfront_serializer.rb +++ b/app/serializers/api/enterprise_shopfront_serializer.rb @@ -10,7 +10,7 @@ module Api :phone, :whatsapp_phone, :whatsapp_url, :visible, :email_address, :hash, :logo, :promo_image, :path, :category, :active, :producers, :orders_close_at, :hubs, :taxons, :supplied_taxons, :pickup, :delivery, :preferred_product_low_stock_display, - :preferred_hide_ofn_navigation + :hide_ofn_navigation has_one :address, serializer: Api::AddressSerializer has_many :supplied_properties, serializer: Api::PropertySerializer diff --git a/app/services/permitted_attributes/enterprise.rb b/app/services/permitted_attributes/enterprise.rb index 9904e88b23..c72a24cfa7 100644 --- a/app/services/permitted_attributes/enterprise.rb +++ b/app/services/permitted_attributes/enterprise.rb @@ -35,7 +35,7 @@ module PermittedAttributes :show_customer_names_to_suppliers, :preferred_shopfront_product_sorting_method, :preferred_invoice_order_by_supplier, :preferred_product_low_stock_display, - :preferred_hide_ofn_navigation + :hide_ofn_navigation ] end end diff --git a/app/views/admin/enterprises/form/_white_label.html.haml b/app/views/admin/enterprises/form/_white_label.html.haml index 892c91a34e..b083ec7700 100644 --- a/app/views/admin/enterprises/form/_white_label.html.haml +++ b/app/views/admin/enterprises/form/_white_label.html.haml @@ -1,6 +1,6 @@ .row .three.columns.alpha - = f.label :preferred_hide_ofn_navigation, t('.hide_ofn_navigation') + = f.label :hide_ofn_navigation, t('.hide_ofn_navigation') .three.columns - = f.check_box :preferred_hide_ofn_navigation + = f.check_box :hide_ofn_navigation diff --git a/db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb b/db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb new file mode 100644 index 0000000000..3fd3906634 --- /dev/null +++ b/db/migrate/20230329080357_add_hide_ofn_navigation_to_enterprises.rb @@ -0,0 +1,5 @@ +class AddHideOfnNavigationToEnterprises < ActiveRecord::Migration[7.0] + def change + add_column :enterprises, :hide_ofn_navigation, :boolean, null: false, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 6e7f939670..04c2560ce1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_03_15_031807) do +ActiveRecord::Schema[7.0].define(version: 2023_03_29_080357) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -224,6 +224,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_15_031807) do t.boolean "show_customer_names_to_suppliers", default: false, null: false t.string "visible", limit: 255, default: "public", null: false t.string "whatsapp_phone", limit: 255 + t.boolean "hide_ofn_navigation", default: false, null: false t.index ["address_id"], name: "index_enterprises_on_address_id" t.index ["is_primary_producer", "sells"], name: "index_enterprises_on_is_primary_producer_and_sells" t.index ["name"], name: "index_enterprises_on_name", unique: true diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 41da37c00f..44b5873661 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -91,7 +91,7 @@ describe Spree::OrdersController, type: :controller do it "redirects to shop when order is empty" do allow(controller).to receive(:current_distributor).and_return(distributor) - allow(distributor).to receive(:preferred_hide_ofn_navigation).and_return false + allow(distributor).to receive(:hide_ofn_navigation).and_return false allow(controller).to receive(:current_order_cycle).and_return(order_cycle) allow(controller).to receive(:current_order).and_return order allow(order).to receive_message_chain(:line_items, :empty?).and_return true diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 1ba51c6a65..5613a6da02 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -600,7 +600,7 @@ describe ' check "Hide OFN navigation" click_button 'Update' expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be true + expect(distributor1.reload.hide_ofn_navigation).to be true visit edit_admin_enterprise_path(distributor1) within(".side_menu") do @@ -610,7 +610,7 @@ describe ' uncheck "Hide OFN navigation" click_button 'Update' expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be false + expect(distributor1.reload.hide_ofn_navigation).to be false end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 58aa0ff5af..24e930725d 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -46,7 +46,7 @@ describe 'White label setting' do context "manage the hide_ofn_navigation preference" do context "when the preference is set to true" do before do - distributor.update_attribute(:preferred_hide_ofn_navigation, true) + distributor.update_attribute(:hide_ofn_navigation, true) end shared_examples "hides the OFN navigation when needed only" do @@ -132,7 +132,7 @@ describe 'White label setting' do context "when the user has a current distributor that is not the distributor's order" do let!(:another_distributor) { create(:distributor_enterprise) } before do - another_distributor.update_attribute(:preferred_hide_ofn_navigation, false) + another_distributor.update_attribute(:hide_ofn_navigation, false) allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(another_distributor) end @@ -153,7 +153,7 @@ describe 'White label setting' do context "when the preference is set to false" do before do - distributor.update_attribute(:preferred_hide_ofn_navigation, false) + distributor.update_attribute(:hide_ofn_navigation, false) set_order(order) allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(distributor)