Autocorrect new rubocop offenses

This commit is contained in:
Henne Vogelsang 2025-08-12 16:44:20 +02:00
parent deda3d4273
commit 988b3bf689
No known key found for this signature in database
GPG key ID: 97DDB66BDAF8D4D6
24 changed files with 48 additions and 41 deletions

View file

@ -8,7 +8,7 @@ module Admin
def index def index
# Redirect to new form if there is no conference # Redirect to new form if there is no conference
if Conference.count == 0 if Conference.none?
redirect_to new_admin_conference_path redirect_to new_admin_conference_path
return return
end end

View file

@ -69,7 +69,7 @@ module Admin
end end
# The conference must have at least 1 organizer # The conference must have at least 1 organizer
if @role.name == 'organizer' && state == 'false' && @role.users.count == 1 if @role.name == 'organizer' && state == 'false' && @role.users.one?
redirect_to admin_conference_role_path(@conference.short_title, @role.name), redirect_to admin_conference_role_path(@conference.short_title, @role.name),
error: 'The conference must have at least 1 organizer!' error: 'The conference must have at least 1 organizer!'
return return

View file

@ -3,6 +3,7 @@
module Admin module Admin
class VolunteersController < Admin::BaseController class VolunteersController < Admin::BaseController
include VolunteersHelper include VolunteersHelper
load_and_authorize_resource :conference, find_by: :short_title load_and_authorize_resource :conference, find_by: :short_title
def index def index

View file

@ -3,6 +3,7 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
before_action :set_paper_trail_whodunnit before_action :set_paper_trail_whodunnit
include ApplicationHelper include ApplicationHelper
add_flash_types :error add_flash_types :error
protect_from_forgery with: :exception, prepend: true protect_from_forgery with: :exception, prepend: true
before_action :store_location before_action :store_location

View file

@ -50,14 +50,14 @@ class ConferencesController < ApplicationController
).order('tracks.name') ).order('tracks.name')
end end
if splashpage.include_booths if splashpage.include_booths
@booths = @conference.confirmed_booths.order('title') @booths = @conference.confirmed_booths.order(:title)
end end
end end
if splashpage.include_registrations || splashpage.include_tickets if splashpage.include_registrations || splashpage.include_tickets
@tickets = @conference.tickets.order('price_cents') @tickets = @conference.tickets.order(:price_cents)
end end
if splashpage.include_lodgings if splashpage.include_lodgings
@lodgings = @conference.lodgings.order('name') @lodgings = @conference.lodgings.order(:name)
end end
if splashpage.include_sponsors if splashpage.include_sponsors
@sponsorship_levels = @conference.sponsorship_levels.eager_load( @sponsorship_levels = @conference.sponsorship_levels.eager_load(

View file

@ -39,7 +39,7 @@ module EventsHelper
end end
def canceled_replacement_event_label(event, event_schedule, *label_classes) def canceled_replacement_event_label(event, event_schedule, *label_classes)
if event.state == 'canceled' || event.state == 'withdrawn' if ['canceled', 'withdrawn'].include?(event.state)
content_tag :span, 'CANCELED', class: (['label', 'label-danger'] + label_classes) content_tag :span, 'CANCELED', class: (['label', 'label-danger'] + label_classes)
elsif event_schedule.present? && event_schedule.replacement?(@withdrawn_event_schedules) elsif event_schedule.present? && event_schedule.replacement?(@withdrawn_event_schedules)
content_tag :span, 'REPLACEMENT', class: (['label', 'label-info'] + label_classes) content_tag :span, 'REPLACEMENT', class: (['label', 'label-info'] + label_classes)

View file

@ -141,7 +141,7 @@ class AdminAbility
# Abilities for Role (Conference resource) # Abilities for Role (Conference resource)
can [:index, :show], Role do |role| can [:index, :show], Role do |role|
role.resource_type == 'Conference' || role.resource_type == 'Track' ['Conference', 'Track'].include?(role.resource_type)
end end
can [:edit, :update, :toggle_user], Role do |role| can [:edit, :update, :toggle_user], Role do |role|
@ -180,7 +180,7 @@ class AdminAbility
# Abilities for Role (Conference resource) # Abilities for Role (Conference resource)
can [:index, :show], Role do |role| can [:index, :show], Role do |role|
role.resource_type == 'Conference' || role.resource_type == 'Track' ['Conference', 'Track'].include?(role.resource_type)
end end
# Can add or remove users from role, when user has that same role for the conference # Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP') # Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
@ -218,7 +218,7 @@ class AdminAbility
# Abilities for Role (Conference resource) # Abilities for Role (Conference resource)
can [:index, :show], Role do |role| can [:index, :show], Role do |role|
role.resource_type == 'Conference' || role.resource_type == 'Track' ['Conference', 'Track'].include?(role.resource_type)
end end
# Can add or remove users from role, when user has that same role for the conference # Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP') # Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
@ -242,7 +242,7 @@ class AdminAbility
# Abilities for Role (Conference resource) # Abilities for Role (Conference resource)
can [:index, :show], Role do |role| can [:index, :show], Role do |role|
role.resource_type == 'Conference' || role.resource_type == 'Track' ['Conference', 'Track'].include?(role.resource_type)
end end
# Can add or remove users from role, when user has that same role for the conference # Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP') # Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
@ -278,7 +278,7 @@ class AdminAbility
# Show Roles in the admin sidebar and allow authorization of the index action # Show Roles in the admin sidebar and allow authorization of the index action
can [:index, :show], Role do |role| can [:index, :show], Role do |role|
role.resource_type == 'Conference' || role.resource_type == 'Track' ['Conference', 'Track'].include?(role.resource_type)
end end
can :toggle_user, Role do |role| can :toggle_user, Role do |role|

View file

@ -2,6 +2,7 @@
class Booth < ApplicationRecord class Booth < ApplicationRecord
include ActiveRecord::Transitions include ActiveRecord::Transitions
has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id } has_paper_trail ignore: [:updated_at], meta: { conference_id: :conference_id }
belongs_to :conference belongs_to :conference

View file

@ -35,13 +35,13 @@ class Comment < ApplicationRecord
# Helper class method to lookup all comments assigned # Helper class method to lookup all comments assigned
# to all commentable types for a given user. # to all commentable types for a given user.
scope :find_comments_by_user, lambda { |user| scope :find_comments_by_user, lambda { |user|
where(user_id: user.id).order('created_at DESC') where(user_id: user.id).order(created_at: :desc)
} }
# Helper class method to look up all comments for # Helper class method to look up all comments for
# commentable class name and commentable id. # commentable class name and commentable id.
scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id| scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id|
where(commentable_type: commentable_str.to_s, commentable_id: commentable_id).order('created_at DESC') where(commentable_type: commentable_str.to_s, commentable_id: commentable_id).order(created_at: :desc)
} }
scope :find_since_last_login, lambda { |user| scope :find_since_last_login, lambda { |user|

View file

@ -2,13 +2,14 @@
class Conference < ApplicationRecord class Conference < ApplicationRecord
include RevisionCount include RevisionCount
require 'uri' require 'uri'
serialize :events_per_week, Hash serialize :events_per_week, Hash
# Needed to call 'Conference.with_role' in /models/ability.rb # Needed to call 'Conference.with_role' in /models/ability.rb
# Dependent destroy will fail as roles#destroy will be cancelled,hence delete_all # Dependent destroy will fail as roles#destroy will be cancelled,hence delete_all
resourcify :roles, dependent: :delete_all resourcify :roles, dependent: :delete_all
default_scope { order('start_date DESC') } default_scope { order(start_date: :desc) }
scope :upcoming, (-> { where(end_date: Date.current..) }) scope :upcoming, (-> { where(end_date: Date.current..) })
scope :past, (-> { where(end_date: ...Date.current) }) scope :past, (-> { where(end_date: ...Date.current) })
@ -39,7 +40,7 @@ class Conference < ApplicationRecord
has_many :participants, through: :registrations, source: :user has_many :participants, through: :registrations, source: :user
has_many :vdays, dependent: :destroy has_many :vdays, dependent: :destroy
has_many :vpositions, dependent: :destroy has_many :vpositions, dependent: :destroy
has_many :sponsorship_levels, -> { order('position ASC') }, dependent: :destroy has_many :sponsorship_levels, -> { order(:position) }, dependent: :destroy
has_many :sponsors, dependent: :destroy has_many :sponsors, dependent: :destroy
has_many :commercials, as: :commercialable, dependent: :destroy has_many :commercials, as: :commercialable, dependent: :destroy
has_many :subscriptions, dependent: :destroy has_many :subscriptions, dependent: :destroy
@ -107,7 +108,7 @@ class Conference < ApplicationRecord
# * +false+ -> If the user is registered # * +false+ -> If the user is registered
# * +true+ - If the user isn't registered # * +true+ - If the user isn't registered
def user_registered? user def user_registered? user
user.present? && registrations.where(user_id: user.id).count > 0 user.present? && registrations.where(user_id: user.id).any?
end end
## ##
@ -350,7 +351,7 @@ class Conference < ApplicationRecord
# * +hash+ -> user: submissions # * +hash+ -> user: submissions
def self.get_top_submitter(limit = 5) def self.get_top_submitter(limit = 5)
submitter = EventUser.select(:user_id).where('event_role = ?', 'submitter').limit(limit).group(:user_id) submitter = EventUser.select(:user_id).where('event_role = ?', 'submitter').limit(limit).group(:user_id)
counter = submitter.order('count_all desc').count(:all) counter = submitter.order(count_all: :desc).count(:all)
calculate_user_submission_hash(submitter, counter) calculate_user_submission_hash(submitter, counter)
end end
@ -363,7 +364,7 @@ class Conference < ApplicationRecord
submitter = EventUser.joins(:event).select(:user_id) submitter = EventUser.joins(:event).select(:user_id)
.where('event_role = ? and program_id = ?', 'submitter', Conference.find(id).program.id) .where('event_role = ? and program_id = ?', 'submitter', Conference.find(id).program.id)
.limit(limit).group(:user_id) .limit(limit).group(:user_id)
counter = submitter.order('count_all desc').count(:all) counter = submitter.order(count_all: :desc).count(:all)
Conference.calculate_user_submission_hash(submitter, counter) Conference.calculate_user_submission_hash(submitter, counter)
end end
@ -921,7 +922,7 @@ class Conference < ApplicationRecord
# * +True+ -> One difficulty level or more # * +True+ -> One difficulty level or more
# * +False+ -> No diffculty level # * +False+ -> No diffculty level
def difficulty_levels_set? def difficulty_levels_set?
program.difficulty_levels.count > 0 program.difficulty_levels.any?
end end
## ##
@ -931,7 +932,7 @@ class Conference < ApplicationRecord
# * +True+ -> One difficulty level or more # * +True+ -> One difficulty level or more
# * +False+ -> No diffculty level # * +False+ -> No diffculty level
def event_types_set? def event_types_set?
program.event_types.count > 0 program.event_types.any?
end end
## ##
@ -941,7 +942,7 @@ class Conference < ApplicationRecord
# * +True+ -> One track or more # * +True+ -> One track or more
# * +False+ -> No track # * +False+ -> No track
def tracks_set? def tracks_set?
program.tracks.count > 0 program.tracks.any?
end end
## ##
@ -951,7 +952,7 @@ class Conference < ApplicationRecord
# * +True+ -> One room or more # * +True+ -> One room or more
# * +False+ -> No room # * +False+ -> No room
def rooms_set? def rooms_set?
venue.present? && venue.rooms.count > 0 venue.present? && venue.rooms.any?
end end
# Checks if the conference has a venue object. # Checks if the conference has a venue object.

View file

@ -4,6 +4,7 @@ class Event < ApplicationRecord
include ActionView::Helpers::NumberHelper # for number_with_precision include ActionView::Helpers::NumberHelper # for number_with_precision
include ActiveRecord::Transitions include ActiveRecord::Transitions
include RevisionCount include RevisionCount
has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id } has_paper_trail on: [:create, :update], ignore: [:updated_at, :guid, :week], meta: { conference_id: :conference_id }
acts_as_commentable acts_as_commentable

View file

@ -82,13 +82,13 @@ class EventSchedule < ApplicationRecord
end end
def start_after_end_hour def start_after_end_hour
return unless event && start_time && event.program&.conference && event.program.conference.end_hour return unless event && start_time && 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 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 end
def start_before_start_hour def start_before_start_hour
return unless event && start_time && event.program&.conference && event.program.conference.start_hour return unless event && start_time && 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 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 end

View file

@ -2,6 +2,7 @@
class Room < ApplicationRecord class Room < ApplicationRecord
include RevisionCount include RevisionCount
belongs_to :venue belongs_to :venue
has_many :event_schedules, dependent: :destroy has_many :event_schedules, dependent: :destroy
has_many :tracks has_many :tracks

View file

@ -25,7 +25,7 @@ class Survey < ActiveRecord::Base
now = Time.current.in_time_zone(timezone) now = Time.current.in_time_zone(timezone)
if start_date && end_date if start_date && end_date
now >= start_date && now <= end_date now.between?(start_date, end_date)
elsif start_date && !end_date elsif start_date && !end_date
now >= start_date now >= start_date
elsif !start_date && end_date elsif !start_date && end_date

View file

@ -81,7 +81,7 @@ class Ticket < ApplicationRecord
def tickets_of_conference_have_same_currency def tickets_of_conference_have_same_currency
tickets = Ticket.where(conference_id: conference_id) tickets = Ticket.where(conference_id: conference_id)
return if tickets.count.zero? || (tickets.count == 1 && self == tickets.first) return if tickets.none? || (tickets.one? && self == tickets.first)
unless tickets.all?{|t| t.price_currency == price_currency } unless tickets.all?{|t| t.price_currency == price_currency }
errors.add(:price_currency, 'is different from the existing tickets of this conference.') errors.add(:price_currency, 'is different from the existing tickets of this conference.')

View file

@ -97,8 +97,6 @@ class TicketPurchase < ApplicationRecord
end end
end end
private
def set_week def set_week
self.week = created_at.strftime('%W') self.week = created_at.strftime('%W')
save! save!

View file

@ -233,8 +233,8 @@ class Track < ApplicationRecord
(program.tracks.accepted + program.tracks.confirmed - [self]).each do |existing_track| (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 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 || if start_date.between?(existing_track.start_date, existing_track.end_date) ||
end_date >= existing_track.start_date && end_date <= existing_track.end_date || end_date.between?(existing_track.start_date, existing_track.end_date) ||
start_date <= existing_track.start_date && end_date >= existing_track.end_date start_date <= existing_track.start_date && end_date >= existing_track.end_date
errors.add(:track, 'has overlapping dates with a confirmed or accepted track in the same room') errors.add(:track, 'has overlapping dates with a confirmed or accepted track in the same room')
break break

View file

@ -30,6 +30,7 @@ class User < ApplicationRecord
:avatar_content_type, :avatar_file_size, :avatar_updated_at, :updated_at, :confirmation_sent_at, :confirmation_token, :reset_password_token] :avatar_content_type, :avatar_file_size, :avatar_updated_at, :updated_at, :confirmation_sent_at, :confirmation_token, :reset_password_token]
include Gravtastic include Gravtastic
gravtastic size: 32 gravtastic size: 32
before_create :setup_role before_create :setup_role
@ -238,7 +239,7 @@ class User < ApplicationRecord
end end
def registered def registered
if registrations.count == 0 if registrations.none?
'None' 'None'
else else
registrations.map { |r| r.conference.title }.join ', ' registrations.map { |r| r.conference.title }.join ', '
@ -247,7 +248,7 @@ class User < ApplicationRecord
def attended def attended
registrations_attended = registrations.where(attended: true) registrations_attended = registrations.where(attended: true)
if registrations_attended.count == 0 if registrations_attended.none?
'None' 'None'
else else
registrations_attended.map { |r| r.conference.title }.join ', ' registrations_attended.map { |r| r.conference.title }.join ', '
@ -271,7 +272,7 @@ class User < ApplicationRecord
end end
def self.empty? def self.empty?
User.count == 1 && User.first.email == 'deleted@localhost.osem' User.one? && User.first.email == 'deleted@localhost.osem'
end end
private private

View file

@ -8,7 +8,7 @@ class MigrateRolesForCancancan < ActiveRecord::Migration
Role.all.each do |role| Role.all.each do |role|
role.users.each do |user| role.users.each do |user|
Conference.all.each do |conference| Conference.all.each do |conference|
if role.name == 'Admin' || role.name == 'Organizer' if ['Admin', 'Organizer'].include?(role.name)
user.add_role :organizer, conference user.add_role :organizer, conference
user.update_columns(is_admin: true) user.update_columns(is_admin: true)
else else

View file

@ -13,7 +13,7 @@ class MoveConferencesToOrganizations < ActiveRecord::Migration
add_reference :conferences, :organization, index: true add_reference :conferences, :organization, index: true
TempConference.reset_column_information TempConference.reset_column_information
if TempConference.count != 0 if TempConference.any?
organization = TempOrganization.create(name: 'organization', description: 'Default organization') organization = TempOrganization.create(name: 'organization', description: 'Default organization')
TempConference.all.each do |conference| TempConference.all.each do |conference|
conference.organization_id = organization.id conference.organization_id = organization.id

View file

@ -5,6 +5,7 @@ namespace :data do
task demo: :environment do task demo: :environment do
include FactoryBot::Syntax::Methods include FactoryBot::Syntax::Methods
conference = create(:full_conference, title: 'Open Source Event Manager Demo', short_title: 'osemdemo' ,description: "This is a [Open Source Event Manager](http://osem.io/) demo instance. You can log in as **admin** with the password **password123** or just you just [sign up](/accounts/sign_up) with your own user. We hope you enjoy checking out all the functionality, if you have questions don't hesitate to [contact us](http://osem.io/#contact)!\r\n\r\n## Data will be destroyed every thirty minutes or whenever someone updates the [OSEM source code on github](https://github.com/openSUSE/osem/commits/master).") conference = create(:full_conference, title: 'Open Source Event Manager Demo', short_title: 'osemdemo' ,description: "This is a [Open Source Event Manager](http://osem.io/) demo instance. You can log in as **admin** with the password **password123** or just you just [sign up](/accounts/sign_up) with your own user. We hope you enjoy checking out all the functionality, if you have questions don't hesitate to [contact us](http://osem.io/#contact)!\r\n\r\n## Data will be destroyed every thirty minutes or whenever someone updates the [OSEM source code on github](https://github.com/openSUSE/osem/commits/master).")
conference.contact.update(email: 'osemdemo@osem.io', sponsor_email: 'osemdemo@osem.io') conference.contact.update(email: 'osemdemo@osem.io', sponsor_email: 'osemdemo@osem.io')
create(:admin, email: 'admin@osem.io', username: 'admin', password: 'password123', password_confirmation: 'password123') create(:admin, email: 'admin@osem.io', username: 'admin', password: 'password123', password_confirmation: 'password123')

View file

@ -7,13 +7,13 @@ namespace :events_registrations do
duplicates = EventsRegistration.all.map { |er| er.id if er.valid? == false}.compact duplicates = EventsRegistration.all.map { |er| er.id if er.valid? == false}.compact
puts "Duplicates found: #{duplicates.count}" puts "Duplicates found: #{duplicates.count}"
if duplicates.count > 0 if duplicates.any?
puts "With IDs: #{duplicates}" puts "With IDs: #{duplicates}"
end end
EventsRegistration.all.each do |er| EventsRegistration.all.each do |er|
records = EventsRegistration.where(registration_id: er.registration_id, event_id: er.event_id) records = EventsRegistration.where(registration_id: er.registration_id, event_id: er.event_id)
if records.count > 1 if records.many?
# Iterate through duplicates (excluding 1st record) # Iterate through duplicates (excluding 1st record)
(1..(records.count - 1)).each do |i| (1..(records.count - 1)).each do |i|
puts "Deleting EventsRegistration record with ID #{records[i].id} ..." puts "Deleting EventsRegistration record with ID #{records[i].id} ..."

View file

@ -32,7 +32,7 @@ describe Mailbot do
end end
describe '.registration_mail' do describe '.registration_mail' do
include_examples 'mailer actions' do it_behaves_like 'mailer actions' do
let(:mail) { Mailbot.registration_mail(conference, user).deliver_now } let(:mail) { Mailbot.registration_mail(conference, user).deliver_now }
end end
end end
@ -44,7 +44,7 @@ describe Mailbot do
accepted_body: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit') accepted_body: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit')
end end
include_examples 'mailer actions' do it_behaves_like 'mailer actions' do
let(:mail) { Mailbot.acceptance_mail(event).deliver_now } let(:mail) { Mailbot.acceptance_mail(event).deliver_now }
end end
end end
@ -56,7 +56,7 @@ describe Mailbot do
rejected_body: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit') rejected_body: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit')
end end
include_examples 'mailer actions' do it_behaves_like 'mailer actions' do
let(:mail) { Mailbot.rejection_mail(event).deliver_now } let(:mail) { Mailbot.rejection_mail(event).deliver_now }
end end
end end
@ -68,7 +68,7 @@ describe Mailbot do
confirmed_without_registration_body: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit') confirmed_without_registration_body: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit')
end end
include_examples 'mailer actions' do it_behaves_like 'mailer actions' do
let(:mail) { Mailbot.confirm_reminder_mail(event).deliver_now } let(:mail) { Mailbot.confirm_reminder_mail(event).deliver_now }
end end
end end

View file

@ -2,6 +2,7 @@
module LoginMacros module LoginMacros
include Warden::Test::Helpers include Warden::Test::Helpers
Warden.test_mode! Warden.test_mode!
def sign_in(user) def sign_in(user)