From 9525306d138a278b04f18d40c2223cbda8df00c0 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Fri, 10 Aug 2018 21:02:17 +0900 Subject: [PATCH] [phase-18]Add test for GlossaryTermsController, and fix redirect_to action --- app/controllers/glossary_terms_controller.rb | 2 +- .../glossary_terms_controller_test.rb | 57 ++++++++++++++++++- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/app/controllers/glossary_terms_controller.rb b/app/controllers/glossary_terms_controller.rb index c544e46..c05f33e 100644 --- a/app/controllers/glossary_terms_controller.rb +++ b/app/controllers/glossary_terms_controller.rb @@ -44,7 +44,7 @@ class GlossaryTermsController < ApplicationController def destroy @term.destroy - redirect_to project_glossary_terms_path + redirect_to project_glossary_terms_path(@project) end def preview diff --git a/test/functional/glossary_terms_controller_test.rb b/test/functional/glossary_terms_controller_test.rb index 263036e..cbeab24 100644 --- a/test/functional/glossary_terms_controller_test.rb +++ b/test/functional/glossary_terms_controller_test.rb @@ -1,8 +1,59 @@ require File.expand_path('../../test_helper', __FILE__) class GlossaryTermsControllerTest < ActionController::TestCase - # Replace this with your real tests. - def test_truth - assert true + fixtures :projects, :users, :roles, :members, :member_roles + plugin_fixtures :glossary_terms + + def setup + @project = projects('projects_001') + @project.enabled_module_names = [:glossary] + roles('roles_001').add_permission! :view_glossary, :manage_glossary + end + + def test_index + @request.session[:user_id] = users('users_002').id + get :index, params: {project_id: 1} + assert_response :success + end + + def test_edit + @request.session[:user_id] = users('users_002').id + get :edit, params: {id: 1, project_id: 1} + assert_response :success + assert_select 'form', true + end + + def test_update + @request.session[:user_id] = users('users_002').id + patch :update, params: {id: 1, project_id: 1, glossary_term: { + name: 'rosso' + }} + term = GlossaryTerm.find(1) + assert_redirected_to project_glossary_term_path(@project, term) + assert_equal 'rosso', term.name + end + + def test_new + @request.session[:user_id] = users('users_002').id + get :new, params: {project_id: 1} + assert_response :success + assert_select 'form', true + end + + def test_create + @request.session[:user_id] = users('users_002').id + post :create, params: { project_id: 1, glossary_term: { + name: 'white', category_id: 1 + }} + term = GlossaryTerm.find_by(name: 'white') + assert_not_nil term + assert_redirected_to project_glossary_term_path(@project, term) + end + + def test_destroy + @request.session[:user_id] = users('users_002').id + delete :destroy, params: {id: 1, project_id: 1} + assert_raise(ActiveRecord::RecordNotFound) { GlossaryTerm.find(1) } + assert_redirected_to project_glossary_terms_path(@project) end end