From fa90f7c21fc53584b3e8fa76157097e7e1ac8821 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 26 Mar 2019 12:32:20 -0300 Subject: [PATCH] rubocop --- .rubocop_todo.yml | 178 ++++++++++++++++++ Capfile | 1 + Gemfile | 29 +-- Gemfile.lock | 18 ++ Rakefile | 2 + app/controllers/application_controller.rb | 5 +- app/controllers/i18n_controller.rb | 4 +- app/controllers/invitadxs_controller.rb | 4 +- app/controllers/login_controller.rb | 4 +- app/controllers/posts_controller.rb | 26 +-- app/controllers/sites_controller.rb | 20 +- app/helpers/application_helper.rb | 2 + app/jobs/application_job.rb | 2 + app/mailers/application_mailer.rb | 2 + app/mailers/invitadx_mailer.rb | 2 + app/models/application_record.rb | 2 + app/models/invitadx.rb | 14 +- app/models/jekyll_i18n.rb | 5 +- app/models/post.rb | 106 ++++++----- app/models/post/image_uploader.rb | 14 +- app/models/post/template_field.rb | 85 +++++---- app/models/site.rb | 43 ++--- app/models/usuaria.rb | 2 + app/policies/i18n_policy.rb | 5 +- app/policies/invitadx_policy.rb | 2 + app/policies/post_policy.rb | 2 + app/policies/site_policy.rb | 2 + app/policies/sutty_policy.rb | 2 + app/views/posts/_form.haml | 2 +- bin/bundle | 38 ++-- bin/cap | 16 +- bin/capify | 16 +- bin/rails | 4 +- bin/rake | 4 +- bin/setup | 5 +- bin/spring | 3 +- bin/update | 4 +- bin/whenever | 14 +- bin/wheneverize | 14 +- bin/yarn | 14 +- config.ru | 2 + config/application.rb | 20 +- config/boot.rb | 2 + config/deploy.rb | 5 +- config/deploy/example.rb | 5 +- config/deploy/production.rb | 5 +- config/environment.rb | 2 + config/environments/development.rb | 2 + config/environments/production.rb | 17 +- config/environments/test.rb | 2 + .../application_controller_renderer.rb | 2 + config/initializers/assets.rb | 2 + config/initializers/backtrace_silencers.rb | 2 + config/initializers/carrierwave.rb | 6 +- config/initializers/commonmarker.rb | 11 +- config/initializers/cookies_serializer.rb | 2 + .../initializers/filter_parameter_logging.rb | 2 + config/initializers/inflections.rb | 2 + config/initializers/locale.rb | 4 +- config/initializers/mime_types.rb | 2 + config/initializers/warden.rb | 4 +- config/initializers/wrap_parameters.rb | 2 + config/puma.rb | 8 +- config/routes.rb | 7 +- config/schedule.rb | 2 + config/spring.rb | 8 +- db/migrate/20180925183241_create_invitadxs.rb | 2 + ...pta_politicas_de_privacidad_to_invitadx.rb | 2 + db/seeds.rb | 2 + lib/warden/email_and_password.rb | 4 +- lib/warden/imap.rb | 1 - test/application_system_test_case.rb | 4 +- test/models/post_test.rb | 2 + test/models/site_test.rb | 18 +- test/models/usuaria_test.rb | 6 +- test/test_helper.rb | 6 +- 76 files changed, 604 insertions(+), 288 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..9c62a5d --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,178 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2019-03-26 12:32:08 -0300 using RuboCop version 0.66.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity. +# SupportedStylesAlignWith: keyword, variable, start_of_line +Layout/EndAlignment: + Exclude: + - 'app/models/post/image_uploader.rb' + +# Offense count: 1 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'app/controllers/invitadxs_controller.rb' + +# Offense count: 4 +Lint/DuplicateMethods: + Exclude: + - 'app/models/post.rb' + - 'app/models/site.rb' + +# Offense count: 1 +Lint/HandleExceptions: + Exclude: + - 'app/controllers/posts_controller.rb' + +# Offense count: 1 +Lint/NonLocalExitFromIterator: + Exclude: + - 'app/models/invitadx.rb' + +# Offense count: 1 +Lint/ShadowingOuterLocalVariable: + Exclude: + - 'app/models/post.rb' + +# Offense count: 3 +Lint/UnderscorePrefixedVariableName: + Exclude: + - 'app/models/post.rb' + - 'app/models/post/template_field.rb' + - 'app/models/site.rb' + +# Offense count: 2 +Lint/UselessAssignment: + Exclude: + - 'app/models/invitadx.rb' + - 'app/models/site.rb' + +# Offense count: 19 +Metrics/AbcSize: + Max: 58 + +# Offense count: 3 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 31 + +# Offense count: 3 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 379 + +# Offense count: 6 +Metrics/CyclomaticComplexity: + Max: 18 + +# Offense count: 15 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 34 + +# Offense count: 5 +Metrics/PerceivedComplexity: + Max: 20 + +# Offense count: 1 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'app/models/post/image_uploader.rb' + +# Offense count: 1 +# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros. +# NamePrefix: is_, has_, have_ +# NamePrefixBlacklist: is_, has_, have_ +# NameWhitelist: is_a? +# MethodDefinitionMacros: define_method, define_singleton_method +Naming/PredicateName: + Exclude: + - 'spec/**/*' + - 'app/models/post.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect. +Performance/TimesMap: + Exclude: + - 'app/models/site.rb' + - 'test/models/site_test.rb' + +# Offense count: 102 +# Configuration parameters: AllowedChars. +Style/AsciiComments: + Exclude: + - 'app/controllers/application_controller.rb' + - 'app/controllers/i18n_controller.rb' + - 'app/controllers/posts_controller.rb' + - 'app/controllers/sites_controller.rb' + - 'app/models/invitadx.rb' + - 'app/models/jekyll_i18n.rb' + - 'app/models/post.rb' + - 'app/models/post/image_uploader.rb' + - 'app/models/post/template_field.rb' + - 'app/models/site.rb' + - 'app/models/usuaria.rb' + - 'app/policies/post_policy.rb' + - 'config/routes.rb' + - 'lib/warden/imap.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'app/models/post/image_uploader.rb' + - 'config/initializers/commonmarker.rb' + - 'config/initializers/warden.rb' + - 'test/test_helper.rb' + +# Offense count: 25 +Style/Documentation: + Enabled: false + +# Offense count: 5 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'app/controllers/posts_controller.rb' + - 'app/models/invitadx.rb' + - 'app/models/post.rb' + - 'lib/warden/email_and_password.rb' + +# Offense count: 7 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'app/models/invitadx.rb' + - 'app/models/jekyll_i18n.rb' + - 'app/models/post.rb' + - 'bin/bundle' + +# Offense count: 2 +Style/MixinUsage: + Exclude: + - 'bin/setup' + - 'bin/update' + +# Offense count: 1 +Style/OptionalArguments: + Exclude: + - 'app/models/site.rb' + +# Offense count: 66 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 190 diff --git a/Capfile b/Capfile index 529ada8..5abc2d8 100644 --- a/Capfile +++ b/Capfile @@ -1,4 +1,5 @@ # frozen_string_literal: true + # Load DSL and Setup Up Stages require 'capistrano/setup' diff --git a/Gemfile b/Gemfile index df03003..cf2df23 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,9 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) do |repo_name| - repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") + repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?('/') "https://github.com/#{repo_name}.git" end @@ -30,21 +32,21 @@ gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'bootstrap', '~> 4.0.0' +gem 'carrierwave' +gem 'carrierwave-bombshelter' +gem 'carrierwave-i18n' gem 'commonmarker' gem 'email_address' -gem 'rails_warden' +gem 'exception_notification' +gem 'font-awesome-rails' gem 'haml-rails' -gem 'bootstrap', '~> 4.0.0' gem 'jekyll' gem 'jquery-rails' -gem 'font-awesome-rails' -gem 'exception_notification' -gem 'whenever', require: false -gem 'carrierwave' -gem 'carrierwave-i18n' gem 'mini_magick' -gem 'carrierwave-bombshelter' gem 'pundit' +gem 'rails_warden' +gem 'whenever', require: false group :development, :test do gem 'pry' @@ -55,17 +57,18 @@ end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. - gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' + gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' - gem 'spring-watcher-listen', '~> 2.0.0' gem 'bcrypt_pbkdf' gem 'capistrano' gem 'capistrano-bundler' gem 'capistrano-passenger' gem 'capistrano-rails' gem 'capistrano-rbenv' - gem 'rbnacl', '< 5.0' gem 'letter_opener' + gem 'rbnacl', '< 5.0' + gem 'rubocop' + gem 'spring' + gem 'spring-watcher-listen', '~> 2.0.0' end diff --git a/Gemfile.lock b/Gemfile.lock index d702de3..e523f24 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,6 +43,7 @@ GEM airbrussh (1.3.1) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) + ast (2.4.0) autoprefixer-rails (9.5.0) execjs bcrypt (3.1.12) @@ -134,6 +135,7 @@ GEM http_parser.rb (0.6.0) i18n (0.9.5) concurrent-ruby (~> 1.0) + jaro_winkler (1.5.2) jbuilder (2.8.0) activesupport (>= 4.2.0) multi_json (>= 1.2) @@ -190,12 +192,16 @@ GEM nio4r (2.3.1) nokogiri (1.10.2) mini_portile2 (~> 2.4.0) + parallel (1.15.0) + parser (2.6.2.0) + ast (~> 2.4.0) pathutil (0.16.2) forwardable-extended (~> 2.6) popper_js (1.14.5) pry (0.12.2) coderay (~> 1.1.0) method_source (~> 0.9.0) + psych (3.1.0) public_suffix (3.0.3) puma (3.12.1) pundit (2.0.1) @@ -228,6 +234,7 @@ GEM method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) + rainbow (3.0.0) rake (12.3.2) rb-fsevent (0.10.3) rb-inotify (0.10.0) @@ -235,8 +242,17 @@ GEM rbnacl (4.0.2) ffi rouge (3.3.0) + rubocop (0.66.0) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.5, != 2.5.1.1) + psych (>= 3.1.0) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 1.6) ruby-enum (0.7.2) i18n + ruby-progressbar (1.10.0) ruby_dep (1.5.0) ruby_parser (3.13.0) sexp_processor (~> 4.9) @@ -289,6 +305,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.5) + unicode-display_width (1.5.0) warden (1.2.8) rack (>= 2.0.6) web-console (3.7.0) @@ -338,6 +355,7 @@ DEPENDENCIES rails (~> 5.1.4) rails_warden rbnacl (< 5.0) + rubocop sass-rails (~> 5.0) selenium-webdriver spring diff --git a/Rakefile b/Rakefile index e85f913..488c551 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fabd520..804c519 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Forma de ingreso a Sutty class ApplicationController < ActionController::Base protect_from_forgery with: :exception @@ -9,8 +11,7 @@ class ApplicationController < ActionController::Base redirect_to sites_path end - def markdown - end + def markdown; end private diff --git a/app/controllers/i18n_controller.rb b/app/controllers/i18n_controller.rb index a8a63fa..bb96044 100644 --- a/app/controllers/i18n_controller.rb +++ b/app/controllers/i18n_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class I18nController < ApplicationController include Pundit before_action :authenticate! @@ -15,7 +17,7 @@ class I18nController < ApplicationController @lang_from = params.fetch(:from, I18n.locale.to_s) @lang_to = params.fetch(:to, @lang_from) @options = I18n.available_locales.map do |lang| - [ t("i18n.#{lang.to_s}"), lang.to_s ] + [t("i18n.#{lang}"), lang.to_s] end end diff --git a/app/controllers/invitadxs_controller.rb b/app/controllers/invitadxs_controller.rb index 19d0e33..d967c43 100644 --- a/app/controllers/invitadxs_controller.rb +++ b/app/controllers/invitadxs_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InvitadxsController < ApplicationController include Pundit @@ -53,6 +55,6 @@ class InvitadxsController < ApplicationController def invitadx_params params.require(:invitadx).permit(:email, :password, - :password_confirmation, :acepta_politicas_de_privacidad) + :password_confirmation, :acepta_politicas_de_privacidad) end end diff --git a/app/controllers/login_controller.rb b/app/controllers/login_controller.rb index 6bae992..da71247 100644 --- a/app/controllers/login_controller.rb +++ b/app/controllers/login_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class LoginController < ApplicationController protect_from_forgery with: :exception @@ -15,7 +17,7 @@ class LoginController < ApplicationController def create authenticate session[:lang] = params[:lang] - referer = request.referer unless /\/login/ =~ request.referer + referer = request.referer unless %r{/login} =~ request.referer referer = params[:referer] if params[:referer].present? if authenticated? diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index e8611ab..2b9ad02 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PostsController < ApplicationController include Pundit before_action :authenticate! @@ -32,9 +34,9 @@ class PostsController < ApplicationController @lang = find_lang(@site) @template = find_template(@site) @post = Post.new(site: @site, - front_matter: { date: Time.now }, - lang: @lang, - template: @template) + front_matter: { date: Time.now }, + lang: @lang, + template: @template) end def create @@ -47,17 +49,17 @@ class PostsController < ApplicationController # El post se guarda como incompleto si se envió con "guardar para # después" - @post.update_attributes({incomplete: params[:commit_incomplete].present?}) + @post.update_attributes(incomplete: params[:commit_incomplete].present?) # Las usuarias pueden especificar una autora, de la contrario por # defecto es la usuaria actual if current_user.is_a? Usuaria - @post.update_attributes({author: params[:post][:author]}) + @post.update_attributes(author: params[:post][:author]) else # Todo lo que crean lxs invitadxs es borrador - @post.update_attributes({draft: true}) + @post.update_attributes(draft: true) end - @post.update_attributes({author: current_user.username}) unless @post.author + @post.update_attributes(author: current_user.username) unless @post.author if @post.save flash[:success] = @site.config.dig('thanks') @@ -87,11 +89,11 @@ class PostsController < ApplicationController # Solo las usuarias pueden modificar la autoría if current_user.is_a? Usuaria - @post.update_attributes({author: params[:post][:author]}) if params[:post][:author].present? - @post.update_attributes({draft: false}) + @post.update_attributes(author: params[:post][:author]) if params[:post][:author].present? + @post.update_attributes(draft: false) else # Todo lo que crean lxs invitadxs es borrador - @post.update_attributes({draft: true}) + @post.update_attributes(draft: true) end if @post.save @@ -114,11 +116,11 @@ class PostsController < ApplicationController obj.each do |key, value| if value.is_a?(ActionController::Parameters) || value.is_a?(Hash) # If any non-integer keys - if value.keys.find {|k, _| k =~ /\D/ } + if value.keys.find { |k, _| k =~ /\D/ } repair_nested_params(value) else obj[key] = value.values - obj[key].each {|h| repair_nested_params(h) } + obj[key].each { |h| repair_nested_params(h) } end end end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 100bf9e..f1cf8da 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Controlador de sitios class SitesController < ApplicationController include Pundit @@ -25,7 +27,7 @@ class SitesController < ApplicationController file = [params[:basename], params[:format]].join('.') path = Pathname.new(File.join(@site.path, 'public', params[:type], file)) - # TODO Verificar que no nos estén sacando archivos del sistema, como + # TODO: Verificar que no nos estén sacando archivos del sistema, como # /etc/passwd # # En sí el matcher de la ruta no admite .. así que estaríamos semi @@ -50,10 +52,10 @@ class SitesController < ApplicationController @site = find_site authorize @site - # TODO eliminar ANSI + # TODO: eliminar ANSI render file: @site.build_log, - layout: false, - content_type: 'text/plain; charset=utf-8' + layout: false, + content_type: 'text/plain; charset=utf-8' end def reorder_posts @@ -61,11 +63,11 @@ class SitesController < ApplicationController authorize @site lang = params.require(:posts).require(:lang) - if params[:posts][:force].present? - result = @site.reorder_collection! lang - else - result = @site.reorder_collection(lang, params.require(:posts).require(:order)) - end + result = if params[:posts][:force].present? + @site.reorder_collection! lang + else + @site.reorder_collection(lang, params.require(:posts).require(:order)) + end if result flash[:info] = I18n.t('info.posts.reorder') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 40fcf4f..f8ca552 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationHelper # Devuelve el atributo name de un campo posiblemente anidado def field_name_for_post(names) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index a009ace..d92ffdd 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..d84cb6e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/mailers/invitadx_mailer.rb b/app/mailers/invitadx_mailer.rb index ee94f5c..cfb80a5 100644 --- a/app/mailers/invitadx_mailer.rb +++ b/app/mailers/invitadx_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InvitadxMailer < ApplicationMailer def confirmation_required @invitadx = params[:invitadx] diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba..71fbba5 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/invitadx.rb b/app/models/invitadx.rb index 3d44063..c9e5393 100644 --- a/app/models/invitadx.rb +++ b/app/models/invitadx.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class Invitadx < ApplicationRecord has_secure_password validates_uniqueness_of :email @@ -15,9 +17,10 @@ class Invitadx < ApplicationRecord File.join(Rails.root, '_invitadxs', email) end - # TODO convertir el Pathname en un helper + # TODO: convertir el Pathname en un helper def site_dirs - return [] unless Dir.exists? path + return [] unless Dir.exist? path + Pathname.new(path).children.map(&:expand_path).map(&:to_s) end @@ -32,7 +35,7 @@ class Invitadx < ApplicationRecord def acepto_politicas_de_privacidad unless acepta_politicas_de_privacidad? errors.add(:acepta_politicas_de_privacidad, - :no_acepta_politicas_de_privacidad) + :no_acepta_politicas_de_privacidad) end end @@ -47,11 +50,11 @@ class Invitadx < ApplicationRecord dir = File.join(path, site.name) file = site.invitadxs_file - unless File.exists? dir + unless File.exist? dir FileUtils.ln_s File.join('..', '..', '_sites', site.name), dir end - if File.exists? file + if File.exist? file invitadxs = File.read(file).split("\n") invitadxs_orig = invitadxs.dup invitadxs << email unless invitadxs.include? email @@ -78,7 +81,6 @@ class Invitadx < ApplicationRecord f.flush f.truncate(f.pos) end - end end end diff --git a/app/models/jekyll_i18n.rb b/app/models/jekyll_i18n.rb index 8267825..d8d06a5 100644 --- a/app/models/jekyll_i18n.rb +++ b/app/models/jekyll_i18n.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Esta clase se encarga de guardan los archivos YAML de idiomas # # TODO se podría convertir en una clase genérica de editor de YAML @@ -45,7 +47,7 @@ class JekyllI18n # Obtiene la ruta a partir del sitio y el idioma def path - File.join(@site.path, '_data', "#{@lang.to_s}.yml") + File.join(@site.path, '_data', "#{@lang}.yml") end def exist? @@ -79,6 +81,7 @@ class JekyllI18n end return true if r.zero? + false end diff --git a/app/models/post.rb b/app/models/post.rb index fac446d..6971f8c 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'jekyll/utils' # Esta clase representa un post en un sitio jekyll e incluye métodos @@ -16,7 +17,7 @@ require 'jekyll/utils' class Post attr_accessor :content, :front_matter attr_reader :post, :site, :errors, :old_post, :lang, :template, - :template_fields + :template_fields REJECT_FROM_DATA = %w[excerpt].freeze # datos que no tienen que terminar en el front matter @@ -24,8 +25,8 @@ class Post # datos que no traemos del template REJECT_FROM_TEMPLATE = %w[draft categories layout title ext tags date slug post pre].freeze DEFAULT_PARAMS = [:title, :date, :content, :slug, :cover, - :layout, :permalink, :dir, - { lang: {} }, { tags: [] }, { categories: [] }] + :layout, :permalink, :dir, + { lang: {} }, { tags: [] }, { categories: [] }].freeze def inspect "#" @@ -37,29 +38,29 @@ class Post def initialize(site:, post: nil, front_matter: {}, lang: nil, template: nil) unless site.is_a?(Site) raise ArgumentError, - I18n.t('errors.argument_error', argument: :site, class: Site) + I18n.t('errors.argument_error', argument: :site, class: Site) end unless post.nil? || post.is_a?(Jekyll::Document) raise ArgumentError, - I18n.t('errors.argument_error', argument: :post, - class: Jekyll::Document) + I18n.t('errors.argument_error', argument: :post, + class: Jekyll::Document) end @site = site @post = post @template = template - # los errores tienen que ser un hash para que + # los errores tienen que ser un hash para que # ActiveModel pueda traer los errores normalmente @errors = {} # Si el sitio está traducido, trabajamos con la colección del # idioma, sino, con posts - if @site.i18n? - @collection = @lang = lang || I18n.locale.to_s - else - @collection = 'posts' - end + @collection = if @site.i18n? + @lang = lang || I18n.locale.to_s + else + 'posts' + end # sincronizar los datos del document if new? @@ -115,6 +116,7 @@ class Post slugs.map do |lang, id| next if lang == @lang + @site.posts_for(lang).find do |p| p.id == id end @@ -141,7 +143,7 @@ class Post add_post_to_site! true end - alias :save! :save + alias save! save def title get_front_matter 'title' @@ -166,7 +168,7 @@ class Post def categories get_front_matter('categories') || [] end - alias :category :categories + alias category categories # Devuelve la ruta del post, si se cambió alguno de los datos, # generamos una ruta nueva para tener siempre la ruta actualizada. @@ -178,13 +180,13 @@ class Post end end - # TODO los slugs se pueden repetir, el identificador real sería + # TODO: los slugs se pueden repetir, el identificador real sería # fecha+slug, pero se ve feo en las urls? def id get_front_matter 'slug' end - alias :slug :id - alias :to_s :id + alias slug id + alias to_s id def basename_changed? @post.try(:basename) != basename_from_front_matter @@ -208,7 +210,7 @@ class Post def has_field?(field) if template - template.fetch_front_matter("has_#{field.to_s}", true) + template.fetch_front_matter("has_#{field}", true) else true end @@ -225,7 +227,7 @@ class Post # convertir los hashes en arrays si los campos son anidados # usamos to_hash por todos lados porque sino son # HashWithIndifferentAccess - _attrs = attrs.to_hash.map do |k,v| + _attrs = attrs.to_hash.map do |k, v| t = template_fields.find { |t| t.key == k } if t # Subir la imagen! @@ -257,7 +259,7 @@ class Post else { k => v } end - end.reduce(Hash.new, :merge).stringify_keys + end.reduce({}, :merge).stringify_keys # el cuerpo se maneja por separado @content = _attrs.delete('content') if _attrs.key? 'content' @@ -275,6 +277,7 @@ class Post # XXX este es un principio de validación de plantillas, aunque no es # recursivo return if fetch_front_matter('incomplete', false) + template_fields.each do |tf| errors = [get_front_matter(tf.key)].flatten.compact if tf.image? && errors.map { |i| File.exist?(File.join(site.path, i)) }.none? @@ -299,6 +302,7 @@ class Post def url?(name) path = get_front_matter(name) return false unless path.is_a?(String) || path.is_a?(Array) + # El primer valor es '' porque la URL empieza con / [path].flatten.map do |p| p.split('/').second == 'public' @@ -308,20 +312,20 @@ class Post def image?(name) return false unless url? name - # TODO no chequear por la extensión - %[gif jpg jpeg png].include? get_front_matter(name).gsub(/.*\./, '') + # TODO: no chequear por la extensión + %(gif jpg jpeg png).include? get_front_matter(name).gsub(/.*\./, '') end # Obtiene metadatos de forma recursiva # TODO devolver un valor por defecto en base al template? def get_front_matter(name) - if name.is_a? Array - # Convertir los indices numericos a integers - name = name.map { |i| i =~ /[0-9]+/ ? i.to_i : i } - else - # XXX retrocompatibilidad - name = name.to_s - end + name = if name.is_a? Array + # Convertir los indices numericos a integers + name.map { |i| /[0-9]+/.match?(i) ? i.to_i : i } + else + # XXX retrocompatibilidad + name.to_s + end @front_matter.dig(*name) end @@ -341,9 +345,10 @@ class Post end end - # TODO convertir a hash para que sea más fácil buscar uno + # TODO: convertir a hash para que sea más fácil buscar uno def template_fields return [] unless template + @template_fields ||= template.front_matter.map do |key, contents| next if REJECT_FROM_TEMPLATE.include? key next if key.start_with? 'has_' @@ -355,9 +360,7 @@ class Post # devuelve las plantillas como strong params, primero los valores # simples, luego los arrays y al final los hashes def template_params - @template_params ||= (DEFAULT_PARAMS + template_fields.map do |k| - k.to_param - end).sort_by do |s| + @template_params ||= (DEFAULT_PARAMS + template_fields.map(&:to_param)).sort_by do |s| s.is_a?(Symbol) ? 0 : 1 end end @@ -375,7 +378,7 @@ class Post # entramos en una race condition return {} unless @template - ft = template_fields.map(&:to_front_matter).reduce(Hash.new, :merge) + ft = template_fields.map(&:to_front_matter).reduce({}, :merge) # Convertimos el slug en layout ft['layout'] = template.slug @@ -430,7 +433,7 @@ class Post # Obtiene el nombre del archivo a partir de los datos que le # pasemos def basename_from_front_matter - ext = get_front_matter('ext') || '.markdown' + ext = get_front_matter('ext') || '.markdown' "#{date_as_string}-#{slug}#{ext}" end @@ -485,7 +488,7 @@ class Post end def remove_empty_front_matter! - @front_matter.delete_if do |k,v| + @front_matter.delete_if do |_k, v| v.blank? end end @@ -526,7 +529,7 @@ class Post # obtener el contenido por defecto si es que no lo enviamos # modificaciones, como en `update_translations!` def full_content - yaml = @front_matter.reject do |k,_| + yaml = @front_matter.reject do |k, _| REJECT_FROM_FRONT_MATTER.include? k end @@ -534,12 +537,12 @@ class Post end def add_error(hash) - hash.each_pair do |k,i| - if @errors.key?(k) - @errors[k] = [@errors[k], i] - else - @errors[k] = i - end + hash.each_pair do |k, i| + @errors[k] = if @errors.key?(k) + [@errors[k], i] + else + i + end end @errors @@ -557,18 +560,17 @@ class Post # XXX es necesario ahora que tenemos select2? def things_to_arrays! - [:tags,:categories].each do |c| + %i[tags categories].each do |c| thing = @front_matter.dig(c.to_s) next if thing.blank? next if thing.is_a? Array + @front_matter[c.to_s] = thing.split(',').map(&:strip) end end def slugify_title! - if slug.blank? - @front_matter['slug'] = Jekyll::Utils.slugify(title) - end + @front_matter['slug'] = Jekyll::Utils.slugify(title) if slug.blank? end # Agregar al final de la cola si no especificamos un orden @@ -585,20 +587,20 @@ class Post def create_glossary! return unless site.glossary? - [:tags,:categories].each do |i| - self.send(i).each do |c| - # TODO no hardcodear, hacer _configurable + %i[tags categories].each do |i| + send(i).each do |c| + # TODO: no hardcodear, hacer _configurable next if c == 'Glossary' next if site.posts.find do |p| p.title == c end glossary = Post.new(site: site, lang: lang) - glossary.update_attributes({ + glossary.update_attributes( title: c, layout: 'glossary', categories: 'Glossary' - }) + ) glossary.save! end diff --git a/app/models/post/image_uploader.rb b/app/models/post/image_uploader.rb index 101b0fe..61837a6 100644 --- a/app/models/post/image_uploader.rb +++ b/app/models/post/image_uploader.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Una clase que permite adjuntar imágenes a artículos class Post::ImageUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick @@ -9,7 +11,7 @@ class Post::ImageUploader < CarrierWave::Uploader::Base version :thumb do process :strip - process resize_to_fit: [200,200] + process resize_to_fit: [200, 200] end def strip @@ -28,7 +30,7 @@ class Post::ImageUploader < CarrierWave::Uploader::Base # Solo aceptamos imágenes def content_type_whitelist - /\Aimage\// + %r{\Aimage/} end # Devuelve la ubicación del directorio dentro de Jekyll, para eso, @@ -46,10 +48,10 @@ class Post::ImageUploader < CarrierWave::Uploader::Base # están repetidos. def filename current_filename = parent_version.try(:filename) || file.try(:filename) - @unique_filename ||= if /\A(thumb_)?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\..*\Z/ =~ current_filename - current_filename - else - [SecureRandom.uuid, '.', file.extension].join + @unique_filename ||= if /\A(thumb_)?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\..*\Z/.match?(current_filename) + current_filename + else + [SecureRandom.uuid, '.', file.extension].join end end diff --git a/app/models/post/template_field.rb b/app/models/post/template_field.rb index 6e9475a..540f09b 100644 --- a/app/models/post/template_field.rb +++ b/app/models/post/template_field.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Representa los distintos tipos de campos que pueden venir de una # plantilla compleja class Post @@ -5,7 +7,7 @@ class Post attr_reader :post, :contents, :key STRING_VALUES = %w[string text url number email password date year - image video audio document].freeze + image video audio document].freeze # Tipo de valores que son archivos FILE_TYPES = %w[image video audio document].freeze @@ -27,50 +29,51 @@ class Post def max return 0 if simple? + contents.fetch('max', 0) end def min return 0 if simple? + contents.fetch('min', 0) end - # TODO volver elegante! + # TODO: volver elegante! def type return @type if @type - case - when image? + if image? @type = 'image' - when email? + elsif email? @type = 'email' - when url? + elsif url? @type = 'url' - when number? + elsif number? @type = 'number' - when password? + elsif password? @type = 'password' - when date? + elsif date? @type = 'date' - when year? + elsif year? @type = 'year' - when text_area? + elsif text_area? @type = 'text_area' - when check_box_group? + elsif check_box_group? @type = 'check_box_group' - when radio_group? + elsif radio_group? @type = 'radio_group' - when string? + elsif string? @type = 'text' - # TODO volver a hacer funcionar esto y ahorranos los multiple: + # TODO: volver a hacer funcionar esto y ahorranos los multiple: # false - when string? && contents.split('/', 2).count == 2 + elsif string? && contents.split('/', 2).count == 2 @type = 'select' - when nested? + elsif nested? @type = 'table' - when array? + elsif array? @type = 'select' - when boolean? + elsif boolean? @type = 'check_box' end @@ -79,15 +82,14 @@ class Post # Devuelve los valores vacíos según el tipo def empty_value - case - when string? + if string? '' - when nested? - # TODO devolver las keys también + elsif nested? + # TODO: devolver las keys también {} - when array? + elsif array? [] - when boolean? + elsif boolean? false end end @@ -124,7 +126,7 @@ class Post def email? value == 'email' || value == 'mail' end - alias :mail? :email? + alias mail? email? def date? value == 'date' @@ -192,7 +194,7 @@ class Post value.is_a? Array end - # TODO detectar cuando es complejo y tomar el valor de :multiple + # TODO: detectar cuando es complejo y tomar el valor de :multiple def multiple? # si la plantilla es simple, es multiple cuando tenemos un array return array? if simple? @@ -211,6 +213,7 @@ class Post # Todos los valores simples son abiertos return true unless complex? return false unless array? + # La cosa se complejiza cuando tenemos valores complejos # # Si tenemos una lista cerrada de valores, necesitamos saber si el @@ -241,7 +244,7 @@ class Post def human h = key.humanize - h = h + ' *' if required? + h += ' *' if required? h end @@ -260,21 +263,21 @@ class Post v = value v = value.first if array? - @nested_fields ||= v.map do |k,sv| + @nested_fields ||= v.map do |k, sv| Post::TemplateField.new post, k, sv end end # Obtiene los valores posibles para el campo de la plantilla def values - return 'false' if self.value == false - return 'true' if self.value == true + return 'false' if value == false + return 'true' if value == true # XXX por alguna razón `value` no refiere a value() :/ - return '' if STRING_VALUES.include? self.value + return '' if STRING_VALUES.include? value # Las listas cerradas no necesitan mayor procesamiento - return self.value if array? && closed? && self.value.count > 1 + return value if array? && closed? && value.count > 1 # Y las vacías tampoco - return self.value if array? && self.value.empty? + return value if array? && value.empty? # Ahorrarnos el trabajo return @values if @values @@ -301,7 +304,7 @@ class Post collection, attr, subattr = v.split('/', 3) if collection == 'site' - # TODO puede ser peligroso permitir acceder a cualquier + # TODO: puede ser peligroso permitir acceder a cualquier # atributo de site? No estamos trayendo nada fuera de # lo normal post.site.send(attr.to_sym) @@ -311,11 +314,11 @@ class Post # TODO volver recursivo! elsif subattr post.site.everything_of(attr, lang: collection) - .compact - .map { |sv| sv[subattr] } - .flatten - .compact - .uniq + .compact + .map { |sv| sv[subattr] } + .flatten + .compact + .uniq else post.site.everything_of(attr, lang: collection).compact end @@ -331,7 +334,7 @@ class Post if _value.count == 1 _value = [(_value.first + value).uniq] elsif _value.count == 2 - _value = _value.each_with_index.map do |v,i| + _value = _value.each_with_index.map do |v, i| v + value.fetch(i, []) end end diff --git a/app/models/site.rb b/app/models/site.rb index a25cd03..93c6712 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true + # Un sitio es un directorio dentro del directorio de sitios de cada # Usuaria class Site - attr_accessor :jekyll, :collections attr_reader :path @@ -71,8 +72,8 @@ class Site def name @name ||= File.basename(@jekyll.config['source']) end - alias :id :name - alias :to_s :name + alias id name + alias to_s name def name_with_i18n(lang) [name, lang].join('/') @@ -108,9 +109,7 @@ class Site @jekyll.config end - def collections - @collections - end + attr_reader :collections def collections_names @jekyll.config['collections'].keys @@ -132,6 +131,7 @@ class Site # Devuelve nil si la colección no existe def posts_for(collection) return unless collections_names.include? collection + # Si pedimos 'posts' pero estamos en un sitio traducido, traemos el # idioma actual collection = default_lang if collection == 'posts' && i18n? @@ -192,6 +192,7 @@ class Site def invitadxs return [] unless invitadxs? + @invitadxs ||= File.read(invitadxs_file).split("\n").map do |i| Invitadx.find_by_email(i) end @@ -208,7 +209,7 @@ class Site def defail FileUtils.rm failed_file if failed? end - alias :defail! :defail + alias defail! defail def build_log File.join(path, 'build.log') @@ -225,13 +226,13 @@ class Site def enqueued? File.exist? queue_file end - alias :queued? :enqueued? + alias queued? enqueued? # El sitio se genera cuando se coloca en una cola de generación, para # que luego lo construya un cronjob def enqueue defail! - # TODO ya van tres métodos donde usamos esta idea, convertir en un + # TODO: ya van tres métodos donde usamos esta idea, convertir en un # helper o algo r = File.open(queue_file, File::RDWR | File::CREAT, 0o640) do |f| # Bloquear el archivo para que no sea accedido por otro @@ -249,19 +250,17 @@ class Site f.truncate(f.pos) end end - alias :enqueue! :enqueue + alias enqueue! enqueue # Eliminar de la cola def dequeue FileUtils.rm(queue_file) if enqueued? end - alias :dequeue! :dequeue + alias dequeue! dequeue # Verifica si los posts están ordenados def ordered?(collection = 'posts') - posts_for(collection).map do |p| - p.order - end.all? + posts_for(collection).map(&:order).all? end # Reordena la colección usando la posición informada @@ -293,10 +292,10 @@ class Site # Reordena la colección usando la posición actual de los artículos def reorder_collection!(collection = 'posts') - order = Hash[posts_for(collection).count.times.map { |i| [i.to_s,i.to_s] }] + order = Hash[posts_for(collection).count.times.map { |i| [i.to_s, i.to_s] }] reorder_collection collection, order end - alias :reorder_posts! :reorder_collection! + alias reorder_posts! reorder_collection! # Obtener una ruta disponible para Sutty def get_url_for_sutty(path) @@ -336,9 +335,9 @@ class Site # Especificamos `safe` para no cargar los _plugins, que interfieren # entre sitios incluso config = ::Jekyll.configuration('source' => path, - 'destination' => File.join(path, '_site'), - 'safe' => true, - 'watch' => false) + 'destination' => File.join(path, '_site'), + 'safe' => true, + 'watch' => false) # No necesitamos cargar plugins en este momento %w[plugins gems theme].each do |unneeded| @@ -348,10 +347,8 @@ class Site # Si estamos usando nuestro propio plugin de i18n, los posts están # en "colecciones" i18n = config.dig('i18n') - if i18n - i18n.each do |i| - config['collections'][i] = {} - end + i18n&.each do |i| + config['collections'][i] = {} end Jekyll::Site.new(config) diff --git a/app/models/usuaria.rb b/app/models/usuaria.rb index 68647fb..707c7b2 100644 --- a/app/models/usuaria.rb +++ b/app/models/usuaria.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Un modelo para la usuaria que no se corresponde con una base de datos # porque vienen de IMAP # diff --git a/app/policies/i18n_policy.rb b/app/policies/i18n_policy.rb index 68b2949..899a3ec 100644 --- a/app/policies/i18n_policy.rb +++ b/app/policies/i18n_policy.rb @@ -1,6 +1,7 @@ -class I18nPolicy < SuttyPolicy +# frozen_string_literal: true - def initialize(usuarix, i18n) +class I18nPolicy < SuttyPolicy + def initialize(usuarix, _i18n) @usuarix = usuarix end diff --git a/app/policies/invitadx_policy.rb b/app/policies/invitadx_policy.rb index 402b201..6c1a5d9 100644 --- a/app/policies/invitadx_policy.rb +++ b/app/policies/invitadx_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class InvitadxPolicy attr_reader :usuarix, :model diff --git a/app/policies/post_policy.rb b/app/policies/post_policy.rb index f3aaba1..9af48ea 100644 --- a/app/policies/post_policy.rb +++ b/app/policies/post_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class PostPolicy < SuttyPolicy attr_reader :post diff --git a/app/policies/site_policy.rb b/app/policies/site_policy.rb index 3050f30..a243fa6 100644 --- a/app/policies/site_policy.rb +++ b/app/policies/site_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SitePolicy < SuttyPolicy attr_reader :site diff --git a/app/policies/sutty_policy.rb b/app/policies/sutty_policy.rb index 4ca31a4..23d71d5 100644 --- a/app/policies/sutty_policy.rb +++ b/app/policies/sutty_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class SuttyPolicy attr_reader :usuarix diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 5757999..dfac48d 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -117,7 +117,7 @@ - @post.template_fields.each do |template| - next unless type = template.type - if template.title.present? - %h1= template.title + %h1{id: template.title.tr(' ', '_').titleize}= template.title - value = @post.new? ? template.values : @post.get_front_matter(template.key) .form-group = label_tag "post_#{template}", id: template do diff --git a/bin/bundle b/bin/bundle index 524dfd3..6965387 100755 --- a/bin/bundle +++ b/bin/bundle @@ -8,22 +8,23 @@ # this file is here to facilitate running it. # -require "rubygems" +require 'rubygems' m = Module.new do - module_function + module_function def invoked_as_script? - File.expand_path($0) == File.expand_path(__FILE__) + File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__) end def env_var_version - ENV["BUNDLER_VERSION"] + ENV['BUNDLER_VERSION'] end def cli_arg_version return unless invoked_as_script? # don't want to hijack other binstubs - return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update` + bundler_version = nil update_index = nil ARGV.each_with_index do |a, i| @@ -31,23 +32,24 @@ m = Module.new do bundler_version = a end next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = $1 || ">= 0.a" + + bundler_version = Regexp.last_match(1) || '>= 0.a' update_index = i end bundler_version end def gemfile - gemfile = ENV["BUNDLE_GEMFILE"] + gemfile = ENV['BUNDLE_GEMFILE'] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../../Gemfile", __FILE__) + File.expand_path('../Gemfile', __dir__) end def lockfile lockfile = case File.basename(gemfile) - when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile) else "#{gemfile}.lock" end File.expand_path(lockfile) @@ -55,8 +57,10 @@ m = Module.new do def lockfile_version return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) end @@ -68,24 +72,26 @@ m = Module.new do end def load_bundler! - ENV["BUNDLE_GEMFILE"] ||= gemfile + ENV['BUNDLE_GEMFILE'] ||= gemfile # must dup string for RG < 1.8 compatibility activate_bundler(bundler_version.dup) end def activate_bundler(bundler_version) - if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") - bundler_version = "< 2" + if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new('2.0') + bundler_version = '< 2' end gem_error = activation_error_handling do - gem "bundler", bundler_version + gem 'bundler', bundler_version end return if gem_error.nil? + require_error = activation_error_handling do - require "bundler/version" + require 'bundler/version' end return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" exit 42 end @@ -100,6 +106,4 @@ end m.load_bundler! -if m.invoked_as_script? - load Gem.bin_path("bundler", "bundle") -end +load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script? diff --git a/bin/cap b/bin/cap index db774dc..2410b2c 100755 --- a/bin/cap +++ b/bin/cap @@ -8,14 +8,14 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300)) load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. @@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this end end -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("capistrano", "cap") +load Gem.bin_path('capistrano', 'cap') diff --git a/bin/capify b/bin/capify index 6892100..eebf2d2 100755 --- a/bin/capify +++ b/bin/capify @@ -8,14 +8,14 @@ # this file is here to facilitate running it. # -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if /This file was generated by Bundler/.match?(File.read(bundle_binstub, 300)) load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. @@ -23,7 +23,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this end end -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("capistrano", "capify") +load Gem.bin_path('capistrano', 'capify') diff --git a/bin/rails b/bin/rails index 5badb2f..3504c3f 100755 --- a/bin/rails +++ b/bin/rails @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/bin/rake b/bin/rake index d87d5f5..1fe6cf0 100755 --- a/bin/rake +++ b/bin/rake @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/bin/setup b/bin/setup index 78c4e86..3b7333e 100755 --- a/bin/setup +++ b/bin/setup @@ -1,10 +1,12 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -21,7 +23,6 @@ chdir APP_ROOT do # Install JavaScript dependencies if using Yarn # system('bin/yarn') - # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') # cp 'config/database.yml.sample', 'config/database.yml' diff --git a/bin/spring b/bin/spring index fb2ec2e..9bd27ec 100755 --- a/bin/spring +++ b/bin/spring @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # This file loads spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. @@ -8,7 +9,7 @@ unless defined?(Spring) require 'bundler' lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) - spring = lockfile.specs.detect { |spec| spec.name == "spring" } + spring = lockfile.specs.detect { |spec| spec.name == 'spring' } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version diff --git a/bin/update b/bin/update index a8e4462..1d6aa6a 100755 --- a/bin/update +++ b/bin/update @@ -1,10 +1,12 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'pathname' require 'fileutils' include FileUtils # path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) +APP_ROOT = Pathname.new File.expand_path('..', __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") diff --git a/bin/whenever b/bin/whenever index 7350453..a29ab70 100755 --- a/bin/whenever +++ b/bin/whenever @@ -8,14 +8,14 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) load(bundle_binstub) if File.file?(bundle_binstub) -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("whenever", "whenever") +load Gem.bin_path('whenever', 'whenever') diff --git a/bin/wheneverize b/bin/wheneverize index de812b6..8e7491a 100755 --- a/bin/wheneverize +++ b/bin/wheneverize @@ -8,14 +8,14 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path('bundle', __dir__) load(bundle_binstub) if File.file?(bundle_binstub) -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", - Pathname.new(__FILE__).realpath) +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("whenever", "wheneverize") +load Gem.bin_path('whenever', 'wheneverize') diff --git a/bin/yarn b/bin/yarn index c2bacef..80b670d 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,11 +1,11 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + VENDOR_PATH = File.expand_path('..', __dir__) Dir.chdir(VENDOR_PATH) do - begin - exec "yarnpkg #{ARGV.join(" ")}" - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end + exec "yarnpkg #{ARGV.join(' ')}" +rescue Errno::ENOENT + warn 'Yarn executable was not detected in the system.' + warn 'Download Yarn at https://yarnpkg.com/en/docs/install' + exit 1 end diff --git a/config.ru b/config.ru index f7ba0b5..842bccc 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/config/application.rb b/config/application.rb index e3c36b1..2cc92e8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + require_relative 'boot' -require "rails" +require 'rails' # Pick the frameworks you want: -require "active_model/railtie" -require "active_job/railtie" -require "active_record/railtie" -require "action_controller/railtie" -require "action_mailer/railtie" -require "action_view/railtie" +require 'active_model/railtie' +require 'active_job/railtie' +require 'active_record/railtie' +require 'action_controller/railtie' +require 'action_mailer/railtie' +require 'action_view/railtie' # require "action_cable/engine" -require "sprockets/railtie" -require "rails/test_unit/railtie" +require 'sprockets/railtie' +require 'rails/test_unit/railtie' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. diff --git a/config/boot.rb b/config/boot.rb index 30f5120..30e594e 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. diff --git a/config/deploy.rb b/config/deploy.rb index ae2674e..5b3fcc7 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,11 +1,12 @@ # frozen_string_literal: true + set :application, 'sutty' set :repo_url, 'git@0xacab.org:itacate-kefir/sutty.git' set :bundle_flags, '--deployment' set :default_env, path: '/usr/lib/passenger/bin:$PATH' -set :linked_dirs, %w{_sites _deploy _usuarias _invitadxs public/covers} -set :linked_files, %w{.env db/production.sqlite3} +set :linked_dirs, %w[_sites _deploy _usuarias _invitadxs public/covers] +set :linked_files, %w[.env db/production.sqlite3] set :keep_releases, 1 diff --git a/config/deploy/example.rb b/config/deploy/example.rb index c1ace7c..29f5abf 100644 --- a/config/deploy/example.rb +++ b/config/deploy/example.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + set :deploy_user, 'DEPLOY_USER' set :deploy_to, '/srv/http/sutty.kefir.red' set :branch, 'rails' @@ -11,7 +12,7 @@ set :rbenv_type, :user set :rbenv_ruby, '2.3.6' set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" -set :rbenv_map_bins, %w(rake gem bundle ruby rails) +set :rbenv_map_bins, %w[rake gem bundle ruby rails] set :rbenv_roles, :all # default value # Evitar compilar nokogiri @@ -19,4 +20,4 @@ set :bundle_env_variables, nokogiri_use_system_libraries: 1 server 'DEPLOY_SERVER', user: fetch(:deploy_user), - roles: %w(app web db) + roles: %w[app web db] diff --git a/config/deploy/production.rb b/config/deploy/production.rb index 94e514e..07c0a26 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + set :deploy_user, 'app' set :deploy_to, '/srv/http/sutty.kefir.red' set :branch, 'rails' @@ -11,7 +12,7 @@ set :rbenv_type, :user set :rbenv_ruby, '2.3.6' set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec" -set :rbenv_map_bins, %w(rake gem bundle ruby rails) +set :rbenv_map_bins, %w[rake gem bundle ruby rails] set :rbenv_roles, :all # default value # Evitar compilar nokogiri @@ -19,4 +20,4 @@ set :bundle_env_variables, nokogiri_use_system_libraries: 1 server 'miso', user: fetch(:deploy_user), - roles: %w(app web db) + roles: %w[app web db] diff --git a/config/environment.rb b/config/environment.rb index 426333b..d5abe55 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Load the Rails application. require_relative 'application' diff --git a/config/environments/development.rb b/config/environments/development.rb index 5d13e7a..ad1c4d9 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/environments/production.rb b/config/environments/production.rb index 7474a05..924b6ef 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. @@ -39,7 +41,6 @@ Rails.application.configure do # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -48,7 +49,7 @@ Rails.application.configure do config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -76,7 +77,7 @@ Rails.application.configure do # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) @@ -93,9 +94,9 @@ Rails.application.configure do config.action_mailer.default_options = { from: ENV.fetch('DEFAULT_FROM', 'sutty@kefir.red') } config.middleware.use ExceptionNotification::Rack, - email: { - email_prefix: '[ERROR]', - sender_address: %(sutty@kefir.red), - exception_recipients: 'sysadmin@kefir.red' - } + email: { + email_prefix: '[ERROR]', + sender_address: %(sutty@kefir.red), + exception_recipients: 'sysadmin@kefir.red' + } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 8e5cbde..669350a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb index 89d2efa..6d56e43 100644 --- a/config/initializers/application_controller_renderer.rb +++ b/config/initializers/application_controller_renderer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # ActiveSupport::Reloader.to_prepare do diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 4b828e8..a9b0d0f 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Version of your assets, change this if you want to expire all your assets. diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index 59385cd..4b63f28 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. diff --git a/config/initializers/carrierwave.rb b/config/initializers/carrierwave.rb index 2ff728f..8b11537 100644 --- a/config/initializers/carrierwave.rb +++ b/config/initializers/carrierwave.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + CarrierWave.configure do |config| - config.permissions = 0640 - config.directory_permissions = 0750 + config.permissions = 0o640 + config.directory_permissions = 0o750 config.storage = :file end diff --git a/config/initializers/commonmarker.rb b/config/initializers/commonmarker.rb index 4f98c68..4d6743f 100644 --- a/config/initializers/commonmarker.rb +++ b/config/initializers/commonmarker.rb @@ -1,18 +1,17 @@ +# frozen_string_literal: true + require 'commonmarker' module Haml::Filters - - remove_filter("Markdown") #remove the existing Markdown filter + remove_filter('Markdown') # remove the existing Markdown filter module Markdown - include Haml::Filters::Base def render(text) CommonMarker.render_html(text, - [:TABLE_PREFER_STYLE_ATTRIBUTES], - [:table,:strikethrough,:autolink,:tagfilter]) + [:TABLE_PREFER_STYLE_ATTRIBUTES], + %i[table strikethrough autolink tagfilter]) end - end end diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb index 5a6a32d..ee8dff9 100644 --- a/config/initializers/cookies_serializer.rb +++ b/config/initializers/cookies_serializer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1..7a4f47b 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index d5cf5d8..cd74149 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.plural 'invitadx', 'invitadxs' inflect.singular 'invitadxs', 'invitadx' diff --git a/config/initializers/locale.rb b/config/initializers/locale.rb index 71e5a74..056f48a 100644 --- a/config/initializers/locale.rb +++ b/config/initializers/locale.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + Rails.application.configure do - config.i18n.available_locales = [:es, :en, :ar] + config.i18n.available_locales = %i[es en ar] config.i18n.default_locale = :es end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index dc18996..be6fedc 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: diff --git a/config/initializers/warden.rb b/config/initializers/warden.rb index aec9a8b..b527966 100644 --- a/config/initializers/warden.rb +++ b/config/initializers/warden.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'warden/imap' require 'warden/email_and_password' Rails.configuration.middleware.use RailsWarden::Manager do |manager| manager.default_strategies :email, :imap - manager.failure_app = -> (env) { LoginController.action(:new).call(env) } + manager.failure_app = ->(env) { LoginController.action(:new).call(env) } end class Warden::SessionSerializer diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index bbfc396..2f3c0db 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which diff --git a/config/puma.rb b/config/puma.rb index 1e19380..7d53b13 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,19 +1,21 @@ +# frozen_string_literal: true + # Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 1 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index 4340a9b..fab13c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Rails.application.routes.draw do root 'application#index' @@ -7,16 +9,15 @@ Rails.application.routes.draw do get 'markdown', to: 'application#markdown' - # XXX Mantenemos solo esta ruta acá porque form_for no reconoce @site # como un objeto válido resources :invitadxs, only: [:create] - resources :sites, only: [:index, :show], constraints: { site_id: /[^\/]+/, id: /[^\/]+/ } do + resources :sites, only: %i[index show], constraints: { site_id: %r{[^/]+}, id: %r{[^/]+} } do get 'public/:type/:basename', to: 'sites#send_public_file' resources :posts resources :templates - resources :invitadxs, only: [:index, :new, :show] do + resources :invitadxs, only: %i[index new show] do get :confirmation, to: 'invitadxs#confirmation' end get :'invitadxs/login/new', to: 'login#new' diff --git a/config/schedule.rb b/config/schedule.rb index 7174101..c17dbfd 100644 --- a/config/schedule.rb +++ b/config/schedule.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + env 'MAILTO', 'sysadmin@kefir.red' job_type :bash, 'cd :path && ./bin/:task' diff --git a/config/spring.rb b/config/spring.rb index 0b96270..b1293ae 100644 --- a/config/spring.rb +++ b/config/spring.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + # https://github.com/thoughtbot/ember-cli-rails/issues/479#issuecomment-241302961 Spring::Watcher::Listen.class_eval do def base_directories - %w(app config db lib test vendor) + %w[app config db lib test vendor] .uniq.map { |path| Pathname.new(File.join(root, path)) } end end -%w( +%w[ .ruby-version .rbenv-vars tmp/restart.txt tmp/caching-dev.txt -).each { |path| Spring.watch(path) } +].each { |path| Spring.watch(path) } diff --git a/db/migrate/20180925183241_create_invitadxs.rb b/db/migrate/20180925183241_create_invitadxs.rb index 7fafd54..99dfb87 100644 --- a/db/migrate/20180925183241_create_invitadxs.rb +++ b/db/migrate/20180925183241_create_invitadxs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateInvitadxs < ActiveRecord::Migration[5.1] def change create_table :invitadxs do |t| diff --git a/db/migrate/20190211184815_add_acepta_politicas_de_privacidad_to_invitadx.rb b/db/migrate/20190211184815_add_acepta_politicas_de_privacidad_to_invitadx.rb index d2cec55..a917389 100644 --- a/db/migrate/20190211184815_add_acepta_politicas_de_privacidad_to_invitadx.rb +++ b/db/migrate/20190211184815_add_acepta_politicas_de_privacidad_to_invitadx.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddAceptaPoliticasDePrivacidadToInvitadx < ActiveRecord::Migration[5.1] def change add_column :invitadxs, :acepta_politicas_de_privacidad, :boolean, default: false diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2a..ebd1889 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # diff --git a/lib/warden/email_and_password.rb b/lib/warden/email_and_password.rb index 8f05f00..3586f9e 100644 --- a/lib/warden/email_and_password.rb +++ b/lib/warden/email_and_password.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'email_address' module Warden module EmailAndPassword - class Strategy < Warden::Strategies::Base def valid? return false unless params.include? 'username' return false unless params.include? 'password' + username = params['username'] @email = EmailAddress.new(username, host_validation: :a) diff --git a/lib/warden/imap.rb b/lib/warden/imap.rb index a5f5646..87ade2e 100644 --- a/lib/warden/imap.rb +++ b/lib/warden/imap.rb @@ -55,4 +55,3 @@ module Warden end end end - diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index d19212a..652febb 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -1,4 +1,6 @@ -require "test_helper" +# frozen_string_literal: true + +require 'test_helper' class ApplicationSystemTestCase < ActionDispatch::SystemTestCase driven_by :selenium, using: :chrome, screen_size: [1400, 1400] diff --git a/test/models/post_test.rb b/test/models/post_test.rb index c67bdb6..ee441b4 100644 --- a/test/models/post_test.rb +++ b/test/models/post_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class PostTest < ActiveSupport::TestCase diff --git a/test/models/site_test.rb b/test/models/site_test.rb index 52deb29..e655a9d 100644 --- a/test/models/site_test.rb +++ b/test/models/site_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class SiteTest < ActiveSupport::TestCase @@ -9,7 +11,7 @@ class SiteTest < ActiveSupport::TestCase @site.read end - test "El directorio es un sitio jekyll" do + test 'El directorio es un sitio jekyll' do assert Site.jekyll?(@path) end @@ -27,21 +29,21 @@ class SiteTest < ActiveSupport::TestCase test 'No podemos poner órdenes arbitrarios' do total = @site.posts.count - new_order = Hash[total.times.map { |i| [i.to_s,rand(total)] }] + new_order = Hash[total.times.map { |i| [i.to_s, rand(total)] }] assert_not @site.reorder_collection('posts', new_order) end test 'Si les damos un orden alternativo los reordenamos' do total = @site.posts.count - order = total.times.map { |i| i.to_s } + order = total.times.map(&:to_s) new_order = Hash[order.zip(order.shuffle)] assert @site.reorder_collection('posts', new_order) # podemos hacer este test porque reordenar los posts no ordena el # array - new_order.each do |k,v| + new_order.each do |k, v| v = v.to_i k = k.to_i assert_equal v, @site.posts[k].order @@ -50,14 +52,14 @@ class SiteTest < ActiveSupport::TestCase test 'Podemos reordenar solo una parte de los artículos' do total = @site.posts.count - order = (total - rand(total - 1)).times.map { |i| i.to_s } + order = (total - rand(total - 1)).times.map(&:to_s) new_order = Hash[order.zip(order.shuffle)] assert @site.reorder_collection('posts', new_order) # podemos hacer este test porque reordenar los posts no ordena el # array - new_order.each do |k,v| + new_order.each do |k, v| v = v.to_i k = k.to_i assert_equal v, @site.posts[k].order @@ -75,7 +77,7 @@ class SiteTest < ActiveSupport::TestCase test 'El sitio tiene layouts' do assert_equal %w[anexo archive default feed header.ar header.en - header.es header license.ar license.en license.es license pandoc - politicas sesion simple style ].sort, @site.layouts + header.es header license.ar license.en license.es license pandoc + politicas sesion simple style ].sort, @site.layouts end end diff --git a/test/models/usuaria_test.rb b/test/models/usuaria_test.rb index fc7d103..1bff620 100644 --- a/test/models/usuaria_test.rb +++ b/test/models/usuaria_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class UsuariaTest < ActiveSupport::TestCase @@ -6,11 +8,11 @@ class UsuariaTest < ActiveSupport::TestCase @usuaria = Usuaria.find(@mail) end - test "La usuaria puede encontrarse por su mail" do + test 'La usuaria puede encontrarse por su mail' do assert_equal @mail, @usuaria.username end - test "La usuaria tiene sitios" do + test 'La usuaria tiene sitios' do @usuaria.sites.each do |s| assert_equal Site, s.class end diff --git a/test/test_helper.rb b/test/test_helper.rb index aad06af..8a5709e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,6 @@ -require File.expand_path('../../config/environment', __FILE__) +# frozen_string_literal: true + +require File.expand_path('../config/environment', __dir__) require 'rails/test_help' require 'open3' @@ -6,7 +8,7 @@ class ActiveSupport::TestCase # Resetear el repositorio a su estado original antes de leerlo def reset_git_repo(path) Dir.chdir(path) do - Open3::popen3('git reset --hard') do |_, _, _, thread| + Open3.popen3('git reset --hard') do |_, _, _, thread| # Wait for the process to finish thread.value end