diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 3f3bf877..39e74dfa 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -42,7 +42,7 @@ describe CustomWizard::Action do } before do - define_client_classes + 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 19728e55..23db81e5 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -29,7 +29,7 @@ describe CustomWizard::Builder do } before do - define_client_classes + 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 eb14d620..e25294a0 100644 --- a/spec/components/custom_wizard/custom_field_spec.rb +++ b/spec/components/custom_wizard/custom_field_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::CustomField do let(:custom_field_subscription_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } before do - define_client_classes + 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 2b07b021..54249380 100644 --- a/spec/components/custom_wizard/submission_spec.rb +++ b/spec/components/custom_wizard/submission_spec.rb @@ -7,7 +7,7 @@ describe CustomWizard::Submission do let(:guest_id) { CustomWizard::Wizard.generate_guest_id } before do - define_client_classes + 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 5ce2a515..7272ecf3 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -15,7 +15,7 @@ describe CustomWizard::Subscription do context "with subscription client gem mocked out" do before do - define_client_classes + stub_out_subscription_classes end context "without a subscription" do diff --git a/spec/components/custom_wizard/template_spec.rb b/spec/components/custom_wizard/template_spec.rb index 8a997dd7..5c16f3fa 100644 --- a/spec/components/custom_wizard/template_spec.rb +++ b/spec/components/custom_wizard/template_spec.rb @@ -7,7 +7,7 @@ describe CustomWizard::Template do fab!(:upload) { Fabricate(:upload) } before do - define_client_classes + 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 02b33db5..83170c34 100644 --- a/spec/components/custom_wizard/template_validator_spec.rb +++ b/spec/components/custom_wizard/template_validator_spec.rb @@ -40,7 +40,7 @@ describe CustomWizard::TemplateValidator do end before do - define_client_classes + stub_out_subscription_classes end it "validates valid templates" do diff --git a/spec/components/custom_wizard/update_validator_spec.rb b/spec/components/custom_wizard/update_validator_spec.rb index 7967dfbc..0cfc7e44 100644 --- a/spec/components/custom_wizard/update_validator_spec.rb +++ b/spec/components/custom_wizard/update_validator_spec.rb @@ -6,7 +6,7 @@ describe CustomWizard::UpdateValidator do let(:url_field) { get_wizard_fixture("field/url") } before do - define_client_classes + 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 390d5f68..91eb7424 100644 --- a/spec/components/custom_wizard/wizard_spec.rb +++ b/spec/components/custom_wizard/wizard_spec.rb @@ -10,7 +10,7 @@ describe CustomWizard::Wizard do let(:step_json) { get_wizard_fixture("step/step") } before do - define_client_classes + 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 b1ddebe6..e73099ca 100644 --- a/spec/extensions/custom_field_extensions_spec.rb +++ b/spec/extensions/custom_field_extensions_spec.rb @@ -11,7 +11,7 @@ describe "custom field extensions" do let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } before do - define_client_classes + 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 55a24036..0590f274 100644 --- a/spec/extensions/extra_locales_controller_spec.rb +++ b/spec/extensions/extra_locales_controller_spec.rb @@ -7,7 +7,7 @@ describe ExtraLocalesControllerCustomWizard, type: :request do let(:permitted) { get_wizard_fixture("wizard/permitted") } before do - define_client_classes + 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 0380f816..c35bd04c 100644 --- a/spec/extensions/guardian_extension_spec.rb +++ b/spec/extensions/guardian_extension_spec.rb @@ -33,7 +33,7 @@ describe ::Guardian do end before do - define_client_classes + 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 59d815b3..ff57ae7d 100644 --- a/spec/extensions/invites_controller_spec.rb +++ b/spec/extensions/invites_controller_spec.rb @@ -6,7 +6,7 @@ describe InvitesControllerCustomWizard, type: :request do let(:template) { get_wizard_fixture("wizard") } before do - define_client_classes + 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 b80b0c10..6f9185af 100644 --- a/spec/extensions/users_controller_spec.rb +++ b/spec/extensions/users_controller_spec.rb @@ -4,7 +4,7 @@ describe CustomWizardUsersController, type: :request do let(:template) { get_wizard_fixture("wizard") } before do - define_client_classes + stub_out_subscription_classes @controller = UsersController.new end diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index 23e1f2f3..436fefcd 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -9,13 +9,13 @@ def get_wizard_fixture(path) end def enable_subscription(type) - define_client_classes + 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 - define_client_classes + stub_out_subscription_classes %w[ standard business @@ -26,11 +26,11 @@ def disable_subscriptions end end -def undefine_client_classes +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 define_client_classes +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 ea68b86d..a6e5df7e 100644 --- a/spec/requests/custom_wizard/admin/api_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/api_controller_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::AdminApiController do let(:api_json) { get_wizard_fixture("api/api") } before do - define_client_classes + 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 f77c772b..dc6de785 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,7 @@ describe CustomWizard::AdminCustomFieldsController do let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } before do - define_client_classes + 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 eaab8a8f..91846d7f 100644 --- a/spec/requests/custom_wizard/admin/logs_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/logs_controller_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::AdminLogsController do let(:template) { get_wizard_fixture("wizard") } before do - define_client_classes + 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 5c26fa94..bbbfafb9 100644 --- a/spec/requests/custom_wizard/admin/manager_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/manager_controller_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::AdminManagerController do let(:template) { get_wizard_fixture("wizard") } before do - define_client_classes + 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 f132d475..7be33f32 100644 --- a/spec/requests/custom_wizard/admin/subscription_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/subscription_controller_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -describe CustomWizard::AdminController do +describe CustomWizard::SubscriptionController do fab!(:admin_user) { Fabricate(:user, admin: true) } it "requires an admin" do @@ -16,7 +16,7 @@ describe CustomWizard::AdminController do context "without a subscription" do before do disable_subscriptions - define_client_classes + stub_out_subscription_classes end it "returns the right subscription details" do @@ -29,7 +29,7 @@ describe CustomWizard::AdminController do context "with a subscription" do before do enable_subscription("standard") - define_client_classes + 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 97c44d2c..1df3442b 100644 --- a/spec/requests/custom_wizard/application_controller_spec.rb +++ b/spec/requests/custom_wizard/application_controller_spec.rb @@ -5,7 +5,7 @@ describe ApplicationController do let(:wizard_template) { get_wizard_fixture("wizard") } before do - define_client_classes + 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 4530f00b..6b8afedb 100644 --- a/spec/requests/custom_wizard/custom_field_extensions_spec.rb +++ b/spec/requests/custom_wizard/custom_field_extensions_spec.rb @@ -10,7 +10,7 @@ describe "custom field extensions" do let(:subscription_custom_field_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } before do - define_client_classes + 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 54a7e49b..953f1149 100644 --- a/spec/requests/custom_wizard/steps_controller_spec.rb +++ b/spec/requests/custom_wizard/steps_controller_spec.rb @@ -11,7 +11,7 @@ describe CustomWizard::StepsController do let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") } before do - define_client_classes + 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 5be10a81..5a073e7d 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -6,7 +6,7 @@ describe CustomWizard::WizardController do let(:permitted_json) { get_wizard_fixture("wizard/permitted") } before do - define_client_classes + 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 8df4f4d3..ea4e4568 100644 --- a/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb +++ b/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::BasicWizardSerializer do let(:template) { get_wizard_fixture("wizard") } before do - define_client_classes + stub_out_subscription_classes end it 'should return basic wizard attributes' do diff --git a/spec/serializers/custom_wizard/custom_field_serializer_spec.rb b/spec/serializers/custom_wizard/custom_field_serializer_spec.rb index 068ad894..490b4775 100644 --- a/spec/serializers/custom_wizard/custom_field_serializer_spec.rb +++ b/spec/serializers/custom_wizard/custom_field_serializer_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::CustomFieldSerializer do let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } before do - define_client_classes + stub_out_subscription_classes end it 'should return custom field attributes' do diff --git a/spec/serializers/custom_wizard/submission_serializer_spec.rb b/spec/serializers/custom_wizard/submission_serializer_spec.rb index 9161d33d..f810a0aa 100644 --- a/spec/serializers/custom_wizard/submission_serializer_spec.rb +++ b/spec/serializers/custom_wizard/submission_serializer_spec.rb @@ -13,7 +13,7 @@ describe CustomWizard::SubmissionSerializer do } before do - define_client_classes + 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 97b94304..be883e6b 100644 --- a/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb @@ -5,7 +5,7 @@ describe CustomWizard::FieldSerializer do let(:template) { get_wizard_fixture("wizard") } before do - define_client_classes + 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 844a370e..3a39827c 100644 --- a/spec/serializers/custom_wizard/wizard_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_serializer_spec.rb @@ -8,7 +8,7 @@ describe CustomWizard::WizardSerializer do let(:advanced_fields) { get_wizard_fixture("field/advanced_types") } before do - define_client_classes + 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 cdecb0e9..4bcc6718 100644 --- a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb @@ -6,7 +6,7 @@ describe CustomWizard::StepSerializer do let(:required_data_json) { get_wizard_fixture("step/required_data") } before do - define_client_classes + stub_out_subscription_classes CustomWizard::Template.save(wizard_template, skip_jobs: true) @wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build end