Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Commit

Permalink
[#74] Add robots.txt for non production sites.
Browse files Browse the repository at this point in the history
  • Loading branch information
taktran committed Apr 29, 2013
1 parent bd7d286 commit b31dc20
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
13 changes: 13 additions & 0 deletions application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'sinatra'
require './lib/partials'
require './lib/string'
require './lib/constants'
require 'haml'
require 'sass'
require 'compass'
Expand Down Expand Up @@ -42,6 +43,18 @@
scss :'stylesheets/screen'
end

# Show lib/robots_txt_to_exclude_all.txt
#
# Only show on non-production sites
get '/robots.txt' do
if is_production?
redirect not_found
else
content_type 'text/plain', :charset => 'utf-8'
File.read(File.join('lib', 'robots_txt_to_exclude_all.txt'))
end
end

get '/' do
protected_unless_disabled!

Expand Down
7 changes: 7 additions & 0 deletions lib/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Constants

HTTP_STATUS_OK = 200
HTTP_STATUS_BAD_REQUEST = 400
HTTP_STATUS_NOT_FOUND = 404
HTTP_STATUS_BAD_REQUEST_CONFLICT = 409
HTTP_STATUS_INTERNAL_SERVER_ERROR = 500
2 changes: 2 additions & 0 deletions lib/robots_txt_to_exclude_all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Disallow: /
23 changes: 23 additions & 0 deletions spec/integration/robots_txt_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require_relative '../spec_helper'

describe "/robots.txt" do
before { @robots_path = "/robots.txt" }

it "shows on development" do
settings.environment = "development"
get @robots_path
expect(last_response.status).to be HTTP_STATUS_OK
end

it "shows on staging" do
settings.environment = "staging"
get @robots_path
expect(last_response.status).to be HTTP_STATUS_OK
end

it "doesn't show in production" do
settings.environment = "production"
get @robots_path
expect(last_response.status).to be HTTP_STATUS_NOT_FOUND
end
end

0 comments on commit b31dc20

Please sign in to comment.