From 35021eb176d7d77f39ba106b3c23a014bd028349 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sat, 25 Nov 2023 13:16:55 +0100 Subject: [PATCH] DEV: Integrate subscription gem classes in rspec suite I've tweaked the subscription client gem so we can just use the gem's models and tables in this plugin's rspec, which makes duplicating and stubbing them unnecessary. See further https://github.com/paviliondev/discourse_subscription_client --- .rubocop.yml | 3 +++ plugin.rb | 2 +- spec/components/custom_wizard/action_spec.rb | 1 - spec/components/custom_wizard/builder_spec.rb | 1 - spec/components/custom_wizard/custom_field_spec.rb | 1 - spec/components/custom_wizard/submission_spec.rb | 1 - spec/components/custom_wizard/subscription_spec.rb | 8 ++------ spec/components/custom_wizard/template_spec.rb | 1 - .../custom_wizard/template_validator_spec.rb | 4 ---- .../components/custom_wizard/update_validator_spec.rb | 1 - spec/components/custom_wizard/wizard_spec.rb | 1 - spec/extensions/custom_field_extensions_spec.rb | 1 - spec/extensions/extra_locales_controller_spec.rb | 1 - spec/extensions/guardian_extension_spec.rb | 1 - spec/extensions/invites_controller_spec.rb | 1 - spec/extensions/users_controller_spec.rb | 1 - spec/plugin_helper.rb | 11 ----------- .../custom_wizard/admin/api_controller_spec.rb | 1 - .../admin/custom_fields_controller_spec.rb | 1 - .../custom_wizard/admin/logs_controller_spec.rb | 1 - .../custom_wizard/admin/manager_controller_spec.rb | 1 - .../admin/subscription_controller_spec.rb | 2 -- .../custom_wizard/application_controller_spec.rb | 1 - .../custom_wizard/custom_field_extensions_spec.rb | 1 - spec/requests/custom_wizard/steps_controller_spec.rb | 1 - spec/requests/custom_wizard/wizard_controller_spec.rb | 1 - .../custom_wizard/basic_wizard_serializer_spec.rb | 4 ---- .../custom_wizard/custom_field_serializer_spec.rb | 4 ---- .../custom_wizard/submission_serializer_spec.rb | 1 - .../custom_wizard/wizard_field_serializer_spec.rb | 1 - .../custom_wizard/wizard_serializer_spec.rb | 1 - .../custom_wizard/wizard_step_serializer_spec.rb | 1 - 32 files changed, 6 insertions(+), 56 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 74c8c853..c092e265 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,3 +9,6 @@ RSpec/DescribeClass: Discourse/TimeEqMatcher: Enabled: false + +Discourse/NoAddReferenceOrAliasesActiveRecordMigration: + Enabled: false diff --git a/plugin.rb b/plugin.rb index 99789ebc..d84ce8a4 100644 --- a/plugin.rb +++ b/plugin.rb @@ -8,7 +8,7 @@ # subscription_url: https://coop.pavilion.tech gem 'liquid', '5.0.1', require: true -gem "discourse_subscription_client", "0.1.0.pre15", require_name: "discourse_subscription_client" +gem "discourse_subscription_client", "0.1.1", require_name: "discourse_subscription_client" gem 'discourse_plugin_statistics', '0.1.0.pre7', require: true register_asset 'stylesheets/common/admin.scss' register_asset 'stylesheets/common/wizard.scss' diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index b867cced..57fe7f56 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -42,7 +42,6 @@ describe CustomWizard::Action do } before do - stub_out_subscription_classes Group.refresh_automatic_group!(:trust_level_2) update_template(wizard_template) end diff --git a/spec/components/custom_wizard/builder_spec.rb b/spec/components/custom_wizard/builder_spec.rb index 23db81e5..1e55b203 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -29,7 +29,6 @@ describe CustomWizard::Builder do } before do - stub_out_subscription_classes Group.refresh_automatic_group!(:trust_level_3) CustomWizard::Template.save(wizard_template, skip_jobs: true) @template = CustomWizard::Template.find('super_mega_fun_wizard') diff --git a/spec/components/custom_wizard/custom_field_spec.rb b/spec/components/custom_wizard/custom_field_spec.rb index 3edff439..5f234b06 100644 --- a/spec/components/custom_wizard/custom_field_spec.rb +++ b/spec/components/custom_wizard/custom_field_spec.rb @@ -5,7 +5,6 @@ describe CustomWizard::CustomField do let(:custom_field_subscription_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } before do - stub_out_subscription_classes CustomWizard::CustomField.invalidate_cache end diff --git a/spec/components/custom_wizard/submission_spec.rb b/spec/components/custom_wizard/submission_spec.rb index 54249380..d0e0c986 100644 --- a/spec/components/custom_wizard/submission_spec.rb +++ b/spec/components/custom_wizard/submission_spec.rb @@ -7,7 +7,6 @@ describe CustomWizard::Submission do let(:guest_id) { CustomWizard::Wizard.generate_guest_id } before do - stub_out_subscription_classes CustomWizard::Template.save(template_json, skip_jobs: true) @wizard = CustomWizard::Wizard.create(template_json["id"], user) described_class.new(@wizard, step_1_field_1: "I am user submission").save diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 7272ecf3..9e9a18eb 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -14,10 +14,6 @@ describe CustomWizard::Subscription do } context "with subscription client gem mocked out" do - before do - stub_out_subscription_classes - end - context "without a subscription" do before do DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(nil) @@ -40,9 +36,9 @@ describe CustomWizard::Subscription do def get_subscription_result(product_ids) result = DiscourseSubscriptionClient::Subscriptions::Result.new - result.supplier = SubscriptionClientSupplier.new(product_slugs) + result.supplier = SubscriptionClientSupplier.new(products: product_slugs) result.resource = SubscriptionClientResource.new - result.subscriptions = product_ids.map { |product_id| ::SubscriptionClientSubscription.new(product_id) } + result.subscriptions = product_ids.map { |product_id| ::SubscriptionClientSubscription.new(product_id: product_id) } result.products = product_slugs result end diff --git a/spec/components/custom_wizard/template_spec.rb b/spec/components/custom_wizard/template_spec.rb index 5c16f3fa..76b229dc 100644 --- a/spec/components/custom_wizard/template_spec.rb +++ b/spec/components/custom_wizard/template_spec.rb @@ -7,7 +7,6 @@ describe CustomWizard::Template do fab!(:upload) { Fabricate(:upload) } before do - stub_out_subscription_classes CustomWizard::Template.save(template_json, skip_jobs: true) end diff --git a/spec/components/custom_wizard/template_validator_spec.rb b/spec/components/custom_wizard/template_validator_spec.rb index 83170c34..fe61be91 100644 --- a/spec/components/custom_wizard/template_validator_spec.rb +++ b/spec/components/custom_wizard/template_validator_spec.rb @@ -39,10 +39,6 @@ describe CustomWizard::TemplateValidator do expect(validator.errors.first.message).to eq("Liquid syntax error in #{object_id}: #{message}") end - before do - stub_out_subscription_classes - end - it "validates valid templates" do expect( CustomWizard::TemplateValidator.new(template).perform diff --git a/spec/components/custom_wizard/update_validator_spec.rb b/spec/components/custom_wizard/update_validator_spec.rb index 0cfc7e44..7caa1784 100644 --- a/spec/components/custom_wizard/update_validator_spec.rb +++ b/spec/components/custom_wizard/update_validator_spec.rb @@ -6,7 +6,6 @@ describe CustomWizard::UpdateValidator do let(:url_field) { get_wizard_fixture("field/url") } before do - stub_out_subscription_classes CustomWizard::Template.save(template, skip_jobs: true) @template = CustomWizard::Template.find('super_mega_fun_wizard') end diff --git a/spec/components/custom_wizard/wizard_spec.rb b/spec/components/custom_wizard/wizard_spec.rb index 91eb7424..3483d211 100644 --- a/spec/components/custom_wizard/wizard_spec.rb +++ b/spec/components/custom_wizard/wizard_spec.rb @@ -10,7 +10,6 @@ describe CustomWizard::Wizard do let(:step_json) { get_wizard_fixture("step/step") } before do - stub_out_subscription_classes Group.refresh_automatic_group!(:trust_level_3) @permitted_template = template_json.dup @permitted_template["permitted"] = permitted_json["permitted"] diff --git a/spec/extensions/custom_field_extensions_spec.rb b/spec/extensions/custom_field_extensions_spec.rb index 1e7f1acc..b8b8db1c 100644 --- a/spec/extensions/custom_field_extensions_spec.rb +++ b/spec/extensions/custom_field_extensions_spec.rb @@ -11,7 +11,6 @@ describe "custom field extensions" do let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } before do - stub_out_subscription_classes custom_field_json['custom_fields'].each do |field_json| custom_field = CustomWizard::CustomField.new(nil, field_json) custom_field.save diff --git a/spec/extensions/extra_locales_controller_spec.rb b/spec/extensions/extra_locales_controller_spec.rb index 0590f274..1be62f36 100644 --- a/spec/extensions/extra_locales_controller_spec.rb +++ b/spec/extensions/extra_locales_controller_spec.rb @@ -7,7 +7,6 @@ describe ExtraLocalesControllerCustomWizard, type: :request do let(:permitted) { get_wizard_fixture("wizard/permitted") } before do - stub_out_subscription_classes CustomWizard::Template.save(template, skip_jobs: true) end diff --git a/spec/extensions/guardian_extension_spec.rb b/spec/extensions/guardian_extension_spec.rb index c35bd04c..ddfeb9ef 100644 --- a/spec/extensions/guardian_extension_spec.rb +++ b/spec/extensions/guardian_extension_spec.rb @@ -33,7 +33,6 @@ describe ::Guardian do end before do - stub_out_subscription_classes CustomWizard::Template.save(wizard_template, skip_jobs: true) @template = CustomWizard::Template.find('super_mega_fun_wizard') end diff --git a/spec/extensions/invites_controller_spec.rb b/spec/extensions/invites_controller_spec.rb index ff57ae7d..99c3b402 100644 --- a/spec/extensions/invites_controller_spec.rb +++ b/spec/extensions/invites_controller_spec.rb @@ -6,7 +6,6 @@ describe InvitesControllerCustomWizard, type: :request do let(:template) { get_wizard_fixture("wizard") } before do - stub_out_subscription_classes @controller = InvitesController.new end diff --git a/spec/extensions/users_controller_spec.rb b/spec/extensions/users_controller_spec.rb index 6f9185af..a28dc08e 100644 --- a/spec/extensions/users_controller_spec.rb +++ b/spec/extensions/users_controller_spec.rb @@ -4,7 +4,6 @@ describe CustomWizardUsersController, type: :request do let(:template) { get_wizard_fixture("wizard") } before do - stub_out_subscription_classes @controller = UsersController.new end diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index 436fefcd..16585e16 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -9,13 +9,11 @@ def get_wizard_fixture(path) end def enable_subscription(type) - stub_out_subscription_classes CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true) CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true) end def disable_subscriptions - stub_out_subscription_classes %w[ standard business @@ -25,12 +23,3 @@ def disable_subscriptions CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(false) end end - -def unstub_out_subscription_classes - Object.send(:remove_const, :DiscourseSubscriptionClient) if Object.constants.include?(:DiscourseSubscriptionClient) - Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) -end - -def stub_out_subscription_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/api_controller_spec.rb b/spec/requests/custom_wizard/admin/api_controller_spec.rb index a6e5df7e..f95681f8 100644 --- a/spec/requests/custom_wizard/admin/api_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/api_controller_spec.rb @@ -5,7 +5,6 @@ describe CustomWizard::AdminApiController do let(:api_json) { get_wizard_fixture("api/api") } before do - stub_out_subscription_classes sign_in(admin_user) end diff --git a/spec/requests/custom_wizard/admin/custom_fields_controller_spec.rb b/spec/requests/custom_wizard/admin/custom_fields_controller_spec.rb index dc6de785..7aef791c 100644 --- a/spec/requests/custom_wizard/admin/custom_fields_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/custom_fields_controller_spec.rb @@ -5,7 +5,6 @@ describe CustomWizard::AdminCustomFieldsController do let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } before do - stub_out_subscription_classes custom_field_json['custom_fields'].each do |field_json| CustomWizard::CustomField.new(nil, field_json).save end diff --git a/spec/requests/custom_wizard/admin/logs_controller_spec.rb b/spec/requests/custom_wizard/admin/logs_controller_spec.rb index 91846d7f..b67907a4 100644 --- a/spec/requests/custom_wizard/admin/logs_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/logs_controller_spec.rb @@ -5,7 +5,6 @@ describe CustomWizard::AdminLogsController do let(:template) { get_wizard_fixture("wizard") } before do - stub_out_subscription_classes ["first", "second", "third"].each_with_index do |key, index| temp = template.dup temp["id"] = "#{key}_test_wizard" diff --git a/spec/requests/custom_wizard/admin/manager_controller_spec.rb b/spec/requests/custom_wizard/admin/manager_controller_spec.rb index bbbfafb9..c5282db6 100644 --- a/spec/requests/custom_wizard/admin/manager_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/manager_controller_spec.rb @@ -5,7 +5,6 @@ describe CustomWizard::AdminManagerController do let(:template) { get_wizard_fixture("wizard") } before do - stub_out_subscription_classes sign_in(admin_user) template_2 = template.dup diff --git a/spec/requests/custom_wizard/admin/subscription_controller_spec.rb b/spec/requests/custom_wizard/admin/subscription_controller_spec.rb index 7be33f32..e1167602 100644 --- a/spec/requests/custom_wizard/admin/subscription_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/subscription_controller_spec.rb @@ -16,7 +16,6 @@ describe CustomWizard::SubscriptionController do context "without a subscription" do before do disable_subscriptions - stub_out_subscription_classes end it "returns the right subscription details" do @@ -29,7 +28,6 @@ describe CustomWizard::SubscriptionController do context "with a subscription" do before do enable_subscription("standard") - stub_out_subscription_classes end it "returns the right subscription details" do diff --git a/spec/requests/custom_wizard/application_controller_spec.rb b/spec/requests/custom_wizard/application_controller_spec.rb index 1df3442b..1eb1b857 100644 --- a/spec/requests/custom_wizard/application_controller_spec.rb +++ b/spec/requests/custom_wizard/application_controller_spec.rb @@ -5,7 +5,6 @@ describe ApplicationController do let(:wizard_template) { get_wizard_fixture("wizard") } before do - stub_out_subscription_classes CustomWizard::Template.save(wizard_template, skip_jobs: true) @template = CustomWizard::Template.find('super_mega_fun_wizard') end diff --git a/spec/requests/custom_wizard/custom_field_extensions_spec.rb b/spec/requests/custom_wizard/custom_field_extensions_spec.rb index 6b8afedb..44556ef1 100644 --- a/spec/requests/custom_wizard/custom_field_extensions_spec.rb +++ b/spec/requests/custom_wizard/custom_field_extensions_spec.rb @@ -10,7 +10,6 @@ describe "custom field extensions" do let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } before do - stub_out_subscription_classes custom_field_json['custom_fields'].each do |field_json| custom_field = CustomWizard::CustomField.new(nil, field_json) custom_field.save diff --git a/spec/requests/custom_wizard/steps_controller_spec.rb b/spec/requests/custom_wizard/steps_controller_spec.rb index 953f1149..4d8b96eb 100644 --- a/spec/requests/custom_wizard/steps_controller_spec.rb +++ b/spec/requests/custom_wizard/steps_controller_spec.rb @@ -11,7 +11,6 @@ describe CustomWizard::StepsController do let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") } before do - stub_out_subscription_classes CustomWizard::Template.save(wizard_template, skip_jobs: true) end diff --git a/spec/requests/custom_wizard/wizard_controller_spec.rb b/spec/requests/custom_wizard/wizard_controller_spec.rb index 5a073e7d..93ec196b 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -6,7 +6,6 @@ describe CustomWizard::WizardController do let(:permitted_json) { get_wizard_fixture("wizard/permitted") } before do - stub_out_subscription_classes CustomWizard::Template.save(wizard_template, skip_jobs: true) @template = CustomWizard::Template.find("super_mega_fun_wizard") end diff --git a/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb b/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb index ea4e4568..4a2f353a 100644 --- a/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb +++ b/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb @@ -4,10 +4,6 @@ describe CustomWizard::BasicWizardSerializer do fab!(:user) { Fabricate(:user) } let(:template) { get_wizard_fixture("wizard") } - before do - stub_out_subscription_classes - end - it 'should return basic wizard attributes' do CustomWizard::Template.save(template, skip_jobs: true) json = CustomWizard::BasicWizardSerializer.new( diff --git a/spec/serializers/custom_wizard/custom_field_serializer_spec.rb b/spec/serializers/custom_wizard/custom_field_serializer_spec.rb index 490b4775..1da62245 100644 --- a/spec/serializers/custom_wizard/custom_field_serializer_spec.rb +++ b/spec/serializers/custom_wizard/custom_field_serializer_spec.rb @@ -4,10 +4,6 @@ describe CustomWizard::CustomFieldSerializer do fab!(:user) { Fabricate(:user) } let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } - before do - stub_out_subscription_classes - end - it 'should return custom field attributes' do custom_field_json['custom_fields'].each do |field_json| CustomWizard::CustomField.new(nil, field_json).save diff --git a/spec/serializers/custom_wizard/submission_serializer_spec.rb b/spec/serializers/custom_wizard/submission_serializer_spec.rb index 0548f381..fc2c46a2 100644 --- a/spec/serializers/custom_wizard/submission_serializer_spec.rb +++ b/spec/serializers/custom_wizard/submission_serializer_spec.rb @@ -13,7 +13,6 @@ describe CustomWizard::SubmissionSerializer do } before do - stub_out_subscription_classes CustomWizard::Template.save(template_json, skip_jobs: true) wizard = CustomWizard::Wizard.create(template_json["id"], user1) diff --git a/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb b/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb index be883e6b..0568f898 100644 --- a/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb @@ -5,7 +5,6 @@ describe CustomWizard::FieldSerializer do let(:template) { get_wizard_fixture("wizard") } before do - stub_out_subscription_classes CustomWizard::Template.save(template, skip_jobs: true) @wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build end diff --git a/spec/serializers/custom_wizard/wizard_serializer_spec.rb b/spec/serializers/custom_wizard/wizard_serializer_spec.rb index 3a39827c..aa1d82f2 100644 --- a/spec/serializers/custom_wizard/wizard_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_serializer_spec.rb @@ -8,7 +8,6 @@ describe CustomWizard::WizardSerializer do let(:advanced_fields) { get_wizard_fixture("field/advanced_types") } before do - stub_out_subscription_classes CustomWizard::Template.save(template, skip_jobs: true) @template = CustomWizard::Template.find('super_mega_fun_wizard') end diff --git a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb index 4bcc6718..2c28479c 100644 --- a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb @@ -6,7 +6,6 @@ describe CustomWizard::StepSerializer do let(:required_data_json) { get_wizard_fixture("step/required_data") } before do - stub_out_subscription_classes CustomWizard::Template.save(wizard_template, skip_jobs: true) @wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build end