Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
include Authentication
include Authorization
include BlockSearchEngineIndexing
include CurrentRequest, CurrentTimezone, SetPlatform
include RequestForgeryProtection
include TurboFlash, ViewTransitions
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/concerns/block_search_engine_indexing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tell crawlers like Googlebot to drop pages entirely from search results, even
# if other sites link to it
module BlockSearchEngineIndexing
extend ActiveSupport::Concern

included do
after_action :block_search_engine_indexing
end

private
def block_search_engine_indexing
headers["X-Robots-Tag"] = "none"
end
end
3 changes: 2 additions & 1 deletion public/robots.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
User-Agent: *
Disallow: /
28 changes: 28 additions & 0 deletions test/controllers/concerns/block_search_engine_indexing_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "test_helper"

class BlockSearchEngineIndexingTest < ActionDispatch::IntegrationTest
test "sets X-Robots-Tag header to none on authenticated requests" do
sign_in_as :david

get board_path(boards(:writebook))
assert_response :success
assert_equal "none", response.headers["X-Robots-Tag"]
end

test "sets X-Robots-Tag header to none on unauthenticated requests" do
untenanted do
get new_session_path
end

assert_response :success
assert_equal "none", response.headers["X-Robots-Tag"]
end

test "sets X-Robots-Tag header to none on public board pages" do
boards(:writebook).publish

get public_board_path(boards(:writebook).publication.key)
assert_response :success
assert_equal "none", response.headers["X-Robots-Tag"]
end
end