tabletop-companion/test/controllers/tables_controller_test.rb

69 lines
1.5 KiB
Ruby
Raw Normal View History

2024-05-28 19:16:43 +00:00
# frozen_string_literal: true
require "test_helper"
class TablesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
sign_in users(:trevor)
get tables_url
assert_response :success
end
test "should get show" do
sign_in users(:trevor)
get table_url(tables(:table))
assert_response :success
end
test "should get new" do
sign_in users(:trevor)
get new_table_url
assert_response :success
end
test "should create table" do
sign_in users(:trevor)
assert_changes("Table.count", +1) do
post(tables_url, params: { table: table_params })
end
assert_redirected_to table_path(Table.last)
end
test "should alert to invalid table" do
sign_in users(:trevor)
assert_no_changes("Table.count") do
post(tables_url, params: { table: { name: "new_table" } })
end
assert_response :unprocessable_entity
end
test "should get edit" do
sign_in users(:trevor)
get edit_table_url(tables(:table))
assert_response :success
end
test "should update table" do
sign_in users(:trevor)
patch table_url(tables(:table)), params: { table: { name: "new name" } }
assert_redirected_to table_path(tables(:table))
end
test "should destroy table" do
sign_in users(:trevor)
assert_difference("Table.count", -1) do
delete table_url(tables(:table))
end
assert_redirected_to tables_url
end
private
def table_params
{
name: "A new table",
game_system_id: game_systems(:dnd).id,
}
end
end