[phase-18]Add test for GlossaryTermsController, and fix redirect_to action

This commit is contained in:
Toru Takahashi 2018-08-10 21:02:17 +09:00 committed by TAKAHASHI,Toru
parent aca71c076c
commit 9525306d13
2 changed files with 55 additions and 4 deletions

View File

@ -44,7 +44,7 @@ class GlossaryTermsController < ApplicationController
def destroy def destroy
@term.destroy @term.destroy
redirect_to project_glossary_terms_path redirect_to project_glossary_terms_path(@project)
end end
def preview def preview

View File

@ -1,8 +1,59 @@
require File.expand_path('../../test_helper', __FILE__) require File.expand_path('../../test_helper', __FILE__)
class GlossaryTermsControllerTest < ActionController::TestCase class GlossaryTermsControllerTest < ActionController::TestCase
# Replace this with your real tests. fixtures :projects, :users, :roles, :members, :member_roles
def test_truth plugin_fixtures :glossary_terms
assert true
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
end end