mirror of
https://github.com/iritmaximus/brewery.git
synced 2026-10-12 19:13:49 +03:00
rubocop fixing
This commit is contained in:
@@ -8,9 +8,8 @@ class Beerclub < ApplicationRecord
|
||||
validate :creation_year_not_in_future
|
||||
|
||||
def creation_year_not_in_future
|
||||
if founded > Time.now.year
|
||||
errors.add :founded, "cannot be in the future"
|
||||
end
|
||||
end
|
||||
return unless founded > Time.now.year
|
||||
|
||||
errors.add :founded, "cannot be in the future"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,9 +10,9 @@ class Brewery < ApplicationRecord
|
||||
validate :creation_year_not_in_future
|
||||
|
||||
def creation_year_not_in_future
|
||||
if year > Time.now.year
|
||||
errors.add :year, "cannot be in the future"
|
||||
end
|
||||
return unless year > Time.now.year
|
||||
|
||||
errors.add :year, "cannot be in the future"
|
||||
end
|
||||
|
||||
def print_report
|
||||
|
||||
@@ -5,8 +5,8 @@ class Membership < ApplicationRecord
|
||||
validate :user_not_in_club
|
||||
|
||||
def user_not_in_club
|
||||
if not Membership.find_by(user_id:user_id, beerclub_id:beerclub_id).nil?
|
||||
errors.add :user_id, "is already in the beerclub"
|
||||
end
|
||||
return if Membership.find_by(user_id:, beerclub_id:).nil?
|
||||
|
||||
errors.add :user_id, "is already in the beerclub"
|
||||
end
|
||||
end
|
||||
|
||||
+5
-5
@@ -5,17 +5,17 @@ class User < ApplicationRecord
|
||||
|
||||
validates :username, uniqueness: true, length: { minimum: 3, maximum: 30 }
|
||||
validates :password, length: { minimum: 3 }
|
||||
validate :has_proper_characters_in_password
|
||||
validate :proper_characters_in_password?
|
||||
|
||||
has_many :ratings, dependent: :destroy
|
||||
has_many :beers, through: :ratings
|
||||
has_many :memberships, dependent: :destroy
|
||||
has_many :beer_clubs, through: :memberships
|
||||
|
||||
def has_proper_characters_in_password
|
||||
def proper_characters_in_password?
|
||||
regex = "(?=.*[[:upper:]])(?=.*[0-9])"
|
||||
if not password&.match(regex)
|
||||
errors.add :password, "doesn't contain uppercase letter and a number"
|
||||
end
|
||||
return false if password&.match(regex)
|
||||
|
||||
errors.add :password, "doesn't contain uppercase letter and a number"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user