diff --git a/Gemfile.lock b/Gemfile.lock index c8f6ddb..4e33a49 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,11 +7,31 @@ GIT GEM remote: https://rubygems.org/ specs: + activesupport (7.1.3.2) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.6) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) + drb (2.2.1) + i18n (1.14.3) + concurrent-ruby (~> 1.0) + racc (~> 1.7) json (2.7.1) language_server-protocol (3.17.0.3) + minitest (5.22.2) + mutex_m (0.2.0) parallel (1.24.0) - parser (3.3.0.4) + parser (3.3.0.5) ast (~> 2.4.1) racc prettier_print (1.2.1) @@ -19,7 +39,7 @@ GEM rainbow (3.1.1) regexp_parser (2.9.0) rexml (3.2.6) - rubocop (1.60.0) + rubocop (1.62.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) @@ -27,25 +47,30 @@ GEM rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.30.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.30.0) - parser (>= 3.2.1.0) + rubocop-ast (1.31.1) + parser (>= 3.3.0.4) rubocop-capybara (2.20.0) rubocop (~> 1.41) - rubocop-discourse (3.6.0) + rubocop-discourse (3.7.1) + activesupport (>= 6.1) rubocop (>= 1.59.0) + rubocop-capybara (>= 2.0.0) + rubocop-factory_bot (>= 2.0.0) rubocop-rspec (>= 2.25.0) rubocop-factory_bot (2.25.1) rubocop (~> 1.41) - rubocop-rspec (2.26.1) + rubocop-rspec (2.27.1) rubocop (~> 1.40) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) syntax_tree (6.2.0) prettier_print (>= 1.2.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) PLATFORMS diff --git a/app/controllers/discourse_subscriptions/admin/coupons_controller.rb b/app/controllers/discourse_subscriptions/admin/coupons_controller.rb index 80fc551..1ef1d5f 100644 --- a/app/controllers/discourse_subscriptions/admin/coupons_controller.rb +++ b/app/controllers/discourse_subscriptions/admin/coupons_controller.rb @@ -5,6 +5,9 @@ module DiscourseSubscriptions class CouponsController < ::Admin::AdminController include DiscourseSubscriptions::Stripe include DiscourseSubscriptions::Group + + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + before_action :set_api_key def index diff --git a/app/controllers/discourse_subscriptions/admin/plans_controller.rb b/app/controllers/discourse_subscriptions/admin/plans_controller.rb index 354de83..7867581 100644 --- a/app/controllers/discourse_subscriptions/admin/plans_controller.rb +++ b/app/controllers/discourse_subscriptions/admin/plans_controller.rb @@ -5,6 +5,8 @@ module DiscourseSubscriptions class PlansController < ::Admin::AdminController include DiscourseSubscriptions::Stripe + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + before_action :set_api_key def index diff --git a/app/controllers/discourse_subscriptions/admin/products_controller.rb b/app/controllers/discourse_subscriptions/admin/products_controller.rb index 9a3e026..d2d21fb 100644 --- a/app/controllers/discourse_subscriptions/admin/products_controller.rb +++ b/app/controllers/discourse_subscriptions/admin/products_controller.rb @@ -5,6 +5,8 @@ module DiscourseSubscriptions class ProductsController < ::Admin::AdminController include DiscourseSubscriptions::Stripe + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + before_action :set_api_key def index diff --git a/app/controllers/discourse_subscriptions/admin/subscriptions_controller.rb b/app/controllers/discourse_subscriptions/admin/subscriptions_controller.rb index d4c529d..53ba5a5 100644 --- a/app/controllers/discourse_subscriptions/admin/subscriptions_controller.rb +++ b/app/controllers/discourse_subscriptions/admin/subscriptions_controller.rb @@ -3,6 +3,8 @@ module DiscourseSubscriptions module Admin class SubscriptionsController < ::Admin::AdminController + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + include DiscourseSubscriptions::Stripe include DiscourseSubscriptions::Group before_action :set_api_key diff --git a/app/controllers/discourse_subscriptions/admin_controller.rb b/app/controllers/discourse_subscriptions/admin_controller.rb index 62e4508..4efa424 100644 --- a/app/controllers/discourse_subscriptions/admin_controller.rb +++ b/app/controllers/discourse_subscriptions/admin_controller.rb @@ -2,6 +2,8 @@ module DiscourseSubscriptions class AdminController < ::Admin::AdminController + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + def index head 200 end diff --git a/app/controllers/discourse_subscriptions/hooks_controller.rb b/app/controllers/discourse_subscriptions/hooks_controller.rb index f020c01..e779c6d 100644 --- a/app/controllers/discourse_subscriptions/hooks_controller.rb +++ b/app/controllers/discourse_subscriptions/hooks_controller.rb @@ -5,6 +5,8 @@ module DiscourseSubscriptions include DiscourseSubscriptions::Group include DiscourseSubscriptions::Stripe + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + layout false skip_before_action :check_xhr diff --git a/app/controllers/discourse_subscriptions/subscribe_controller.rb b/app/controllers/discourse_subscriptions/subscribe_controller.rb index 53834ca..0670fec 100644 --- a/app/controllers/discourse_subscriptions/subscribe_controller.rb +++ b/app/controllers/discourse_subscriptions/subscribe_controller.rb @@ -4,6 +4,9 @@ module DiscourseSubscriptions class SubscribeController < ::ApplicationController include DiscourseSubscriptions::Stripe include DiscourseSubscriptions::Group + + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + before_action :set_api_key requires_login except: %i[index contributors show] diff --git a/app/controllers/discourse_subscriptions/user/payments_controller.rb b/app/controllers/discourse_subscriptions/user/payments_controller.rb index 136933a..bc01287 100644 --- a/app/controllers/discourse_subscriptions/user/payments_controller.rb +++ b/app/controllers/discourse_subscriptions/user/payments_controller.rb @@ -4,6 +4,9 @@ module DiscourseSubscriptions module User class PaymentsController < ::ApplicationController include DiscourseSubscriptions::Stripe + + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + before_action :set_api_key requires_login diff --git a/app/controllers/discourse_subscriptions/user/subscriptions_controller.rb b/app/controllers/discourse_subscriptions/user/subscriptions_controller.rb index c8b5721..e992dfa 100644 --- a/app/controllers/discourse_subscriptions/user/subscriptions_controller.rb +++ b/app/controllers/discourse_subscriptions/user/subscriptions_controller.rb @@ -5,6 +5,9 @@ module DiscourseSubscriptions class SubscriptionsController < ::ApplicationController include DiscourseSubscriptions::Stripe include DiscourseSubscriptions::Group + + requires_plugin DiscourseSubscriptions::PLUGIN_NAME + before_action :set_api_key requires_login diff --git a/plugin.rb b/plugin.rb index c39b69a..e764156 100644 --- a/plugin.rb +++ b/plugin.rb @@ -54,9 +54,13 @@ Discourse::Application.routes.append do } end -load File.expand_path("lib/discourse_subscriptions/engine.rb", __dir__) -load File.expand_path("app/controllers/concerns/stripe.rb", __dir__) -load File.expand_path("app/controllers/concerns/group.rb", __dir__) +module ::DiscourseSubscriptions + PLUGIN_NAME = "discourse-subscriptions" +end + +require_relative "lib/discourse_subscriptions/engine" +require_relative "app/controllers/concerns/stripe" +require_relative "app/controllers/concerns/group" after_initialize do ::Stripe.api_version = "2020-08-27" diff --git a/spec/requests/admin/coupons_controller_spec.rb b/spec/requests/admin/coupons_controller_spec.rb index 749793d..42fe693 100644 --- a/spec/requests/admin/coupons_controller_spec.rb +++ b/spec/requests/admin/coupons_controller_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::Admin::CouponsController do + before { SiteSetting.discourse_subscriptions_enabled = true } + it "is a subclass of AdminController" do expect(DiscourseSubscriptions::Admin::CouponsController < ::Admin::AdminController).to eq(true) end diff --git a/spec/requests/admin/plans_controller_spec.rb b/spec/requests/admin/plans_controller_spec.rb index 79d348e..7344100 100644 --- a/spec/requests/admin/plans_controller_spec.rb +++ b/spec/requests/admin/plans_controller_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::Admin::PlansController do + before { SiteSetting.discourse_subscriptions_enabled = true } + it "is a subclass of AdminController" do expect(DiscourseSubscriptions::Admin::PlansController < ::Admin::AdminController).to eq(true) end diff --git a/spec/requests/admin/products_controller_spec.rb b/spec/requests/admin/products_controller_spec.rb index f9f1650..75ffe63 100644 --- a/spec/requests/admin/products_controller_spec.rb +++ b/spec/requests/admin/products_controller_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::Admin::ProductsController do + before { SiteSetting.discourse_subscriptions_enabled = true } + it "is a subclass of AdminController" do expect(DiscourseSubscriptions::Admin::ProductsController < ::Admin::AdminController).to eq(true) end diff --git a/spec/requests/admin/subscriptions_controller_spec.rb b/spec/requests/admin/subscriptions_controller_spec.rb index 488cfba..bb47de4 100644 --- a/spec/requests/admin/subscriptions_controller_spec.rb +++ b/spec/requests/admin/subscriptions_controller_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::Admin::SubscriptionsController do + before { SiteSetting.discourse_subscriptions_enabled = true } + it "is a subclass of AdminController" do expect(DiscourseSubscriptions::Admin::SubscriptionsController < ::Admin::AdminController).to eq( true, diff --git a/spec/requests/admin_controller_spec.rb b/spec/requests/admin_controller_spec.rb index e5b4697..42779ba 100644 --- a/spec/requests/admin_controller_spec.rb +++ b/spec/requests/admin_controller_spec.rb @@ -5,7 +5,10 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::AdminController do let(:admin) { Fabricate(:admin) } - before { sign_in(admin) } + before do + sign_in(admin) + SiteSetting.discourse_subscriptions_enabled = true + end it "is a subclass of AdminController" do expect(DiscourseSubscriptions::AdminController < ::Admin::AdminController).to eq(true) diff --git a/spec/requests/hooks_controller_spec.rb b/spec/requests/hooks_controller_spec.rb index 08247f4..60a863d 100644 --- a/spec/requests/hooks_controller_spec.rb +++ b/spec/requests/hooks_controller_spec.rb @@ -3,7 +3,10 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::HooksController do - before { SiteSetting.discourse_subscriptions_webhook_secret = "zascharoo" } + before do + SiteSetting.discourse_subscriptions_webhook_secret = "zascharoo" + SiteSetting.discourse_subscriptions_enabled = true + end it "constructs a webhook event" do payload = "we-want-a-shrubbery" diff --git a/spec/requests/subscribe_controller_spec.rb b/spec/requests/subscribe_controller_spec.rb index f564e85..67a93f4 100644 --- a/spec/requests/subscribe_controller_spec.rb +++ b/spec/requests/subscribe_controller_spec.rb @@ -6,6 +6,8 @@ RSpec.describe DiscourseSubscriptions::SubscribeController do let(:user) { Fabricate(:user) } let(:campaign_user) { Fabricate(:user) } + before { SiteSetting.discourse_subscriptions_enabled = true } + context "when showing products" do let(:product) do { diff --git a/spec/requests/user/payments_controller_spec.rb b/spec/requests/user/payments_controller_spec.rb index 3dcac29..5ad0563 100644 --- a/spec/requests/user/payments_controller_spec.rb +++ b/spec/requests/user/payments_controller_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::User::PaymentsController do + before { SiteSetting.discourse_subscriptions_enabled = true } + it "is a subclass of ApplicationController" do expect(DiscourseSubscriptions::User::PaymentsController < ::ApplicationController).to eq(true) end diff --git a/spec/requests/user/subscriptions_controller_spec.rb b/spec/requests/user/subscriptions_controller_spec.rb index a0e62df..e00f74d 100644 --- a/spec/requests/user/subscriptions_controller_spec.rb +++ b/spec/requests/user/subscriptions_controller_spec.rb @@ -3,6 +3,8 @@ require "rails_helper" RSpec.describe DiscourseSubscriptions::User::SubscriptionsController do + before { SiteSetting.discourse_subscriptions_enabled = true } + it "is a subclass of ApplicationController" do expect(DiscourseSubscriptions::User::SubscriptionsController < ::ApplicationController).to eq( true, diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb index 096c41e..db1da07 100644 --- a/spec/serializers/site_serializer_spec.rb +++ b/spec/serializers/site_serializer_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe SiteSerializer do - fab!(:user) { Fabricate(:user) } + fab!(:user) let(:guardian) { Guardian.new(user) } before do diff --git a/spec/system/subscription_product_spec.rb b/spec/system/subscription_product_spec.rb index 29da4bc..b16e5ab 100644 --- a/spec/system/subscription_product_spec.rb +++ b/spec/system/subscription_product_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe "Subscription products", type: :system do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) fab!(:product) { Fabricate(:product, external_id: "prod_OiKyO6ZMFCIhQa") } before { SiteSetting.discourse_subscriptions_enabled = true }