Rubocop autocorrections

This commit is contained in:
James Mason 2018-11-13 18:01:49 -08:00
parent 299738f58d
commit 43bef689fc
85 changed files with 622 additions and 578 deletions

View file

@ -57,6 +57,7 @@ module Admin
def sponsorship_level_required
return unless @conference.sponsorship_levels.empty?
redirect_to admin_conference_sponsorship_levels_path(conference_id: @conference.short_title),
alert: 'You need to create atleast one sponsorship level to add a sponsor'
end

View file

@ -14,6 +14,7 @@ module Admin
@conferences_with_role.uniq!
return if @conference.blank?
@versions = PaperTrail::Version.where(conference_id: @conference.id).accessible_by(current_ability)
end

View file

@ -12,6 +12,7 @@ class ApplicationController < ActionController::Base
def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
return unless request.get?
if (request.path != '/accounts/sign_in' &&
request.path != '/accounts/sign_up' &&
request.path != '/accounts/password/new' &&

View file

@ -15,6 +15,7 @@ class PaymentsController < ApplicationController
if @total_amount_to_pay.zero?
raise CanCan::AccessDenied.new('Nothing to pay for!', :new, Payment)
end
@unpaid_ticket_purchases = current_user.ticket_purchases.unpaid.by_conference(@conference)
end

View file

@ -99,6 +99,7 @@ module ApplicationHelper
def concurrent_events(event)
return nil unless event.scheduled? && event.program.selected_event_schedules
event_schedule = event.program.selected_event_schedules.find { |es| es.event == event }
other_event_schedules = event.program.selected_event_schedules.reject { |other_event_schedule| other_event_schedule == event_schedule }
concurrent_events = []
@ -106,6 +107,7 @@ module ApplicationHelper
event_time_range = (event_schedule.start_time.strftime '%Y-%m-%d %H:%M')...(event_schedule.end_time.strftime '%Y-%m-%d %H:%M')
other_event_schedules.each do |other_event_schedule|
next unless other_event_schedule.event.confirmed?
other_event_time_range = (other_event_schedule.start_time.strftime '%Y-%m-%d %H:%M')...(other_event_schedule.end_time.strftime '%Y-%m-%d %H:%M')
if (event_time_range.to_a & other_event_time_range.to_a).present?
concurrent_events << other_event_schedule.event

View file

@ -20,6 +20,7 @@ module DateTimeHelper
# * +String+ -> formated datetime object
def format_datetime(obj)
return unless obj
obj.strftime('%Y-%m-%d %H:%M')
end

View file

@ -9,6 +9,7 @@ module EventsHelper
# * +String+ -> number of registrations / max allowed registrations
def registered_text(event)
return "Registered: #{event.registrations.count}/#{event.max_attendees}" if event.max_attendees
"Registered: #{event.registrations.count}"
end

View file

@ -205,6 +205,7 @@ module FormatHelper
def quantity_left_of(resource)
return '-/-' if resource.quantity.blank?
"#{resource.quantity - resource.used}/#{resource.quantity}"
end
end

View file

@ -13,6 +13,7 @@ module VersionsHelper
org = Organization.find_by(id: organization_id)
return current_or_last_object_state('Organization', organization_id).try(:name) unless org
org.name.to_s
end
@ -47,6 +48,7 @@ module VersionsHelper
# Otherwise Returns object state just before deletion
def current_or_last_object_state(model_name, id)
return nil unless id.present? && model_name.present?
begin
object = model_name.constantize.find_by(id: id)
rescue NameError

View file

@ -670,6 +670,7 @@ class Conference < ApplicationRecord
return false unless email_settings.send_on_conference_dates_updated
# do not notify unless one of the dates changed
return false unless start_date_changed? || end_date_changed?
# do not notify unless the mail content is set up
(email_settings.conference_dates_updated_subject.present? && email_settings.conference_dates_updated_body.present?)
end
@ -686,6 +687,7 @@ class Conference < ApplicationRecord
return false unless registration_period
# do not notify unless one of the dates changed
return false unless registration_period.start_date_changed? || registration_period.end_date_changed?
# do not notify unless the mail content is set up
(email_settings.conference_registration_dates_updated_subject.present? && email_settings.conference_registration_dates_updated_body.present?)
end

View file

@ -12,6 +12,7 @@ class Contact < ApplicationRecord
def has_social_media?
return true if facebook.present? || twitter.present? || googleplus.present? || instagram.present? || mastodon.present? || email.present?
false
end
end

View file

@ -94,6 +94,7 @@ class Event < ApplicationRecord
def registration_possible?
return false unless require_registration && state == 'confirmed'
return true if max_attendees.nil?
registrations.count < max_attendees
end
@ -278,6 +279,7 @@ class Event < ApplicationRecord
def ended?
event_schedule = event_schedules.find_by(schedule_id: selected_schedule_id)
return false unless event_schedule
event_schedule.end_time < Time.current
end
@ -291,12 +293,14 @@ class Event < ApplicationRecord
# Do not allow, for the event, more attendees than the size of the room
def max_attendees_no_more_than_room_size
return unless room && max_attendees_changed?
errors.add(:max_attendees, "cannot be more than the room's capacity (#{room.size})") if max_attendees && (max_attendees > room.size)
end
def abstract_limit
# If we don't have an event type, there is no need to count anything
return unless event_type && abstract
len = abstract.split.size
max_words = event_type.maximum_abstract_length
min_words = event_type.minimum_abstract_length
@ -335,6 +339,7 @@ class Event < ApplicationRecord
#
def valid_track
return unless track&.program && program
errors.add(:track, 'is invalid') unless track.confirmed? && track.program == program
end

View file

@ -56,6 +56,7 @@ class EventSchedule < ApplicationRecord
def replacement?(event_schedule_source = nil)
return false unless event.state == 'confirmed'
return replaced_event_schedules.exists? unless event_schedule_source
event_schedule_source.any? { |event_schedule| intersects_with?(event_schedule) }
end
@ -82,11 +83,13 @@ class EventSchedule < ApplicationRecord
def start_after_end_hour
return unless event && start_time && event.program && event.program.conference && event.program.conference.end_hour
errors.add(:start_time, "can't be after the conference end hour (#{event.program.conference.end_hour})") if start_time.hour >= event.program.conference.end_hour
end
def start_before_start_hour
return unless event && start_time && event.program && event.program.conference && event.program.conference.start_hour
errors.add(:start_time, "can't be before the conference start hour (#{event.program.conference.start_hour})") if start_time.hour < event.program.conference.start_hour
end
@ -99,6 +102,7 @@ class EventSchedule < ApplicationRecord
#
def same_room_as_track
return unless event.try(:track).try(:room)
errors.add(:room, "must be the same as the track's room (#{event.track.room.name})") unless event.track.room == room
end
@ -122,6 +126,7 @@ class EventSchedule < ApplicationRecord
#
def valid_schedule
return unless event.try(:track).try(:self_organized?) && schedule
errors.add(:schedule, "must be one of #{event.track.name} track's schedules") unless event.track.schedules.include?(schedule)
end
end

View file

@ -82,6 +82,7 @@ class Program < ApplicationRecord
event_schedules = selected_schedule.event_schedules.includes(*includes).order(start_time: :asc) if selected_schedule
tracks.self_organized.confirmed.includes(selected_schedule: { event_schedules: includes }).order(start_date: :asc).each do |track|
next unless track.selected_schedule
event_schedules += track.selected_schedule.event_schedules
end
event_schedules.sort_by(&:start_time)
@ -157,6 +158,7 @@ class Program < ApplicationRecord
return false unless conference.email_settings.send_on_program_schedule_public
# do not notify if the schedule is not public
return false unless schedule_public
# do not notify unless the mail content is set up
(!conference.email_settings.program_schedule_public_subject.blank? && !conference.email_settings.program_schedule_public_body.blank?)
end
@ -173,6 +175,7 @@ class Program < ApplicationRecord
# * +False+ -> If there is not any event for the given date
def any_event_for_this_date?(date)
return false unless selected_schedule.present?
parsed_date = DateTime.parse("#{date} 00:00").utc
range = parsed_date..(parsed_date + 1.day)
selected_schedule.event_schedules.any? { |es| range.cover?(es.start_time) }
@ -185,6 +188,7 @@ class Program < ApplicationRecord
# * +ActiveRecord+ -> The program's cfp with cfp_type == 'events'
def cfp
return nil if cfps.for_events.blank?
cfps.for_events
end
@ -231,6 +235,7 @@ class Program < ApplicationRecord
#
def check_languages_format
return unless languages.present?
# All white spaces are removed to allow languages to be separated by ',' and ', '. The languages string without spaces is saved
self.languages = languages.delete(' ').downcase
errors.add(:languages, 'must be two letters separated by commas') && return unless

View file

@ -19,6 +19,7 @@ class Survey < ActiveRecord::Base
# * +false+ -> If the survey is closed
def active?
return true unless start_date || end_date
# Find timezone of conference (survyeable is Conference or Event)
timezone = surveyable.is_a?(Conference) ? surveyable.timezone : surveyable.conference.timezone
now = Time.current.in_time_zone(timezone)

View file

@ -66,6 +66,7 @@ class Ticket < ApplicationRecord
def tickets_turnover_total(id)
ticket = Ticket.find(id)
return Money.new(0, 'USD') unless ticket
sum = ticket.ticket_purchases.paid.total
Money.new(sum, ticket.price_currency)
end
@ -79,6 +80,7 @@ class Ticket < ApplicationRecord
def tickets_of_conference_have_same_currency
tickets = Ticket.where(conference_id: conference_id)
return if tickets.count.zero? || (tickets.count == 1 && self == tickets.first)
unless tickets.all?{|t| t.price_currency == price_currency }
errors.add(:price_currency, 'is different from the existing tickets of this conference.')
end

View file

@ -92,6 +92,7 @@ class Track < ApplicationRecord
# * +false+ -> if the track doesn't have a submitter
def self_organized?
return true if submitter
false
end
@ -200,6 +201,7 @@ class Track < ApplicationRecord
#
def dates_within_conference_dates
return unless start_date && end_date && program.try(:conference).try(:start_date) && program.try(:conference).try(:end_date)
errors.add(:start_date, "can't be outside of the conference's dates (#{program.conference.start_date}-#{program.conference.end_date})") unless (program.conference.start_date..program.conference.end_date).cover?(start_date)
errors.add(:end_date, "can't be outside of the conference's dates (#{program.conference.start_date}-#{program.conference.end_date})") unless (program.conference.start_date..program.conference.end_date).cover?(end_date)
end
@ -209,6 +211,7 @@ class Track < ApplicationRecord
#
def start_date_before_end_date
return unless start_date && end_date
errors.add(:start_date, 'can\'t be after the end date') if start_date > end_date
end
@ -217,6 +220,7 @@ class Track < ApplicationRecord
#
def valid_room
return unless room.try(:venue).try(:conference) && program.try(:conference)
errors.add(:room, "must be a room of #{program.conference.venue.name}") unless room.venue.conference == program.conference
end
@ -225,8 +229,10 @@ class Track < ApplicationRecord
#
def overlapping
return unless start_date && end_date && room && program.try(:tracks)
(program.tracks.accepted + program.tracks.confirmed - [self]).each do |existing_track|
next unless existing_track.room == room && existing_track.start_date && existing_track.end_date
if start_date >= existing_track.start_date && start_date <= existing_track.end_date ||
end_date >= existing_track.start_date && end_date <= existing_track.end_date ||
start_date <= existing_track.start_date && end_date >= existing_track.end_date

View file

@ -103,6 +103,7 @@ class User < ApplicationRecord
event_registration = event.events_registrations.find_by(registration: registrations)
return false unless event_registration.present?
event_registration.attended
end

View file

@ -38,6 +38,7 @@ class Venue < ApplicationRecord
return false unless conference.try(:email_settings).try(:send_on_venue_updated)
# do not notify unless the address changed
return false unless name_changed? || street_changed? || city_changed? || country_changed?
# do not notify unless the mail content is set up
(!conference.email_settings.venue_updated_subject.blank? && !conference.email_settings.venue_updated_body.blank?)
end

View file

@ -13,6 +13,7 @@ class MigrateDataPersonToUser < ActiveRecord::Migration
TempPerson.all.each do |p|
user = TempUser.find_by(id: p.user_id)
next unless user
if p.public_name.empty?
user.name = p.email
else

View file

@ -4,9 +4,11 @@
FactoryBot.define do
factory :splashpage do
public { false }
factory :full_splashpage do
public { true }
include_tracks { true }

View file

@ -6,6 +6,7 @@ module Flash
if results.empty?
return 'none'
end
if results.count > 1
texts = results.map { |r| r.text }
fail "One flash expected, but we had #{texts.inspect}"