From 7c1343be9eade5c58c09acdd156de71a95685ea3 Mon Sep 17 00:00:00 2001 From: Nick Taylor Date: Wed, 17 Mar 2021 10:57:56 -0400 Subject: [PATCH] Revert "Revert "Removed service worker (#12974)" (#13014)" (#13015) This reverts commit 2416387fb4a06b0abc839baeacd05ec8bc74069a. --- .env_sample | 1 - app/assets/javascripts/base.js.erb | 1 - .../javascripts/serviceworker-companion.js | 36 -- app/controllers/application_controller.rb | 6 - app/controllers/pages_controller.rb | 3 +- app/controllers/registrations_controller.rb | 3 +- app/controllers/service_worker_controller.rb | 7 +- app/helpers/application_helper.rb | 4 - app/lib/url.rb | 17 - app/views/articles/show.html.erb | 3 +- app/views/layouts/application.html.erb | 100 ++++- app/views/service_worker/index.js.erb | 98 +---- app/views/service_worker/manifest.json.erb | 26 -- app/views/shell/_bottom.html.erb | 19 - app/views/shell/_top.html.erb | 88 ----- config/routes.rb | 3 - docs/frontend/tips.md | 9 - docs/technical-overview/architecture.md | 26 +- lib/tasks/cache.rake | 6 - public/offline.html | 360 ------------------ spec/helpers/application_helper_spec.rb | 14 - spec/requests/pages_spec.rb | 14 - spec/requests/service_worker_spec.rb | 37 -- spec/requests/shells_spec.rb | 39 -- 24 files changed, 125 insertions(+), 795 deletions(-) delete mode 100644 app/assets/javascripts/serviceworker-companion.js delete mode 100644 app/views/service_worker/manifest.json.erb delete mode 100644 app/views/shell/_bottom.html.erb delete mode 100644 app/views/shell/_top.html.erb delete mode 100644 public/offline.html delete mode 100644 spec/requests/service_worker_spec.rb delete mode 100644 spec/requests/shells_spec.rb diff --git a/.env_sample b/.env_sample index 54734e893..178cb5ed8 100644 --- a/.env_sample +++ b/.env_sample @@ -1,5 +1,4 @@ # Development options -SKIP_SERVICEWORKERS="true" # App core values APP_DOMAIN="localhost:3000" diff --git a/app/assets/javascripts/base.js.erb b/app/assets/javascripts/base.js.erb index 9158b558f..d10fa6328 100644 --- a/app/assets/javascripts/base.js.erb +++ b/app/assets/javascripts/base.js.erb @@ -5,7 +5,6 @@ //= require utilities/getImageForLink //= require honeybadger-js/dist/honeybadger.js //= require ahoy.js/dist/ahoy.js -//= require serviceworker-companion var instantClick , InstantClick = instantClick = function(document, location, $userAgent) { diff --git a/app/assets/javascripts/serviceworker-companion.js b/app/assets/javascripts/serviceworker-companion.js deleted file mode 100644 index a1aaab448..000000000 --- a/app/assets/javascripts/serviceworker-companion.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; - -if ('serviceWorker' in navigator) { - // Safari has issues with the service worker, so we'll just skip it on those browsers, and unregister it if it's loaded - if ( - /Safari/i.test(navigator.userAgent) && - /Apple Computer/.test(navigator.vendor) - ) { - //unregister serviceworker - navigator.serviceWorker - .getRegistration('/serviceworker.js') - .then(function (registration) { - if (registration) { - registration.unregister(); - } - }); - } else { - navigator.serviceWorker - .register('/serviceworker.js', { scope: '/' }) - .then(function swStart(registration) { - // registered! - }) - .catch((error) => { - // eslint-disable-next-line no-console - console.log('ServiceWorker registration failed: ', error); - }); - } -} - -window.addEventListener('beforeinstallprompt', (e) => { - // beforeinstallprompt Event fired - // e.userChoice will return a Promise. - e.userChoice.then((choiceResult) => { - ga('send', 'event', 'PWA-install', choiceResult.outcome); - }); -}); diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4bfa8c03a..329c47b4c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -41,14 +41,8 @@ class ApplicationController < ActionController::Base health_checks].freeze private_constant :PUBLIC_CONTROLLERS - # TODO: Remove the "shell" endpoints, because they are for service worker - # functionality we no longer need. We are keeping these around mid-March - # 2021 because previously-installed service workers may still expect them. CONTENT_CHANGE_PATHS = [ "/tags/onboarding", # Needs to change when suggested_tags is edited. - "/shell_top", # Cached at edge, sent to service worker. - "/shell_bottom", # Cached at edge, sent to service worker. - "/async_info/shell_version", # Checks if current users should be busted. "/onboarding", # Page is cached at edge. "/", # Page is cached at edge. ].freeze diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 714765244..6fb9e3411 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -83,8 +83,7 @@ class PagesController < ApplicationController end def report_abuse - referer = URL.sanitized_referer(request.referer) - reported_url = params[:reported_url] || params[:url] || referer + reported_url = params[:reported_url] || params[:url] || request.referer.presence @feedback_message = FeedbackMessage.new( reported_url: reported_url&.chomp("?i=i"), ) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 9ce064fc2..7852342e9 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -5,8 +5,7 @@ class RegistrationsController < Devise::RegistrationsController if user_signed_in? redirect_to root_path(signin: "true") else - referer_path = URI(request.referer || "").path - if URI(request.referer || "").host == URI(request.base_url).host && referer_path != "/serviceworker.js" + if URI(request.referer || "").host == URI(request.base_url).host store_location_for(:user, request.referer) end super diff --git a/app/controllers/service_worker_controller.rb b/app/controllers/service_worker_controller.rb index d7a6c6bbd..bbbedd577 100644 --- a/app/controllers/service_worker_controller.rb +++ b/app/controllers/service_worker_controller.rb @@ -1,14 +1,9 @@ class ServiceWorkerController < ApplicationController skip_before_action :verify_authenticity_token - before_action :set_cache_control_headers, only: %i[index manifest] + before_action :set_cache_control_headers, only: %i[index] def index set_surrogate_key_header "serviceworker-js" render formats: [:js] end - - def manifest - set_surrogate_key_header "manifest-json" - render formats: [:json] - end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 201561287..68f5d0ddc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -261,10 +261,6 @@ module ApplicationHelper URL.organization(organization) end - def sanitized_referer(referer) - URL.sanitized_referer(referer) - end - def sanitize_and_decode(str) # using to_str instead of to_s to prevent removal of html entity code HTMLEntities.new.decode(sanitize(str).to_str) diff --git a/app/lib/url.rb b/app/lib/url.rb index b82512488..af1f6f283 100644 --- a/app/lib/url.rb +++ b/app/lib/url.rb @@ -1,7 +1,5 @@ # Utilities methods to safely build app wide URLs module URL - SERVICE_WORKER = "/serviceworker.js".freeze - def self.protocol ApplicationConfig["APP_PROTOCOL"] end @@ -72,19 +70,4 @@ module URL def self.organization(organization) url(organization.slug) end - - # Ensures we don't consider serviceworker.js as referer - # - # @param referer [String] the unsanitized referer - # @example A safe referer - # sanitized_referer("/some/path") #=> "/some/path" - # @example serviceworker.js as referer - # sanitized_referer("serviceworker.js") #=> nil - # @example An empty string - # sanitized_referer("") #=> nil - def self.sanitized_referer(referer) - return if referer.blank? || URI(referer).path == SERVICE_WORKER - - referer - end end diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index 71c20fa82..1b3a2f84d 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -48,7 +48,8 @@ <% end %> <% if internal_navigation? %> - + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e85f1e26d..b8a2cb155 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,4 +1,86 @@ -<%= render "shell/top" %> + + + + + <% title = yield(:title) %> + <%= title || community_name.to_s %> + <% unless internal_navigation? %> + + + + <% if SiteConfig.payment_pointer.present? %> + + + + + + + <% end %> + + <%= render "layouts/styles", qualifier: "main" %> + <% unless user_signed_in? %> + <%= javascript_packs_with_chunks_tag "base", "Search", defer: true %> + <% end %> + <%= javascript_include_tag "base", defer: true %> + <% if user_signed_in? %> + <%= javascript_packs_with_chunks_tag "base", "Search", "onboardingRedirectCheck", "contentDisplayPolicy", defer: true %> + <% end %> + <%= yield(:page_meta) %> + + <%= favicon_link_tag Images::Optimizer.call(SiteConfig.favicon_url, width: 32) %> + "> + "> + "> + "> + " rel="icon" sizes="192x192" /> + " rel="icon" sizes="128x128" /> + + + + " type="application/opensearchdescription+xml" title="<%= community_name %>" /> + + + " /> + + <% end %> + + <% unless internal_navigation? %> + <% cache(release_adjusted_cache_key("top-html-and-config--#{user_signed_in?}")) do %> + -article-body default-header" + data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>" + data-app-domain="<%= ChatChannel.urlsafe_encoded_app_domain %>" + data-honeybadger-key="<%= ApplicationConfig["HONEYBADGER_JS_API_KEY"] %>" + data-deployed-at="<%= ForemInstance.deployed_at %>" + data-latest-commit-id="<%= ForemInstance.latest_commit_id %>" + data-ga-tracking="<%= SiteConfig.ga_tracking_id %>"> + <%# Repeat of stylesheets in to fix rendering glitch: https://github.com/forem/forem/issues/12377 %> + <%= render "layouts/styles", qualifier: "secondary" %> +
+ +
+ <% if user_signed_in? %> + <%= render "layouts/user_config" %> + <% end %> +
+ <%= yield(:audio) %> +
+ <%= render "layouts/top_bar" %> +
+
+
+ loading... +
+ <% end %> + <% end %> <% if SiteConfig.payment_pointer.present? %>
<% end %> @@ -24,4 +106,18 @@ <%= yield %> -<%= render "shell/bottom" %> +<% unless internal_navigation? %> + <% cache("footer-and-signup-modal-#{user_signed_in?}-#{ForemInstance.deployed_at}-#{SiteConfig.admin_action_taken_at&.rfc3339}", expires_in: 24.hours) do %> + <%= render "layouts/footer" %> + <%= render "layouts/signup_modal" unless user_signed_in? %> + <% end %> + <% if @shell %> + + <% end %> + + +<% end %> diff --git a/app/views/service_worker/index.js.erb b/app/views/service_worker/index.js.erb index 94586bccd..f15a0a651 100644 --- a/app/views/service_worker/index.js.erb +++ b/app/views/service_worker/index.js.erb @@ -1,91 +1,21 @@ // Service worker file. Renders as serviceworker.js +// This is now a self-destructing service worker. See https://github.com/NekR/self-destroying-sw -<% unless Rails.env.test? || ENV["SKIP_SERVICEWORKERS"] == "true" %> - const VERSION = "1.0" // Increment to invalidate old assets. - const OFFLINE_URL = "offline.html"; - const OFFLINE_NAME = OFFLINE_URL + VERSION - - self.addEventListener("install", (event) => { - event.waitUntil( - (async () => { - - // Setting {cache: 'reload'} in the new request will ensure that the - // response isn't fulfilled from the HTTP cache; i.e., it will be from - // the network. - const offlineCache = await caches.open(OFFLINE_NAME); - await offlineCache.add(new Request(OFFLINE_URL, { cache: "reload" })); - })() - ); - // Force the waiting service worker to become the active service worker. +<% unless Rails.env.test? %> + self.addEventListener('install', function(e) { self.skipWaiting(); }); - self.addEventListener("activate", (event) => { - event.waitUntil( - (async () => { - // Enable navigation preload if it's supported. - // See https://developers.google.com/web/updates/2017/02/navigation-preload - if ("navigationPreload" in self.registration) { - await self.registration.navigationPreload.enable(); - } - })() - ); - - // Tell the active service worker to take control of the page immediately. - self.clients.claim(); - }); - - function includesUnsupportedPath(url) { - return [ - '/%F0%9F%92%B8', // 💸 (hiring) - '/admin', // Don't run on admin dashboard. - '/new', // Don't run on editor. - '/enter', // Don't run on sign in page. - '/oauth/', // Skip oauth apps - '/onboarding', // Don't run on onboarding. - '/shop', // Don't run on Shop - '/sidekiq', // Skip for Sidekiq dashboard - '/users/auth', // Don't run on authentication. - '/users/sign_in', // Don't run on sign in page. - '/welcome', // Don't run on welcome reroutes. - ].some(path => url.includes(path)) - } - - self.addEventListener("fetch", (event) => { - // We only want to call event.respondWith() if this is a navigation request - // for an HTML page with a few exceptions. - if (event.request.mode === "navigate" && !includesUnsupportedPath(event.request.url)) { - event.respondWith( - (async () => { - try { - // First, try to use the navigation preload response if it's supported. - const preloadResponse = await event.preloadResponse; - if (preloadResponse) { - return preloadResponse; - } - - // Always try the network first. - const networkResponse = await fetch(event.request); - return networkResponse; - } catch (error) { - // catch is only triggered if an exception is thrown, which is likely - // due to a network error. - // If fetch() returns a valid HTTP response with a response code in - // the 4xx or 5xx range, the catch() will NOT be called. - console.log("Fetch failed; returning offline page instead.", error); - - const cache = await caches.open(OFFLINE_NAME); - const cachedResponse = await cache.match(OFFLINE_URL); - return cachedResponse; - } - })() - ); - } - - // If our if() condition is false, then this fetch handler won't intercept the - // request. If there are any other fetch handlers registered, they will get a - // chance to call event.respondWith(). If no fetch handlers call - // event.respondWith(), the request will be handled by the browser as if there - // were no service worker involvement. + self.addEventListener('activate', function(e) { + self.registration.unregister() + .then(function() { + return self.clients.matchAll(); + }) + .then(function(clients) { + clients.forEach(client => { + // Check if client.navigate is supported before running it. + client.navigate && client.navigate(client.url); + }) + }); }); <% end %> diff --git a/app/views/service_worker/manifest.json.erb b/app/views/service_worker/manifest.json.erb deleted file mode 100644 index cd204a184..000000000 --- a/app/views/service_worker/manifest.json.erb +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "<%= community_name %>", - "short_name": "<%= SiteConfig.app_domain %>", - "description": "<%= SiteConfig.community_description %>", - "start_url": "/", - "display": "standalone", - "background_color": "#000000", - "theme_color": "#000000", - "homepage_url": "<%= app_url %>", - "icons": [{ - "src": "<%= optimized_image_url(SiteConfig.logo_png, width: 192, fetch_format: "png") %>", - "sizes": "192x192", - "type": "image/png", - "purpose": "any maskable" - }, { - "src": "<%= optimized_image_url(SiteConfig.logo_png, width: 128, fetch_format: "png") %>", - "sizes": "128x128", - "type": "image/png", - "purpose": "any maskable" - }, { - "src": "<%= optimized_image_url(SiteConfig.logo_png, width: 512, fetch_format: "png") %>", - "sizes": "512x512", - "type": "image/png", - "purpose": "any maskable" - }] -} diff --git a/app/views/shell/_bottom.html.erb b/app/views/shell/_bottom.html.erb deleted file mode 100644 index 111d4a33e..000000000 --- a/app/views/shell/_bottom.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -<% # TODO: This file supports removed service worker functionality. We are keeping it around until mid-March to support previously downloaded service workers. %> -<% # After that, these contents can be moved right into application.html. %> - - -<% unless internal_navigation? %> - <% cache("footer-and-signup-modal-#{user_signed_in?}-#{ForemInstance.deployed_at}-#{SiteConfig.admin_action_taken_at&.rfc3339}", expires_in: 24.hours) do %> - <%= render "layouts/footer" %> - <%= render "layouts/signup_modal" unless user_signed_in? %> - <% end %> - <% if @shell %> - - <% end %> - - -<% end %> diff --git a/app/views/shell/_top.html.erb b/app/views/shell/_top.html.erb deleted file mode 100644 index de4089f23..000000000 --- a/app/views/shell/_top.html.erb +++ /dev/null @@ -1,88 +0,0 @@ -<% # TODO: This file supports removed service worker functionality. We are keeping it around until mid-March to support previously downloaded service workers. %> -<% # After that, these contents can be moved right into application.html. %> - - - - - - <% title = yield(:title) %> - <%= title || community_name.to_s %> - <% unless internal_navigation? %> - - - - <% if SiteConfig.payment_pointer.present? %> - - - - - - - <% end %> - - <%= render "layouts/styles", qualifier: "main" %> - <% unless user_signed_in? %> - <%= javascript_packs_with_chunks_tag "base", "Search", defer: true %> - <% end %> - <%= javascript_include_tag "base", defer: true %> - <% if user_signed_in? %> - <%= javascript_packs_with_chunks_tag "base", "Search", "onboardingRedirectCheck", "contentDisplayPolicy", defer: true %> - <% end %> - <%= yield(:page_meta) %> - - <%= favicon_link_tag Images::Optimizer.call(SiteConfig.favicon_url, width: 32) %> - "> - "> - "> - "> - " rel="icon" sizes="192x192" /> - " rel="icon" sizes="128x128" /> - - - - - " type="application/opensearchdescription+xml" title="<%= community_name %>" /> - - - " /> - - <% end %> - - <% unless internal_navigation? %> - <% cache(release_adjusted_cache_key("top-html-and-config--#{user_signed_in?}")) do %> - -article-body default-header" - data-pusher-key="<%= ApplicationConfig["PUSHER_KEY"] %>" - data-app-domain="<%= ChatChannel.urlsafe_encoded_app_domain %>" - data-honeybadger-key="<%= ApplicationConfig["HONEYBADGER_JS_API_KEY"] %>" - data-deployed-at="<%= ForemInstance.deployed_at %>" - data-latest-commit-id="<%= ForemInstance.latest_commit_id %>" - data-ga-tracking="<%= SiteConfig.ga_tracking_id %>"> - <%# Repeat of stylesheets in to fix rendering glitch: https://github.com/forem/forem/issues/12377 %> - <%= render "layouts/styles", qualifier: "secondary" %> -
- -
- <% if user_signed_in? %> - <%= render "layouts/user_config" %> - <% end %> -
- <%= yield(:audio) %> -
- <%= render "layouts/top_bar" %> -
-
-
- loading... -
- <% end %> - - <% end %> diff --git a/config/routes.rb b/config/routes.rb index af407f487..2d8718baf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -577,9 +577,6 @@ Rails.application.routes.draw do get "/open-search", to: "open_search#show", constraints: { format: /xml/ } - get "/shell_top", to: "shell#top" - get "/shell_bottom", to: "shell#bottom" - get "/new", to: "articles#new" get "/new/:template", to: "articles#new" diff --git a/docs/frontend/tips.md b/docs/frontend/tips.md index 9102168e5..4c90d8c53 100644 --- a/docs/frontend/tips.md +++ b/docs/frontend/tips.md @@ -44,12 +44,3 @@ selectors more sophisticated than a simple id, class or tag name. - [Forem PR 6380](https://github.com/forem/forem/issues/6380#issuecomment-592989438) - [Why is getElementsByTagName() faster than querySelectorAll()?](https://humanwhocodes.com/blog/2010/09/28/why-is-getelementsbytagname-faster-that-queryselectorall/) - [What is the difference between querySelectorAll and getElementsByTagName?](https://stackoverflow.com/a/30921553/4186181) - -## Service workers in development - -By default our -[service worker code](https://github.com/forem/forem/blob/master/app/views/service_worker/index.js.erb) -doesn't run in development. - -If you're planning to do any work around service workers you'll need to enable -them by setting the `SKIP_SERVICEWORKERS` environment variable to `"false"`. diff --git a/docs/technical-overview/architecture.md b/docs/technical-overview/architecture.md index 2fe1cd033..c6ed9a2fa 100644 --- a/docs/technical-overview/architecture.md +++ b/docs/technical-overview/architecture.md @@ -25,18 +25,18 @@ caching. ## Content precision In some situations we may want more precise content than in others. Often when -we do not need a precise number, it offers an opportunity to either estimate -the content or bust the cache less frequently. +we do not need a precise number, it offers an opportunity to either estimate the +content or bust the cache less frequently. ### Examples - We use the `estimated_count` for a more efficient query of registered users on -the home page. We have deemed that this is probably close enough. -- On posts and comment trees without recent comments, we do not asynchronously fetch -the absolute latest individual reaction counts for logged-out users because this -number is likely to be correct without the async call, and if it is off-by-one, we -can make the choice that it is not important that it be more precise than this. - + the home page. We have deemed that this is probably close enough. +- On posts and comment trees without recent comments, we do not asynchronously + fetch the absolute latest individual reaction counts for logged-out users + because this number is likely to be correct without the async call, and if it + is off-by-one, we can make the choice that it is not important that it be more + precise than this. ## We Mostly defer scripts for usage performance improvements @@ -54,16 +54,6 @@ We use [PreactJS](/frontend/preact), a lightweight alternative to ReactJS, and we try to reduce our bundle size with [dynamic imports](/frontend/dynamic-imports). -## Service workers and shell architecture - -We make use of serviceworkers to cache portions of the page. - -Serviceworkers can be controlled in the `application` tab of Chrome. -Serviceworkers are a reverse proxy that runs in the browser in a non-blocking -thread, supported by most major browsers. You may want to disable or bypass -Serviceworkers in development while making changes to avoid having everything -cached. - ## Worst technical debt The most widespread elements of technical debt in this application reside on the diff --git a/lib/tasks/cache.rake b/lib/tasks/cache.rake index de7d383b9..00a96521e 100644 --- a/lib/tasks/cache.rake +++ b/lib/tasks/cache.rake @@ -4,12 +4,6 @@ namespace :cache do # Trigger cache purges for globally-cached endpoints that could have changed [30, 180, 600].each do |n| BustCachePathWorker.set(queue: :high_priority).perform_in(n.seconds, "/") - # TODO: Remove these "shell" endpoints, because they are for service worker functionality we no longer need. - # We are keeping these around mid-March 2021 because previously-installed service workers may still expect them. - BustCachePathWorker.set(queue: :high_priority).perform_in(n.seconds, "/shell_top") - BustCachePathWorker.set(queue: :high_priority).perform_in(n.seconds, "/shell_bottom") - BustCachePathWorker.set(queue: :high_priority).perform_in(n.seconds, "/async_info/shell_version") - BustCachePathWorker.set(queue: :high_priority).perform_in(n.seconds, "/onboarding") end end diff --git a/public/offline.html b/public/offline.html deleted file mode 100644 index edd3d73e5..000000000 --- a/public/offline.html +++ /dev/null @@ -1,360 +0,0 @@ - - - - You are not connected to the Internet - - - - - - - - - - - - - - - - - -
- -

So, there's good news and bad news

-

Bad news: It looks like you're offline

-

Good news: You can draw a picture anywhere on this page while you wait to get it back!

-

(pick a color below && start drawing!)

-
- -
-
-
- - -
- - - - - - - - - - - - - diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index bac034c13..e2262474c 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -139,20 +139,6 @@ RSpec.describe ApplicationHelper, type: :helper do end end - describe "#sanitized_referer" do - it "returns a safe referrer unmodified" do - expect(sanitized_referer("/some/path")).to eq("/some/path") - end - - it "returns nil if the referer is the service worker" do - expect(sanitized_referer("/serviceworker.js")).to be nil - end - - it "returns nil if the referer is empty" do - expect(sanitized_referer("")).to be nil - end - end - describe "#collection_link" do let(:collection) { create(:collection, :with_articles) } diff --git a/spec/requests/pages_spec.rb b/spec/requests/pages_spec.rb index 8f6719896..bcc9792a6 100644 --- a/spec/requests/pages_spec.rb +++ b/spec/requests/pages_spec.rb @@ -246,20 +246,6 @@ RSpec.describe "Pages", type: :request do get "/report-abuse", headers: { referer: url } expect(response.body).to include(url) end - - it "does not prefill if the provide url is /serviceworker.js" do - url = "https://dev.to/serviceworker.js" - get "/report-abuse", headers: { referer: url } - expect(response.body).not_to include(url) - end - end - - context "when provided the params" do - it "prefills with the provided param url" do - url = "https://dev.to/serviceworker.js" - get "/report-abuse", params: { url: url } - expect(response.body).to include(url) - end end end end diff --git a/spec/requests/service_worker_spec.rb b/spec/requests/service_worker_spec.rb deleted file mode 100644 index 868eb1602..000000000 --- a/spec/requests/service_worker_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -require "rails_helper" - -RSpec.describe "ServiceWorker", type: :request do - describe "GET /serviceworker.js" do - it "renders file with proper text" do - get "/serviceworker.js" - expect(response.body).to include("Service worker file") - end - - it "renders javascript file" do - get "/serviceworker.js" - expect(response.header["Content-Type"]).to include("text/javascript") - end - - it "sends a surrogate key (for Fastly's user)" do - get "/serviceworker.js" - expect(response.header["Surrogate-Key"]).to include("serviceworker-js") - end - end - - describe "GET /manifest.json" do - it "renders file with proper text" do - get "/manifest.json" - expect(response.body).to include("\"name\": \"#{SiteConfig.community_name}\"") - end - - it "renders json file" do - get "/manifest.json" - expect(response.header["Content-Type"]).to include("application/json") - end - - it "sends a surrogate key (for Fastly's user)" do - get "/manifest.json" - expect(response.header["Surrogate-Key"]).to include("manifest-json") - end - end -end diff --git a/spec/requests/shells_spec.rb b/spec/requests/shells_spec.rb deleted file mode 100644 index 03c3bcc49..000000000 --- a/spec/requests/shells_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require "rails_helper" - -RSpec.describe "Shells", type: :request do - describe "GET /shell_top" do - it "renders file with proper text" do - get "/shell_top" - expect(response.body).to include("user-signed-in") - end - - it "sends a surrogate key (for Fastly's user)" do - get "/shell_top" - expect(response.header["Surrogate-Key"]).to include("shell-top") - end - - it "renders normal response even if site config is private" do - allow(SiteConfig).to receive(:public).and_return(false) - get "/shell_top" - expect(response.body).to include("user-signed-in") - end - end - - describe "GET /shell_bottom" do - it "renders file with proper text" do - get "/shell_bottom" - expect(response.body).to include("footer-container") - end - - it "sends a surrogate key (for Fastly's user)" do - get "/shell_bottom" - expect(response.header["Surrogate-Key"]).to include("shell-bottom") - end - - it "renders normal response even if site config is private" do - allow(SiteConfig).to receive(:public).and_return(false) - get "/shell_bottom" - expect(response.body).to include("footer-container") - end - end -end