rubocop fixing

This commit is contained in:
Aaro Koivukangas
2023-08-14 18:11:35 +03:00
parent da643b6614
commit 4e74c30afb
8 changed files with 37 additions and 38 deletions
+3 -4
View File
@@ -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
+3 -3
View File
@@ -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
+3 -3
View File
@@ -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
View File
@@ -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