# HG changeset patch # User Nattee Niparnan # Date 2019-07-05 08:54:05 # Node ID 3a8a3897c9265a779367cc61fd5f66f3a1cbc5ac # Parent 01b657de42d94166fd40cbbbc6b7931b01a031d9 more test on user_admin diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -209,7 +209,7 @@ @prefix = params[:prefix] || '' @non_admin_users = User.find_non_admin_with_prefix(@prefix) @changed = false - if request.request_method == 'POST' + if params[:commit] == 'Go ahead' @non_admin_users.each do |user| password = random_password user.password = password @@ -220,7 +220,6 @@ end end - # contest management def contests diff --git a/app/views/user_admin/_form.html.haml b/app/views/user_admin/_form.html.haml --- a/app/views/user_admin/_form.html.haml +++ b/app/views/user_admin/_form.html.haml @@ -1,38 +1,14 @@ -= error_messages_for 'user' -/ [form:user] -.form-group - %label.col-md-2.control-label{for: :login} Login - .col-md-4 - = text_field 'user', 'login', class: 'form-control' - .col-md-6 -.form-group - %label.col-md-2.control-label{for: :full_name} Full name - .col-md-4 - = text_field 'user', 'full_name', class: 'form-control' - .col-md-6 -.form-group - %label.col-md-2.control-label{for: :password} Password - .col-md-4 - = password_field 'user', 'password', class: 'form-control' - .col-md-6 -.form-group - %label.col-md-2.control-label{for: :password_confirmation} Password (confirm) - .col-md-4 - = password_field 'user', 'password_confirmation', class: 'form-control' - .col-md-6 -.form-group - %label.col-md-2.control-label{for: :email} E-mail - .col-md-4 - = email_field 'user', 'email', class: 'form-control' - .col-md-6 -.form-group - %label.col-md-2.control-label{for: :alias} Alias - .col-md-4 - = text_field 'user', 'alias', class: 'form-control' - .col-md-6 -.form-group - %label.col-md-2.control-label{for: :remark} Remark - .col-md-4 - = text_field 'user', 'remark', class: 'form-control' - .col-md-6 -/ [eoform:user] += simple_form_for(@user) do |f| + = f.error_notification + .row + .col-md-6.col-md-offset-2 + = f.input :login, label: 'Login' + = f.input :full_name, label: 'Full name' + = f.input :password + = f.input :password_confirmation + = f.input :email + = f.input :alias + = f.input :remark + = f.button :submit, class: 'btn btn-success' + = link_to 'Cancel', :back, class: 'btn btn-default' + diff --git a/app/views/user_admin/edit.html.haml b/app/views/user_admin/edit.html.haml --- a/app/views/user_admin/edit.html.haml +++ b/app/views/user_admin/edit.html.haml @@ -1,13 +1,4 @@ %h1 Editing user += simple_form_for @user, url: user_admin_path(@user) do |f| + = render partial: 'form', local: f -= form_tag( {:action => 'update', :id => @user}, {class: 'form-horizontal'}) do - = error_messages_for 'user' - = render partial: "form" - .form-group - .col-md-offset-2.col-md-4 - = submit_tag "Edit", class: 'btn btn-primary' - - -= link_to 'Show', :action => 'show', :id => @user -| -= link_to 'Back', :action => 'index' diff --git a/app/views/user_admin/new.html.haml b/app/views/user_admin/new.html.haml --- a/app/views/user_admin/new.html.haml +++ b/app/views/user_admin/new.html.haml @@ -1,7 +1,3 @@ %h1 New user -= form_tag( {action: 'create'}, { class: 'form-horizontal'}) do - = render :partial => 'form' - .form-group - .col-md-offset-2.col-md-10 - = submit_tag "Create", class: 'btn btn-primary' -= link_to 'Back', :action => 'index' += simple_form_for @user, url: user_admin_index_path do |f| + = render partial: 'form', local: f diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -99,11 +99,11 @@ get 'import' get 'new_list' get 'admin' - get 'random_all_passwords' get 'active' get 'mass_mailing' + post 'grant_admin' match 'create_from_list', via: [:get, :post] - post 'grant_admin' + match 'random_all_passwords', via: [:get, :post] end member do get 'clear_last_ip' diff --git a/test/system/users_test.rb b/test/system/users_test.rb new file mode 100644 --- /dev/null +++ b/test/system/users_test.rb @@ -0,0 +1,50 @@ +require "application_system_test_case" + +class UsersTest < ApplicationSystemTestCase + # test "visiting the index" do + # visit users_url + # + # assert_selector "h1", text: "User" + # end + + test "add new user and edit" do + login('admin','admin') + within 'header' do + click_on 'Manage' + click_on 'Users', match: :first + end + + assert_text "Users" + assert_text "New user" + + click_on "New user", match: :first + fill_in 'Login', with: 'test1' + fill_in 'Full name', with: 'test1 McTestface' + fill_in 'e-mail', with: 'a@a.com' + fill_in 'Password', with: 'abcdef' + fill_in 'Password confirmation', with: 'abcdef' + + click_on 'Create' + + assert_text 'User was successfully created' + assert_text 'a@a.com' + assert_text 'test1 McTestface' + + within('tr', text: 'McTestface') do + click_on 'Edit' + end + + fill_in 'Alias', with: 'hahaha' + fill_in 'Remark', with: 'section 2' + click_on 'Update User' + + assert_text 'section 2' + end + + def login(username,password) + visit root_path + fill_in "Login", with: username + fill_in "Password", with: password + click_on "Login" + end +end