A platform for community discussion. Free, open, simple.
DEV: Do not process requests initiated by browser in a different example (#25809)
Alan Guo Xiang Tan6e9fbb5babf5
diff --git a/config/initializers/200-first_middlewares.rb b/config/initializers/200-first_middlewares.rbindex 79bbb199040..618a083dedb 100644--- a/config/initializers/200-first_middlewares.rb+++ b/config/initializers/200-first_middlewares.rb@@ -33,6 +33,10 @@ if Rails.env.test?RailsMultisite::DiscoursePatches.configclass BlockRequestsMiddleware+ RSPEC_CURRENT_EXAMPLE_COOKIE_STRING = "rspec_current_example_location"++ cattr_accessor :current_example_location+@@block_requests = falsedef self.block_requests!@@ -48,7 +52,17 @@ if Rails.env.test?enddef call(env)- if @@block_requests+ request = Rack::Request.new(env)++ if request.xhr? &&+ (+ @@block_requests ||+ (+ self.class.current_example_location.present? &&+ self.class.current_example_location !=+ request.cookies[RSPEC_CURRENT_EXAMPLE_COOKIE_STRING]+ )+ )[503, { "Content-Type" => "text/plain" }, ["Blocked by BlockRequestsMiddleware"]]else@app.call(env)diff --git a/plugins/chat/spec/system/chat_new_message_spec.rb b/plugins/chat/spec/system/chat_new_message_spec.rbindex a3116a038d6..1ee12b31d9f 100644--- a/plugins/chat/spec/system/chat_new_message_spec.rb+++ b/plugins/chat/spec/system/chat_new_message_spec.rb@@ -27,7 +27,7 @@ RSpec.describe "Chat New Message from params", type: :system doexpect(page).to have_current_path("/chat/c/#{user_2.username}/#{Chat::Channel.last.id}")end- xit "redirects to chat channel if recipients param is missing" do+ it "redirects to chat channel if recipients param is missing" dovisit("/chat/new-message")# chat service selects public channel from getIdealFirstChannelIddiff --git a/plugins/chat/spec/system/single_thread_spec.rb b/plugins/chat/spec/system/single_thread_spec.rbindex 3cd32345c4b..382d70d7915 100644--- a/plugins/chat/spec/system/single_thread_spec.rb+++ b/plugins/chat/spec/system/single_thread_spec.rb@@ -20,7 +20,7 @@ describe "Single thread in side panel", type: :system dobefore { channel.update!(threading_enabled: false) }- it "does not open the side panel for a single thread", capture_log: true do+ it "does not open the side panel for a single thread" dothread =chat_thread_chain_bootstrap(channel: channel, users: [current_user, Fabricate(:user)])chat_page.visit_channel(channel)diff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex c34c465bb14..af8f3d93dac 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -152,6 +152,7 @@ module TestSetupMiddleware::AnonymousCache.disable_anon_cacheBlockRequestsMiddleware.allow_requests!+ BlockRequestsMiddleware.current_example_location = nilendend@@ -592,6 +593,14 @@ RSpec.configure do |config|ActiveRecord::Base.connection.schema_cache.add(table)end+ ApplicationController.before_action do+ if BlockRequestsMiddleware.current_example_location+ cookies[+ BlockRequestsMiddleware::RSPEC_CURRENT_EXAMPLE_COOKIE_STRING+ ] = BlockRequestsMiddleware.current_example_location+ end+ end+system_tests_initialized = trueend@@ -609,6 +618,8 @@ RSpec.configure do |config|driven_by driver.join("_").to_symsetup_system_test++ BlockRequestsMiddleware.current_example_location = example.locationendconfig.after(:each, type: :system) do |example|