Skip to content

Commit

Permalink
Merge pull request #281 from paviliondev/improve_subscription_classes…
Browse files Browse the repository at this point in the history
…_rspec_handling

DEV: Integrate subscription gem classes in rspec suite
  • Loading branch information
merefield authored Dec 7, 2023
2 parents 4d2dfb9 + 8ef30f9 commit 4178b33
Show file tree
Hide file tree
Showing 32 changed files with 7 additions and 57 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ RSpec/DescribeClass:

Discourse/TimeEqMatcher:
Enabled: false

Discourse/NoAddReferenceOrAliasesActiveRecordMigration:
Enabled: false
4 changes: 2 additions & 2 deletions plugin.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 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.5.2
# version: 2.5.3
# 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: [email protected]
# 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'
Expand Down
1 change: 0 additions & 1 deletion spec/components/custom_wizard/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def update_template(template)
}

before do
stub_out_subscription_classes
Group.refresh_automatic_group!(:trust_level_2)
update_template(wizard_template)
end
Expand Down
1 change: 0 additions & 1 deletion spec/components/custom_wizard/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
}

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')
Expand Down
1 change: 0 additions & 1 deletion spec/components/custom_wizard/custom_field_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
let(:custom_field_subscription_json) { get_wizard_fixture("custom_field/subscription_custom_fields") }

before do
stub_out_subscription_classes
CustomWizard::CustomField.invalidate_cache
end

Expand Down
1 change: 0 additions & 1 deletion spec/components/custom_wizard/submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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
Expand Down
8 changes: 2 additions & 6 deletions spec/components/custom_wizard/subscription_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
}

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)
Expand All @@ -40,9 +36,9 @@

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
Expand Down
1 change: 0 additions & 1 deletion spec/components/custom_wizard/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
fab!(:upload) { Fabricate(:upload) }

before do
stub_out_subscription_classes
CustomWizard::Template.save(template_json, skip_jobs: true)
end

Expand Down
4 changes: 0 additions & 4 deletions spec/components/custom_wizard/template_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ def expect_validation_failure(object_id, message)
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
Expand Down
1 change: 0 additions & 1 deletion spec/components/custom_wizard/update_validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/components/custom_wizard/wizard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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"]
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/custom_field_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/extra_locales_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
let(:permitted) { get_wizard_fixture("wizard/permitted") }

before do
stub_out_subscription_classes
CustomWizard::Template.save(template, skip_jobs: true)
end

Expand Down
1 change: 0 additions & 1 deletion spec/extensions/guardian_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def create_topic_by_wizard(wizard)
end

before do
stub_out_subscription_classes
CustomWizard::Template.save(wizard_template, skip_jobs: true)
@template = CustomWizard::Template.find('super_mega_fun_wizard')
end
Expand Down
1 change: 0 additions & 1 deletion spec/extensions/invites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
let(:template) { get_wizard_fixture("wizard") }

before do
stub_out_subscription_classes
@controller = InvitesController.new
end

Expand Down
1 change: 0 additions & 1 deletion spec/extensions/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
let(:template) { get_wizard_fixture("wizard") }

before do
stub_out_subscription_classes
@controller = UsersController.new
end

Expand Down
11 changes: 0 additions & 11 deletions spec/plugin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion spec/requests/custom_wizard/admin/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
let(:api_json) { get_wizard_fixture("api/api") }

before do
stub_out_subscription_classes
sign_in(admin_user)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/requests/custom_wizard/admin/logs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
let(:template) { get_wizard_fixture("wizard") }

before do
stub_out_subscription_classes
sign_in(admin_user)

template_2 = template.dup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
context "without a subscription" do
before do
disable_subscriptions
stub_out_subscription_classes
end

it "returns the right subscription details" do
Expand All @@ -29,7 +28,6 @@
context "with a subscription" do
before do
enable_subscription("standard")
stub_out_subscription_classes
end

it "returns the right subscription details" do
Expand Down
1 change: 0 additions & 1 deletion spec/requests/custom_wizard/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/requests/custom_wizard/steps_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") }

before do
stub_out_subscription_classes
CustomWizard::Template.save(wizard_template, skip_jobs: true)
end

Expand Down
1 change: 0 additions & 1 deletion spec/requests/custom_wizard/wizard_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
}

before do
stub_out_subscription_classes
CustomWizard::Template.save(template_json, skip_jobs: true)

wizard = CustomWizard::Wizard.create(template_json["id"], user1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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
Expand Down
1 change: 0 additions & 1 deletion spec/serializers/custom_wizard/wizard_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
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
Expand Down

0 comments on commit 4178b33

Please sign in to comment.