diff --git a/Gemfile.lock b/Gemfile.lock index 23ad67d..4c42077 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,30 @@ 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.1) + concurrent-ruby (~> 1.0) 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.3) + parser (3.3.0.5) ast (~> 2.4.1) racc prettier_print (1.2.1) @@ -13,33 +32,38 @@ GEM rainbow (3.1.1) regexp_parser (2.9.0) rexml (3.2.6) - rubocop (1.59.0) + rubocop (1.61.0) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.2.4) + parser (>= 3.3.0.2) 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) 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/adstxt_controller.rb b/app/controllers/adstxt_controller.rb new file mode 100644 index 0000000..3297867 --- /dev/null +++ b/app/controllers/adstxt_controller.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true +# +class AdstxtController < ::ApplicationController + requires_plugin AdPlugin.plugin_name + + skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required + + def index + raise Discourse::NotFound unless SiteSetting.ads_txt.present? + + render plain: SiteSetting.ads_txt + end +end diff --git a/plugin.rb b/plugin.rb index 08c2204..4f2f41d 100755 --- a/plugin.rb +++ b/plugin.rb @@ -32,12 +32,12 @@ module ::AdPlugin end after_initialize do - require_dependency File.expand_path("../app/models/house_ad", __FILE__) - require_dependency File.expand_path("../app/models/house_ad_setting", __FILE__) - require_dependency File.expand_path("../app/controllers/house_ads_controller", __FILE__) - require_dependency File.expand_path("../app/controllers/house_ad_settings_controller", __FILE__) - require_dependency File.expand_path("../lib/adplugin/guardian_extensions", __FILE__) - require_dependency "application_controller" + require_relative "app/models/house_ad" + require_relative "app/models/house_ad_setting" + require_relative "app/controllers/house_ads_controller" + require_relative "app/controllers/house_ad_settings_controller" + require_relative "app/controllers/adstxt_controller" + require_relative "lib/adplugin/guardian_extensions" reloadable_patch { Guardian.prepend ::AdPlugin::GuardianExtensions } @@ -75,16 +75,6 @@ after_initialize do scope.show_to_groups? end - class ::AdstxtController < ::ApplicationController - skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required - - def index - raise Discourse::NotFound unless SiteSetting.ads_txt.present? - - render plain: SiteSetting.ads_txt - end - end - class AdPlugin::Engine < ::Rails::Engine engine_name "adplugin" isolate_namespace AdPlugin diff --git a/spec/requests/site_controller_spec.rb b/spec/requests/site_controller_spec.rb index f618d71..b565b5a 100644 --- a/spec/requests/site_controller_spec.rb +++ b/spec/requests/site_controller_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe SiteController do - fab!(:user) { Fabricate(:user) } + fab!(:user) let!(:anon_ad) do AdPlugin::HouseAd.create( diff --git a/spec/serializer/current_user_serializer_spec.rb b/spec/serializer/current_user_serializer_spec.rb index 9439653..53ac5b5 100644 --- a/spec/serializer/current_user_serializer_spec.rb +++ b/spec/serializer/current_user_serializer_spec.rb @@ -4,7 +4,7 @@ RSpec.describe CurrentUserSerializer do fab!(:tl0_user) { Fabricate(:user, trust_level: 0, refresh_auto_groups: true) } fab!(:tl2_user) { Fabricate(:user, trust_level: 2, refresh_auto_groups: true) } fab!(:tl3_user) { Fabricate(:user, trust_level: 3, refresh_auto_groups: true) } - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) let(:tl0_serializer) { described_class.new(tl0_user, scope: Guardian.new(tl0_user), root: false) } diff --git a/spec/system/admin_house_ad_spec.rb b/spec/system/admin_house_ad_spec.rb index 4491072..8f22e64 100644 --- a/spec/system/admin_house_ad_spec.rb +++ b/spec/system/admin_house_ad_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true describe "Admin House Ad", type: :system, js: true do - fab!(:admin) { Fabricate(:admin) } + fab!(:admin) let(:house_ad) do AdPlugin::HouseAd.create( name: "some-name",