Skip to content

Commit

Permalink
Test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed Nov 1, 2024
1 parent 801a272 commit ed579b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 6 additions & 0 deletions app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ def new
end

def create
unless Current.user.admin?
flash[:alert] = t(".failure")
redirect_to settings_profile_path
return
end

@invitation = Current.family.invitations.build(invitation_params)
@invitation.inviter = Current.user

Expand Down
5 changes: 1 addition & 4 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ def set_expiration
end

def inviter_is_admin
unless inviter.admin?
errors.add(:role, "can only be set to member for non-admin inviters")
self.role = "member"
end
inviter.admin?
end
end
8 changes: 4 additions & 4 deletions test/controllers/invitations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class InvitationsControllerTest < ActionDispatch::IntegrationTest
assert_equal I18n.t("invitations.create.success"), flash[:notice]
end

test "non-admin cannot create admin invitation" do
test "non-admin cannot create invitations" do
sign_in users(:family_member)

assert_difference("Invitation.count") do
assert_no_difference("Invitation.count") do
post invitations_url, params: {
invitation: {
email: "[email protected]",
Expand All @@ -43,8 +43,8 @@ class InvitationsControllerTest < ActionDispatch::IntegrationTest
}
end

invitation = Invitation.last
assert_equal "member", invitation.role # Role should be downgraded to member
assert_redirected_to settings_profile_path
assert_equal I18n.t("invitations.create.failure"), flash[:alert]
end

test "admin can create admin invitation" do
Expand Down

0 comments on commit ed579b3

Please sign in to comment.