This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
forked from Growstuff/growstuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Growstuff#740 from yez/feature/robots-dissalow-on-…
…staging Feature/robots dissalow on staging
- Loading branch information
Showing
7 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class RobotsController < ApplicationController | ||
|
||
DEFAULT_FILENAME = 'config/robots.txt'.freeze | ||
|
||
def robots | ||
filename = if subdomain && subdomain != 'www' | ||
"config/robots.#{ subdomain }.txt" | ||
end | ||
|
||
file_to_render = File.exists?(filename.to_s) ? filename : DEFAULT_FILENAME | ||
|
||
render file: file_to_render, layout: false, content_type: 'text/plain' | ||
end | ||
|
||
private | ||
|
||
def subdomain | ||
request.subdomain.present? ? request.subdomain : nil | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-Agent: * | ||
Disallow: / |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
Growstuff::Application.routes.draw do | ||
|
||
get '/robots.txt' => 'robots#robots' | ||
|
||
resources :plant_parts | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'rails_helper' | ||
|
||
describe RobotsController do | ||
describe '#robots' do | ||
let(:production_filename) { 'config/robots.txt' } | ||
let(:staging_filename) { 'config/robots.staging.txt' } | ||
|
||
before do | ||
@request.host = "#{ subdomain }.localhost.com" | ||
end | ||
|
||
context 'subdomain is staging' do | ||
let(:subdomain) { 'staging' } | ||
|
||
it 'loads the staging robots.txt file' do | ||
get :robots | ||
|
||
expect(response).to be_success | ||
expect(response.body).to eq(File.read(staging_filename)) | ||
end | ||
end | ||
|
||
context 'subdomain is www' do | ||
let(:subdomain) { 'www' } | ||
|
||
it 'loads the production robots.txt file' do | ||
get :robots | ||
|
||
expect(response).to be_success | ||
expect(response.body).to eq(File.read(production_filename)) | ||
end | ||
end | ||
|
||
context 'subdomain is not present' do | ||
let(:subdomain) { '' } | ||
|
||
it 'loads the production robots.txt file' do | ||
get :robots | ||
|
||
expect(response).to be_success | ||
expect(response.body).to eq(File.read(production_filename)) | ||
end | ||
end | ||
|
||
context 'subdomain is nonsense' do | ||
let(:subdomain) { '1874ajnfien' } | ||
|
||
it 'loads the production robots.txt file' do | ||
get :robots | ||
|
||
expect(response).to be_success | ||
expect(response.body).to eq(File.read(production_filename)) | ||
end | ||
end | ||
end | ||
end |