ftp-manager/test/controllers/accounts_controller/edit_test.rb
2016-09-28 22:12:55 -05:00

62 lines
1.5 KiB
Ruby

# frozen_string_literal: true
require 'test_helper'
class AccountsControllerTest < ActionDispatch::IntegrationTest
include TestAuthHelper
setup do
get auth_path
@account = accounts(:account1)
end
test "should create account" do
assert_difference('Account.count') do
post accounts_url, params: { account: {
home_folder: @account.home_folder,
password: @account.password,
contact_email: @account.contact_email,
username: 'client-new'
} }
end
assert_redirected_to account_url(Account.last)
end
test "should FAIL to create account" do
assert_difference('Account.count', 0) do
post accounts_url, params: { account: {
password: @account.password,
username: 'client-new'
} }
end
assert_response :success
assert_match(/failed to create/i, flash[:error])
end
test "should update account" do
patch account_url(@account), params: { account: {
home_folder: @account.home_folder,
password: @account.password,
contact_email: @account.contact_email,
username: @account.username
} }
assert_redirected_to account_url(@account)
end
test "should FAIL to update account" do
patch account_url(@account.id), params: { account: { username: nil } }
assert_response :success
assert_match(/failed to update/i, flash[:error])
end
test "should destroy account" do
assert_difference('Account.count', -1) do
delete account_url(@account)
end
assert_redirected_to accounts_url
end
end