From e39cc464b166575e97a47154ce2d1296308a94a2 Mon Sep 17 00:00:00 2001 From: Stephan Kaag Date: Mon, 1 Jul 2013 20:00:06 +0200 Subject: [PATCH] Refactor routes in order to be compatible with Rails 4 --- app/controllers/application_controller.rb | 2 +- app/controllers/invites_controller.rb | 2 +- app/controllers/static_controller.rb | 2 +- app/views/users/activate_account.html.erb | 2 +- app/views/users/authorize_email.html.erb | 2 +- app/views/users/password_reset.html.erb | 2 +- config/routes.rb | 16 ++++++++-------- spec/controllers/static_controller_spec.rb | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 41e9e5af5..2c324ae5a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -61,7 +61,7 @@ class ApplicationController < ActionController::Base rescue_from Discourse::NotLoggedIn do |e| raise e if Rails.env.test? - redirect_to root_path + redirect_to "/" end rescue_from Discourse::NotFound do diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb index c0e9744a8..85b3c1f6e 100644 --- a/app/controllers/invites_controller.rb +++ b/app/controllers/invites_controller.rb @@ -24,7 +24,7 @@ class InvitesController < ApplicationController end end - redirect_to root_path + redirect_to "/" end def destroy diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 76b6a2094..860e21c40 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -44,7 +44,7 @@ class StaticController < ApplicationController redirect_to( if params[:redirect].blank? || params[:redirect].match(login_path) - root_path + "/" else params[:redirect] end diff --git a/app/views/users/activate_account.html.erb b/app/views/users/activate_account.html.erb index c77532726..402de69ec 100644 --- a/app/views/users/activate_account.html.erb +++ b/app/views/users/activate_account.html.erb @@ -10,7 +10,7 @@ <% if @needs_approval %> <%= t 'activation.approval_required' %> <% else %> - <%= raw t('activation.please_continue', link: link_to(SiteSetting.title, root_path)) %>. + <%= raw t('activation.please_continue', link: link_to(SiteSetting.title, '/')) %>. <% end %>

diff --git a/app/views/users/authorize_email.html.erb b/app/views/users/authorize_email.html.erb index be2872ed1..a7a6cd2d3 100644 --- a/app/views/users/authorize_email.html.erb +++ b/app/views/users/authorize_email.html.erb @@ -6,7 +6,7 @@ <%else%>

<%= t 'change_email.confirmed' %>

- <%= raw t('change_email.please_continue', link: link_to(SiteSetting.title, root_path)) %> + <%= raw t('change_email.please_continue', link: link_to(SiteSetting.title, '/')) %>

<%end%> diff --git a/app/views/users/password_reset.html.erb b/app/views/users/password_reset.html.erb index b7b95a9e1..b5b73e277 100644 --- a/app/views/users/password_reset.html.erb +++ b/app/views/users/password_reset.html.erb @@ -18,7 +18,7 @@ <%- if @requires_approval %> <%= t 'login.not_approved' %> <% else %> - <%= link_to( t('password_reset.continue', site_name: SiteSetting.title), root_path ) %> + <%= link_to( t('password_reset.continue', site_name: SiteSetting.title), '/' ) %> <% end %>

<% else %> diff --git a/config/routes.rb b/config/routes.rb index 1057ceff8..81a8afaba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ USERNAME_ROUTE_FORMAT = /[A-Za-z0-9\_]+/ unless defined? USERNAME_ROUTE_FORMAT Discourse::Application.routes.draw do - match "/404", to: "exceptions#not_found" + match "/404", to: "exceptions#not_found", via: [:get, :post] mount Sidekiq::Web => '/sidekiq', constraints: AdminConstraint.new @@ -84,7 +84,7 @@ Discourse::Application.routes.draw do end end - get 'email_preferences' => 'email#preferences_redirect' + get 'email_preferences' => 'email#preferences_redirect', :as => 'email_preferences_redirect' get 'email/unsubscribe/:key' => 'email#unsubscribe', as: 'email_unsubscribe' post 'email/resubscribe/:key' => 'email#resubscribe', as: 'email_resubscribe' @@ -148,8 +148,8 @@ Discourse::Application.routes.draw do resources :notifications resources :categories - match "/auth/:provider/callback", to: "users/omniauth_callbacks#complete" - match "/auth/failure", to: "users/omniauth_callbacks#failure" + match "/auth/:provider/callback", to: "users/omniauth_callbacks#complete", via: [:get, :post] + match "/auth/failure", to: "users/omniauth_callbacks#failure", via: [:get, :post] resources :clicks do collection do @@ -170,8 +170,8 @@ Discourse::Application.routes.draw do get 'category/:category.rss' => 'list#category_feed', format: :rss, as: 'category_feed' get 'category/:category' => 'list#category' - get 'category/:category' => 'list#category', as: 'category' - get 'category/:category/more' => 'list#category', as: 'category' + get 'category/:category' => 'list#category' + get 'category/:category/more' => 'list#category' get 'categories' => 'categories#index' # We've renamed popular to latest. If people access it we want a permanent redirect. @@ -241,9 +241,9 @@ Discourse::Application.routes.draw do get 'robots.txt' => 'robots_txt#index' [:latest, :hot, :unread, :new, :favorited, :read, :posted].each do |filter| - root to: "list##{filter}", constraints: HomePageConstraint.new("#{filter}") + root to: "list##{filter}", constraints: HomePageConstraint.new("#{filter}"), :as => "list_#{filter}" end # special case for categories - root to: "categories#index", constraints: HomePageConstraint.new("categories") + root to: "categories#index", constraints: HomePageConstraint.new("categories"), :as => "categories_index" end diff --git a/spec/controllers/static_controller_spec.rb b/spec/controllers/static_controller_spec.rb index 8928118f4..c97c0c233 100644 --- a/spec/controllers/static_controller_spec.rb +++ b/spec/controllers/static_controller_spec.rb @@ -48,7 +48,7 @@ describe StaticController do context 'without a redirect path' do it 'redirects to the root url' do xhr :post, :enter - expect(response).to redirect_to root_path + expect(response).to redirect_to '/' end end @@ -62,7 +62,7 @@ describe StaticController do context 'when the redirect path is the login page' do it 'redirects to the root url' do xhr :post, :enter, redirect: login_path - expect(response).to redirect_to root_path + expect(response).to redirect_to '/' end end end