fga-gpp-mds/2017.1-Escola-X

View on GitHub
app/controllers/notifications_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
# File name: notifications_controller.rb
# Class name: NotificationsController
Line is too long. [88/80]
# Description: Controller used to communicate with the proprietary view of notifications
NotificationsController assumes too much for instance variable '@notification'
NotificationsController assumes too much for instance variable '@current_user'
class NotificationsController < ApplicationController
include SessionsHelper
 
def index
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( logged_in? )
@notifications = Notification.all
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def show
Use a guard clause instead of wrapping the code inside a conditional expression.
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
Don't use parentheses around a method call.
if ( logged_in? )
@notification = Notification.find(params[:id])
NotificationsController#show calls '@notification.employee_id' 2 times
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Line is too long. [132/80]
@assignee = Employee.exists?(@notification.employee_id) ? Employee.find_by_id(@notification.employee_id).name : "Desconhecido"
end
end
 
def new
NotificationsController tests '( is_employee? )' at least 5 times
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
Space inside parentheses detected.
if ( is_employee? )
@notification = Notification.new
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
Method has too many lines. [13/10]
NotificationsController#create has approx 7 statements
def create
Space inside parentheses detected.
Don't use parentheses around the condition of an `if`.
Don't use parentheses around a method call.
if ( is_employee? )
@notification = Notification.new(notification_params)
@notification.employee_id = @current_user.id
@notification.notification_date = @notification.get_date
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if (@notification.save)
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:success] = "A notificação foi criada com sucesso."
redirect_to notification_path(@notification)
else
render new_notification_path
end
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def edit
Space inside parentheses detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( is_employee? )
@notification = Notification.find(params[:id])
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
Method has too many lines. [11/10]
def update
Space inside parentheses detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( is_employee? )
@notification = Notification.find(params[:id])
Space inside parentheses detected.
Don't use parentheses around a method call.
Don't use parentheses around the condition of an `if`.
if ( @notification.update(notification_params) )
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:notice] = "A notificação foi alterada com sucesso."
redirect_to notification_path(@notification)
else
render edit_notification_path
end
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
def destroy
Don't use parentheses around the condition of an `if`.
Space inside parentheses detected.
Don't use parentheses around a method call.
if ( is_employee? )
@notification = Notification.find(params[:id])
@notification.destroy
Prefer single-quoted strings when you don't need string interpolation or special symbols.
flash[:alert] = "Notificação excluída com sucesso"
redirect_to notifications_path
else
Prefer single-quoted strings when you don't need string interpolation or special symbols.
redirect_to "/errors/error_500"
end
end
 
Keep a blank line before and after `private`.
private
def notification_params
Space inside parentheses detected.
params.require(:notification).permit( :title,
:motive,
:notification_text,
:employee_id,
:notification_date,
:notification_hour)
end
end