rubocop files update and auto correction

This commit is contained in:
raluka 2015-10-21 17:33:53 +02:00
parent 1a62dc930e
commit 1f82fbbdc6
88 changed files with 519 additions and 452 deletions

View file

@ -22,7 +22,7 @@ module Admin
# Grouping all comments by conference, and by event. It returns {:conference => {:event => [{comment_2}, {comment_1 }]}}
def grouped_comments(remarks)
remarks.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by{|comment| comment.commentable}]}.to_h
remarks.group_by{ |comment| comment.commentable.conference }.map {|conference, comments| [conference, comments.group_by(&:commentable)]}.to_h
end
end
end

View file

@ -21,7 +21,7 @@ module Admin
@active_conferences = Conference.get_active_conferences_for_dashboard # pending or the last two
@deactive_conferences = Conference.
get_conferences_without_active_for_dashboard(@active_conferences) # conferences without active
get_conferences_without_active_for_dashboard(@active_conferences) # conferences without active
@conferences = @active_conferences + @deactive_conferences
@recent_users = User.limit(5).order(created_at: :desc)
@ -102,7 +102,7 @@ module Admin
@total_submissions = @conference.events.count
@new_submissions = @conference.events.
where('created_at > ?', current_user.last_sign_in_at).count
where('created_at > ?', current_user.last_sign_in_at).count
@program_length = @conference.current_program_hours
@new_program_length = @conference.new_program_hours(current_user.last_sign_in_at)
@ -135,7 +135,7 @@ module Admin
@difficulty_levels_distribution = @conference.difficulty_levels_distribution
@difficulty_levels_distribution_confirmed = @conference.
difficulty_levels_distribution(:confirmed)
difficulty_levels_distribution(:confirmed)
@tracks_distribution = @conference.tracks_distribution
@tracks_distribution_confirmed = @conference.tracks_distribution(:confirmed)

View file

@ -6,7 +6,7 @@ module Admin
def update
@conference.email_settings.update_attributes(params[:email_settings])
redirect_to(admin_conference_emails_path(
@conference.short_title),
@conference.short_title),
notice: 'Settings have been successfully updated.')
end

View file

@ -106,7 +106,7 @@ module Admin
def update
if @event.submitter.update_attributes(params[:user]) &&
@event.update_attributes(params[:event])
@event.update_attributes(params[:event])
if request.xhr?
render js: 'index'

View file

@ -73,12 +73,9 @@ module Admin
# Delete question and its answers
begin
Question.transaction do
@question.destroy
@question.answers.each do |a|
a.destroy
end
flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map {|a| a.title}.join ','}"
@question.answers.each(&:destroy)
flash[:notice] = "Deleted question: #{@question.title} and its answers: #{@question.answers.map(&:title).join ','}"
end
rescue ActiveRecord::RecordInvalid
flash[:error] = 'Could not delete question.'

View file

@ -53,14 +53,14 @@ module Admin
def registration_params
params.require(:registration).
permit(
:conference_id, :arrival, :departure,
:volunteer,
vchoice_ids: [], qanswer_ids: [], event_ids: [],
qanswers_attributes: [],
user_attributes: [
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages,
:nickname, :affiliation])
permit(
:conference_id, :arrival, :departure,
:volunteer,
vchoice_ids: [], qanswer_ids: [], event_ids: [],
qanswers_attributes: [],
user_attributes: [
:id, :name, :tshirt, :mobile, :volunteer_experience, :languages,
:nickname, :affiliation])
end
end
end

View file

@ -27,7 +27,7 @@ module Admin
def update
if @sponsor.update_attributes(sponsor_params)
redirect_to(admin_conference_sponsors_path(
conference_id: @conference.short_title),
conference_id: @conference.short_title),
notice: 'Sponsor successfully updated.')
else
flash[:error] = "Update sponsor failed: #{@sponsor.errors.full_messages.join('. ')}."

View file

@ -27,7 +27,7 @@ module Admin
def update
if @sponsorship_level.update_attributes(sponsorship_level_params)
redirect_to(admin_conference_sponsorship_levels_path(
conference_id: @conference.short_title),
conference_id: @conference.short_title),
notice: 'Sponsorship level successfully updated.')
else
flash[:error] = "Update Sponsorship level failed: #{@sponsorship_level.errors.full_messages.join('. ')}."

View file

@ -25,9 +25,9 @@ class ApplicationController < ActionController::Base
def after_sign_in_path_for(_resource)
if (can? :view, Conference) &&
(!session[:return_to] ||
session[:return_to] &&
session[:return_to] == root_path)
(!session[:return_to] ||
session[:return_to] &&
session[:return_to] == root_path)
admin_conference_index_path
else
session[:return_to] || root_path

View file

@ -59,7 +59,7 @@ class ConferenceRegistrationsController < ApplicationController
if @conference.tickets.any? && !current_user.supports?(@conference)
redirect_to conference_tickets_path(@conference.short_title)
else
redirect_to conference_conference_registrations_path(@conference.short_title)
redirect_to conference_conference_registrations_path(@conference.short_title)
end
else
flash[:error] = "Could not create your registration for #{@conference.title}: "\
@ -106,14 +106,14 @@ class ConferenceRegistrationsController < ApplicationController
def registration_params
params.require(:registration).
permit(
:conference_id, :arrival, :departure,
:volunteer,
vchoice_ids: [], qanswer_ids: [],
qanswers_attributes: [],
event_ids: [],
user_attributes: [
:username, :email, :name, :password, :password_confirmation]
)
permit(
:conference_id, :arrival, :departure,
:volunteer,
vchoice_ids: [], qanswer_ids: [],
qanswers_attributes: [],
event_ids: [],
user_attributes: [
:username, :email, :name, :password, :password_confirmation]
)
end
end

View file

@ -24,11 +24,11 @@ class RegistrationsController < Devise::RegistrationsController
def configure_permitted_parameters
devise_parameter_sanitizer.for(:account_update) do |u|
u.
permit(:email, :password, :password_confirmation, :current_password, :username)
permit(:email, :password, :password_confirmation, :current_password, :username)
end
devise_parameter_sanitizer.for(:sign_up) do |u|
u.
permit(:email, :password, :password_confirmation, :name, :username)
permit(:email, :password, :password_confirmation, :name, :username)
end
end
end

View file

@ -184,7 +184,7 @@ module ApplicationHelper
end
def event_types(conference)
all = conference.event_types.map { |et | et.title.pluralize }
all = conference.event_types.map { |et| et.title.pluralize }
first = all[0...-1]
last = all[-1]
ets = ''
@ -198,7 +198,7 @@ module ApplicationHelper
end
def tracks(conference)
all = conference.tracks.map {|t| t.name}
all = conference.tracks.map(&:name)
first = all[0...-1]
last = all[-1]
ts = ''
@ -215,7 +215,7 @@ module ApplicationHelper
def word_pluralize(count, singular, plural = nil)
word = if (count == 1 || count =~ /^1(\.0+)?$/)
singular
else
else
plural || singular.pluralize
end

View file

@ -50,12 +50,8 @@ class Ability
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
can :show, User
unless CONFIG['authentication']['ichain']['enabled']
can [:show, :create], Registration do |registration|
registration.new_record?
end
can [:show, :create], Event do |event|
event.new_record?
end
can [:show, :create], Registration, &:new_record?
can [:show, :create], Event, &:new_record?
end
end

View file

@ -49,6 +49,7 @@ class CallForPaper < ActiveRecord::Base
&& !self.conference.email_settings.call_for_papers_dates_updates_subject.blank?\
&& !self.conference.email_settings.call_for_papers_dates_updates_template.blank?
end
##
# Checks whether cfp dates is updated
#
@ -72,14 +73,14 @@ class CallForPaper < ActiveRecord::Base
def before_end_of_conference
errors.
add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date)
add(:end_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && end_date && (end_date > conference.end_date)
errors.
add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date)
add(:start_date, "can't be after the conference end date (#{conference.end_date})") if conference && conference.end_date && start_date && (start_date > conference.end_date)
end
def start_after_end_date
errors.
add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
add(:start_date, "can't be after the end date") if start_date && end_date && start_date > end_date
end
end

View file

@ -1,6 +1,6 @@
##
# This class represents a conference
# rubocop:disable Style/ClassLength
# rubocop:disable Metrics/ClassLength
class Conference < ActiveRecord::Base
require 'uri'
serialize :events_per_week, Hash
@ -218,7 +218,7 @@ class Conference < ActiveRecord::Base
result[state] = pad_array_left_not_kumulative(start_week, values)
end
end
result['Weeks'] = weeks > 0 ? (1..weeks).to_a : 0
result['Weeks'] = weeks > 0 ? (1..weeks).to_a : 0
end
result
end
@ -232,9 +232,9 @@ class Conference < ActiveRecord::Base
result = []
if registrations &&
registration_period &&
registration_period.start_date &&
registration_period.end_date
registration_period &&
registration_period.start_date &&
registration_period.end_date
reg = registrations.group(:week).count
start_week = get_registration_start_week
@ -253,10 +253,10 @@ class Conference < ActiveRecord::Base
result = 0
weeks = 0
if registration_period &&
registration_period.start_date &&
registration_period.end_date
registration_period.start_date &&
registration_period.end_date
weeks = Date.new(registration_period.start_date.year, 12, 31).
strftime('%W').to_i
strftime('%W').to_i
result = get_registration_end_week - get_registration_start_week + 1
end
@ -353,8 +353,8 @@ class Conference < ActiveRecord::Base
# * +hash+ -> user: submissions
def get_top_submitter(limit = 5)
submitter = EventUser.joins(:event).
where('event_role = ? and conference_id = ?', 'submitter', id).
limit(limit).group(:user_id)
where('event_role = ? and conference_id = ?', 'submitter', id).
limit(limit).group(:user_id)
counter = submitter.order('count_all desc').count
Conference.calculate_user_submission_hash(submitter, counter)
end
@ -476,12 +476,12 @@ class Conference < ActiveRecord::Base
# * +ActiveRecord+
def self.get_active_conferences_for_dashboard
result = Conference.where('start_date > ?', Time.now).
select('id, short_title, color, start_date')
select('id, short_title, color, start_date')
if result.length == 0
result = Conference.
select('id, short_title, color, start_date').limit(2).
order(start_date: :desc)
select('id, short_title, color, start_date').limit(2).
order(start_date: :desc)
end
result
end
@ -570,9 +570,9 @@ class Conference < ActiveRecord::Base
# * +False+ -> Either conference is not updated or one or more parameter is not set
def notify_on_dates_changed?
(self.start_date_changed? || self.end_date_changed?) &&
self.email_settings.send_on_updated_conference_dates &&
!self.email_settings.updated_conference_dates_subject.blank? &&
self.email_settings.updated_conference_dates_template
self.email_settings.send_on_updated_conference_dates &&
!self.email_settings.updated_conference_dates_subject.blank? &&
self.email_settings.updated_conference_dates_template
end
##
@ -583,10 +583,10 @@ class Conference < ActiveRecord::Base
# * +False+ -> Either registration date is not updated or one or more parameter is not set
def notify_on_registration_dates_changed?
registration_period &&
(registration_period.start_date_changed? || registration_period.end_date_changed?) &&
email_settings.send_on_updated_conference_registration_dates &&
!email_settings.updated_conference_registration_dates_subject.blank? &&
email_settings.updated_conference_registration_dates_template
(registration_period.start_date_changed? || registration_period.end_date_changed?) &&
email_settings.send_on_updated_conference_registration_dates &&
!email_settings.updated_conference_registration_dates_subject.blank? &&
email_settings.updated_conference_registration_dates_template
end
private

View file

@ -74,7 +74,7 @@ class Datatable
def sort_order
colnum = 0
sort_by = []
while true
loop do
break if !sorted?(colnum)
sort_by << "#{sort_column(colnum)} #{sort_direction(colnum)}"
colnum += 1

View file

@ -20,12 +20,12 @@ class EmailSettings < ActiveRecord::Base
'conference_start_date' => conference.start_date,
'conference_end_date' => conference.end_date,
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registrations_url(
conference.short_title, host: CONFIG['url_for_emails']),
conference.short_title, host: CONFIG['url_for_emails']),
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
conference.short_title, host: CONFIG['url_for_emails']),
conference.short_title, host: CONFIG['url_for_emails']),
'schedule_link' => Rails.application.routes.url_helpers.schedule_conference_url(
conference.short_title, host: CONFIG['url_for_emails'])
conference.short_title, host: CONFIG['url_for_emails'])
}
if conference.call_for_paper
@ -52,7 +52,7 @@ class EmailSettings < ActiveRecord::Base
if event
h['eventtitle'] = event.title
h['proposalslink'] = Rails.application.routes.url_helpers.conference_proposal_index_url(
conference.short_title, host: CONFIG['url_for_emails'])
conference.short_title, host: CONFIG['url_for_emails'])
end
h
end

View file

@ -112,8 +112,8 @@ class Event < ActiveRecord::Base
def process_confirmation
if conference.email_settings.send_on_confirmed_without_registration? &&
conference.email_settings.confirmed_email_template &&
conference.email_settings.confirmed_without_registration_subject
conference.email_settings.confirmed_email_template &&
conference.email_settings.confirmed_without_registration_subject
if conference.registrations.where(user_id: submitter.id).first.nil?
Mailbot.delay.confirm_reminder_mail(self)
end
@ -122,9 +122,9 @@ class Event < ActiveRecord::Base
def process_acceptance(options)
if conference.email_settings.send_on_accepted &&
conference.email_settings.accepted_email_template &&
conference.email_settings.accepted_subject &&
!options[:send_mail].blank?
conference.email_settings.accepted_email_template &&
conference.email_settings.accepted_subject &&
!options[:send_mail].blank?
Rails.logger.debug 'Sending event acceptance mail'
Mailbot.delay.acceptance_mail(self)
end
@ -132,9 +132,9 @@ class Event < ActiveRecord::Base
def process_rejection(options)
if conference.email_settings.send_on_rejected &&
conference.email_settings.rejected_email_template &&
conference.email_settings.rejected_subject &&
!options[:send_mail].blank?
conference.email_settings.rejected_email_template &&
conference.email_settings.rejected_subject &&
!options[:send_mail].blank?
Rails.logger.debug 'Sending rejected mail'
Mailbot.delay.rejection_mail(self)
end
@ -244,7 +244,7 @@ class Event < ActiveRecord::Base
def before_end_of_conference
errors.
add(:created_at, "can't be after the conference end date!") if conference.end_date &&
(Date.today > conference.end_date)
add(:created_at, "can't be after the conference end date!") if conference.end_date &&
(Date.today > conference.end_date)
end
end

View file

@ -58,7 +58,7 @@ class Target < ActiveRecord::Base
numerator = conference.current_program_minutes
end
progress = (numerator / target_count.to_f * 100).round(0).to_s
progress = (numerator / target_count.to_f * 100).round(0).to_s
result = {
'target_name' => to_s,
'campaign_name' => campaign.name,

View file

@ -38,7 +38,7 @@ class Ticket < ActiveRecord::Base
tickets.each do |ticket|
price = ticket.total_price(user)
if result
result += price unless price.zero?
result += price unless price.zero?
else
result = price
end

View file

@ -134,7 +134,7 @@ class User < ActiveRecord::Base
result = {}
Role::ACTIONABLES.each do |role|
resources = self.roles.where(name: role.parameterize.underscore).map{ |myrole| Conference.find(myrole.resource_id).short_title }.join ', '
result[role.parameterize.underscore] = "(#{ resources })" unless resources.blank?
result[role.parameterize.underscore] = "(#{resources})" unless resources.blank?
end
result
end

View file

@ -33,10 +33,10 @@ class Venue < ActiveRecord::Base
def venue_notify?(conference)
(self.name_changed? || self.street_changed?) &&
(!self.name.blank? && !self.street.blank?) &&
(conference.email_settings.send_on_venue_update &&
!conference.email_settings.venue_update_subject.blank? &&
conference.email_settings.venue_update_template)
(!self.name.blank? && !self.street.blank?) &&
(conference.email_settings.send_on_venue_update &&
!conference.email_settings.venue_update_subject.blank? &&
conference.email_settings.venue_update_template)
end
# TODO: create a module to be mixed into model to perform same operation