From b5697eff56d35a1baaba30223a88e0f09e492422 Mon Sep 17 00:00:00 2001 From: Philipp Fischbeck Date: Sun, 26 Nov 2017 14:32:18 +0100 Subject: [PATCH] Add redirects, update test types --- app/views/layouts/_header.html.erb | 2 +- config/routes.rb | 11 ++++++++--- test/controllers/about_controller_test.rb | 5 +++++ .../controllers/admin/dashboard_controller_test.rb | 14 +++++++------- .../admin/translations_controller_test.rb | 8 ++++---- test/controllers/problems_controller_test.rb | 14 +++++++++----- test/controllers/translations_controller_test.rb | 12 +++++------- 7 files changed, 39 insertions(+), 27 deletions(-) diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 1c2c49d..cd19456 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -7,7 +7,7 @@ <%= link_to t('application.info'), about_info_path %> <%= link_to Problem.model_name.human(count: 2), problems_path %> <% if admin_signed_in? %> - <%= link_to t('admin.dashboard.index.administration'), :admin %> + <%= link_to t('admin.dashboard.index.administration'), admin_dashboard_index_path %> <% end %> <% end %> <%= nav class: 'navbar-right' do %> diff --git a/config/routes.rb b/config/routes.rb index 3cb0d31..27b3c81 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,16 +3,21 @@ Rails.application.routes.draw do get 'about/info' get 'about/copyright' get 'about/legal' + get 'about/roman_numerals' - devise_for :admins, skip: :registrations + get 'about=:page', to: redirect('/about/%{page}') + + get 'problem=:id', to: redirect('/problems/%{id}') + resources :problems, only: [:index, :show] do resources :translations, only: [:new, :create] end + devise_for :admins, skip: :registrations namespace :admin do - get '', to: 'dashboard#index', as: '/' - post '/update_problem_count', to: 'dashboard#update_problem_count' + get '', to: 'dashboard#index', as: 'dashboard_index' + post '/update_problem_count', to: 'dashboard#update_problem_count', as: 'dashboard_update_problem_count' resources :translations, only: [:index, :show] end diff --git a/test/controllers/about_controller_test.rb b/test/controllers/about_controller_test.rb index bba912d..eb0604a 100644 --- a/test/controllers/about_controller_test.rb +++ b/test/controllers/about_controller_test.rb @@ -26,4 +26,9 @@ class AboutControllerTest < ActionDispatch::IntegrationTest assert_response :success end + test "should redirect about pages" do + get '/about=roman_numerals' + assert_redirected_to about_roman_numerals_url + end + end diff --git a/test/controllers/admin/dashboard_controller_test.rb b/test/controllers/admin/dashboard_controller_test.rb index 22a1753..be3e2ed 100644 --- a/test/controllers/admin/dashboard_controller_test.rb +++ b/test/controllers/admin/dashboard_controller_test.rb @@ -1,26 +1,26 @@ require 'test_helper' -class Admin::DashboardControllerTest < ActionController::TestCase - include Devise::Test::ControllerHelpers +class Admin::DashboardControllerTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers setup do login end test "should get index" do - get :index + get admin_dashboard_index_url assert_response :success end test "should post new problem count" do - post :update_problem_count, params: { problem_count: 15 } - assert_redirected_to controller: 'admin/dashboard', action: 'index' + post admin_dashboard_update_problem_count_url(problem_count: 15) + assert_redirected_to admin_dashboard_index_url assert_equal 15, Problem.count end test "should fail incorrect problem count" do - post :update_problem_count, params: { problem_count: 2 } - assert_redirected_to controller: 'admin/dashboard', action: 'index' + post admin_dashboard_update_problem_count_url(problem_count: 2) + assert_redirected_to admin_dashboard_index_url assert_equal 3, Problem.count end diff --git a/test/controllers/admin/translations_controller_test.rb b/test/controllers/admin/translations_controller_test.rb index 565c56b..31bc4d0 100644 --- a/test/controllers/admin/translations_controller_test.rb +++ b/test/controllers/admin/translations_controller_test.rb @@ -1,20 +1,20 @@ require 'test_helper' -class Admin::TranslationsControllerTest < ActionController::TestCase - include Devise::Test::ControllerHelpers +class Admin::TranslationsControllerTest < ActionDispatch::IntegrationTest + include Devise::Test::IntegrationHelpers setup do login @translation = translations(:translation_one) end test "should get index" do - get :index + get admin_translations_url assert_response :success assert_not_nil assigns(:translations) end test "should show translation" do - get :show, params: { id: @translation } + get admin_translation_url(id: @translation) assert_response :success end diff --git a/test/controllers/problems_controller_test.rb b/test/controllers/problems_controller_test.rb index 070b8a9..788fe69 100644 --- a/test/controllers/problems_controller_test.rb +++ b/test/controllers/problems_controller_test.rb @@ -1,21 +1,25 @@ require 'test_helper' -class ProblemsControllerTest < ActionController::TestCase - include Devise::Test::ControllerHelpers +class ProblemsControllerTest < ActionDispatch::IntegrationTest test "should get index" do - get :index + get problems_url assert_response :success end test "should get show" do - get :show, params: { id: 1 } + get problem_url(id: 1) assert_response :success end test "should get untranslated problem" do - get :show, params: { id: 3 } + get problem_url(id: 3) assert_response :success end + test "should redirect to correct problem" do + get '/problem=2' + assert_redirected_to problem_path(id: 2) + end + end diff --git a/test/controllers/translations_controller_test.rb b/test/controllers/translations_controller_test.rb index c4a8803..6f165b4 100644 --- a/test/controllers/translations_controller_test.rb +++ b/test/controllers/translations_controller_test.rb @@ -1,8 +1,6 @@ require 'test_helper' -class TranslationsControllerTest < ActionController::TestCase - include Devise::Test::ControllerHelpers - +class TranslationsControllerTest < ActionDispatch::IntegrationTest setup do @update = { title: 'New title', @@ -15,18 +13,18 @@ class TranslationsControllerTest < ActionController::TestCase end test "should get new for translated problem" do - get :new, params: { problem_id: 1 } + get new_problem_translation_url(problem_id: 1) assert_response :success end test "should get new for untranslated problem" do - get :new, params: { problem_id: 3 } + get new_problem_translation_url(problem_id: 3) assert_response :success end test "should create translation" do assert_difference('Translation.count') do - post :create, params: { problem_id: 1, translation: @update } + post problem_translations_url(problem_id: 1, translation: @update) end assert_redirected_to problem_path(id: 1) @@ -34,7 +32,7 @@ class TranslationsControllerTest < ActionController::TestCase test "should not create incorrect translation" do assert_no_difference('Translation.count') do - post :create, params: { problem_id: 1, translation: @incorrect } + post problem_translations_url(problem_id: 1, translation: @incorrect) end end end