From 99e747a331543999112e44fdc2b8b1411068424c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 31 May 2023 12:09:00 +0200 Subject: [PATCH 1/4] Ensure subscriptions are not stubbed if testing for no subscription --- spec/plugin_helper.rb | 11 +++++++++++ .../custom_wizard/admin/admin_controller_spec.rb | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index 5334c1fa..16585e16 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -12,3 +12,14 @@ def enable_subscription(type) CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true) CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true) end + +def disable_subscriptions + %w[ + standard + business + community + ].each do |type| + CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(false) + CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(false) + end +end diff --git a/spec/requests/custom_wizard/admin/admin_controller_spec.rb b/spec/requests/custom_wizard/admin/admin_controller_spec.rb index 6a7d721c..5e2b722c 100644 --- a/spec/requests/custom_wizard/admin/admin_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/admin_controller_spec.rb @@ -14,6 +14,10 @@ describe CustomWizard::AdminController do end context "without a subscription" do + before do + disable_subscriptions + end + it "returns the right subscription details" do get "/admin/wizards.json" expect(response.parsed_body["subscribed"]).to eq(false) From c256a41668bcb7ab968e7ff4fe91d9764be85bc9 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 31 May 2023 14:27:00 +0200 Subject: [PATCH 2/4] Also ensure subscription client definition is in the right state --- spec/components/custom_wizard/subscription_spec.rb | 9 --------- spec/plugin_helper.rb | 9 +++++++++ .../custom_wizard/admin/admin_controller_spec.rb | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 0bfb1839..2db8dae0 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -13,15 +13,6 @@ describe CustomWizard::Subscription do } } - def undefine_client_classes - Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient) - Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) - end - - def define_client_classes - load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) - end - after do undefine_client_classes end diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index 16585e16..8436f7c9 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -23,3 +23,12 @@ def disable_subscriptions CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(false) end end + +def undefine_client_classes + Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient) + Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) +end + +def define_client_classes + load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) +end diff --git a/spec/requests/custom_wizard/admin/admin_controller_spec.rb b/spec/requests/custom_wizard/admin/admin_controller_spec.rb index 5e2b722c..877f4262 100644 --- a/spec/requests/custom_wizard/admin/admin_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/admin_controller_spec.rb @@ -16,20 +16,21 @@ describe CustomWizard::AdminController do context "without a subscription" do before do disable_subscriptions + define_client_classes end it "returns the right subscription details" do get "/admin/wizards.json" expect(response.parsed_body["subscribed"]).to eq(false) expect(response.parsed_body["subscription_attributes"]).to eq(CustomWizard::Subscription.attributes.as_json) - expect(response.parsed_body["subscription_client_installed"]).to eq(false) + expect(response.parsed_body["subscription_client_installed"]).to eq(true) end end context "with a subscription" do before do enable_subscription("standard") - load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) + define_client_classes end it "returns the right subscription details" do From 2fe8501c6556c6cd2665c87fd33fa8e30ec21dbe Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 2 Jun 2023 12:51:28 +0200 Subject: [PATCH 3/4] Fix failing specs --- plugin.rb | 2 +- spec/components/custom_wizard/log_spec.rb | 6 +++--- spec/components/custom_wizard/mapper_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugin.rb b/plugin.rb index ba3f8bf1..955063f4 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.2 +# version: 2.4.3 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech diff --git a/spec/components/custom_wizard/log_spec.rb b/spec/components/custom_wizard/log_spec.rb index e4f5550f..c5cafba9 100644 --- a/spec/components/custom_wizard/log_spec.rb +++ b/spec/components/custom_wizard/log_spec.rb @@ -2,9 +2,9 @@ describe CustomWizard::Log do before do - CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message') - CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message') - CustomWizard::Log.create('third-test-wizard', 'perform_third_action', 'third_test_user', 'Third log message') + CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message', 5.minutes.ago) + CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message', 3.minutes.ago) + CustomWizard::Log.create('third-test-wizard', 'perform_third_action', 'third_test_user', 'Third log message', 1.minutes.ago) end it "creates logs" do diff --git a/spec/components/custom_wizard/mapper_spec.rb b/spec/components/custom_wizard/mapper_spec.rb index 3e0e6ce6..2e18cabd 100644 --- a/spec/components/custom_wizard/mapper_spec.rb +++ b/spec/components/custom_wizard/mapper_spec.rb @@ -281,13 +281,13 @@ describe CustomWizard::Mapper do it "avatar with valid size" do avatar_inputs = inputs['interpolate_avatar'].dup - avatar_inputs[0]["output"] = "Avatar: ![avatar](u{avatar.120})" + avatar_inputs[0]["output"] = "Avatar: ![avatar](u{avatar.144})" expect(CustomWizard::Mapper.new( inputs: avatar_inputs, data: data, user: user1 - ).perform).to eq("Avatar: ![avatar](#{user1.avatar_template_url.gsub("{size}", "120")})") + ).perform).to eq("Avatar: ![avatar](#{user1.avatar_template_url.gsub("{size}", "144")})") end end From 42d6e094a2da7d9e837629a7b9432bdf0ce02551 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 6 Jun 2023 09:15:16 +0200 Subject: [PATCH 4/4] Fix failing spec See further https://github.com/discourse/discourse/commit/6cf863080a2dfa4136d084f9ad3e766cee3d8ae5 --- spec/requests/custom_wizard/admin/manager_controller_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/requests/custom_wizard/admin/manager_controller_spec.rb b/spec/requests/custom_wizard/admin/manager_controller_spec.rb index 608b61fb..c5282db6 100644 --- a/spec/requests/custom_wizard/admin/manager_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/manager_controller_spec.rb @@ -13,8 +13,8 @@ describe CustomWizard::AdminManagerController do template_3["id"] = 'super_mega_fun_wizard_3' @template_array = [template, template_2, template_3] - FileUtils.mkdir_p(file_from_fixtures_tmp_folder) unless Dir.exist?(file_from_fixtures_tmp_folder) - @tmp_file_path = File.join(file_from_fixtures_tmp_folder, SecureRandom.hex << 'wizards.json') + FileUtils.mkdir_p(concurrency_safe_tmp_dir) unless Dir.exist?(concurrency_safe_tmp_dir) + @tmp_file_path = File.join(concurrency_safe_tmp_dir, SecureRandom.hex << 'wizards.json') File.write(@tmp_file_path, @template_array.to_json) end