From af39c567ea1b7ae690fe97ecb49fe2e99b2c58ff Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 29 Jun 2023 10:26:39 +0200 Subject: [PATCH] Add product slug env variable --- lib/custom_wizard/subscription.rb | 4 +++- plugin.rb | 2 +- .../custom_wizard/subscription_spec.rb | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 6ca592f9..ecb97e06 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -124,6 +124,8 @@ class CustomWizard::Subscription @product_slug = id_and_slug[:slug] end end + + @product_slug ||= ENV["CUSTOM_WIZARD_PRODUCT_SLUG"] end def includes?(feature, attribute, value = nil) @@ -153,8 +155,8 @@ class CustomWizard::Subscription def type return :none unless subscribed? - return :standard if standard? return :business if business? + return :standard if standard? return :community if community? end diff --git a/plugin.rb b/plugin.rb index 77b124fa..5122cbed 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.4.8 +# version: 2.4.9 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 2db8dae0..a072eb92 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -147,4 +147,28 @@ describe CustomWizard::Subscription do end end end + + context "with environment variable" do + before do + ENV["CUSTOM_WIZARD_PRODUCT_SLUG"] = "standard" + end + + after do + ENV["CUSTOM_WIZARD_PRODUCT_SLUG"] = nil + end + + it "enables the relevant subscription" do + expect(described_class.type).to eq(:standard) + end + + context "with a subscription" do + before do + enable_subscription("business") + end + + it "respects the subscription" do + expect(described_class.type).to eq(:business) + end + end + end end