remove local codecov reports & rubocop offenses fixes (#1776)

* remove codecov local

* rubocop offenses fixes
This commit is contained in:
Cess
2022-07-07 19:36:36 +03:00
committed by GitHub
parent 1e471682a5
commit bd29c72a89
6 changed files with 100 additions and 27 deletions

View File

@@ -84,3 +84,65 @@ Layout/LineLength:
Style/Documentation: Style/Documentation:
Enabled: false 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

View File

@@ -24,7 +24,7 @@ class SpamController < ApplicationController
include ModerationGuards include ModerationGuards
before_action :require_login 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 def spam_map
@map = Map.find(params[:id]) @map = Map.find(params[:id])

View File

@@ -16,7 +16,7 @@ class TagsController < ApplicationController
@tag = Tag.find_by_name(params[:id]) @tag = Tag.find_by_name(params[:id])
@maps = @tag.maps.paginate(page: params[:page], per_page: 24) @maps = @tag.maps.paginate(page: params[:page], per_page: 24)
@title = "Maps tagged with ' #{@tag.name} '" @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 @unpaginated = true
@authors = User.where(login: tag.maps.collect(&:author)) if tag @authors = User.where(login: tag.maps.collect(&:author)) if tag
@authors ||= [] @authors ||= []

View File

@@ -62,11 +62,11 @@ class Map < ApplicationRecord
def self.bbox(minlat, minlon, maxlat, maxlon, tag = nil) def self.bbox(minlat, minlon, maxlat, maxlon, tag = nil)
if tag.nil? if tag.nil?
Map.where(['lat > ? AND lat < ? AND lon > ? AND lon < ?', Map.where(['lat > ? AND lat < ? AND lon > ? AND lon < ?',
minlat, maxlat, minlon, maxlon]) minlat, maxlat, minlon, maxlon,])
else else
Map.where(['lat > ? AND lat < ? AND lon > ? AND lon < ?', Map.where(['lat > ? AND lat < ? AND lon > ? AND lon < ?',
minlat, maxlat, minlon, maxlon]) minlat, maxlat, minlon, maxlon,])
.joins(:tags).where("tags.name = ?", tag) .joins(:tags).where("tags.name = ?", tag)
end end
end end
@@ -91,10 +91,10 @@ class Map < ApplicationRecord
def self.search(query) def self.search(query)
query = query.squeeze(' ').strip query = query.squeeze(' ').strip
Map.active Map.active.where([
.where(['author LIKE ? OR name LIKE ? 'author LIKE ? OR name LIKE ? OR location LIKE ? OR description LIKE ?',
OR location LIKE ? OR description LIKE ?', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%",
"%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%"]) ])
end end
def self.featured def self.featured
@@ -132,9 +132,10 @@ class Map < ApplicationRecord
end end
def self.maps_nearby(lat:, lon:, dist:) def self.maps_nearby(lat:, lon:, dist:)
Map.active Map.active.where([
.where(['lat>? AND lat<? AND lon>? AND lon<?', 'lat>? AND lat<? AND lon>? AND lon<?',
lat - dist, lat + dist, lon - dist, lon + dist]) lat - dist, lat + dist, lon - dist, lon + dist,
])
end end
def nodes def nodes
@@ -169,8 +170,7 @@ class Map < ApplicationRecord
placed_warpables.each do |warpable| placed_warpables.each do |warpable|
pxperms << 100.00 / warpable.cm_per_pixel if warpable.placed? pxperms << 100.00 / warpable.cm_per_pixel if warpable.placed?
end end
average = (pxperms.inject { |sum, n| sum + n }) / pxperms.length pxperms.sum / pxperms.length
average
end end
def best_cm_per_pixel def best_cm_per_pixel
@@ -202,7 +202,7 @@ class Map < ApplicationRecord
res = 1 if res.zero? # let's not ever try to go for infinite resolution res = 1 if res.zero? # let's not ever try to go for infinite resolution
scales << res unless res.nil? scales << res unless res.nil?
end end
total_sum = (scales.inject { |sum, n| sum + n }) if scales total_sum = scales.sum unless scales.empty?
average = total_sum / count if total_sum average = total_sum / count if total_sum
average average
else else

View File

@@ -19,7 +19,7 @@ class Warpable < ApplicationRecord
belongs_to :map, optional: true belongs_to :map, optional: true
belongs_to :user, optional: true belongs_to :user, optional: true
has_paper_trail on: %i(create update), only: %i(nodes) has_paper_trail on: %i(create update), only: :nodes
# overriding JSON formatting for Leaflet.DistortableImage # overriding JSON formatting for Leaflet.DistortableImage
def as_json(options = {}) def as_json(options = {})
@@ -32,20 +32,24 @@ class Warpable < ApplicationRecord
# JSON formatting for file upload plugin # JSON formatting for file upload plugin
def fup_json def fup_json
{ "name" => read_attribute(:image_filename), {
"name" => read_attribute(:image_filename),
"size" => read_attribute(:image_size), "size" => read_attribute(:image_size),
"url" => image.url(:medium), "url" => image.url(:medium),
"original_url" => image.url(:original), "original_url" => image.url(:original),
"id" => read_attribute(:id), "id" => read_attribute(:id),
"thumbnail_url" => image.url(:thumb), "thumbnail_url" => image.url(:thumb),
"delete_url" => image.url, "delete_url" => image.url,
"delete_type" => "DELETE" } "delete_type" => "DELETE",
}
end end
def fup_error_json def fup_error_json
{ "name" => read_attribute(:image_filename), {
"name" => read_attribute(:image_filename),
"size" => read_attribute(:image_size), "size" => read_attribute(:image_size),
"error" => errors["base"] } "error" => errors["base"],
}
end end
after_save :save_dimensions after_save :save_dimensions
@@ -135,14 +139,17 @@ class Warpable < ApplicationRecord
# needs update for Paperclip!! # needs update for Paperclip!!
require 'open-uri' require 'open-uri'
attr_reader :url attr_reader :url
def url=(uri) def url=(uri)
nil if uri.blank? nil if uri.blank?
io = (begin io = (
URI.parse(uri).open begin
rescue StandardError URI.parse(uri).open
nil rescue StandardError
end) nil
end
)
(class << io; self; end;).class_eval do (class << io; self; end;).class_eval do
define_method(:original_filename) { base_uri.path.split('/').last } define_method(:original_filename) { base_uri.path.split('/').last }
end end

View File

@@ -1,8 +1,12 @@
require_relative '../config/environment' require_relative '../config/environment'
require 'simplecov' require 'simplecov'
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov if ENV['CI'] == 'true'
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end
SimpleCov.start SimpleCov.start
require "rack_session_access/capybara" require "rack_session_access/capybara"