96 lines
2.9 KiB
Ruby
96 lines
2.9 KiB
Ruby
require File.expand_path('../../test_helper', __FILE__)
|
||
|
||
class CoursesControllerTest < ActionController::TestCase
|
||
fixtures :courses, :users, :user_extensions, :roles, :members, :member_roles, :enabled_modules, :boards, :messages
|
||
|
||
def setup
|
||
@request.session[:user_id] = nil
|
||
@request.session[:ctime] = Time.now.to_i
|
||
@request.session[:atime] = Time.now.to_i
|
||
Setting.default_language = 'en'
|
||
end
|
||
|
||
def test_index_by_anonymous_should_not_show_private_projects
|
||
get :index
|
||
assert_response :success
|
||
assert_template 'index'
|
||
courses = assigns(:courses)
|
||
assert_not_nil courses
|
||
assert courses.all?(&:is_public?)
|
||
end
|
||
|
||
# 人员添加课程的权限是不属于任何角色
|
||
def test_new_course_anyone_temporary
|
||
@request.session[:user_id] = 5
|
||
Role.find_by_name("Non member").add_permission! :add_course #Non member
|
||
|
||
get :new
|
||
assert_response :success
|
||
assert_template :new
|
||
end
|
||
|
||
def test_create_course_with_access_control
|
||
@request.session[:user_id] = 5
|
||
Role.find_by_name("Non member").add_permission! :add_course #Non member
|
||
course_name = 'course_one'
|
||
|
||
post :create,
|
||
:class_period => '32',
|
||
:time => '2014',
|
||
:term => 'spring',
|
||
:course => {
|
||
:name => course_name, # names can't contain space.
|
||
:password => '1234',
|
||
:description => 'description',
|
||
:is_public => '1',
|
||
:course_type => '1'
|
||
}
|
||
|
||
assert_response :found
|
||
course = Course.find_by_name(course_name)
|
||
red_url = "courses/#{course.id}/settings"
|
||
assert_match %r(#{red_url}), @response.redirect_url
|
||
# 创建成功跳转settings方法会带参数一枚,故一下方法失败
|
||
# assert_redirected_to "courses/#{course.id}/settings"
|
||
end
|
||
|
||
def test_create_course_without_access_control
|
||
@request.session[:user_id] = 5
|
||
#Role.find_by_name("Non member").add_permission! :add_course #Non member
|
||
course_name = 'course_one'
|
||
|
||
post :create,
|
||
:class_period => '32',
|
||
:time => '2014',
|
||
:term => 'spring',
|
||
:course => {
|
||
:name => course_name, # names can't contain space.
|
||
:password => '1234',
|
||
:description => 'description',
|
||
:is_public => '1',
|
||
:course_type => '1'
|
||
}
|
||
|
||
assert_response :forbidden
|
||
end
|
||
|
||
# test "#index by non-admin user with view_time_entries permission should show overall spent time link" do
|
||
# @request.session[:user_id] = 3
|
||
# get :index
|
||
# assert_template 'index'
|
||
# assert_select 'a[href=?]', '/time_entries'
|
||
# end
|
||
#
|
||
# test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do
|
||
# Role.find(2).remove_permission! :view_time_entries
|
||
# Role.non_member.remove_permission! :view_time_entries
|
||
# Role.anonymous.remove_permission! :view_time_entries
|
||
# @request.session[:user_id] = 3
|
||
#
|
||
# get :index
|
||
# assert_template 'index'
|
||
# assert_select 'a[href=?]', '/time_entries', 0
|
||
# end
|
||
end
|
||
|