1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00
Maybe/test/controllers/settings/profiles_controller_test.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

require "test_helper"
class Settings::ProfilesControllerTest < ActionDispatch::IntegrationTest
setup do
@admin = users(:family_admin)
@member = users(:family_member)
end
test "should get show" do
sign_in @admin
get settings_profile_path
assert_response :success
end
test "admin can remove a family member" do
sign_in @admin
assert_difference("User.count", -1) do
delete settings_profile_path(user_id: @member)
end
assert_redirected_to settings_profile_path
assert_equal I18n.t("settings.profiles.destroy.member_removed"), flash[:notice]
assert_raises(ActiveRecord::RecordNotFound) { User.find(@member.id) }
end
test "admin cannot remove themselves" do
sign_in @admin
assert_no_difference("User.count") do
delete settings_profile_path(user_id: @admin)
end
assert_redirected_to settings_profile_path
assert_equal I18n.t("settings.profiles.destroy.cannot_remove_self"), flash[:alert]
assert User.find(@admin.id)
end
test "non-admin cannot remove members" do
sign_in @member
assert_no_difference("User.count") do
delete settings_profile_path(user_id: @admin)
end
assert_redirected_to settings_profile_path
assert_equal I18n.t("settings.profiles.destroy.not_authorized"), flash[:alert]
assert User.find(@admin.id)
end
end