Rebuild rubocop TODOs after auto-correcting

This commit is contained in:
James Mason 2018-04-04 10:18:51 -07:00
parent 31c50255e9
commit 84dbb52d11
No known key found for this signature in database
GPG key ID: 1B3951886C449023
580 changed files with 3689 additions and 3133 deletions

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :data do
desc 'Catitalize tracks, event types and difficult levels colors'

View file

@ -1,8 +1,8 @@
# frozen_string_literal: true
namespace :db do
desc 'setup DATABASE_URL from CLEARDB_DATABASE_URL in config/database.yml'
task 'cleardb_env' do
unless ENV['CLEARDB_DATABASE_URL'].nil?
FileUtils.copy_file('config/database.yml.heroku', 'config/database.yml')
end
FileUtils.copy_file('config/database.yml.heroku', 'config/database.yml') unless ENV['CLEARDB_DATABASE_URL'].nil?
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :data do
desc 'Nullify wrong foreign keys'
@ -20,7 +22,7 @@ namespace :data do
if collection.any?
puts "IDs: #{collection.map(&:id)}"
collection.each do |item|
item.send(attribute+'=', nil)
item.send(attribute + '=', nil)
item.save!
end
puts "Fixed #{attribute}!"

View file

@ -1,10 +1,12 @@
# frozen_string_literal: true
namespace :data do
desc 'Create demo data using our factories'
task demo: :environment do
include FactoryGirl::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.contact.update_attributes(email: 'osemdemo@osem.io', sponsor_email: 'osemdemo@osem.io')
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')
create(:admin, email: 'admin@osem.io', username: 'admin', password: 'password123', password_confirmation: 'password123')
end
end

View file

@ -1,9 +1,11 @@
# frozen_string_literal: true
namespace :data do
desc 'Create demo data for our local development'
task test: :environment do
include FactoryGirl::Syntax::Methods
def generate_program conference
def generate_program(conference)
program = conference.program
user1 = create(:user)
user2 = create(:user)
@ -12,7 +14,7 @@ namespace :data do
selected_schedule = create(:schedule, program: program)
demo_schedule = create(:schedule, program: program)
program.update_attributes!(selected_schedule: selected_schedule)
program.update!(selected_schedule: selected_schedule)
create(:event, program: program, title: 'Demo Event', abstract: 'This is a demo event instance whose state not defined.')
create(:event, program: program, title: 'Demo Rejected Event', state: 'rejected', abstract: 'This is demo event instance in a rejected state.')
@ -48,9 +50,9 @@ namespace :data do
# So that events can be created without any failure in validations.
conference = create(:full_conference, title: 'Jangouts Demo Conference', short_title: 'jangouts', start_date: 7.days.ago, end_date: 6.days.from_now, start_hour: 15, end_hour: 20, description: 'This is a full conference demo instance happened in the past. It contains open cfp, venue/rooms, submitted talks by multiple speakers, partly confirmed talks and multiple schedules.')
generate_program conference
conference.program.cfp.update_attributes!(start_date: 4.days.ago, end_date: 2.days.ago)
conference.update_attributes!(end_date: 1.day.ago)
conference.registration_period.update_attributes!(start_date: 9.days.ago, end_date: 8.days.ago)
conference.program.cfp.update!(start_date: 4.days.ago, end_date: 2.days.ago)
conference.update!(end_date: 1.day.ago)
conference.registration_period.update!(start_date: 9.days.ago, end_date: 8.days.ago)
# This is a conference that will happen in the future
# It only has a registration period and unscheduled events

View file

@ -1,11 +1,13 @@
# frozen_string_literal: true
require 'yaml'
task :dump_db do
yaml = YAML.load_file("config/database.yml")
conf = yaml["production"]
filename = "#{conf["database"]}-#{Time.now.strftime("%Y-%m-%d-%H:%M:%S:%L")}.sql"
if conf["adapter"] == 'mysql2'
system "mysqldump -u #{conf["username"]} --password=#{conf["password"]} -h #{conf["host"]} #{conf["database"]} > ~/#{filename}"
yaml = YAML.load_file('config/database.yml')
conf = yaml['production']
filename = "#{conf['database']}-#{Time.now.strftime('%Y-%m-%d-%H:%M:%S:%L')}.sql"
if conf['adapter'] == 'mysql2'
system "mysqldump -u #{conf['username']} --password=#{conf['password']} -h #{conf['host']} #{conf['database']} > ~/#{filename}"
else
puts "Error: This rake task only works for MYSQL"
puts 'Error: This rake task only works for MYSQL'
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :db do
desc 'Destroy event_attachments versions'
@ -5,4 +7,4 @@ namespace :db do
PaperTrail::Version.where(item_type: 'EventAttachment').try(:destroy_all)
puts 'Version records with event_attachment have been destroyed'
end
end
end

View file

@ -1,25 +1,24 @@
# frozen_string_literal: true
namespace :events_registrations do
desc "Deletes dupicate entries"
desc 'Deletes dupicate entries'
task deduplicate: :environment do
if ActiveRecord::Migrator.get_all_versions.include? 20160403214841
duplicates = EventsRegistration.all.map { |er| er.id if er.valid? == false}.compact
if ActiveRecord::Migrator.get_all_versions.include? 20_160_403_214_841
duplicates = EventsRegistration.all.map { |er| er.id if er.valid? == false }.compact
puts "Duplicates found: #{duplicates.count}"
if duplicates.count > 0
puts "With IDs: #{duplicates}"
end
puts "With IDs: #{duplicates}" if duplicates.count > 0
EventsRegistration.all.each do |er|
records = EventsRegistration.where(registration_id: er.registration_id, event_id: er.event_id)
if records.count > 1
# Iterate through duplicates (excluding 1st record)
(1..(records.count - 1)).each do |i|
puts "Deleting EventsRegistration record with ID #{records[i].id} ..."
if records[i].destroy
puts 'Succeeded!'
else
puts 'Faild!'
end
next unless records.count > 1
# Iterate through duplicates (excluding 1st record)
(1..(records.count - 1)).each do |i|
puts "Deleting EventsRegistration record with ID #{records[i].id} ..."
if records[i].destroy
puts 'Succeeded!'
else
puts 'Faild!'
end
end
end

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
namespace :factory_girl do
desc "Verify that all FactoryGirl factories are valid"
desc 'Verify that all FactoryGirl factories are valid'
task lint: :environment do
if Rails.env.test?
begin

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :data do
namespace :migrate do
desc 'Resize existing logo of sponsors after change in image manipulation specifications'

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :data do
namespace :migrate do
desc 'Create a dotenv file from config/config.yml'
@ -14,8 +16,8 @@ namespace :data do
config_yml = Rails.root.join('config', 'config.yml')
begin
CONFIG = YAML.load_file(config_yml)[Rails.env]
rescue
CONFIG = {}
rescue StandardError
CONFIG = {}.freeze
end
# Write the dotenv file
@ -23,7 +25,7 @@ namespace :data do
dot_env.puts "OSEM_NAME=\"#{CONFIG['name']}\""
dot_env.puts "OSEM_HOSTNAME=\"#{CONFIG['url_for_emails']}\""
dot_env.puts "OSEM_EMAIL_ADDRESS=\"#{CONFIG['sender_for_emails']}\""
dot_env.puts "OSEM_ICHAIN_ENABLED=\"#{CONFIG['authentication']['ichain']['enabled']}\"" if CONFIG.has_key?(:authentication)
dot_env.puts "OSEM_ICHAIN_ENABLED=\"#{CONFIG['authentication']['ichain']['enabled']}\"" if CONFIG.key?(:authentication)
dot_env.puts "OSEM_TRANSIFEX_APIKEY=\"#{CONFIG['transifex_live_api_key']}\""
dot_env.puts "OSEM_ERRBIT_HOST=\"#{CONFIG['errbit_host']}\""
dot_env.puts "OSEM_FACTORY_LINT=\"#{CONFIG['factory_girl_lint']}\""

View file

@ -1,12 +1,12 @@
# frozen_string_literal: true
namespace :data do
desc 'Update resources with nil quantity/used fields'
task normalize_resources: :environment do
Resource.where('used is ? or quantity is ?', nil, nil).each do |resource|
resource.used = 0 if resource.used.blank?
resource.quantity = resource.used if resource.quantity.blank?
unless resource.save
puts "Failed to update resource #{resource.name} (ID #{resource.id})"
end
puts "Failed to update resource #{resource.name} (ID #{resource.id})" unless resource.save
end
end
end

View file

@ -1,7 +1,8 @@
# frozen_string_literal: true
namespace :roles do
desc 'Adds back deleted roles to all conferences'
task add: :environment do
Organization.all.each do |org|
Role.where(name: 'organization_admin', resource: org).first_or_create(description: 'For the administrators of an organization and its conferences')
end
@ -16,4 +17,3 @@ namespace :roles do
puts 'All done!'
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :data do
desc 'Move the start_time and room attributes from Event to EventSchedule'
@ -7,16 +9,15 @@ namespace :data do
program.selected_schedule = schedule
program.save
program.events.each do |event|
unless event.start_time.nil? && event.room_id.nil?
# we can not use .room as this relation has been removed
EventSchedule.create(event: event,
schedule: schedule,
start_time: event.start_time,
room_id: event.room_id)
event.start_time = nil
event.room_id = nil
event.save
end
next if event.start_time.nil? && event.room_id.nil?
# we can not use .room as this relation has been removed
EventSchedule.create(event: event,
schedule: schedule,
start_time: event.start_time,
room_id: event.room_id)
event.start_time = nil
event.room_id = nil
event.save
end
end
puts 'The start_time and room attributes has been moved from Event to EventSchedule'

View file

@ -1,21 +1,20 @@
namespace :user do
desc "Makes is_admin attribute true for user based on the supplied email address."
task :admin, [:email] => :environment do |t, args|
# frozen_string_literal: true
namespace :user do
desc 'Makes is_admin attribute true for user based on the supplied email address.'
task :admin, [:email] => :environment do |_t, args|
# Check if an email address was supplied
fail 'You need to define the email address of the user you want to make an admin.' unless args.email
raise 'You need to define the email address of the user you want to make an admin.' unless args.email
user = User.find_by(email: args.email)
# Check if a user is found based on the supplied email address
fail "There is no user with email #{args.email}!" unless user
raise "There is no user with email #{args.email}!" unless user
if user.update_columns(is_admin: true)
puts "User with email #{args.email} is now an admin!"
end
puts "User with email #{args.email} is now an admin!" if user.update_columns(is_admin: true)
end
desc "Set email_public attrubute true for all users"
task :set_email_public => :environment do
desc 'Set email_public attrubute true for all users'
task set_email_public: :environment do
User.update_all email_public: true
end
end

View file

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :data do
desc 'Sets conference_id in all pre-existing PaperTrail::Version objects'
task set_conference_in_versions: :environment do
@ -5,7 +7,7 @@ namespace :data do
PaperTrail::Version.where(conference_id: nil, item_type: %w[Conference Event]).each do |version|
# All pre-existing versions are either of Conference or Event
if version.item_type == 'Conference'
version.update_attributes(conference_id: version.item_id)
version.update(conference_id: version.item_id)
elsif version.item_type == 'Event'
event = (version.item || version.reify || version.next.reify)
@ -24,7 +26,7 @@ namespace :data do
puts "Setting conference_id value failed for PaperTrail::Version object with ID=#{version.id}"
nil
end
version.update_attributes(conference_id: conference_id)
version.update(conference_id: conference_id)
end
end
puts 'All done!'