Skip to content

Commit

Permalink
Fix or disable the latest in Rails rubocop rules
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgrathwell committed Feb 16, 2017
1 parent d38fb0c commit 716fbe3
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 31 deletions.
10 changes: 10 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,29 @@ Rails/Date:
Rails/Delegate:
Enabled: false

Bundler/DuplicatedGem:
Enabled: false

Rails/Exit:
Exclude:
- lib/tasks/support/rspec_rerunner.rb

Rails/HasAndBelongsToMany:
Enabled: false

# TODO: remove in rails 5
Rails/HttpPositionalArguments:
Enabled: false

Rails/Output:
Enabled: false

Rails/ReadWriteAttribute:
Enabled: false

Rails/SkipsModelValidations:
Enabled: false

Rails/TimeZone:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events/attendee_names_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def index
private

def find_event
@event = Event.find_by_id(params[:event_id])
@event = Event.find_by(id: params[:event_id])
end

def attendee_csv_data(rsvps)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events/attendees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def update
private

def find_event
@event = Event.find_by_id(params[:event_id])
@event = Event.find_by(id: params[:event_id])
end

def attendee_csv_data(rsvps)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events/emails_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def email_params
end

def find_event
@event = Event.find_by_id(params[:event_id])
@event = Event.find_by(id: params[:event_id])
end

def present_form_data
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/events/organizer_tools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def diets

def rsvp_preview
authorize @event, :edit?
role = Role.find_by_id(params[:role_id])
role = Role.find_by(id: params[:role_id].to_i)
@rsvp = @event.rsvps.build(role: role)
@rsvp.setup_for_role(role)
@rsvp_preview_mode = true
Expand Down Expand Up @@ -75,6 +75,6 @@ def send_announcement_email
private

def find_event
@event = Event.find_by_id(params[:event_id])
@event = Event.find_by(id: params[:event_id])
end
end
2 changes: 1 addition & 1 deletion app/controllers/events/students_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
private

def find_event
@event = Event.find_by_id(params[:event_id])
@event = Event.find_by(id: params[:event_id])
end

def student_csv_data(rsvps)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/rsvps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def rsvp_params
end

def load_rsvp
@rsvp = Rsvp.find_by_id(params[:id])
@rsvp = Rsvp.find_by(id: params[:id])
unless @rsvp && ((@rsvp.user == current_user) || @rsvp.event.organizer?(current_user))
redirect_to events_path, notice: 'You are not signed up for this event'
end
Expand All @@ -149,7 +149,7 @@ def redirect_if_event_in_past
end

def assign_event
@event = Event.find_by_id(params[:event_id])
@event = Event.find_by(id: params[:event_id])
if @event.nil?
redirect_to events_path, notice: 'You are not signed up for this event'
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def arrange
private

def find_event
@event = Event.find_by_id(params[:event_id])
@event = Event.find_by(id: params[:event_id])
end

def section_params
Expand Down
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def organizers_with_legacy
end

def rsvp_for_user(user)
rsvps.find_by_user_id(user.id)
rsvps.find_by(user_id: user.id)
end

def no_rsvp?(user)
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
# Send to local mailserver for viewing mail with mailcatcher
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { address: "localhost", port: 1025 }
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
config.action_mailer.preview_path = Rails.root.join('spec', 'mailers', 'previews')

# Setup default url options for your specific environment.
config.action_mailer.default_url_options = { host: 'localhost:3000' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SetIdSequenceForNewCourses < ActiveRecord::Migration
def change
def up
if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
execute("ALTER SEQUENCE courses_id_seq START with 10000 RESTART;")
else
Expand Down
8 changes: 4 additions & 4 deletions db/seeds/seed_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def self.seed_event(options={})
title: 'Seeded Test Event',
student_rsvp_limit: 5,
time_zone: 'Pacific Time (US & Canada)',
course: Course.find_by_name('RAILS'),
course: Course.find_by(name: 'RAILS'),
location: location,
chapter: chapter,
current_state: :published,
Expand Down Expand Up @@ -182,14 +182,14 @@ def self.seed_event(options={})
recipient_rsvps: event.volunteer_rsvps
)

User.find_by_email('volunteer1@example.com').rsvps.last.create_survey!(
User.find_by(email: 'volunteer1@example.com').rsvps.last.create_survey!(
good_things: 'The textboxes! Boy, I love filling out textboxes!',
bad_things: 'Too many terminator robots allowed at the workshop',
other_comments: 'jolly good show, old bean',
recommendation_likelihood: 7
)

User.find_by_email('student1-1@example.com').rsvps.last.create_survey!(
User.find_by(email: 'student1-1@example.com').rsvps.last.create_survey!(
good_things: 'I liked the food and also the learning',
bad_things: "Volunteers could've tried to do a more interesting dance",
other_comments: 'pip pip, cheerio',
Expand Down Expand Up @@ -231,7 +231,7 @@ def self.seed_multiple_location_event(options={})
title: 'Seeded Multiple Location Event',
student_rsvp_limit: 15,
time_zone: 'Pacific Time (US & Canada)',
course: Course.find_by_name("RAILS"),
course: Course.find_by(name: "RAILS"),
location: location,
chapter: chapter,
current_state: :published,
Expand Down
12 changes: 10 additions & 2 deletions lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

Rake::Task["db:schema:dump"].clear

def db_dump_filename(args)
if args[:filename]
Rails.root.join(args[:filename])
else
Rails.root.join('db', 'PRODUCTION.dump')
end
end

db_namespace = namespace :db do
namespace :schema do
desc 'Create a db/schema.rb file that is portable against any DB supported by AR'
Expand Down Expand Up @@ -76,7 +84,7 @@ db_namespace = namespace :db do

desc "Dump current database to a file"
task :dump, [:filename] => [:environment] do |t, args|
filename = Rails.root.join(args[:filename] || 'db/PRODUCTION.dump')
filename = db_dump_filename(args)
cmd = nil
with_config do |app, host, db|
cmd = "pg_dump --host #{host} --no-owner --no-acl --format=c #{db} > #{filename}"
Expand All @@ -95,7 +103,7 @@ db_namespace = namespace :db do

desc "Restores the database from a dump file"
task :restore, [:filename] => [:environment, 'db:drop', 'db:create'] do |t, args|
filename = Rails.root.join(args[:filename] || 'db/PRODUCTION.dump')
filename = db_dump_filename(args)
cmd = nil
with_config do |app, host, db|
cmd = "pg_restore --verbose --host #{host} --clean --no-owner --no-acl --dbname #{db} #{filename}"
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def make_request

it "destroys the event and redirects to the events page" do
make_request
expect(Event.find_by_id(event.id)).to eq(nil)
expect(Event.find_by(id: event.id)).to eq(nil)
expect(response).to redirect_to events_path
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/sections_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
expect {
delete :destroy, event_id: @event.id, id: @section.id
}.to change(@event.sections, :count).by(-1)
expect(Section.find_by_id(@section.id)).to be_nil
expect(Section.find_by(id: @section.id)).to be_nil
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@
factory :rsvp, aliases: [:volunteer_rsvp] do
user
event
role Role.find_by_title('Volunteer')
role Role.find_by(title: 'Volunteer')
teaching_experience "Quite experienced"
subject_experience "Use professionally"
childcare_info "Bobby: 8\nSusie: 4"
job_details "Horse whisperer"
dietary_info "Paleo"

factory :student_rsvp do
role Role.find_by_title 'Student'
role Role.find_by title: 'Student'
operating_system OperatingSystem::OSX_LION
class_level 2
end
Expand All @@ -141,7 +141,7 @@
end

factory :organizer_rsvp do
role Role.find_by_title 'Organizer'
role Role.find_by title: 'Organizer'
end
transient do
session_checkins nil
Expand Down
4 changes: 2 additions & 2 deletions spec/features/events/event_listing_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
expect(page).to have_content good_event_title
expect(page).to have_content("My Amazing Session")
expect(page).to have_content("This event currently has no location!")
expect(page).to have_content(Course.find_by_name('RAILS').description.split('.')[0])
expect(page).to have_content(Course.find_by(name: 'RAILS').description.split('.')[0])

visit events_path

Expand Down Expand Up @@ -316,7 +316,7 @@

it "allows user to cancel their event RSVP" do
click_link('Cancel RSVP')
expect(Rsvp.find_by_id(@rsvp.id)).to be_nil
expect(Rsvp.find_by(id: @rsvp.id)).to be_nil
end

it "allows user to edit volunteer responsibilities" do
Expand Down
4 changes: 2 additions & 2 deletions spec/mailers/mailer_previews_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'rails_helper'

require Rails.root.join('db', 'seeds', 'seed_event')
Dir[Rails.root.join("app/mailers/*.rb")].each { |f| require f }
Dir[Rails.root.join("spec/mailers/previews/**/*.rb")].each { |f| require f }
Dir[Rails.root.join("app", "mailers", "*.rb")].each { |f| require f }
Dir[Rails.root.join("spec", "mailers", "previews", "**", "*.rb")].each { |f| require f }

RSpec.describe 'mailer previews' do
def find_preview_class(mailer_class)
Expand Down
2 changes: 1 addition & 1 deletion spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
describe "#rsvp_for_user" do
it "should return the rsvp for a user" do
event = create(:event)
expect(event.rsvp_for_user(@user)).to eq(event.rsvps.find_by_user_id(@user.id))
expect(event.rsvp_for_user(@user)).to eq(event.rsvps.find_by(user_id: @user.id))
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
rsvp = create(:rsvp, event_id: event.id, user: user)

user.destroy
expect(Rsvp.find_by_id(rsvp.id)).to be_nil
expect(Rsvp.find_by(id: rsvp.id)).to be_nil
end

it 'can update the profile via nested attributes' do
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

Capybara.asset_host = "http://#{Rails.application.routes.default_url_options[:host]}"

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Dir[Rails.root.join("spec", "support", "**", "*.rb")].each {|f| require f}

Shoulda::Matchers.configure do |config|
config.integrate do |with|
Expand Down
2 changes: 1 addition & 1 deletion spec/seeds/seeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
event.organizers << innocent_user

Seeder.destroy_event(event)
expect(User.find_by_id(innocent_user.id)).to be_present
expect(User.find_by(id: innocent_user.id)).to be_present
end
end

Expand Down

0 comments on commit 716fbe3

Please sign in to comment.