Skip to content

Commit

Permalink
must_be_an_organizer_or_delegate_to_set_receive_registration_emails
Browse files Browse the repository at this point in the history
spuriously fires when a board member tries to remove themselves from a
competition entirely.
  • Loading branch information
jfly committed Nov 24, 2015
1 parent 9a2d712 commit dc93fd6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
8 changes: 0 additions & 8 deletions WcaOnRails/app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ def can_receive_registration_emails?(user_id)
return false
end

validate :must_be_an_organizer_or_delegate_to_set_receive_registration_emails
def must_be_an_organizer_or_delegate_to_set_receive_registration_emails
if editing_user_id && !@receive_registration_emails.nil?
if !can_receive_registration_emails?(editing_user_id)
errors.add(:receive_registration_emails, "You cannot receive registration emails for this competition.")
end
end
end
after_save :update_receive_registration_emails
def update_receive_registration_emails
if editing_user_id && !@receive_registration_emails.nil?
Expand Down
6 changes: 3 additions & 3 deletions WcaOnRails/spec/controllers/competitions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
let(:organizer) { FactoryGirl.create(:delegate) }
before :each do
competition.organizers << organizer
competition.save
competition.save!
sign_in organizer
end

Expand All @@ -222,7 +222,7 @@
it "who is also the delegate can remove oneself as delegate" do
# First, make the organizer of the competition the delegate of the competition.
competition.delegates << organizer
competition.save
competition.save!

# Remove ourself as a delegate. This should be allowed, because we're
# still an organizer.
Expand Down Expand Up @@ -259,7 +259,7 @@

# Remove ourself as an organizer. This should be allowed, because we're
# still able to administer results.
patch :update, id: competition, competition: { delegate_ids: "", organizer_ids: "" }
patch :update, id: competition, competition: { delegate_ids: "", organizer_ids: "", receive_registration_emails: true }
expect(competition.reload.delegates).to eq []
expect(competition.reload.organizers).to eq []
end
Expand Down

0 comments on commit dc93fd6

Please sign in to comment.