From da2a56adc611488ee1f082c4cb1493a921e5e3dd Mon Sep 17 00:00:00 2001 From: merefield Date: Thu, 28 Sep 2023 13:47:22 +0100 Subject: [PATCH] specs: ensure sub client code is mocked out --- app/controllers/custom_wizard/admin/admin.rb | 16 ++++++++-------- spec/components/custom_wizard/action_spec.rb | 1 + spec/components/custom_wizard/builder_spec.rb | 1 + .../custom_wizard/custom_field_spec.rb | 1 + spec/components/custom_wizard/submission_spec.rb | 1 + .../custom_wizard/subscription_spec.rb | 2 +- spec/components/custom_wizard/template_spec.rb | 1 + .../custom_wizard/template_validator_spec.rb | 4 ++++ .../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 + .../custom_wizard/admin/api_controller_spec.rb | 1 + .../admin/custom_fields_controller_spec.rb | 1 + .../custom_wizard/admin/logs_controller_spec.rb | 1 + .../admin/manager_controller_spec.rb | 1 + ...r_spec.rb => subscription_controller_spec.rb} | 0 .../admin/wizard_controller_spec.rb | 3 +-- .../custom_wizard/application_controller_spec.rb | 1 + .../custom_field_extensions_spec.rb | 1 + .../custom_wizard/steps_controller_spec.rb | 1 + .../custom_wizard/wizard_controller_spec.rb | 1 + .../basic_wizard_serializer_spec.rb | 4 ++++ .../custom_field_serializer_spec.rb | 4 ++++ .../custom_wizard/submission_serializer_spec.rb | 1 + .../wizard_field_serializer_spec.rb | 1 + .../custom_wizard/wizard_serializer_spec.rb | 1 + .../custom_wizard/wizard_step_serializer_spec.rb | 1 + 31 files changed, 46 insertions(+), 11 deletions(-) rename spec/requests/custom_wizard/admin/{admin_controller_spec.rb => subscription_controller_spec.rb} (100%) diff --git a/app/controllers/custom_wizard/admin/admin.rb b/app/controllers/custom_wizard/admin/admin.rb index cba3ac43..832d23d2 100644 --- a/app/controllers/custom_wizard/admin/admin.rb +++ b/app/controllers/custom_wizard/admin/admin.rb @@ -2,14 +2,14 @@ class CustomWizard::AdminController < ::Admin::AdminController before_action :ensure_admin - def index - subcription = CustomWizard::Subscription.new - render_json_dump( - subscribed: subcription.subscribed?, - subscription_type: subcription.type, - subscription_attributes: CustomWizard::Subscription.attributes, - ) - end + # def index + # subcription = CustomWizard::Subscription.new + # render_json_dump( + # subscribed: subcription.subscribed?, + # subscription_type: subcription.type, + # subscription_attributes: CustomWizard::Subscription.attributes, + # ) + # end private diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index c450582d..3f3bf877 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -42,6 +42,7 @@ describe CustomWizard::Action do } before do + define_client_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 1e55b203..19728e55 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -29,6 +29,7 @@ describe CustomWizard::Builder do } before do + define_client_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 4b8d43e2..eb14d620 100644 --- a/spec/components/custom_wizard/custom_field_spec.rb +++ b/spec/components/custom_wizard/custom_field_spec.rb @@ -5,6 +5,7 @@ describe CustomWizard::CustomField do let(:custom_field_subscription_json) { get_wizard_fixture("custom_field/subscription_custom_fields") } before do + define_client_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 d0e0c986..2b07b021 100644 --- a/spec/components/custom_wizard/submission_spec.rb +++ b/spec/components/custom_wizard/submission_spec.rb @@ -7,6 +7,7 @@ describe CustomWizard::Submission do let(:guest_id) { CustomWizard::Wizard.generate_guest_id } before do + define_client_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 6a0ee09c..5ce2a515 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -13,7 +13,7 @@ describe CustomWizard::Subscription do } } - context "with subscription client gem" do + context "with subscription client gem mocked out" do before do define_client_classes end diff --git a/spec/components/custom_wizard/template_spec.rb b/spec/components/custom_wizard/template_spec.rb index 76b229dc..8a997dd7 100644 --- a/spec/components/custom_wizard/template_spec.rb +++ b/spec/components/custom_wizard/template_spec.rb @@ -7,6 +7,7 @@ describe CustomWizard::Template do fab!(:upload) { Fabricate(:upload) } before do + define_client_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 fe61be91..02b33db5 100644 --- a/spec/components/custom_wizard/template_validator_spec.rb +++ b/spec/components/custom_wizard/template_validator_spec.rb @@ -39,6 +39,10 @@ describe CustomWizard::TemplateValidator do expect(validator.errors.first.message).to eq("Liquid syntax error in #{object_id}: #{message}") end + before do + define_client_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 7caa1784..7967dfbc 100644 --- a/spec/components/custom_wizard/update_validator_spec.rb +++ b/spec/components/custom_wizard/update_validator_spec.rb @@ -6,6 +6,7 @@ describe CustomWizard::UpdateValidator do let(:url_field) { get_wizard_fixture("field/url") } before do + define_client_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 3483d211..390d5f68 100644 --- a/spec/components/custom_wizard/wizard_spec.rb +++ b/spec/components/custom_wizard/wizard_spec.rb @@ -10,6 +10,7 @@ describe CustomWizard::Wizard do let(:step_json) { get_wizard_fixture("step/step") } before do + define_client_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 b0088972..b1ddebe6 100644 --- a/spec/extensions/custom_field_extensions_spec.rb +++ b/spec/extensions/custom_field_extensions_spec.rb @@ -11,6 +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 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 1be62f36..55a24036 100644 --- a/spec/extensions/extra_locales_controller_spec.rb +++ b/spec/extensions/extra_locales_controller_spec.rb @@ -7,6 +7,7 @@ describe ExtraLocalesControllerCustomWizard, type: :request do let(:permitted) { get_wizard_fixture("wizard/permitted") } before do + define_client_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 ddfeb9ef..0380f816 100644 --- a/spec/extensions/guardian_extension_spec.rb +++ b/spec/extensions/guardian_extension_spec.rb @@ -33,6 +33,7 @@ describe ::Guardian do end before do + define_client_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 99c3b402..59d815b3 100644 --- a/spec/extensions/invites_controller_spec.rb +++ b/spec/extensions/invites_controller_spec.rb @@ -6,6 +6,7 @@ describe InvitesControllerCustomWizard, type: :request do let(:template) { get_wizard_fixture("wizard") } before do + define_client_classes @controller = InvitesController.new end diff --git a/spec/extensions/users_controller_spec.rb b/spec/extensions/users_controller_spec.rb index a28dc08e..b80b0c10 100644 --- a/spec/extensions/users_controller_spec.rb +++ b/spec/extensions/users_controller_spec.rb @@ -4,6 +4,7 @@ describe CustomWizardUsersController, type: :request do let(:template) { get_wizard_fixture("wizard") } before do + define_client_classes @controller = UsersController.new end diff --git a/spec/requests/custom_wizard/admin/api_controller_spec.rb b/spec/requests/custom_wizard/admin/api_controller_spec.rb index f95681f8..ea68b86d 100644 --- a/spec/requests/custom_wizard/admin/api_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/api_controller_spec.rb @@ -5,6 +5,7 @@ describe CustomWizard::AdminApiController do let(:api_json) { get_wizard_fixture("api/api") } before do + define_client_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 7aef791c..f77c772b 100644 --- a/spec/requests/custom_wizard/admin/custom_fields_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/custom_fields_controller_spec.rb @@ -5,6 +5,7 @@ describe CustomWizard::AdminCustomFieldsController do let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } before do + define_client_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 b67907a4..eaab8a8f 100644 --- a/spec/requests/custom_wizard/admin/logs_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/logs_controller_spec.rb @@ -5,6 +5,7 @@ describe CustomWizard::AdminLogsController do let(:template) { get_wizard_fixture("wizard") } before do + define_client_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 c5282db6..5c26fa94 100644 --- a/spec/requests/custom_wizard/admin/manager_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/manager_controller_spec.rb @@ -5,6 +5,7 @@ describe CustomWizard::AdminManagerController do let(:template) { get_wizard_fixture("wizard") } before do + define_client_classes sign_in(admin_user) template_2 = template.dup diff --git a/spec/requests/custom_wizard/admin/admin_controller_spec.rb b/spec/requests/custom_wizard/admin/subscription_controller_spec.rb similarity index 100% rename from spec/requests/custom_wizard/admin/admin_controller_spec.rb rename to spec/requests/custom_wizard/admin/subscription_controller_spec.rb diff --git a/spec/requests/custom_wizard/admin/wizard_controller_spec.rb b/spec/requests/custom_wizard/admin/wizard_controller_spec.rb index c94007e2..9690fbc7 100644 --- a/spec/requests/custom_wizard/admin/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/wizard_controller_spec.rb @@ -8,9 +8,8 @@ describe CustomWizard::AdminWizardController do let(:category) { Fabricate(:category, custom_fields: { create_topic_wizard: template['name'].parameterize(separator: "_") }) } before do - CustomWizard::Template.save(template, skip_jobs: true) enable_subscription("standard") - + CustomWizard::Template.save(template, skip_jobs: true) template_2 = template.dup template_2["id"] = 'super_mega_fun_wizard_2' template_2["permitted"] = template_2['permitted'] diff --git a/spec/requests/custom_wizard/application_controller_spec.rb b/spec/requests/custom_wizard/application_controller_spec.rb index 1eb1b857..97c44d2c 100644 --- a/spec/requests/custom_wizard/application_controller_spec.rb +++ b/spec/requests/custom_wizard/application_controller_spec.rb @@ -5,6 +5,7 @@ describe ApplicationController do let(:wizard_template) { get_wizard_fixture("wizard") } before do + define_client_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 44556ef1..4530f00b 100644 --- a/spec/requests/custom_wizard/custom_field_extensions_spec.rb +++ b/spec/requests/custom_wizard/custom_field_extensions_spec.rb @@ -10,6 +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 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 4d8b96eb..54a7e49b 100644 --- a/spec/requests/custom_wizard/steps_controller_spec.rb +++ b/spec/requests/custom_wizard/steps_controller_spec.rb @@ -11,6 +11,7 @@ describe CustomWizard::StepsController do let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") } before do + define_client_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 93ec196b..5be10a81 100644 --- a/spec/requests/custom_wizard/wizard_controller_spec.rb +++ b/spec/requests/custom_wizard/wizard_controller_spec.rb @@ -6,6 +6,7 @@ describe CustomWizard::WizardController do let(:permitted_json) { get_wizard_fixture("wizard/permitted") } before do + define_client_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 4a2f353a..8df4f4d3 100644 --- a/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb +++ b/spec/serializers/custom_wizard/basic_wizard_serializer_spec.rb @@ -4,6 +4,10 @@ describe CustomWizard::BasicWizardSerializer do fab!(:user) { Fabricate(:user) } let(:template) { get_wizard_fixture("wizard") } + before do + define_client_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 1da62245..068ad894 100644 --- a/spec/serializers/custom_wizard/custom_field_serializer_spec.rb +++ b/spec/serializers/custom_wizard/custom_field_serializer_spec.rb @@ -4,6 +4,10 @@ describe CustomWizard::CustomFieldSerializer do fab!(:user) { Fabricate(:user) } let(:custom_field_json) { get_wizard_fixture("custom_field/custom_fields") } + before do + define_client_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 2fa000e8..9161d33d 100644 --- a/spec/serializers/custom_wizard/submission_serializer_spec.rb +++ b/spec/serializers/custom_wizard/submission_serializer_spec.rb @@ -13,6 +13,7 @@ describe CustomWizard::SubmissionSerializer do } before do + define_client_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 0568f898..97b94304 100644 --- a/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_field_serializer_spec.rb @@ -5,6 +5,7 @@ describe CustomWizard::FieldSerializer do let(:template) { get_wizard_fixture("wizard") } before do + define_client_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 aa1d82f2..844a370e 100644 --- a/spec/serializers/custom_wizard/wizard_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_serializer_spec.rb @@ -8,6 +8,7 @@ describe CustomWizard::WizardSerializer do let(:advanced_fields) { get_wizard_fixture("field/advanced_types") } before do + define_client_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 2c28479c..cdecb0e9 100644 --- a/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_step_serializer_spec.rb @@ -6,6 +6,7 @@ describe CustomWizard::StepSerializer do let(:required_data_json) { get_wizard_fixture("step/required_data") } before do + define_client_classes CustomWizard::Template.save(wizard_template, skip_jobs: true) @wizard = CustomWizard::Builder.new("super_mega_fun_wizard", user).build end