diff --git a/.rubocop.yml b/.rubocop.yml index a89826970..568f53a0f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -64,6 +64,9 @@ Rails/Date: Rails/Delegate: Enabled: false +Bundler/DuplicatedGem: + Enabled: false + Rails/Exit: Exclude: - lib/tasks/support/rspec_rerunner.rb @@ -71,12 +74,19 @@ Rails/Exit: 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 diff --git a/app/controllers/events/attendee_names_controller.rb b/app/controllers/events/attendee_names_controller.rb index 23564deb4..904ffe7ec 100644 --- a/app/controllers/events/attendee_names_controller.rb +++ b/app/controllers/events/attendee_names_controller.rb @@ -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) diff --git a/app/controllers/events/attendees_controller.rb b/app/controllers/events/attendees_controller.rb index 3e09cc717..354189dfc 100644 --- a/app/controllers/events/attendees_controller.rb +++ b/app/controllers/events/attendees_controller.rb @@ -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) diff --git a/app/controllers/events/emails_controller.rb b/app/controllers/events/emails_controller.rb index f6c970416..db5341a23 100644 --- a/app/controllers/events/emails_controller.rb +++ b/app/controllers/events/emails_controller.rb @@ -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 diff --git a/app/controllers/events/organizer_tools_controller.rb b/app/controllers/events/organizer_tools_controller.rb index 22c3b50d9..8d1a1db6d 100644 --- a/app/controllers/events/organizer_tools_controller.rb +++ b/app/controllers/events/organizer_tools_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/events/students_controller.rb b/app/controllers/events/students_controller.rb index 7cbe0cf16..ef1de00ba 100644 --- a/app/controllers/events/students_controller.rb +++ b/app/controllers/events/students_controller.rb @@ -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) diff --git a/app/controllers/rsvps_controller.rb b/app/controllers/rsvps_controller.rb index fd2d4a2d7..e6dd85758 100644 --- a/app/controllers/rsvps_controller.rb +++ b/app/controllers/rsvps_controller.rb @@ -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 @@ -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 diff --git a/app/controllers/sections_controller.rb b/app/controllers/sections_controller.rb index 1f353272c..61e36430b 100644 --- a/app/controllers/sections_controller.rb +++ b/app/controllers/sections_controller.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index ecb67c20e..93a122829 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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) diff --git a/config/environments/development.rb b/config/environments/development.rb index 29455c470..05f5d81eb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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' } diff --git a/db/migrate/20170110062210_set_id_sequence_for_new_courses.rb b/db/migrate/20170110062210_set_id_sequence_for_new_courses.rb index 8b7f0dc01..3985875b9 100644 --- a/db/migrate/20170110062210_set_id_sequence_for_new_courses.rb +++ b/db/migrate/20170110062210_set_id_sequence_for_new_courses.rb @@ -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 diff --git a/db/seeds/seed_event.rb b/db/seeds/seed_event.rb index ba5347af1..46260b60f 100644 --- a/db/seeds/seed_event.rb +++ b/db/seeds/seed_event.rb @@ -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, @@ -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', @@ -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, diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index c067086ee..fc74f2dd3 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -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' @@ -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}" @@ -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}" diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index f8eace485..41a7b2510 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -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 diff --git a/spec/controllers/sections_controller_spec.rb b/spec/controllers/sections_controller_spec.rb index 617c61a01..826321ef4 100644 --- a/spec/controllers/sections_controller_spec.rb +++ b/spec/controllers/sections_controller_spec.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 61eea9bcf..71f90f7da 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -121,7 +121,7 @@ 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" @@ -129,7 +129,7 @@ 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 @@ -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 diff --git a/spec/features/events/event_listing_request_spec.rb b/spec/features/events/event_listing_request_spec.rb index 1b67f2e16..1940f8ec6 100644 --- a/spec/features/events/event_listing_request_spec.rb +++ b/spec/features/events/event_listing_request_spec.rb @@ -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 @@ -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 diff --git a/spec/mailers/mailer_previews_spec.rb b/spec/mailers/mailer_previews_spec.rb index e0814f69c..58e54cc44 100644 --- a/spec/mailers/mailer_previews_spec.rb +++ b/spec/mailers/mailer_previews_spec.rb @@ -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) diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index fc9a9dbe3..ab7a78451 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index bdb56cd69..d0fb3526b 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 0b0ca8979..b0294ed08 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -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| diff --git a/spec/seeds/seeds_spec.rb b/spec/seeds/seeds_spec.rb index aff901a6a..d4fc17f0c 100644 --- a/spec/seeds/seeds_spec.rb +++ b/spec/seeds/seeds_spec.rb @@ -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