issues controller & unit testing, word log print.
This commit is contained in:
parent
0d7bedeb0d
commit
1755d7a790
|
@ -199,6 +199,7 @@ class WordsController < ApplicationController
|
|||
def obj_distinguish_url_origin
|
||||
#modify by nwb
|
||||
#添加对课程留言的支持
|
||||
binding.pry
|
||||
referer = request.headers["Referer"]
|
||||
obj_id = referer.match(%r(/([0-9]{1,})(/|$)))[1]
|
||||
if referer.match(/project/)
|
||||
|
@ -216,7 +217,7 @@ class WordsController < ApplicationController
|
|||
elsif ( referer.match(/homework_attach/) || referer.match(/homework_attach/) ) #new added
|
||||
obj = HomeworkAttach.find_by_id(obj_id)
|
||||
else
|
||||
raise 'create reply obj unknow type.'
|
||||
raise "create reply obj unknow type.#{referer}"
|
||||
end
|
||||
obj
|
||||
end
|
||||
|
@ -240,8 +241,8 @@ class WordsController < ApplicationController
|
|||
elsif obj.kind_of? HomeworkAttach
|
||||
obj.add_jour(nil, nil, obj.id, options) #new added
|
||||
else
|
||||
raise 'create reply obj unknow type.'
|
||||
raise "create reply obj unknow type.#{obj.class}"
|
||||
end
|
||||
end
|
||||
#######end of message
|
||||
end
|
||||
end
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,145 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class IssueCategoriesControllerTest < ActionController::TestCase
|
||||
fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories,
|
||||
:issues
|
||||
|
||||
def setup
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 2
|
||||
end
|
||||
|
||||
def test_new
|
||||
@request.session[:user_id] = 2 # manager
|
||||
get :new, :project_id => '1'
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_select 'input[name=?]', 'issue_category[name]'
|
||||
end
|
||||
|
||||
def test_new_from_issue_form
|
||||
@request.session[:user_id] = 2 # manager
|
||||
xhr :get, :new, :project_id => '1'
|
||||
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
end
|
||||
|
||||
def test_create
|
||||
@request.session[:user_id] = 2 # manager
|
||||
assert_difference 'IssueCategory.count' do
|
||||
post :create, :project_id => '1', :issue_category => {:name => 'New category'}
|
||||
end
|
||||
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||||
category = IssueCategory.find_by_name('New category')
|
||||
assert_not_nil category
|
||||
assert_equal 1, category.project_id
|
||||
end
|
||||
|
||||
def test_create_failure
|
||||
@request.session[:user_id] = 2
|
||||
post :create, :project_id => '1', :issue_category => {:name => ''}
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
end
|
||||
|
||||
def test_create_from_issue_form
|
||||
@request.session[:user_id] = 2 # manager
|
||||
assert_difference 'IssueCategory.count' do
|
||||
xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
|
||||
end
|
||||
category = IssueCategory.first(:order => 'id DESC')
|
||||
assert_equal 'New category', category.name
|
||||
|
||||
assert_response :success
|
||||
assert_template 'create'
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
end
|
||||
|
||||
def test_create_from_issue_form_with_failure
|
||||
@request.session[:user_id] = 2 # manager
|
||||
assert_no_difference 'IssueCategory.count' do
|
||||
xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
end
|
||||
|
||||
def test_edit
|
||||
@request.session[:user_id] = 2
|
||||
get :edit, :id => 2
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
|
||||
end
|
||||
|
||||
def test_update
|
||||
assert_no_difference 'IssueCategory.count' do
|
||||
put :update, :id => 2, :issue_category => { :name => 'Testing' }
|
||||
end
|
||||
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||||
assert_equal 'Testing', IssueCategory.find(2).name
|
||||
end
|
||||
|
||||
def test_update_failure
|
||||
put :update, :id => 2, :issue_category => { :name => '' }
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_update_not_found
|
||||
put :update, :id => 97, :issue_category => { :name => 'Testing' }
|
||||
assert_response 404
|
||||
end
|
||||
|
||||
def test_destroy_category_not_in_use
|
||||
delete :destroy, :id => 2
|
||||
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||||
assert_nil IssueCategory.find_by_id(2)
|
||||
end
|
||||
|
||||
def test_destroy_category_in_use
|
||||
delete :destroy, :id => 1
|
||||
assert_response :success
|
||||
assert_template 'destroy'
|
||||
assert_not_nil IssueCategory.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_destroy_category_in_use_with_reassignment
|
||||
issue = Issue.where(:category_id => 1).first
|
||||
delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
|
||||
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||||
assert_nil IssueCategory.find_by_id(1)
|
||||
# check that the issue was reassign
|
||||
assert_equal 2, issue.reload.category_id
|
||||
end
|
||||
|
||||
def test_destroy_category_in_use_without_reassignment
|
||||
issue = Issue.where(:category_id => 1).first
|
||||
delete :destroy, :id => 1, :todo => 'nullify'
|
||||
assert_redirected_to '/projects/ecookbook/settings/categories'
|
||||
assert_nil IssueCategory.find_by_id(1)
|
||||
# check that the issue category was nullified
|
||||
assert_nil issue.reload.category_id
|
||||
end
|
||||
end
|
|
@ -0,0 +1,147 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class IssueRelationsControllerTest < ActionController::TestCase
|
||||
fixtures :projects,
|
||||
:users,
|
||||
:roles,
|
||||
:members,
|
||||
:member_roles,
|
||||
:issues,
|
||||
:issue_statuses,
|
||||
:issue_relations,
|
||||
:enabled_modules,
|
||||
:enumerations,
|
||||
:trackers,
|
||||
:projects_trackers
|
||||
|
||||
def setup
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 3
|
||||
end
|
||||
|
||||
def test_create
|
||||
assert_difference 'IssueRelation.count' do
|
||||
post :create, :issue_id => 1,
|
||||
:relation => {:issue_to_id => '2', :relation_type => 'relates', :delay => ''}
|
||||
end
|
||||
relation = IssueRelation.first(:order => 'id DESC')
|
||||
assert_equal 1, relation.issue_from_id
|
||||
assert_equal 2, relation.issue_to_id
|
||||
assert_equal 'relates', relation.relation_type
|
||||
end
|
||||
|
||||
def test_create_xhr
|
||||
assert_difference 'IssueRelation.count' do
|
||||
xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '1', :relation_type => 'relates', :delay => ''}
|
||||
assert_response :success
|
||||
assert_template 'create'
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
end
|
||||
relation = IssueRelation.first(:order => 'id DESC')
|
||||
assert_equal 3, relation.issue_from_id
|
||||
assert_equal 1, relation.issue_to_id
|
||||
|
||||
assert_match /Bug #1/, response.body
|
||||
end
|
||||
|
||||
def test_create_should_accept_id_with_hash
|
||||
assert_difference 'IssueRelation.count' do
|
||||
post :create, :issue_id => 1,
|
||||
:relation => {:issue_to_id => '#2', :relation_type => 'relates', :delay => ''}
|
||||
end
|
||||
relation = IssueRelation.first(:order => 'id DESC')
|
||||
assert_equal 2, relation.issue_to_id
|
||||
end
|
||||
|
||||
def test_create_should_strip_id
|
||||
assert_difference 'IssueRelation.count' do
|
||||
post :create, :issue_id => 1,
|
||||
:relation => {:issue_to_id => ' 2 ', :relation_type => 'relates', :delay => ''}
|
||||
end
|
||||
relation = IssueRelation.first(:order => 'id DESC')
|
||||
assert_equal 2, relation.issue_to_id
|
||||
end
|
||||
|
||||
def test_create_should_not_break_with_non_numerical_id
|
||||
assert_no_difference 'IssueRelation.count' do
|
||||
assert_nothing_raised do
|
||||
post :create, :issue_id => 1,
|
||||
:relation => {:issue_to_id => 'foo', :relation_type => 'relates', :delay => ''}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_create_follows_relation_should_update_relations_list
|
||||
issue1 = Issue.generate!(:subject => 'Followed issue', :start_date => Date.yesterday, :due_date => Date.today)
|
||||
issue2 = Issue.generate!
|
||||
|
||||
assert_difference 'IssueRelation.count' do
|
||||
xhr :post, :create, :issue_id => issue2.id,
|
||||
:relation => {:issue_to_id => issue1.id, :relation_type => 'follows', :delay => ''}
|
||||
end
|
||||
assert_match /Followed issue/, response.body
|
||||
end
|
||||
|
||||
def test_should_create_relations_with_visible_issues_only
|
||||
Setting.cross_project_issue_relations = '1'
|
||||
assert_nil Issue.visible(User.find(3)).find_by_id(4)
|
||||
|
||||
assert_no_difference 'IssueRelation.count' do
|
||||
post :create, :issue_id => 1,
|
||||
:relation => {:issue_to_id => '4', :relation_type => 'relates', :delay => ''}
|
||||
end
|
||||
end
|
||||
|
||||
should "prevent relation creation when there's a circular dependency"
|
||||
|
||||
def test_create_xhr_with_failure
|
||||
assert_no_difference 'IssueRelation.count' do
|
||||
xhr :post, :create, :issue_id => 3, :relation => {:issue_to_id => '999', :relation_type => 'relates', :delay => ''}
|
||||
|
||||
assert_response :success
|
||||
assert_template 'create'
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
end
|
||||
|
||||
assert_match /errorExplanation/, response.body
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
assert_difference 'IssueRelation.count', -1 do
|
||||
delete :destroy, :id => '2'
|
||||
end
|
||||
end
|
||||
|
||||
def test_destroy_xhr
|
||||
IssueRelation.create!(:relation_type => IssueRelation::TYPE_RELATES) do |r|
|
||||
r.issue_from_id = 3
|
||||
r.issue_to_id = 1
|
||||
end
|
||||
|
||||
assert_difference 'IssueRelation.count', -1 do
|
||||
xhr :delete, :destroy, :id => '2'
|
||||
|
||||
assert_response :success
|
||||
assert_template 'destroy'
|
||||
assert_equal 'text/javascript', response.content_type
|
||||
assert_match /relation-2/, response.body
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,123 @@
|
|||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
class IssueStatusesControllerTest < ActionController::TestCase
|
||||
fixtures :issue_statuses, :issues, :users
|
||||
|
||||
def setup
|
||||
User.current = nil
|
||||
@request.session[:user_id] = 1 # admin
|
||||
end
|
||||
|
||||
def test_index
|
||||
get :index
|
||||
assert_response :success
|
||||
assert_template 'index'
|
||||
end
|
||||
|
||||
def test_index_by_anonymous_should_redirect_to_login_form
|
||||
@request.session[:user_id] = nil
|
||||
get :index
|
||||
assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Fissue_statuses'
|
||||
end
|
||||
|
||||
def test_index_by_user_should_respond_with_406
|
||||
@request.session[:user_id] = 2
|
||||
get :index
|
||||
assert_response 406
|
||||
end
|
||||
|
||||
def test_new
|
||||
get :new
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
end
|
||||
|
||||
def test_create
|
||||
assert_difference 'IssueStatus.count' do
|
||||
post :create, :issue_status => {:name => 'New status'}
|
||||
end
|
||||
assert_redirected_to :action => 'index'
|
||||
status = IssueStatus.order('id DESC').first
|
||||
assert_equal 'New status', status.name
|
||||
end
|
||||
|
||||
def test_create_with_failure
|
||||
post :create, :issue_status => {:name => ''}
|
||||
assert_response :success
|
||||
assert_template 'new'
|
||||
assert_error_tag :content => /name can't be blank/i
|
||||
end
|
||||
|
||||
def test_edit
|
||||
get :edit, :id => '3'
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
end
|
||||
|
||||
def test_update
|
||||
put :update, :id => '3', :issue_status => {:name => 'Renamed status'}
|
||||
assert_redirected_to :action => 'index'
|
||||
status = IssueStatus.find(3)
|
||||
assert_equal 'Renamed status', status.name
|
||||
end
|
||||
|
||||
def test_update_with_failure
|
||||
put :update, :id => '3', :issue_status => {:name => ''}
|
||||
assert_response :success
|
||||
assert_template 'edit'
|
||||
assert_error_tag :content => /name can't be blank/i
|
||||
end
|
||||
|
||||
def test_destroy
|
||||
Issue.delete_all("status_id = 1")
|
||||
|
||||
assert_difference 'IssueStatus.count', -1 do
|
||||
delete :destroy, :id => '1'
|
||||
end
|
||||
assert_redirected_to :action => 'index'
|
||||
assert_nil IssueStatus.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_destroy_should_block_if_status_in_use
|
||||
assert_not_nil Issue.find_by_status_id(1)
|
||||
|
||||
assert_no_difference 'IssueStatus.count' do
|
||||
delete :destroy, :id => '1'
|
||||
end
|
||||
assert_redirected_to :action => 'index'
|
||||
assert_not_nil IssueStatus.find_by_id(1)
|
||||
end
|
||||
|
||||
def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_field
|
||||
with_settings :issue_done_ratio => 'issue_field' do
|
||||
post :update_issue_done_ratio
|
||||
assert_match /not updated/, flash[:error].to_s
|
||||
assert_redirected_to '/issue_statuses'
|
||||
end
|
||||
end
|
||||
|
||||
def test_update_issue_done_ratio_with_issue_done_ratio_set_to_issue_status
|
||||
with_settings :issue_done_ratio => 'issue_status' do
|
||||
post :update_issue_done_ratio
|
||||
assert_match /Issue done ratios updated/, flash[:notice].to_s
|
||||
assert_redirected_to '/issue_statuses'
|
||||
end
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue