tabletop-companion/test/controllers/characters_controller_test.rb

56 lines
1.4 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
class CharactersControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
sign_in users(:trevor)
get characters_url
assert_response :success
end
test "should get show" do
sign_in users(:trevor)
get character_url(characters(:nardren))
assert_response :success
end
test "should get new" do
sign_in users(:trevor)
get new_character_url
assert_response :success
end
test "should create character" do
sign_in users(:trevor)
assert_difference("Character.count") do
post characters_url, params: { character: {
name: "Acornia", game_system_id: game_systems(:dnd).id, table_id: tables(:dnd_table).id,
} }
end
assert_redirected_to character_url(Character.last)
end
test "should get edit" do
sign_in users(:trevor)
get edit_character_url(characters(:nardren))
assert_response :success
end
test "should update character" do
sign_in users(:trevor)
patch character_url(characters(:nardren)), params: { character: {
name: "Acornia",
} }
assert_redirected_to character_url(characters(:nardren))
end
test "should destroy character" do
sign_in users(:trevor)
assert_difference("Character.count", -1) do
delete character_url(characters(:nardren))
end
assert_redirected_to characters_url
end
end