Skip to content

Commit

Permalink
Update rubocop config and fix various rubocoppy sort of things
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgrathwell committed Aug 19, 2016
1 parent 71f131b commit 4dcec5b
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 47 deletions.
56 changes: 54 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Lint/UnusedMethodArgument:
Lint/UselessAssignment:
Enabled: false

Lint/Void:
Enabled: false

Metrics/AbcSize:
Max: 160

Expand Down Expand Up @@ -111,12 +114,18 @@ Style/ExtraSpacing:
- 'db/migrate/20131210054655_init_schema.rb'
- 'db/schema.rb'

Style/FrozenStringLiteralComment:
Enabled: false

Style/GuardClause:
Enabled: false

Style/IfUnlessModifier:
Enabled: false

Style/IndentArray:
Enabled: false

Style/IndentationWidth:
Enabled: false

Expand All @@ -132,21 +141,49 @@ Style/LeadingCommentSpace:
Style/MethodDefParentheses:
Enabled: false

Style/MethodMissing:
Exclude:
- 'app/models/meetup_user.rb'

Style/MultilineBlockChain:
Enabled: false

Style/MultilineBlockLayout:
Enabled: false

Style/MultilineMethodCallBraceLayout:
Enabled: false

Style/MultilineMethodCallIndentation:
Enabled: false

Style/MultilineOperationIndentation:
Enabled: false

Style/MutableConstant:
Enabled: false

Style/NestedParenthesizedCalls:
Enabled: false

Style/NumericLiterals:
MinDigits: 15

Style/NumericPredicate:
Enabled: false

Style/ParallelAssignment:
Enabled: false

Style/PredicateName:
Enabled: false

Style/Proc:
Enabled: false

Style/RaiseArgs:
Enabled: false

Style/RedundantReturn:
Enabled: false

Expand All @@ -165,6 +202,9 @@ Style/SpaceAroundOperators:
Style/SpaceBeforeBlockBraces:
Enabled: false

Style/SpaceBeforeFirstArg:
Enabled: false

Style/SpaceInsideBlockBraces:
Enabled: false

Expand All @@ -177,7 +217,7 @@ Style/SpaceInsideHashLiteralBraces:
Style/SpaceInsideParens:
Enabled: false

Style/SingleSpaceBeforeFirstArg:
Style/SpaceInsidePercentLiteralDelimiters:
Enabled: false

Style/SpecialGlobalVars:
Expand All @@ -186,14 +226,26 @@ Style/SpecialGlobalVars:
Style/StringLiterals:
Enabled: false

Style/StringLiteralsInInterpolation:
Enabled: false

Style/TernaryParentheses:
Enabled: false

Style/TrailingBlankLines:
Enabled: false

Style/TrailingComma:
Style/TrailingCommaInArguments:
Enabled: false

Style/TrailingCommaInLiteral:
Enabled: false

Style/TrailingWhitespace:
Enabled: false

Style/WordArray:
MinSize: 3
Exclude:
- 'db/schema.rb'
- 'db/migrate/20131210054655_init_schema.rb'
2 changes: 0 additions & 2 deletions app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def download_subscriptions
end
end

private

class ChapterEventLocation
attr_reader :event, :location, :chapter
def initialize(event)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/rsvps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def rsvp_params

def load_rsvp
@rsvp = Rsvp.find_by_id(params[:id])
unless @rsvp && ((@rsvp.user == current_user) || (@rsvp.event.organizer?(current_user)))
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
end
Expand All @@ -159,10 +159,10 @@ def assign_event

def signup_for_new_region?
regions = Region.joins(locations: :events).where('events.id IN (?)', current_user.events.pluck(:id)).distinct
if regions.length > 0
!regions.include?(@event.region)
else
if regions.empty?
false
else
!regions.include?(@event.region)
end
end
end
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def levels
end

def set_defaults
if self.has_attribute?(:details)
if has_attribute?(:details)
self.details ||= Event::DEFAULT_DETAILS['default_details.html']
self.student_details ||= Event::DEFAULT_DETAILS['default_student_details.html']
self.volunteer_details ||= Event::DEFAULT_DETAILS['default_volunteer_details.html']
Expand Down
2 changes: 1 addition & 1 deletion app/models/location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def as_json(options = {})
def most_recent_event_date
relevant_events = (events + event_sessions.map(&:event)).compact
if relevant_events.present?
event = relevant_events.sort_by { |e| e.starts_at }.last
event = relevant_events.sort_by(&:starts_at).last
event.starts_at.in_time_zone(event.time_zone).strftime("%b %d, %Y")
else
"No events found."
Expand Down
2 changes: 1 addition & 1 deletion app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def has_leader?(user)

def subscription_csv
CSV.generate do |csv|
csv << ["email", "first_name", "last_name"]
csv << %w(email first_name last_name)
users.each do |user|
csv << [user.email, user.first_name, user.last_name]
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/rsvp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def full_dietary_info
end

def dietary_restriction_diets
self.dietary_restrictions.map(&:restriction)
dietary_restrictions.map(&:restriction)
end

def dietary_restriction_diets=(diets)
Expand Down
2 changes: 1 addition & 1 deletion app/services/account_merger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def merge!
Is this cool? (y/n)
EOT

return unless get_answer.downcase == 'y'
return unless get_answer.casecmp('y')

to_destroy.destroy_all

Expand Down
2 changes: 0 additions & 2 deletions app/services/omniauth_providers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ def self.user_attributes_from_omniauth(omniauth)
end
end

private

class OmniauthAttributeGenerator
attr_reader :omniauth

Expand Down
30 changes: 18 additions & 12 deletions app/services/user_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ def meetup_users
SQL
users = MeetupUser.where(query).order(:full_name)
if @search_query
if using_postgres
sql = "LOWER(UNACCENT(full_name)) LIKE CONCAT('%', LOWER(UNACCENT(?)), '%')"
else
sql = "LOWER(full_name) LIKE '%' || LOWER(?) || '%'"
end
users.where(sql, @search_query)
users.where(meetup_user_search_sql, @search_query)
else
users
end
Expand All @@ -78,12 +73,7 @@ def meetup_users
def bridgetroll_users
users = User.select('id, first_name, last_name').order(:first_name, :last_name)
if @search_query
if using_postgres
sql = "LOWER(UNACCENT(CONCAT(first_name, ' ', last_name))) LIKE CONCAT('%', LOWER(UNACCENT(?)), '%')"
else
sql = "LOWER(first_name || ' ' || last_name) LIKE '%' || LOWER(?) || '%'"
end
users.where(sql, @search_query)
users.where(bridgetroll_user_search_sql, @search_query)
else
users
end
Expand All @@ -93,6 +83,22 @@ def using_postgres
@using_postgres ||= (ActiveRecord::Base.connection.adapter_name == "PostgreSQL")
end

def meetup_user_search_sql
if using_postgres
"LOWER(UNACCENT(full_name)) LIKE CONCAT('%', LOWER(UNACCENT(?)), '%')"
else
"LOWER(full_name) LIKE '%' || LOWER(?) || '%'"
end
end

def bridgetroll_user_search_sql
if using_postgres
"LOWER(UNACCENT(CONCAT(first_name, ' ', last_name))) LIKE CONCAT('%', LOWER(UNACCENT(?)), '%')"
else
"LOWER(first_name || ' ' || last_name) LIKE '%' || LOWER(?) || '%'"
end
end

def attendances_for(user_type)
# TODO: This fetches one row for each user+role combo that exists in the system.
# This may someday be too much to fit in memory, but find_each doesn't work
Expand Down
2 changes: 1 addition & 1 deletion bin/find_spec_or_impl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
end

related_file = if in_spec
filename.gsub(/^#{spec_prefix}/, impl_prefix).gsub(/_spec#{extension}$/, "#{extension}")
filename.gsub(/^#{spec_prefix}/, impl_prefix).gsub(/_spec#{extension}$/, extension.to_s)
else
filename.gsub(/^#{impl_prefix}/, spec_prefix).gsub(/#{extension}$/, "_spec#{extension}")
end
Expand Down
2 changes: 1 addition & 1 deletion bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Dir.chdir APP_ROOT do
require 'yaml'
require 'erb'
db_config = YAML.load(ERB.new(File.read("config/database.yml")).result)
if File.exists?(db_config['development']['database'])
if File.exist?(db_config['development']['database'])
puts "Database already exists, running migrations..."
system "bin/rake db:migrate"
else
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/simple_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
# config.item_wrapper_class = nil

# How the label text should be generated altogether with the required text.
config.label_text = lambda { |label, required, explicit_label| "#{label}" }
config.label_text = lambda { |label, required, explicit_label| label.to_s }

# You can define the class to use on all labels. Default is nil.
# config.label_class = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def up
Event.find_each do |e|
rsvp_ids = e.rsvps.pluck(:id)
surveys = Survey.where(rsvp_id: rsvp_ids)
if surveys.length > 0
unless surveys.empty?
e.update_attribute(:survey_sent_at, e.ends_at)
end
end
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20151207004629_seed_chapters_from_regions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def up

Region.find_each do |region|
chapter_name = region.name
chapter_name = "RailsBridge #{chapter_name}" unless chapter_name.match('RailsBridge')
chapter_name = "RailsBridge #{chapter_name}" unless chapter_name =~ 'RailsBridge'
chapter = Chapter.create(name: chapter_name, organization: rb_org)
region.events.update_all(chapter_id: chapter.id)
end
Expand All @@ -46,7 +46,7 @@ def up
ExternalEvent.find_each do |external_event|
if external_event.region
chapter_name = external_event.region.name
chapter_name = "RailsBridge #{chapter_name}" unless chapter_name.match('RailsBridge')
chapter_name = "RailsBridge #{chapter_name}" unless chapter_name =~ 'RailsBridge'
chapter = Chapter.find_or_create_by(name: chapter_name, organization: rb_org)
external_event.update_attributes(chapter_id: chapter.id)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/db.rake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ db_namespace = namespace :db do
end

File.write(filename, new_schema_content)
rescue Exception => e
rescue StandardError => e
File.write(filename, existing_schema_content)
raise
end
Expand Down
6 changes: 2 additions & 4 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@
rsvp.rsvp_sessions << build(:rsvp_session, rsvp: rsvp, event_session_id: event_session_id, checked_in: checked_in)
end
rsvp.checkins_count = evaluator.session_checkins.values.select { |v| v }.length
else
unless rsvp.rsvp_sessions.length > 0
rsvp.rsvp_sessions << build(:rsvp_session, rsvp: rsvp, event_session: rsvp.event.event_sessions.first)
end
elsif rsvp.rsvp_sessions.empty?
rsvp.rsvp_sessions << build(:rsvp_session, rsvp: rsvp, event_session: rsvp.event.event_sessions.first)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/event_listing_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
title: 'mytitle2',
time_zone: 'Pacific Time (US & Canada)')
event.event_sessions.first.update_attributes(
starts_at: Time.utc(next_year, 01, 31, 11, 20),
ends_at: Time.utc(next_year, 01, 31, 11, 55)
starts_at: Time.utc(next_year, 1, 31, 11, 20),
ends_at: Time.utc(next_year, 1, 31, 11, 55)
)

event.save!
Expand Down Expand Up @@ -100,7 +100,7 @@

sign_in_with_modal(@user)

expect(page.find('div.header-container > h1')).to have_content("#{event.title}")
expect(page.find('div.header-container > h1')).to have_content(event.title)
expect(current_path).to eq(event_path(event))
end
end
Expand Down
12 changes: 8 additions & 4 deletions spec/support/mailers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
end

shared_examples_for 'a mailer view' do
it "uses absolute URLs" do
def extract_body(mail)
if mail.multipart?
body = mail.parts.find do |p|
mail.parts.find do |p|
p.content_type.starts_with?('text/html')
end.body.encoded
else
body = mail.body.encoded
else
mail.body.encoded
end
end

it "uses absolute URLs" do
body = extract_body(mail)

urls = Capybara.string(body).all('a').map { |a| a[:href] }

Expand Down
4 changes: 2 additions & 2 deletions spec/support/waiting_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def wait_for_condition
Timeout::timeout(5) do
while true
Timeout.timeout(5) do
loop do
return if yield
sleep 0.1
end
Expand Down

0 comments on commit 4dcec5b

Please sign in to comment.