chore: rubocop
chore: fix api test conventions chore: rubocop -A spec/ chore: more rubocop -A fix failing test rubocop fixes removes helper methods that are in my opinion dead code more rubocop fixes rubocop -a --auto-gen-config
This commit is contained in:
parent
f6fb804bbe
commit
fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions
|
|
@ -5,12 +5,12 @@ class Invite < ApplicationRecord
|
|||
belongs_to :user
|
||||
belongs_to :group
|
||||
|
||||
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
|
||||
validates_presence_of :user
|
||||
validates_presence_of :group
|
||||
validates_presence_of :token
|
||||
validates_presence_of :expires_at
|
||||
validate :email_not_already_registered, :on => :create
|
||||
validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
|
||||
validates :user, presence: true
|
||||
validates :group, presence: true
|
||||
validates :token, presence: true
|
||||
validates :expires_at, presence: true
|
||||
validate :email_not_already_registered, on: :create
|
||||
|
||||
before_validation :set_token_and_expires_at
|
||||
|
||||
|
|
@ -19,15 +19,15 @@ class Invite < ApplicationRecord
|
|||
# Before validation, set token and expires_at.
|
||||
def set_token_and_expires_at
|
||||
self.token = Digest::SHA1.hexdigest(Time.now.to_s + rand(100).to_s)
|
||||
self.expires_at = Time.now.advance(:days => 7)
|
||||
self.expires_at = Time.now.advance(days: 7)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Custom validation: check that email does not already belong to a registered user.
|
||||
def email_not_already_registered
|
||||
unless User.find_by_email(self.email).nil?
|
||||
errors.add(:email, I18n.t('invites.errors.already_member'))
|
||||
end
|
||||
return if User.find_by_email(email).nil?
|
||||
|
||||
errors.add(:email, I18n.t('invites.errors.already_member'))
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue