# frozen_string_literal: true require "test_helper" class ChecksControllerTest < ActionDispatch::IntegrationTest def login(email, password) post "/login", params: { email: email, password: password } assert_redirected_to "/" end def logout post "/logout" assert_redirected_to "/" end teardown do logout end setup do @principle = principles(:one) @check = checks(:deletable) Account.create(email: "test@example.com", password: "password") login("test@example.com", "password") end test "should get index" do get checks_url assert_response :success end 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: { principle_id: @principle.id, number: Check.maximum(:number) + 1, level: @check.level, name_de: @check.name_de, position: @check.position, criterion_de: @check.criterion_de } } end assert_redirected_to check_url(Check.last) end test "should show check" do get check_url(@check) assert_response :success end 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: { principle_id: @principle.id, level: @check.level, name_de: @check.t_name, position: @check.position, criterion_de: @check.criterion_de } } assert_redirected_to check_url(@check) end test "should destroy check" do assert_difference("Check.count", -1) do delete check_url(@check) end assert_redirected_to checks_url end end