completing test coverage
This commit is contained in:
parent
12332cc6bf
commit
4d89a5ecc3
12
Guardfile
12
Guardfile
@ -70,12 +70,12 @@ guard :minitest, spring: "bin/rails test", all_after_pass: true do
|
|||||||
end
|
end
|
||||||
|
|
||||||
# ESLint
|
# ESLint
|
||||||
guard :shell, all_on_start: true do
|
# guard :shell, all_on_start: true do
|
||||||
watch %r{app/assets/javascripts/*/.*} do |file|
|
# watch %r{app/assets/javascripts/*/.*} do |file|
|
||||||
system %(echo "ESLint:\033[32m #{file[0]}\033[0m")
|
# system %(echo "ESLint:\033[32m #{file[0]}\033[0m")
|
||||||
system %(eslint #{file[0]})
|
# system %(eslint #{file[0]})
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
guard :rubocop, cli: %w(-D -S) do
|
guard :rubocop, cli: %w(-D -S) do
|
||||||
watch(/.+\.rb$/)
|
watch(/.+\.rb$/)
|
||||||
|
@ -2,23 +2,17 @@
|
|||||||
class AccountsController < ApplicationController
|
class AccountsController < ApplicationController
|
||||||
before_action :set_account, only: [:show, :edit, :reveal, :update, :destroy]
|
before_action :set_account, only: [:show, :edit, :reveal, :update, :destroy]
|
||||||
|
|
||||||
# GET /accounts
|
|
||||||
# GET /accounts.json
|
|
||||||
def index
|
def index
|
||||||
@accounts = Account.all
|
@accounts = Account.all
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /accounts/1
|
|
||||||
# GET /accounts/1.json
|
|
||||||
def show
|
def show
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /accounts/new
|
|
||||||
def new
|
def new
|
||||||
@account = Account.new
|
@account = Account.new
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /accounts/1/edit
|
|
||||||
def edit
|
def edit
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,54 +20,37 @@ class AccountsController < ApplicationController
|
|||||||
render json: { hash: @account.password }.to_json
|
render json: { hash: @account.password }.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
# POST /accounts
|
|
||||||
# POST /accounts.json
|
|
||||||
def create
|
def create
|
||||||
@account = Account.new(account_params)
|
@account = Account.new(account_params)
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
if @account.save
|
if @account.save
|
||||||
format.html { redirect_to @account, notice: 'Account was successfully created.' }
|
redirect_to @account, notice: 'Account was successfully created.'
|
||||||
format.json { render :show, status: :created, location: @account }
|
|
||||||
else
|
else
|
||||||
format.html { render :new }
|
flash[:error] = 'Failed to create account'
|
||||||
format.json { render json: @account.errors, status: :unprocessable_entity }
|
render :new
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# PATCH/PUT /accounts/1
|
|
||||||
# PATCH/PUT /accounts/1.json
|
|
||||||
def update
|
def update
|
||||||
respond_to do |format|
|
|
||||||
if @account.update(account_params)
|
if @account.update(account_params)
|
||||||
format.html { redirect_to @account, notice: 'Account was successfully updated.' }
|
redirect_to @account, notice: 'Account was successfully updated.'
|
||||||
format.json { render :show, status: :ok, location: @account }
|
|
||||||
else
|
else
|
||||||
format.html { render :edit }
|
flash[:error] = 'Failed to update account'
|
||||||
format.json { render json: @account.errors, status: :unprocessable_entity }
|
render :edit
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# DELETE /accounts/1
|
|
||||||
# DELETE /accounts/1.json
|
|
||||||
def destroy
|
def destroy
|
||||||
@account.destroy
|
@account.destroy
|
||||||
respond_to do |format|
|
redirect_to accounts_url, notice: 'Account was successfully destroyed.'
|
||||||
format.html { redirect_to accounts_url, notice: 'Account was successfully destroyed.' }
|
|
||||||
format.json { head :no_content }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
|
||||||
def set_account
|
def set_account
|
||||||
@account = Account.find(params[:id])
|
@account = Account.find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
|
||||||
def account_params
|
def account_params
|
||||||
params.require(:account).permit(:username, :password, :home, :site)
|
params.require(:account).permit(:username, :password, :home, :site)
|
||||||
end
|
end
|
||||||
|
@ -10,6 +10,7 @@ class AuthController < ApplicationController
|
|||||||
redirect_to login_path
|
redirect_to login_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :nocov:
|
||||||
def auth
|
def auth
|
||||||
redirect_to client.auth_code.authorize_url(redirect_uri: ENV['callback_url'])
|
redirect_to client.auth_code.authorize_url(redirect_uri: ENV['callback_url'])
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
class Account < ApplicationRecord
|
class Account < ApplicationRecord
|
||||||
serialize :password, CryptSerializer
|
serialize :password, CryptSerializer
|
||||||
|
|
||||||
|
validates :username, presence: true
|
||||||
|
validates :password, presence: true
|
||||||
|
validates :home, presence: true
|
||||||
|
validates :site, presence: true
|
||||||
end
|
end
|
||||||
|
@ -9,17 +9,6 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
@account = accounts(:account1)
|
@account = accounts(:account1)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
|
||||||
get accounts_url
|
|
||||||
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
|
|
||||||
test "should get new" do
|
|
||||||
get new_account_url
|
|
||||||
assert_response :success
|
|
||||||
end
|
|
||||||
|
|
||||||
test "should create account" do
|
test "should create account" do
|
||||||
assert_difference('Account.count') do
|
assert_difference('Account.count') do
|
||||||
post accounts_url, params: { account: {
|
post accounts_url, params: { account: {
|
||||||
@ -33,14 +22,16 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_redirected_to account_url(Account.last)
|
assert_redirected_to account_url(Account.last)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show account" do
|
test "should FAIL to create account" do
|
||||||
get account_url(@account)
|
assert_difference('Account.count', 0) do
|
||||||
assert_response :success
|
post accounts_url, params: { account: {
|
||||||
|
password: @account.password,
|
||||||
|
username: 'client-new'
|
||||||
|
} }
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get edit" do
|
|
||||||
get edit_account_url(@account)
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
|
assert_match(/failed to create/i, flash[:error])
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update account" do
|
test "should update account" do
|
||||||
@ -53,6 +44,13 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_redirected_to account_url(@account)
|
assert_redirected_to account_url(@account)
|
||||||
end
|
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
|
test "should destroy account" do
|
||||||
assert_difference('Account.count', -1) do
|
assert_difference('Account.count', -1) do
|
||||||
delete account_url(@account)
|
delete account_url(@account)
|
||||||
@ -60,12 +58,4 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
assert_redirected_to accounts_url
|
assert_redirected_to accounts_url
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'reveal should provide password' do
|
|
||||||
get reveal_password_url(@account.to_i), xhr: true
|
|
||||||
json = JSON.parse(response.body).to_hash
|
|
||||||
|
|
||||||
assert_response :success
|
|
||||||
assert_match '1q2w3e4r5t6y7u', json['hash']
|
|
||||||
end
|
|
||||||
end
|
end
|
40
test/controllers/accounts_controller/view_test.rb
Normal file
40
test/controllers/accounts_controller/view_test.rb
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
include TestAuthHelper
|
||||||
|
|
||||||
|
setup do
|
||||||
|
get auth_path
|
||||||
|
@account = accounts(:account1)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get accounts_url
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get new_account_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show account" do
|
||||||
|
get account_url(@account)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get edit_account_url(@account)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'reveal should provide password' do
|
||||||
|
get reveal_password_url(@account.to_i), xhr: true
|
||||||
|
json = JSON.parse(response.body).to_hash
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
assert_match '1q2w3e4r5t6y7u', json['hash']
|
||||||
|
end
|
||||||
|
end
|
@ -4,7 +4,7 @@ require 'test_helper'
|
|||||||
class AuthControllerTest < ActionDispatch::IntegrationTest
|
class AuthControllerTest < ActionDispatch::IntegrationTest
|
||||||
include TestAuthHelper
|
include TestAuthHelper
|
||||||
|
|
||||||
test "should get auth" do
|
test "Should fake login process" do
|
||||||
# This is not a real test of AuthController!
|
# This is not a real test of AuthController!
|
||||||
# We are really testing that the monkey path is correct
|
# We are really testing that the monkey path is correct
|
||||||
#
|
#
|
||||||
@ -26,4 +26,13 @@ class AuthControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
assert_equal "redirect_to accounts_path", last_line_in_callback
|
assert_equal "redirect_to accounts_path", last_line_in_callback
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'should logout' do
|
||||||
|
get auth_path
|
||||||
|
assert session[:token]
|
||||||
|
|
||||||
|
get logout_path
|
||||||
|
assert session[:token].nil?
|
||||||
|
assert_redirected_to login_path
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user