Add tests
This commit is contained in:
parent
363dfaa7d3
commit
cdea0e1218
14 changed files with 116 additions and 52 deletions
23
.forgejo/workflows/test.yml
Normal file
23
.forgejo/workflows/test.yml
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
on: [push]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: docker
|
||||
image: ruby:3.3.4
|
||||
name: Text
|
||||
steps:
|
||||
- name: Cache repository
|
||||
uses: actions/cache@v4
|
||||
id: cache-repository
|
||||
with:
|
||||
path: repository
|
||||
key: ${{ runner.os }}-repository-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-repository-
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: repository
|
||||
submodules: recursive
|
||||
- run: cd repository
|
||||
- run: bundle install
|
||||
- run: bundle exec rails test
|
||||
|
|
@ -24,7 +24,7 @@ class ChecklistsController < ApplicationController
|
|||
@checklist = Checklist.new(checklist_params)
|
||||
|
||||
if @checklist.save
|
||||
redirect_to [:edit, @checklist], notice: 'Checklist was successfully created.'
|
||||
redirect_to @checklist, notice: 'Checklist was successfully created.'
|
||||
else
|
||||
render :new, status: :unprocessable_entity
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,8 +42,13 @@ class SuccessCriteriaController < ApplicationController
|
|||
# DELETE /success_criteria/1
|
||||
def destroy
|
||||
@success_criterion.destroy!
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to success_criteria_url, notice: 'Success criterion was successfully destroyed.', status: :see_other
|
||||
end
|
||||
format.turbo_stream
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
|||
|
|
@ -10,4 +10,20 @@ module SuccessCriteriaHelper
|
|||
'bi bi-question text-warning'
|
||||
end
|
||||
end
|
||||
|
||||
def success_criterion_edit_button(success_criterion, edit_mode)
|
||||
path = if success_criterion.persisted?
|
||||
if edit_mode
|
||||
success_criterion
|
||||
else
|
||||
[:edit,
|
||||
success_criterion]
|
||||
end
|
||||
else
|
||||
success_criterion.element
|
||||
end
|
||||
link_to tag.i(class: 'bi bi-pencil'),
|
||||
path,
|
||||
class: "btn btn-#{edit_mode ? 'link text-warning' : 'link text-secondary'}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
<td><%= link_to(element.title, url_for(element)) %></td>
|
||||
|
||||
<td><%= link_to(truncate(strip_tags(element.description_html)), url_for(element)) %></td>
|
||||
<td><%= link_to(truncate(element.description_html&.to_plain_text), url_for(element)) %></td>
|
||||
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<i class="bi bi-pencil text-warning"></i>
|
||||
<% end %>
|
||||
</h3>
|
||||
<%= link_to tag.i(class: "bi bi-#{edit_mode ? "pencil" : "pencil"}"), edit_mode ? success_criterion : [:edit, success_criterion], class: "btn btn-#{edit_mode ? "link text-warning" : "link text-secondary"}" %>
|
||||
<%= success_criterion_edit_button(success_criterion, edit_mode) %>
|
||||
<div class="flex-fill d-flex justify-content-end">
|
||||
<button class="btn btn-link text-body"
|
||||
data-controller="collapse-chevron-toggler"
|
||||
|
|
|
|||
1
app/views/success_criteria/destroy.turbo_stream.erb
Normal file
1
app/views/success_criteria/destroy.turbo_stream.erb
Normal file
|
|
@ -0,0 +1 @@
|
|||
<%= turbo_stream.delete dom_id(@success_criterion) %>
|
||||
|
|
@ -27,13 +27,13 @@
|
|||
|
||||
<td><%= link_to(success_criterion.title, url_for(success_criterion)) %></td>
|
||||
|
||||
<td><%= link_to(truncate(strip_tags(success_criterion.description_html)), url_for(success_criterion)) %></td>
|
||||
<td><%= link_to(truncate(success_criterion.description_html.to_plain_text), url_for(success_criterion)) %></td>
|
||||
|
||||
<td><%= link_to(success_criterion.level, url_for(success_criterion)) %></td>
|
||||
|
||||
<td><%= link_to(success_criterion.result, url_for(success_criterion)) %></td>
|
||||
|
||||
<td><%= link_to(truncate(strip_tags(success_criterion.comment_html)), url_for(success_criterion)) %></td>
|
||||
<td><%= link_to(truncate(success_criterion.comment_html.to_plain_text), url_for(success_criterion)) %></td>
|
||||
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1,45 +1,49 @@
|
|||
require "test_helper"
|
||||
require 'test_helper'
|
||||
|
||||
class ChecklistEntriesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@checklist_entry = checklist_entries(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
test 'should get index' do
|
||||
get checklist_entries_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_checklist_entry_url
|
||||
test 'should get new' do
|
||||
get new_checklist_entry_url(checklist_id: @checklist_entry.checklist_id)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create checklist_entry" do
|
||||
assert_difference("ChecklistEntry.count") do
|
||||
post checklist_entries_url, params: { checklist_entry: { check_id: @checklist_entry.check_id, checklist_id: @checklist_entry.checklist_id, position: @checklist_entry.position } }
|
||||
test 'should create checklist_entry' do
|
||||
assert_difference('ChecklistEntry.count') do
|
||||
post checklist_entries_url,
|
||||
params: { checklist_entry: { check_id: @checklist_entry.check_id, checklist_id: @checklist_entry.checklist_id,
|
||||
position: @checklist_entry.position } }
|
||||
end
|
||||
|
||||
assert_redirected_to checklist_entry_url(ChecklistEntry.last)
|
||||
assert_redirected_to checklist_url(ChecklistEntry.last.checklist)
|
||||
end
|
||||
|
||||
test "should show checklist_entry" do
|
||||
test 'should show checklist_entry' do
|
||||
get checklist_entry_url(@checklist_entry)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
test 'should get edit' do
|
||||
get edit_checklist_entry_url(@checklist_entry)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update checklist_entry" do
|
||||
patch checklist_entry_url(@checklist_entry), params: { checklist_entry: { check_id: @checklist_entry.check_id, checklist_id: @checklist_entry.checklist_id, position: @checklist_entry.position } }
|
||||
assert_redirected_to checklist_entry_url(@checklist_entry)
|
||||
test 'should update checklist_entry' do
|
||||
patch checklist_entry_url(@checklist_entry),
|
||||
params: { checklist_entry: { check_id: @checklist_entry.check_id, checklist_id: @checklist_entry.checklist_id,
|
||||
position: @checklist_entry.position } }
|
||||
assert_redirected_to checklist_url(@checklist_entry.checklist)
|
||||
end
|
||||
|
||||
test "should destroy checklist_entry" do
|
||||
assert_difference("ChecklistEntry.count", -1) do
|
||||
test 'should destroy checklist_entry' do
|
||||
assert_difference('ChecklistEntry.count', -1) do
|
||||
delete checklist_entry_url(@checklist_entry)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,49 @@
|
|||
require "test_helper"
|
||||
require 'test_helper'
|
||||
|
||||
class ChecksControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@check = checks(:one)
|
||||
@check = checks(:deletable)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
test 'should get index' do
|
||||
get checks_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
test 'should get new' do
|
||||
get new_check_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create check" do
|
||||
assert_difference("Check.count") do
|
||||
post checks_url, params: { check: { level: @check.level, name: @check.name, position: @check.position, success_criterion: @check.success_criterion } }
|
||||
test 'should create check' do
|
||||
assert_difference('Check.count') do
|
||||
post checks_url,
|
||||
params: { check: { level: @check.level, name: @check.name, position: @check.position,
|
||||
success_criterion: @check.success_criterion } }
|
||||
end
|
||||
|
||||
assert_redirected_to check_url(Check.last)
|
||||
end
|
||||
|
||||
test "should show check" do
|
||||
test 'should show check' do
|
||||
get check_url(@check)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
test 'should get edit' do
|
||||
get edit_check_url(@check)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update check" do
|
||||
patch check_url(@check), params: { check: { level: @check.level, name: @check.name, position: @check.position, success_criterion: @check.success_criterion } }
|
||||
test 'should update check' do
|
||||
patch check_url(@check),
|
||||
params: { check: { level: @check.level, name: @check.name, position: @check.position,
|
||||
success_criterion: @check.success_criterion } }
|
||||
assert_redirected_to check_url(@check)
|
||||
end
|
||||
|
||||
test "should destroy check" do
|
||||
assert_difference("Check.count", -1) do
|
||||
test 'should destroy check' do
|
||||
assert_difference('Check.count', -1) do
|
||||
delete check_url(@check)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +1,50 @@
|
|||
require "test_helper"
|
||||
require 'test_helper'
|
||||
|
||||
class ElementsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@element = elements(:one)
|
||||
@checklist = checklists(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
test 'should get index' do
|
||||
get elements_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
test 'should get new' do
|
||||
get new_element_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create element" do
|
||||
assert_difference("Element.count") do
|
||||
post elements_url, params: { element: { description: @element.description, path: @element.path, report_id: @element.report_id, title: @element.title } }
|
||||
test 'should create element' do
|
||||
assert_difference('Element.count') do
|
||||
post elements_url,
|
||||
params: { element: { description: @element.description, path: @element.path, report_id: @element.report_id,
|
||||
title: @element.title, checklist_id: @checklist.id } }
|
||||
end
|
||||
|
||||
assert_redirected_to element_url(Element.last)
|
||||
assert_redirected_to report_url(Element.last.report)
|
||||
end
|
||||
|
||||
test "should show element" do
|
||||
test 'should show element' do
|
||||
get element_url(@element)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
test 'should get edit' do
|
||||
get edit_element_url(@element)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update element" do
|
||||
patch element_url(@element), params: { element: { description: @element.description, path: @element.path, report_id: @element.report_id, title: @element.title } }
|
||||
test 'should update element' do
|
||||
patch element_url(@element),
|
||||
params: { element: { description: @element.description, path: @element.path, report_id: @element.report_id,
|
||||
title: @element.title } }
|
||||
assert_redirected_to element_url(@element)
|
||||
end
|
||||
|
||||
test "should destroy element" do
|
||||
assert_difference("Element.count", -1) do
|
||||
test 'should destroy element' do
|
||||
assert_difference('Element.count', -1) do
|
||||
delete element_url(@element)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'test_helper'
|
|||
|
||||
class HomeControllerTest < ActionDispatch::IntegrationTest
|
||||
test 'should get show' do
|
||||
get home_show_url
|
||||
get root_url
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
|
|
|||
6
test/fixtures/checks.yml
vendored
6
test/fixtures/checks.yml
vendored
|
|
@ -11,3 +11,9 @@ two:
|
|||
name: MyString
|
||||
success_criterion: MyText
|
||||
level: 1
|
||||
|
||||
deletable:
|
||||
position: MyString
|
||||
name: MyString
|
||||
success_criterion: MyText
|
||||
level: 1
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
require "test_helper"
|
||||
require 'test_helper'
|
||||
|
||||
class ReportTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
test 'the truth' do
|
||||
assert_not Report.new.valid?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue