72 lines
2.1 KiB
Ruby
72 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
||
|
||
require "test_helper"
|
||
|
||
class TableInviteInvitesControllerTest < ActionDispatch::IntegrationTest
|
||
test "should get index" do
|
||
sign_in users(:trevor)
|
||
get table_invites_url
|
||
assert_response :success
|
||
end
|
||
|
||
test "only a table owner can invite players" do
|
||
sign_in users(:trevor)
|
||
get new_table_table_invite_url(tables(:gimlis_table))
|
||
assert_response :not_found
|
||
end
|
||
|
||
test "should get new" do
|
||
sign_in users(:trevor)
|
||
get new_table_table_invite_url(tables(:table))
|
||
assert_response :success
|
||
end
|
||
|
||
test "should get edit" do
|
||
sign_in users(:frodo)
|
||
get edit_table_invite_url(table_invites(:unaccepted))
|
||
assert_response :success
|
||
end
|
||
|
||
test "should create table_invite" do
|
||
sign_in users(:trevor)
|
||
assert_changes("TableInvite.count", +1) do
|
||
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "uninvited_user@example.com" } })
|
||
end
|
||
assert_redirected_to table_path(tables(:table))
|
||
end
|
||
|
||
test "can’t invite a user who doesn’t exist" do
|
||
sign_in users(:trevor)
|
||
assert_no_changes("TableInvite.count") do
|
||
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "not_real@example.com" } })
|
||
end
|
||
assert_response :unprocessable_entity
|
||
end
|
||
test "should email user when an invite is created" do
|
||
sign_in users(:trevor)
|
||
assert_emails(+1) do
|
||
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "uninvited_user@example.com" } })
|
||
end
|
||
end
|
||
|
||
test "should accept table_invite" do
|
||
sign_in users(:frodo)
|
||
invite = table_invites(:unaccepted)
|
||
assert_nil invite.accepted_at
|
||
patch table_invite_url(invite), params: { accept: true }
|
||
assert_redirected_to table_path(invite.table)
|
||
invite.reload
|
||
assert_not_nil invite.accepted_at
|
||
end
|
||
|
||
test "should decline table_invite" do
|
||
sign_in users(:frodo)
|
||
invite = table_invites(:unaccepted)
|
||
assert_nil invite.accepted_at
|
||
patch table_invite_url(invite), params: { decline: true }
|
||
assert_redirected_to root_path
|
||
invite.reload
|
||
assert_not_nil invite.declined_at
|
||
end
|
||
end
|