From 1e2ffc4104fe68f14c5520960d4a7d5b5e3a106e Mon Sep 17 00:00:00 2001 From: "Carlos A. da Silva" Date: Thu, 8 Oct 2009 18:26:44 -0300 Subject: [PATCH] Routes using i18n and tests, moving test helpers to support directory. --- config/locales/en.yml | 4 +++ config/routes.rb | 10 ++++--- test/routes/confirmation_routing_test.rb | 22 ++++++++++++++++ test/routes/password_routing_test.rb | 26 +++++++++++++++++++ test/routes/session_routing_test.rb | 22 ++++++++++++++++ test/{ => support}/assertions_helper.rb | 0 test/support/controller_tests_helper.rb | 12 +++++++++ .../{ => support}/integration_tests_helper.rb | 0 .../model_tests_helper.rb} | 0 test/test_helper.rb | 8 +----- 10 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 test/routes/confirmation_routing_test.rb create mode 100644 test/routes/password_routing_test.rb create mode 100644 test/routes/session_routing_test.rb rename test/{ => support}/assertions_helper.rb (100%) create mode 100644 test/support/controller_tests_helper.rb rename test/{ => support}/integration_tests_helper.rb (100%) rename test/{models_helper.rb => support/model_tests_helper.rb} (100%) diff --git a/config/locales/en.yml b/config/locales/en.yml index 3aca377d..ca8be732 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -24,6 +24,10 @@ en: sign_in: 'Sign in' new_password: 'Forgot password?' new_confirmation: "Didn't receive confirmation instructions?" + routes: + session: 'session' + password: 'password' + confirmation: 'confirmation' notifier: confirmation_instructions: 'Confirmation instructions' reset_password_instructions: 'Reset password instructions' diff --git a/config/routes.rb b/config/routes.rb index 0161be06..260166bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,9 @@ ActionController::Routing::Routes.draw do |map| - map.resource :session, :only => [:new, :create, :destroy] - map.resource :password, :only => [:new, :create, :edit, :update] - map.resource :confirmation, :only => [:new, :create, :show] + def t(route_name) + I18n.t(route_name, :scope => [:devise, :routes], :default => route_name.to_s) + end + + map.resource :session, :only => [:new, :create, :destroy], :as => t(:session) + map.resource :password, :only => [:new, :create, :edit, :update], :as => t(:password) + map.resource :confirmation, :only => [:new, :create, :show], :as => t(:confirmation) end diff --git a/test/routes/confirmation_routing_test.rb b/test/routes/confirmation_routing_test.rb new file mode 100644 index 00000000..1a4c49b4 --- /dev/null +++ b/test/routes/confirmation_routing_test.rb @@ -0,0 +1,22 @@ +require 'test_helper' + +class ConfirmationRoutingTest < ActionController::TestCase + + test 'new session route' do + assert_routing('/confirmation/new', :controller => 'confirmations', :action => 'new') + end + + test 'create confirmation route' do + assert_routing({:path => '/confirmation', :method => :post}, {:controller => 'confirmations', :action => 'create'}) + end + + test 'show confirmation route' do + assert_routing('/confirmation', :controller => 'confirmations', :action => 'show') + end + + test 'translated confirmation route' do + translated_route(:confirmation => 'confirmacao') do + assert_routing('/confirmacao/new', :controller => 'confirmations', :action => 'new') + end + end +end diff --git a/test/routes/password_routing_test.rb b/test/routes/password_routing_test.rb new file mode 100644 index 00000000..711c2feb --- /dev/null +++ b/test/routes/password_routing_test.rb @@ -0,0 +1,26 @@ +require 'test_helper' + +class PasswordRoutingTest < ActionController::TestCase + + test 'new password route' do + assert_routing('/password/new', :controller => 'passwords', :action => 'new') + end + + test 'create password route' do + assert_routing({:path => '/password', :method => :post}, {:controller => 'passwords', :action => 'create'}) + end + + test 'edit password route' do + assert_routing('/password/edit', :controller => 'passwords', :action => 'edit') + end + + test 'update password route' do + assert_routing({:path => '/password', :method => :put}, {:controller => 'passwords', :action => 'update'}) + end + + test 'translated password route' do + translated_route(:password => 'senha') do + assert_routing('/senha/new', :controller => 'passwords', :action => 'new') + end + end +end diff --git a/test/routes/session_routing_test.rb b/test/routes/session_routing_test.rb new file mode 100644 index 00000000..23488447 --- /dev/null +++ b/test/routes/session_routing_test.rb @@ -0,0 +1,22 @@ +require 'test_helper' + +class SessionRoutingTest < ActionController::TestCase + + test 'new session route' do + assert_routing('/session/new', :controller => 'sessions', :action => 'new') + end + + test 'create session route' do + assert_routing({:path => '/session', :method => :post}, {:controller => 'sessions', :action => 'create'}) + end + + test 'destroy session route' do + assert_routing({:path => '/session', :method => :delete}, {:controller => 'sessions', :action => 'destroy'}) + end + + test 'translate session route' do + translated_route(:session => 'sessao') do + assert_routing('/sessao/new', :controller => 'sessions', :action => 'new') + end + end +end diff --git a/test/assertions_helper.rb b/test/support/assertions_helper.rb similarity index 100% rename from test/assertions_helper.rb rename to test/support/assertions_helper.rb diff --git a/test/support/controller_tests_helper.rb b/test/support/controller_tests_helper.rb new file mode 100644 index 00000000..1826693d --- /dev/null +++ b/test/support/controller_tests_helper.rb @@ -0,0 +1,12 @@ +class ActionController::TestCase + + def translated_route(translation={}, &block) + I18n.locale = :'pt-BR' + I18n.backend.store_translations(:'pt-BR', :devise => { :routes => translation }) + ActionController::Routing::Routes.reload! + yield + I18n.locale = :en + I18n.reload! + ActionController::Routing::Routes.reload! + end +end diff --git a/test/integration_tests_helper.rb b/test/support/integration_tests_helper.rb similarity index 100% rename from test/integration_tests_helper.rb rename to test/support/integration_tests_helper.rb diff --git a/test/models_helper.rb b/test/support/model_tests_helper.rb similarity index 100% rename from test/models_helper.rb rename to test/support/model_tests_helper.rb diff --git a/test/test_helper.rb b/test/test_helper.rb index e4d7639b..5d5c6d13 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,15 +2,9 @@ RAILS_ENV = ENV["RAILS_ENV"] = "test" require File.join(File.dirname(__FILE__), 'rails_app', 'config', 'environment') require 'test_help' - require 'webrat' -require 'assertions_helper' -require 'models_helper' -require 'integration_tests_helper' - -#ActiveSupport::Dependencies.load_paths << File.expand_path(File.dirname(__FILE__) + '/..') -#require_dependency 'devise' +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true