# HG changeset patch # User Nattee Niparnan # Date 2017-01-06 09:24:54 # Node ID f38d39d4f55599f28997fa403e5924bf04096675 # Parent 7645a0f771ce3e7f7fcec6f41735f500d7cb1378 login test diff --git a/Gemfile b/Gemfile --- a/Gemfile +++ b/Gemfile @@ -70,7 +70,7 @@ gem 'haml-rails' gem 'mail' gem 'rdiscount' -gem 'test-unit' +#gem 'test-unit' gem 'will_paginate', '~> 3.0.7' gem 'dynamic_form' gem 'in_place_editing' diff --git a/Gemfile.lock b/Gemfile.lock --- a/Gemfile.lock +++ b/Gemfile.lock @@ -117,7 +117,6 @@ mysql2 (0.4.5) nokogiri (1.6.8.1) mini_portile2 (~> 2.1.0) - power_assert (0.4.1) rack (1.6.5) rack-test (0.6.3) rack (>= 1.0) @@ -170,8 +169,6 @@ activesupport (>= 4.0) sprockets (>= 3.0.0) sqlite3 (1.3.12) - test-unit (3.2.3) - power_assert thor (0.19.4) thread_safe (0.3.5) tilt (2.0.5) @@ -212,7 +209,6 @@ sass-rails select2-rails sqlite3 - test-unit uglifier verification! will_paginate (~> 3.0.7) diff --git a/app/models/grader_configuration.rb b/app/models/grader_configuration.rb --- a/app/models/grader_configuration.rb +++ b/app/models/grader_configuration.rb @@ -11,6 +11,7 @@ CONTEST_TIME_LIMIT_KEY = 'contest.time_limit' MULTIPLE_IP_LOGIN_KEY = 'right.multiple_ip_login' VIEW_TESTCASE = 'right.view_testcase' + SINGLE_USER_KEY = 'system.single_user' cattr_accessor :config_cache cattr_accessor :task_grading_info_cache diff --git a/app/views/main/_login_box.html.haml b/app/views/main/_login_box.html.haml --- a/app/views/main/_login_box.html.haml +++ b/app/views/main/_login_box.html.haml @@ -12,7 +12,7 @@ %hr/ %div{ :style => "border: solid 1px gray; padding: 4px; background: #eeeeff;"} - = form_tag :controller => 'login', :action => 'login' do + = form_tag login_login_path do %table %tr %td{:align => "right"} diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -3,6 +3,9 @@ root :to => 'main#login' + #logins + get 'login/login', to: 'login#login' + resources :contests resources :sites diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -13,10 +13,10 @@ salt: <%= salt %> activated: true -mary: - login: mary - full_name: mary - hashed_password: <%= User.encrypt("goodbye",salt) %> +admin: + login: admin + full_name: admin + hashed_password: <%= User.encrypt("admin",salt) %> salt: <%= salt %> roles: admin activated: true diff --git a/test/integration/login_test.rb b/test/integration/login_test.rb --- a/test/integration/login_test.rb +++ b/test/integration/login_test.rb @@ -5,9 +5,33 @@ # assert true # end - test "login with valid information" do + test "login with invalid information" do + get root_path + assert_response :success + post login_login_path, login: "root", password: "hahaha" + assert_redirected_to root_path + end + + test "normal user login" do get root_path assert_response :success + post login_login_path, {login: "john", password: "hello" } + assert_redirected_to main_list_path + end + test "normal user login in single_user mode" do + GraderConfiguration[GraderConfiguration::SINGLE_USER_KEY] = 'true' + get root_path + assert_response :success + post login_login_path, {login: "john", password: "hello" } + assert_redirected_to root_path + end + + test "root login in in single_user mode" do + GraderConfiguration[GraderConfiguration::SINGLE_USER_KEY] = 'true' + get root_path + assert_response :success + post login_login_path, {login: "admin", password: "admin" } + assert_redirected_to main_list_path end end