diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index aecfe9c5fa..924b981ae7 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -91,6 +91,16 @@ RSpec.configure do |config| expectations.syntax = :expect end + config.before(:each, :feature) do |example| + feature = example.metadata[:feature].to_s + + unless OpenFoodNetwork::FeatureToggle::CURRENT_FEATURES.key?(feature) + raise "Unkown feature: #{feature}" + end + + Flipper.enable(feature) + end + # Enable caching in any specs tagged with `caching: true`. config.around(:each, :caching) do |example| caching = ActionController::Base.perform_caching diff --git a/spec/jobs/bulk_invoice_job_spec.rb b/spec/jobs/bulk_invoice_job_spec.rb index 55c26897c6..ace4234103 100644 --- a/spec/jobs/bulk_invoice_job_spec.rb +++ b/spec/jobs/bulk_invoice_job_spec.rb @@ -18,11 +18,7 @@ describe BulkInvoiceJob do end end - context "when invoices are enabled" do - before do - Flipper.enable(:invoices) - end - + context "when invoices are enabled", feature: :invoices do describe "#perform" do let!(:order1) { create(:shipped_order) } let!(:order2) { create(:order_with_line_items) } diff --git a/spec/lib/reports/sales_tax_totals_by_order_spec.rb b/spec/lib/reports/sales_tax_totals_by_order_spec.rb index 7fea0dfa12..83b46555df 100644 --- a/spec/lib/reports/sales_tax_totals_by_order_spec.rb +++ b/spec/lib/reports/sales_tax_totals_by_order_spec.rb @@ -105,7 +105,7 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do expect(tax_total).to eq(0.2 + 2) end - context "with a voucher" do + context "with a voucher", feature: :vouchers do let(:voucher) do create(:voucher_flat_rate, code: 'some_code', enterprise: order.distributor, amount: 10) end @@ -133,7 +133,7 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do expect(total).to eq(113.3 - 3.3) end - context "with a voucher" do + context "with a voucher", feature: :vouchers do let(:voucher) do create(:voucher_flat_rate, code: 'some_code', enterprise: order.distributor, amount: 10) end @@ -214,7 +214,7 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do create(:voucher_flat_rate, code: 'some_code', enterprise: order.distributor, amount: 10) end - it "adjusts total_excl_tax and tax with voucher tax" do + it "adjusts total_excl_tax and tax with voucher tax", feature: :vouchers do add_voucher(order, voucher) mock_voucher_adjustment_service(excluded_tax: -0.29) @@ -269,8 +269,6 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do end def add_voucher(order, voucher) - Flipper.enable :vouchers - # Add voucher to the order voucher.create_adjustment(voucher.code, order) VoucherAdjustmentsService.new(order).update diff --git a/spec/mailers/order_mailer_spec.rb b/spec/mailers/order_mailer_spec.rb index a9dabc395e..257b3fc904 100644 --- a/spec/mailers/order_mailer_spec.rb +++ b/spec/mailers/order_mailer_spec.rb @@ -248,10 +248,7 @@ describe Spree::OrderMailer do end end - context "When invoices feature is enabled" do - before do - Flipper.enable(:invoices) - end + context "When invoices feature is enabled", feature: :invoices do it "should call the invoice renderer with invoice's presenter as argument" do expect(generator).to receive(:generate_or_update_latest_invoice) expect(order).to receive(:invoices).and_return([invoice]) diff --git a/spec/reflexes/products_reflex_spec.rb b/spec/reflexes/products_reflex_spec.rb index 0672c46863..ba22d41b84 100644 --- a/spec/reflexes/products_reflex_spec.rb +++ b/spec/reflexes/products_reflex_spec.rb @@ -2,17 +2,12 @@ require "reflex_helper" -describe ProductsReflex, type: :reflex do +describe ProductsReflex, type: :reflex, feature: :admin_style_v3 do let(:current_user) { create(:admin_user) } # todo: set up an enterprise user to test permissions let(:context) { { url: admin_products_url, connection: { current_user: } } } - before do - # activate feature toggle admin_style_v3 to use new admin interface - Flipper.enable(:admin_style_v3) - end - describe '#fetch' do subject{ build_reflex(method_name: :fetch, **context) } diff --git a/spec/requests/admin/vouchers_spec.rb b/spec/requests/admin/vouchers_spec.rb index f3ae69d573..8ec34f28a1 100644 --- a/spec/requests/admin/vouchers_spec.rb +++ b/spec/requests/admin/vouchers_spec.rb @@ -2,13 +2,11 @@ require "spec_helper" -describe "/admin/enterprises/:enterprise_id/vouchers", type: :request do +describe "/admin/enterprises/:enterprise_id/vouchers", type: :request, feature: :vouchers do let(:enterprise) { create(:supplier_enterprise, name: "Feedme") } let(:enterprise_user) { create(:user, enterprise_limit: 1) } before do - Flipper.enable(:vouchers) - enterprise_user.enterprise_roles.build(enterprise:).save sign_in enterprise_user end diff --git a/spec/requests/api/v1/customers_spec.rb b/spec/requests/api/v1/customers_spec.rb index a4032d26af..1ca08263fe 100644 --- a/spec/requests/api/v1/customers_spec.rb +++ b/spec/requests/api/v1/customers_spec.rb @@ -2,7 +2,7 @@ require "swagger_helper" -describe "Customers", type: :request, swagger_doc: "v1.yaml" do +describe "Customers", type: :request, swagger_doc: "v1.yaml", feature: :api_v1 do let!(:enterprise1) { create(:enterprise, name: "The Farm") } let!(:enterprise2) { create(:enterprise) } let!(:enterprise3) { create(:enterprise) } @@ -21,7 +21,6 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do let!(:customer3) { create(:customer, enterprise: enterprise2, created_manually: true,) } before do - Flipper.enable(:api_v1) login_as enterprise1.owner end diff --git a/spec/services/order_available_shipping_methods_spec.rb b/spec/services/order_available_shipping_methods_spec.rb index b1b687cb9d..57b2ff3535 100644 --- a/spec/services/order_available_shipping_methods_spec.rb +++ b/spec/services/order_available_shipping_methods_spec.rb @@ -215,7 +215,7 @@ describe OrderAvailableShippingMethods do end end - context "when certain shipping categories are required" do + context "when certain shipping categories are required", feature: :match_shipping_categories do subject { OrderAvailableShippingMethods.new(order) } let(:order) { build(:order, distributor:, order_cycle: oc) } let(:oc) { create(:order_cycle) } @@ -232,8 +232,6 @@ describe OrderAvailableShippingMethods do before { standard_shipping cooled_shipping - - Flipper.enable(:match_shipping_categories) } it "provides all shipping methods for an empty order" do diff --git a/spec/system/admin/invoice_print_spec.rb b/spec/system/admin/invoice_print_spec.rb index 3e713c38ba..24649c98ce 100644 --- a/spec/system/admin/invoice_print_spec.rb +++ b/spec/system/admin/invoice_print_spec.rb @@ -136,9 +136,6 @@ describe ' end context "when invoice feature is not enabled" do - before do - Flipper.disable(:invoices) - end it_behaves_like "contains right Payment Description at Checkout information" it_behaves_like "Check display on each invoice: legacy and alternative", false it_behaves_like "Check display on each invoice: legacy and alternative", true @@ -442,10 +439,7 @@ describe ' end end end - context "when invoice feature is enabled" do - before do - Flipper.enable(:invoices) - end + context "when invoice feature is enabled", feature: :invoices do it_behaves_like "contains right Payment Description at Checkout information" it_behaves_like "Check display on each invoice: legacy and alternative", false it_behaves_like "Check display on each invoice: legacy and alternative", true diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index dbe544c167..1d586e3e2d 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -1042,9 +1042,8 @@ describe ' end end - describe "Legal Invoices" do + describe "Legal Invoices", feature: :invoices do before do - Flipper.enable(:invoices) login_as user end diff --git a/spec/system/admin/orders/invoices_spec.rb b/spec/system/admin/orders/invoices_spec.rb index 8440ad83f4..da7086ebf2 100644 --- a/spec/system/admin/orders/invoices_spec.rb +++ b/spec/system/admin/orders/invoices_spec.rb @@ -5,7 +5,7 @@ require 'system_helper' describe ' As an administrator I want to manage invoices for an order -' do +', feature: :invoices do include WebHelper include AuthenticationHelper @@ -28,7 +28,6 @@ describe ' let(:customer) { order.customer } before do - Flipper.enable(:invoices) order.finalize! login_as_admin visit spree.edit_admin_order_path(order) diff --git a/spec/system/admin/products_v3/products_spec.rb b/spec/system/admin/products_v3/products_spec.rb index 5316a3118f..14a59ebd3e 100644 --- a/spec/system/admin/products_v3/products_spec.rb +++ b/spec/system/admin/products_v3/products_spec.rb @@ -2,14 +2,12 @@ require "system_helper" -describe 'As an admin, I can see the new product page' do +describe 'As an admin, I can see the new product page', feature: :admin_style_v3 do include WebHelper include AuthenticationHelper include FileHelper before do - # activate feature toggle admin_style_v3 to use new admin interface - Flipper.enable(:admin_style_v3) login_as_admin end diff --git a/spec/system/admin/reports_spec.rb b/spec/system/admin/reports_spec.rb index 2547e59c2f..5616575110 100644 --- a/spec/system/admin/reports_spec.rb +++ b/spec/system/admin/reports_spec.rb @@ -31,11 +31,7 @@ describe ' end end - describe "Background processing" do - before do - Flipper.enable(:background_reports) - end - + describe "Background processing", feature: :background_reports do it "can run the customers report" do login_as_admin visit admin_report_path(report_type: :customers) diff --git a/spec/system/consumer/checkout/payment_spec.rb b/spec/system/consumer/checkout/payment_spec.rb index 12536e30d6..2b351ce693 100644 --- a/spec/system/consumer/checkout/payment_spec.rb +++ b/spec/system/consumer/checkout/payment_spec.rb @@ -116,9 +116,7 @@ describe "As a consumer, I want to checkout my order" do end end - describe "vouchers" do - before { Flipper.enable :vouchers } - + describe "vouchers", feature: :vouchers do context "with no voucher available" do before do visit checkout_step_path(:payment) diff --git a/spec/system/consumer/checkout/tax_incl_spec.rb b/spec/system/consumer/checkout/tax_incl_spec.rb index 5d582ace64..63abfc998f 100644 --- a/spec/system/consumer/checkout/tax_incl_spec.rb +++ b/spec/system/consumer/checkout/tax_incl_spec.rb @@ -108,9 +108,7 @@ describe "As a consumer, I want to see adjustment breakdown" do assert_db_tax_incl end - context "when using a voucher" do - before { Flipper.enable :vouchers } - + context "when using a voucher", feature: :vouchers do let!(:voucher) do create(:voucher_flat_rate, code: 'some_code', enterprise: distributor, amount: 10) end diff --git a/spec/system/consumer/checkout/tax_not_incl_spec.rb b/spec/system/consumer/checkout/tax_not_incl_spec.rb index 03db5dba38..bc1eddbbb7 100644 --- a/spec/system/consumer/checkout/tax_not_incl_spec.rb +++ b/spec/system/consumer/checkout/tax_not_incl_spec.rb @@ -2,7 +2,7 @@ require "system_helper" -describe "As a consumer, I want to see adjustment breakdown" do +describe "As a consumer, I want to see adjustment breakdown", feature: :vouchers do include ShopWorkflow include SplitCheckoutHelper include CheckoutRequestsHelper @@ -63,7 +63,6 @@ describe "As a consumer, I want to see adjustment breakdown" do before do # assures tax is charged in dependence of shipping address Spree::Config.set(tax_using_ship_address: true) - Flipper.enable :vouchers end describe "a not-included tax" do