Skip to content

Commit

Permalink
bugfix: actually raise on too many code collisions (lobsters#729)
Browse files Browse the repository at this point in the history
Use inclusive range instead of exclusive, remove conditional.
  • Loading branch information
brianchhun authored and pushcx committed Aug 25, 2019
1 parent 234c67e commit d7328d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
11 changes: 3 additions & 8 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@ class Invitation < ApplicationRecord
before_validation :create_code, :on => :create

def create_code
(1...10).each do |tries|
if tries == 10
raise "too many hash collisions"
end

10.times do
self.code = Utils.random_str(15)
unless Invitation.exists?(:code => self.code)
break
end
return unless Invitation.exists?(:code => self.code)
end
raise "too many hash collisions"
end

def send_email
Expand Down
11 changes: 3 additions & 8 deletions app/models/invitation_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ def self.verified_count
end

def create_code
(1...10).each do |tries|
if tries == 10
raise "too many hash collisions"
end

10.times do
self.code = Utils.random_str(15)
unless InvitationRequest.exists?(:code => self.code)
break
end
return unless InvitationRequest.exists?(:code => self.code)
end
raise "too many hash collisions"
end

def markeddown_memo
Expand Down

0 comments on commit d7328d3

Please sign in to comment.