diff --git a/.rubocop.yml b/.rubocop.yml index aa078ef5..a889a2fd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -84,3 +84,65 @@ Layout/LineLength: Style/Documentation: Enabled: false + +Style/SymbolArray: + Enabled: true + EnforcedStyle: percent + +Style/WordArray: + Enabled: true + EnforcedStyle: percent + +Performance/AncestorsInclude: # new in 1.7 + Enabled: true + +Performance/BigDecimalWithNumericArgument: # new in 1.7 + Enabled: true + +Performance/BlockGivenWithExplicitBlock: # new in 1.9 + Enabled: true + +Performance/CollectionLiteralInLoop: # new in 1.8 + Enabled: true + +Performance/ConcurrentMonotonicTime: # new in 1.12 + Enabled: true + +Performance/ConstantRegexp: # new in 1.9 + Enabled: true + +Performance/MapCompact: # new in 1.11 + Enabled: true + +Performance/MethodObjectAsBlock: # new in 1.9 + Enabled: true + +Performance/RedundantEqualityComparisonBlock: # new in 1.10 + Enabled: true + +Performance/RedundantSortBlock: # new in 1.7 + Enabled: true + +Performance/RedundantSplitRegexpArgument: # new in 1.10 + Enabled: true + +Performance/RedundantStringChars: # new in 1.7 + Enabled: true + +Performance/ReverseFirst: # new in 1.7 + Enabled: true + +Performance/SortReverse: # new in 1.7 + Enabled: true + +Performance/Squeeze: # new in 1.7 + Enabled: true + +Performance/StringIdentifierArgument: # new in 1.13 + Enabled: true + +Performance/StringInclude: # new in 1.7 + Enabled: true + +Performance/Sum: # new in 1.8 + Enabled: true diff --git a/app/controllers/spam_controller.rb b/app/controllers/spam_controller.rb index 6321d78b..dd9ef780 100644 --- a/app/controllers/spam_controller.rb +++ b/app/controllers/spam_controller.rb @@ -24,7 +24,7 @@ class SpamController < ApplicationController include ModerationGuards before_action :require_login - before_action { logged_in_as(['admin', 'moderator'], 'moderate maps and users') } + before_action { logged_in_as(%w[admin moderator], 'moderate maps and users') } def spam_map @map = Map.find(params[:id]) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index e59062bf..10ca5056 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -16,7 +16,7 @@ class TagsController < ApplicationController @tag = Tag.find_by_name(params[:id]) @maps = @tag.maps.paginate(page: params[:page], per_page: 24) @title = "Maps tagged with ' #{@tag.name} '" - tag = Tag.where(name: 'featured').first # note that this is not a join table but the .maps method still works + tag = Tag.where(name: 'featured').first # NOTE: that this is not a join table but the .maps method still works @unpaginated = true @authors = User.where(login: tag.maps.collect(&:author)) if tag @authors ||= [] diff --git a/app/models/map.rb b/app/models/map.rb index bb799b8c..2c762e6b 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -62,11 +62,11 @@ class Map < ApplicationRecord def self.bbox(minlat, minlon, maxlat, maxlon, tag = nil) if tag.nil? Map.where(['lat > ? AND lat < ? AND lon > ? AND lon < ?', - minlat, maxlat, minlon, maxlon]) + minlat, maxlat, minlon, maxlon,]) else Map.where(['lat > ? AND lat < ? AND lon > ? AND lon < ?', - minlat, maxlat, minlon, maxlon]) - .joins(:tags).where("tags.name = ?", tag) + minlat, maxlat, minlon, maxlon,]) + .joins(:tags).where("tags.name = ?", tag) end end @@ -91,10 +91,10 @@ class Map < ApplicationRecord def self.search(query) query = query.squeeze(' ').strip - Map.active - .where(['author LIKE ? OR name LIKE ? - OR location LIKE ? OR description LIKE ?', - "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"]) + Map.active.where([ + 'author LIKE ? OR name LIKE ? OR location LIKE ? OR description LIKE ?', + "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", + ]) end def self.featured @@ -132,9 +132,10 @@ class Map < ApplicationRecord end def self.maps_nearby(lat:, lon:, dist:) - Map.active - .where(['lat>? AND lat? AND lon? AND lat? AND lon read_attribute(:image_filename), + { + "name" => read_attribute(:image_filename), "size" => read_attribute(:image_size), "url" => image.url(:medium), "original_url" => image.url(:original), "id" => read_attribute(:id), "thumbnail_url" => image.url(:thumb), "delete_url" => image.url, - "delete_type" => "DELETE" } + "delete_type" => "DELETE", + } end def fup_error_json - { "name" => read_attribute(:image_filename), + { + "name" => read_attribute(:image_filename), "size" => read_attribute(:image_size), - "error" => errors["base"] } + "error" => errors["base"], + } end after_save :save_dimensions @@ -135,14 +139,17 @@ class Warpable < ApplicationRecord # needs update for Paperclip!! require 'open-uri' attr_reader :url + def url=(uri) nil if uri.blank? - io = (begin - URI.parse(uri).open - rescue StandardError - nil - end) + io = ( + begin + URI.parse(uri).open + rescue StandardError + nil + end + ) (class << io; self; end;).class_eval do define_method(:original_filename) { base_uri.path.split('/').last } end diff --git a/test/test_helper.rb b/test/test_helper.rb index 7f991a18..66576e9f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,8 +1,12 @@ require_relative '../config/environment' require 'simplecov' -require 'codecov' -SimpleCov.formatter = SimpleCov::Formatter::Codecov + +if ENV['CI'] == 'true' + require 'codecov' + SimpleCov.formatter = SimpleCov::Formatter::Codecov +end + SimpleCov.start require "rack_session_access/capybara"