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
+10 -9
View File
@@ -1,5 +1,5 @@
class BeerclubsController < ApplicationController class BeerclubsController < ApplicationController
before_action :set_beerclub, only: %i[ show edit update destroy ] before_action :set_beerclub, only: %i[show edit update destroy]
# GET /beerclubs or /beerclubs.json # GET /beerclubs or /beerclubs.json
def index def index
@@ -58,13 +58,14 @@ class BeerclubsController < ApplicationController
end end
private private
# Use callbacks to share common setup or constraints between actions.
def set_beerclub
@beerclub = Beerclub.find(params[:id])
end
# Only allow a list of trusted parameters through. # Use callbacks to share common setup or constraints between actions.
def beerclub_params def set_beerclub
params.require(:beerclub).permit(:name, :founded, :city) @beerclub = Beerclub.find(params[:id])
end end
# Only allow a list of trusted parameters through.
def beerclub_params
params.require(:beerclub).permit(:name, :founded, :city)
end
end end
+10 -9
View File
@@ -1,5 +1,5 @@
class MembershipsController < ApplicationController class MembershipsController < ApplicationController
before_action :set_membership, only: %i[ show edit update destroy ] before_action :set_membership, only: %i[show edit update destroy]
# GET /memberships or /memberships.json # GET /memberships or /memberships.json
def index def index
@@ -63,13 +63,14 @@ class MembershipsController < ApplicationController
end end
private private
# Use callbacks to share common setup or constraints between actions.
def set_membership
@membership = Membership.find(params[:id])
end
# Only allow a list of trusted parameters through. # Use callbacks to share common setup or constraints between actions.
def membership_params def set_membership
params.require(:membership).permit(:user_id, :beerclub_id) @membership = Membership.find(params[:id])
end end
# Only allow a list of trusted parameters through.
def membership_params
params.require(:membership).permit(:user_id, :beerclub_id)
end
end end
+1 -1
View File
@@ -5,7 +5,7 @@ class SessionsController < ApplicationController
def create def create
user = User.find_by username: params[:username] user = User.find_by username: params[:username]
if user && user.authenticate(params[:password]) if user&.authenticate(params[:password])
session[:user_id] = user.id if user session[:user_id] = user.id if user
redirect_to user_path user, notice: "Welcome back :)" redirect_to user_path user, notice: "Welcome back :)"
else else
+2 -4
View File
@@ -17,9 +17,8 @@ class UsersController < ApplicationController
# GET /users/1/edit # GET /users/1/edit
def edit def edit
if not @user == current_user return if @user == current_user
# redirect_to user_path(@user), notice: "Not permitted to edit user" # redirect_to user_path(@user), notice: "Not permitted to edit user"
end
end end
# POST /users or /users.json # POST /users or /users.json
@@ -39,7 +38,6 @@ class UsersController < ApplicationController
# PATCH/PUT /users/1 or /users/1.json # PATCH/PUT /users/1 or /users/1.json
def update def update
respond_to do |format| respond_to do |format|
if user_params[:username].nil? && @user == current_user && @user.update(user_params) if user_params[:username].nil? && @user == current_user && @user.update(user_params)
format.html { redirect_to user_url(@user), notice: "User was successfully updated." } format.html { redirect_to user_url(@user), notice: "User was successfully updated." }
+3 -4
View File
@@ -8,9 +8,8 @@ class Beerclub < ApplicationRecord
validate :creation_year_not_in_future validate :creation_year_not_in_future
def creation_year_not_in_future def creation_year_not_in_future
if founded > Time.now.year return unless founded > Time.now.year
errors.add :founded, "cannot be in the future"
end
end
errors.add :founded, "cannot be in the future"
end
end end
+3 -3
View File
@@ -10,9 +10,9 @@ class Brewery < ApplicationRecord
validate :creation_year_not_in_future validate :creation_year_not_in_future
def creation_year_not_in_future def creation_year_not_in_future
if year > Time.now.year return unless year > Time.now.year
errors.add :year, "cannot be in the future"
end errors.add :year, "cannot be in the future"
end end
def print_report def print_report
+3 -3
View File
@@ -5,8 +5,8 @@ class Membership < ApplicationRecord
validate :user_not_in_club validate :user_not_in_club
def user_not_in_club def user_not_in_club
if not Membership.find_by(user_id:user_id, beerclub_id:beerclub_id).nil? return if Membership.find_by(user_id:, beerclub_id:).nil?
errors.add :user_id, "is already in the beerclub"
end errors.add :user_id, "is already in the beerclub"
end end
end end
+5 -5
View File
@@ -5,17 +5,17 @@ class User < ApplicationRecord
validates :username, uniqueness: true, length: { minimum: 3, maximum: 30 } validates :username, uniqueness: true, length: { minimum: 3, maximum: 30 }
validates :password, length: { minimum: 3 } validates :password, length: { minimum: 3 }
validate :has_proper_characters_in_password validate :proper_characters_in_password?
has_many :ratings, dependent: :destroy has_many :ratings, dependent: :destroy
has_many :beers, through: :ratings has_many :beers, through: :ratings
has_many :memberships, dependent: :destroy has_many :memberships, dependent: :destroy
has_many :beer_clubs, through: :memberships has_many :beer_clubs, through: :memberships
def has_proper_characters_in_password def proper_characters_in_password?
regex = "(?=.*[[:upper:]])(?=.*[0-9])" regex = "(?=.*[[:upper:]])(?=.*[0-9])"
if not password&.match(regex) return false if password&.match(regex)
errors.add :password, "doesn't contain uppercase letter and a number"
end errors.add :password, "doesn't contain uppercase letter and a number"
end end
end end