Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle old book site's url path

  • Loading branch information...
commit 0c9707393c409904e1b6842da52b48776a2924aa 1 parent d71e5de
@bry4n bry4n authored
View
1  .gitignore
@@ -22,3 +22,4 @@
#Ignore vim swpfiles
*.swp
+*.swo
View
1  Gemfile
@@ -58,4 +58,5 @@ end
group :test do
gem 'factory_girl_rails'
gem 'shoulda', :require => false
+ gem 'rspec-rails'
end
View
13 Gemfile.lock
@@ -159,6 +159,18 @@ GEM
ref (1.0.5)
rest-client (1.6.7)
mime-types (>= 1.16)
+ rspec-core (2.14.7)
+ rspec-expectations (2.14.4)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.4)
+ rspec-rails (2.14.1)
+ actionpack (>= 3.0)
+ activemodel (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
rubyzip (1.0.0)
sass (3.2.12)
sass-rails (3.2.6)
@@ -250,6 +262,7 @@ DEPENDENCIES
rails_12factor
redcarpet
rest-client
+ rspec-rails
rubyzip
sass-rails
shoulda
View
10 app/controllers/books_controller.rb
@@ -1,6 +1,7 @@
class BooksController < ApplicationController
- before_filter :book_resource, :only => [:section, :chapter]
+ before_filter :book_resource, only: [:section, :chapter]
+ before_filter :redirect_book, only: [:show]
def show
@book = Book.includes(:sections).where(:code => (params[:lang] || "en")).first
@@ -44,6 +45,13 @@ def chapter
private
+ def redirect_book
+ uri_path = params[:lang]
+ if slug = REDIRECT[uri_path]
+ return redirect_to lang_book_path(lang: slug)
+ end
+ end
+
def book_resource
@book ||= Book.where(:code => (params[:lang] || "en")).first
raise PageNotFound unless @book
View
10 app/controllers/site_controller.rb
@@ -58,16 +58,6 @@ def redirect_wgibtx
redirect_to "http://git-scm.com/about"
end
- # like '5_submodules.html', etc
- def redirect_combook
- current_uri = request.env['PATH_INFO'].gsub('/', '')
- if slug = REDIRECT[current_uri]
- redirect_to "http://git-scm.com/book/#{slug}"
- else
- redirect_to "http://git-scm.com/book"
- end
- end
-
def redirect_book
current_uri = request.env['PATH_INFO']
if current_uri == '/'
View
10 config/routes.rb
@@ -9,10 +9,10 @@
match '*path' => 'site#redirect_book'
end
- constraints(:subdomain => 'book') do
- root :to => 'site#redirect_book'
- match '*path' => 'site#redirect_combook'
- end
+# constraints(:subdomain => 'book') do
+# root :to => 'site#redirect_book'
+# match '*path' => 'site#redirect_combook'
+# end
get "site/index"
@@ -35,7 +35,7 @@
match "/:lang/ch:chapter-:section.html" => "books#chapter"
match "/index" => redirect("/book")
match "/commands" => "books#commands"
- match "/:lang" => "books#show"
+ match "/:lang" => "books#show", as: :lang
match "/:lang/:slug" => "books#section"
end
View
104 lib/constants.rb
@@ -33,57 +33,57 @@
# SiteController#redirect_combook
REDIRECT = {
- "1_welcome_to_git.html" => "en/Getting-Started",
- "1_the_git_object_model.html" => "en/Git-Internals-Git-Objects",
- "1_git_directory_and_working_directory.html" => "en/Git-Basics-Recording-Changes-to-the-Repository",
- "1_the_git_index.html" => "en/Git-Basics-Recording-Changes-to-the-Repository",
- "2_installing_git.html" => "en/Getting-Started-Installing-Git",
- "2_setup_and_initialization.html" => "en/Getting-Started-First-Time-Git-Setup",
- "3_getting_a_git_repository.html" => "en/Git-Basics-Getting-a-Git-Repository",
- "3_normal_workflow.html" => "en/Git-Basics-Recording-Changes-to-the-Repository",
- "3_basic_branching_and_merging.html" => "en/Git-Branching-Basic-Branching-and-Merging",
- "3_reviewing_history_-_git_log.html" => "en/Git-Basics-Viewing-the-Commit-History",
- "3_comparing_commits_-_git_diff.html" => "en/Git-Basics-Recording-Changes-to-the-Repository#Viewing-Your-Staged-and-Unstaged-Changes",
- "3_distributed_workflows.html" => "en/Distributed-Git-Distributed-Workflows",
- "3_git_tag.html" => "en/Git-Basics-Tagging",
- "4_ignoring_files.html" => "en/Git-Basics-Recording-Changes-to-the-Repository#Ignoring-Files",
- "4_rebasing.html" => "en/Git-Branching-Rebasing",
- "4_interactive_rebasing.html" => "en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages",
- "4_interactive_adding.html" => "en/Git-Tools-Interactive-Staging",
- "4_stashing.html" => "en/Git-Tools-Stashing",
- "4_git_treeishes.html" => "en/Git-Tools-Revision-Selection",
- "4_tracking_branches.html" => "en/Git-Branching-Remote-Branches#Tracking-Branches",
- "4_finding_with_git_grep.html" => "",
- "4_undoing_in_git_-_reset,_checkout_and_revert.html" => "en/Git-Basics-Undoing-Things",
- "4_maintaining_git.html" => "en/Git-Internals-Maintenance-and-Data-Recovery",
- "4_setting_up_a_public_repository.html" => "en/Git-on-the-Server-Public-Access",
- "4_setting_up_a_private_repository.html" => "en/Git-on-the-Server-Setting-Up-the-Server",
- "5_creating_new_empty_branches.html" => "",
- "5_modifying_your_history.html" => "en/Git-Tools-Rewriting-History",
- "5_advanced_branching_and_merging.html" => "en/Git-Branching-Basic-Branching-and-Merging",
- "5_finding_issues_-_git_bisect.html" => "en/Git-Tools-Debugging-with-Git#Binary-Search",
- "5_finding_issues_-_git_blame.html" => "en/Git-Tools-Debugging-with-Git#File-Annotation",
- "5_git_and_email.html" => "en/Distributed-Git-Contributing-to-a-Project#Public-Large-Project",
- "5_customizing_git.html" => "en/Customizing-Git-Git-Configuration",
- "5_git_hooks.html" => "en/Customizing-Git-Git-Hooks",
- "5_recovering_corrupted_objects.html" => "en/Git-Internals-Maintenance-and-Data-Recovery#Data-Recovery",
- "5_submodules.html" => "en/Git-Tools-Submodules",
- "6_git_on_windows.html" => "",
- "6_deploying_with_git.html" => "",
- "6_subversion_integration.html" => "en/Git-and-Other-Systems-Git-and-Subversion",
- "6_scm_migration.html" => "en/Git-and-Other-Systems-Migrating-to-Git",
- "6_graphical_git.html" => "",
- "6_hosted_git.html" => "en/Git-on-the-Server-Hosted-Git",
- "6_alternative_uses.html" => "",
- "6_scripting_and_git.html" => "en/Customizing-Git-An-Example-Git-Enforced-Policy",
- "6_git_and_editors.html" => "",
- "7_how_git_stores_objects.html" => "en/Git-Internals-Git-Objects",
- "7_browsing_git_objects.html" => "en/Git-Internals-Git-Objects",
- "7_git_references.html" => "en/Git-Internals-Git-References",
- "7_the_git_index.html" => "",
- "7_the_packfile.html" => "en/Git-Internals-Packfiles",
- "7_raw_git.html" => "en/Git-Internals-Git-Objects",
- "7_transfer_protocols.html" => "en/Git-Internals-Transfer-Protocols",
- "7_glossary.html" => "commands"
+ "1_welcome_to_git" => "en/Getting-Started",
+ "1_the_git_object_model" => "en/Git-Internals-Git-Objects",
+ "1_git_directory_and_working_directory" => "en/Git-Basics-Recording-Changes-to-the-Repository",
+ "1_the_git_index" => "en/Git-Basics-Recording-Changes-to-the-Repository",
+ "2_installing_git" => "en/Getting-Started-Installing-Git",
+ "2_setup_and_initialization" => "en/Getting-Started-First-Time-Git-Setup",
+ "3_getting_a_git_repository" => "en/Git-Basics-Getting-a-Git-Repository",
+ "3_normal_workflow" => "en/Git-Basics-Recording-Changes-to-the-Repository",
+ "3_basic_branching_and_merging" => "en/Git-Branching-Basic-Branching-and-Merging",
+ "3_reviewing_history_-_git_log" => "en/Git-Basics-Viewing-the-Commit-History",
+ "3_comparing_commits_-_git_diff" => "en/Git-Basics-Recording-Changes-to-the-Repository#Viewing-Your-Staged-and-Unstaged-Changes",
+ "3_distributed_workflows" => "en/Distributed-Git-Distributed-Workflows",
+ "3_git_tag" => "en/Git-Basics-Tagging",
+ "4_ignoring_files" => "en/Git-Basics-Recording-Changes-to-the-Repository#Ignoring-Files",
+ "4_rebasing" => "en/Git-Branching-Rebasing",
+ "4_interactive_rebasing" => "en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages",
+ "4_interactive_adding" => "en/Git-Tools-Interactive-Staging",
+ "4_stashing" => "en/Git-Tools-Stashing",
+ "4_git_treeishes" => "en/Git-Tools-Revision-Selection",
+ "4_tracking_branches" => "en/Git-Branching-Remote-Branches#Tracking-Branches",
+ "4_finding_with_git_grep" => "",
+ "4_undoing_in_git_-_reset,_checkout_and_revert" => "en/Git-Basics-Undoing-Things",
+ "4_maintaining_git" => "en/Git-Internals-Maintenance-and-Data-Recovery",
+ "4_setting_up_a_public_repository" => "en/Git-on-the-Server-Public-Access",
+ "4_setting_up_a_private_repository" => "en/Git-on-the-Server-Setting-Up-the-Server",
+ "5_creating_new_empty_branches" => "",
+ "5_modifying_your_history" => "en/Git-Tools-Rewriting-History",
+ "5_advanced_branching_and_merging" => "en/Git-Branching-Basic-Branching-and-Merging",
+ "5_finding_issues_-_git_bisect" => "en/Git-Tools-Debugging-with-Git#Binary-Search",
+ "5_finding_issues_-_git_blame" => "en/Git-Tools-Debugging-with-Git#File-Annotation",
+ "5_git_and_email" => "en/Distributed-Git-Contributing-to-a-Project#Public-Large-Project",
+ "5_customizing_git" => "en/Customizing-Git-Git-Configuration",
+ "5_git_hooks" => "en/Customizing-Git-Git-Hooks",
+ "5_recovering_corrupted_objects" => "en/Git-Internals-Maintenance-and-Data-Recovery#Data-Recovery",
+ "5_submodules" => "en/Git-Tools-Submodules",
+ "6_git_on_windows" => "",
+ "6_deploying_with_git" => "",
+ "6_subversion_integration" => "en/Git-and-Other-Systems-Git-and-Subversion",
+ "6_scm_migration" => "en/Git-and-Other-Systems-Migrating-to-Git",
+ "6_graphical_git" => "",
+ "6_hosted_git" => "en/Git-on-the-Server-Hosted-Git",
+ "6_alternative_uses" => "",
+ "6_scripting_and_git" => "en/Customizing-Git-An-Example-Git-Enforced-Policy",
+ "6_git_and_editors" => "",
+ "7_how_git_stores_objects" => "en/Git-Internals-Git-Objects",
+ "7_browsing_git_objects" => "en/Git-Internals-Git-Objects",
+ "7_git_references" => "en/Git-Internals-Git-References",
+ "7_the_git_index" => "",
+ "7_the_packfile" => "en/Git-Internals-Packfiles",
+ "7_raw_git" => "en/Git-Internals-Git-Objects",
+ "7_transfer_protocols" => "en/Git-Internals-Transfer-Protocols",
+ "7_glossary" => "commands"
}
View
6 test/functional/books_controller_test.rb
@@ -1,6 +1,12 @@
require 'test_helper'
class BooksControllerTest < ActionController::TestCase
+
+ test "redirects old book site" do
+ get :show, lang: "1_welcome_to_git"
+ assert_redirected_to controller: "books", action: "show", lang: "en/Getting-Started"
+ end
+
test "gets the book page" do
book = FactoryGirl.create(:book, :code =>'en')
get :show, :lang => 'en'
View
11 test/functional/site_controller_test.rb
@@ -12,17 +12,6 @@ class SiteControllerTest < ActionController::TestCase
assert_redirected_to "http://git-scm.com/about"
end
- test "if no slug then should redirect to the book page" do
- get :redirect_combook
- assert_redirected_to "http://git-scm.com/book"
- end
-
- test "should redirect to particular book page" do
- @request.env['PATH_INFO'] = "/5_submodules.html"
- get :redirect_combook
- assert_redirected_to "http://git-scm.com/book/en/Git-Tools-Submodules"
- end
-
test "should redirect to the book page" do
get :redirect_book
assert_redirected_to "http://git-scm.com/book"
Please sign in to comment.
Something went wrong with that request. Please try again.