diff --git a/.rubocop.yml b/.rubocop.yml index b81f69685..61a117f97 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,7 @@ AllCops: DisplayStyleGuide: true Exclude: - "db/schema.rb" - - "lib/ckeditor/backend/active_storage.rb" + - "app/lib/ckeditor/backend/active_storage.rb" DisabledByDefault: true Bundler/DuplicatedGem: @@ -480,7 +480,7 @@ Rails/SkipsModelValidations: - update_attribute Exclude: - app/models/tenant.rb - - lib/acts_as_paranoid_aliases.rb + - app/lib/acts_as_paranoid_aliases.rb Rails/TimeZone: Enabled: true diff --git a/Gemfile b/Gemfile index fdd7d9c47..7514d7801 100644 --- a/Gemfile +++ b/Gemfile @@ -64,7 +64,7 @@ gem "wkhtmltopdf-binary", "~> 0.12.6" group :development, :test do gem "bullet", "~> 7.1.6" - gem "byebug", "~> 11.1.3" + gem "debug", "~> 1.9.2" gem "factory_bot_rails", "~> 6.4.3" gem "faker", "~> 3.2.3" gem "i18n-tasks", "~> 0.9.37" diff --git a/Gemfile.lock b/Gemfile.lock index 537e4b816..538c88148 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,7 +106,6 @@ GEM bullet (7.1.6) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) - byebug (11.1.3) cancancan (3.5.0) capistrano (3.18.1) airbrussh (>= 1.0.0) @@ -171,6 +170,9 @@ GEM daemons (1.4.1) dalli (3.2.8) date (3.3.4) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) delayed_job (4.1.11) activesupport (>= 3.0, < 8.0) delayed_job_active_record (4.1.8) @@ -282,6 +284,10 @@ GEM ruby-vips (>= 2.0.17, < 3) invisible_captcha (2.3.0) rails (>= 5.2) + io-console (0.7.2) + irb (1.12.0) + rdoc + reline (>= 0.4.2) json (2.7.1) jwt (2.7.1) kaminari (1.2.2) @@ -438,6 +444,8 @@ GEM pronto-stylelint (0.10.3) pronto (>= 0.10, < 0.12) rugged (>= 0.24, < 2.0) + psych (5.1.2) + stringio public_suffix (4.0.7) puma (5.6.8) nio4r (~> 2.0) @@ -486,10 +494,14 @@ GEM rainbow (3.1.1) rake (13.1.0) rbtree3 (0.7.1) + rdoc (6.6.3.1) + psych (>= 4.0.0) recipient_interceptor (0.3.1) mail redcarpet (3.6.0) regexp_parser (2.9.0) + reline (0.5.1) + io-console (~> 0.5) request_store (1.6.0) rack (>= 1.4) responders (3.1.1) @@ -615,6 +627,7 @@ GEM net-scp (>= 1.1.2) net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) + stringio (3.1.0) terminal-table (3.0.2) unicode-display_width (>= 1.1.1, < 3) terrapin (0.6.0) @@ -683,7 +696,6 @@ DEPENDENCIES autoprefixer-rails (~> 10.4.16) bing_translator (~> 6.2.0) bullet (~> 7.1.6) - byebug (~> 11.1.3) cancancan (~> 3.5.0) capistrano (~> 3.18.1) capistrano-bundler (~> 2.1.0) @@ -699,6 +711,7 @@ DEPENDENCIES cocoon (~> 1.2.15) daemons (~> 1.4.1) dalli (~> 3.2.8) + debug (~> 1.9.2) delayed_job_active_record (~> 4.1.8) devise (~> 4.9.3) devise-security (~> 0.18.0) diff --git a/app/components/layout/common_html_attributes_component.rb b/app/components/layout/common_html_attributes_component.rb index 0d4d8b741..63f35e0f6 100644 --- a/app/components/layout/common_html_attributes_component.rb +++ b/app/components/layout/common_html_attributes_component.rb @@ -1,4 +1,4 @@ -class Layout::CommonHTMLAttributesComponent < ApplicationComponent +class Layout::CommonHtmlAttributesComponent < ApplicationComponent use_helpers :rtl? private diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index acd3ba587..76092d526 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,3 @@ -require "application_responder" - class ApplicationController < ActionController::Base include TenantVariants include GlobalizeFallbacks diff --git a/app/controllers/management/sessions_controller.rb b/app/controllers/management/sessions_controller.rb index 2a36ded0a..0e4168975 100644 --- a/app/controllers/management/sessions_controller.rb +++ b/app/controllers/management/sessions_controller.rb @@ -1,5 +1,3 @@ -require "manager_authenticator" - class Management::SessionsController < ActionController::Base include TenantVariants include GlobalizeFallbacks diff --git a/app/helpers/layouts_helper.rb b/app/helpers/layouts_helper.rb index 32ddde240..c602ba983 100644 --- a/app/helpers/layouts_helper.rb +++ b/app/helpers/layouts_helper.rb @@ -11,6 +11,6 @@ module LayoutsHelper end def common_html_attributes - render Layout::CommonHTMLAttributesComponent.new + render Layout::CommonHtmlAttributesComponent.new end end diff --git a/app/helpers/votes_helper.rb b/app/helpers/votes_helper.rb index 8292717e4..9772a8f04 100644 --- a/app/helpers/votes_helper.rb +++ b/app/helpers/votes_helper.rb @@ -1,6 +1,6 @@ module VotesHelper def debate_percentage_of_likes(debate) - debate.likes.percent_of(debate.total_votes) + (debate.likes.to_f * 100 / debate.total_votes).to_i end def votes_percentage(vote, debate) diff --git a/lib/active_model/dates.rb b/app/lib/active_model/dates.rb similarity index 100% rename from lib/active_model/dates.rb rename to app/lib/active_model/dates.rb diff --git a/lib/active_storage/service/tenant_disk_service.rb b/app/lib/active_storage/service/tenant_disk_service.rb similarity index 100% rename from lib/active_storage/service/tenant_disk_service.rb rename to app/lib/active_storage/service/tenant_disk_service.rb diff --git a/lib/acts_as_paranoid_aliases.rb b/app/lib/acts_as_paranoid_aliases.rb similarity index 100% rename from lib/acts_as_paranoid_aliases.rb rename to app/lib/acts_as_paranoid_aliases.rb diff --git a/lib/admin_legislation_sanitizer.rb b/app/lib/admin_legislation_sanitizer.rb similarity index 100% rename from lib/admin_legislation_sanitizer.rb rename to app/lib/admin_legislation_sanitizer.rb diff --git a/lib/admin_wysiwyg_sanitizer.rb b/app/lib/admin_wysiwyg_sanitizer.rb similarity index 100% rename from lib/admin_wysiwyg_sanitizer.rb rename to app/lib/admin_wysiwyg_sanitizer.rb diff --git a/lib/age.rb b/app/lib/age.rb similarity index 100% rename from lib/age.rb rename to app/lib/age.rb diff --git a/lib/application_logger.rb b/app/lib/application_logger.rb similarity index 100% rename from lib/application_logger.rb rename to app/lib/application_logger.rb diff --git a/lib/application_responder.rb b/app/lib/application_responder.rb similarity index 100% rename from lib/application_responder.rb rename to app/lib/application_responder.rb diff --git a/lib/asset_finder.rb b/app/lib/asset_finder.rb similarity index 100% rename from lib/asset_finder.rb rename to app/lib/asset_finder.rb diff --git a/lib/authentication_logger.rb b/app/lib/authentication_logger.rb similarity index 100% rename from lib/authentication_logger.rb rename to app/lib/authentication_logger.rb diff --git a/lib/census_api.rb b/app/lib/census_api.rb similarity index 99% rename from lib/census_api.rb rename to app/lib/census_api.rb index 09fcbcc87..d290a1bbf 100644 --- a/lib/census_api.rb +++ b/app/lib/census_api.rb @@ -1,5 +1,6 @@ -include DocumentParser class CensusApi + include DocumentParser + def call(document_type, document_number) response = nil get_document_number_variants(document_type, document_number).each do |variant| diff --git a/lib/census_caller.rb b/app/lib/census_caller.rb similarity index 100% rename from lib/census_caller.rb rename to app/lib/census_caller.rb diff --git a/lib/ckeditor/backend/active_storage.rb b/app/lib/ckeditor/backend/active_storage.rb similarity index 96% rename from lib/ckeditor/backend/active_storage.rb rename to app/lib/ckeditor/backend/active_storage.rb index 8ff442443..1f990e041 100644 --- a/lib/ckeditor/backend/active_storage.rb +++ b/app/lib/ckeditor/backend/active_storage.rb @@ -67,7 +67,5 @@ module Ckeditor end end end - - autoload :ActiveStorage, "ckeditor/backend/active_storage" end end diff --git a/lib/comment_tree.rb b/app/lib/comment_tree.rb similarity index 100% rename from lib/comment_tree.rb rename to app/lib/comment_tree.rb diff --git a/lib/consul_form_builder.rb b/app/lib/consul_form_builder.rb similarity index 100% rename from lib/consul_form_builder.rb rename to app/lib/consul_form_builder.rb diff --git a/lib/assets/.keep b/app/lib/custom/.keep similarity index 100% rename from lib/assets/.keep rename to app/lib/custom/.keep diff --git a/lib/document_parser.rb b/app/lib/document_parser.rb similarity index 100% rename from lib/document_parser.rb rename to app/lib/document_parser.rb diff --git a/lib/email_digest.rb b/app/lib/email_digest.rb similarity index 100% rename from lib/email_digest.rb rename to app/lib/email_digest.rb diff --git a/lib/evaluation_comment_email.rb b/app/lib/evaluation_comment_email.rb similarity index 100% rename from lib/evaluation_comment_email.rb rename to app/lib/evaluation_comment_email.rb diff --git a/lib/geozone_stats.rb b/app/lib/geozone_stats.rb similarity index 100% rename from lib/geozone_stats.rb rename to app/lib/geozone_stats.rb diff --git a/lib/local_census.rb b/app/lib/local_census.rb similarity index 97% rename from lib/local_census.rb rename to app/lib/local_census.rb index 1f6d3f903..dc566f5fb 100644 --- a/lib/local_census.rb +++ b/app/lib/local_census.rb @@ -1,5 +1,6 @@ -include DocumentParser class LocalCensus + include DocumentParser + def call(document_type, document_number) record = nil get_document_number_variants(document_type, document_number).each do |variant| diff --git a/lib/manager_authenticator.rb b/app/lib/manager_authenticator.rb similarity index 100% rename from lib/manager_authenticator.rb rename to app/lib/manager_authenticator.rb diff --git a/lib/markdown_converter.rb b/app/lib/markdown_converter.rb similarity index 100% rename from lib/markdown_converter.rb rename to app/lib/markdown_converter.rb diff --git a/lib/merged_comment_tree.rb b/app/lib/merged_comment_tree.rb similarity index 100% rename from lib/merged_comment_tree.rb rename to app/lib/merged_comment_tree.rb diff --git a/lib/omniauth_tenant_setup.rb b/app/lib/omniauth_tenant_setup.rb similarity index 55% rename from lib/omniauth_tenant_setup.rb rename to app/lib/omniauth_tenant_setup.rb index 57d010947..1aef1cad4 100644 --- a/lib/omniauth_tenant_setup.rb +++ b/app/lib/omniauth_tenant_setup.rb @@ -1,27 +1,19 @@ module OmniauthTenantSetup class << self - def twitter - ->(env) do - oauth(env, secrets.twitter_key, secrets.twitter_secret) - end + def twitter(env) + oauth(env, secrets.twitter_key, secrets.twitter_secret) end - def facebook - ->(env) do - oauth2(env, secrets.facebook_key, secrets.facebook_secret) - end + def facebook(env) + oauth2(env, secrets.facebook_key, secrets.facebook_secret) end - def google_oauth2 - ->(env) do - oauth2(env, secrets.google_oauth2_key, secrets.google_oauth2_secret) - end + def google_oauth2(env) + oauth2(env, secrets.google_oauth2_key, secrets.google_oauth2_secret) end - def wordpress_oauth2 - ->(env) do - oauth2(env, secrets.wordpress_oauth2_key, secrets.wordpress_oauth2_secret) - end + def wordpress_oauth2(env) + oauth2(env, secrets.wordpress_oauth2_key, secrets.wordpress_oauth2_secret) end private diff --git a/lib/percentage_calculator.rb b/app/lib/percentage_calculator.rb similarity index 100% rename from lib/percentage_calculator.rb rename to app/lib/percentage_calculator.rb diff --git a/lib/remote_census_api.rb b/app/lib/remote_census_api.rb similarity index 99% rename from lib/remote_census_api.rb rename to app/lib/remote_census_api.rb index c5db70365..99ed06445 100644 --- a/lib/remote_census_api.rb +++ b/app/lib/remote_census_api.rb @@ -1,5 +1,6 @@ -include DocumentParser class RemoteCensusApi + include DocumentParser + def call(document_type, document_number, date_of_birth, postal_code) response = nil get_document_number_variants(document_type, document_number).each do |variant| diff --git a/lib/remote_translations/caller.rb b/app/lib/remote_translations/caller.rb similarity index 100% rename from lib/remote_translations/caller.rb rename to app/lib/remote_translations/caller.rb diff --git a/lib/remote_translations/microsoft/available_locales.rb b/app/lib/remote_translations/microsoft/available_locales.rb similarity index 100% rename from lib/remote_translations/microsoft/available_locales.rb rename to app/lib/remote_translations/microsoft/available_locales.rb diff --git a/lib/remote_translations/microsoft/client.rb b/app/lib/remote_translations/microsoft/client.rb similarity index 97% rename from lib/remote_translations/microsoft/client.rb rename to app/lib/remote_translations/microsoft/client.rb index ad17adccd..81ccff153 100644 --- a/lib/remote_translations/microsoft/client.rb +++ b/app/lib/remote_translations/microsoft/client.rb @@ -1,5 +1,5 @@ class RemoteTranslations::Microsoft::Client - include SentencesParser + include RemoteTranslations::Microsoft::SentencesParser CHARACTERS_LIMIT_PER_REQUEST = 5000 PREVENTING_TRANSLATION_KEY = "notranslate".freeze diff --git a/lib/remote_translations/microsoft/sentences_parser.rb b/app/lib/remote_translations/microsoft/sentences_parser.rb similarity index 100% rename from lib/remote_translations/microsoft/sentences_parser.rb rename to app/lib/remote_translations/microsoft/sentences_parser.rb diff --git a/lib/reply_email.rb b/app/lib/reply_email.rb similarity index 100% rename from lib/reply_email.rb rename to app/lib/reply_email.rb diff --git a/lib/score_calculator.rb b/app/lib/score_calculator.rb similarity index 100% rename from lib/score_calculator.rb rename to app/lib/score_calculator.rb diff --git a/lib/search_dictionary_selector.rb b/app/lib/search_dictionary_selector.rb similarity index 100% rename from lib/search_dictionary_selector.rb rename to app/lib/search_dictionary_selector.rb diff --git a/lib/sms_api.rb b/app/lib/sms_api.rb similarity index 99% rename from lib/sms_api.rb rename to app/lib/sms_api.rb index d6373e934..db61fffe3 100644 --- a/lib/sms_api.rb +++ b/app/lib/sms_api.rb @@ -1,5 +1,5 @@ require "open-uri" -class SMSApi +class SmsApi attr_accessor :client def initialize diff --git a/lib/tag_sanitizer.rb b/app/lib/tag_sanitizer.rb similarity index 100% rename from lib/tag_sanitizer.rb rename to app/lib/tag_sanitizer.rb diff --git a/lib/user_segments.rb b/app/lib/user_segments.rb similarity index 100% rename from lib/user_segments.rb rename to app/lib/user_segments.rb diff --git a/lib/wysiwyg_sanitizer.rb b/app/lib/wysiwyg_sanitizer.rb similarity index 100% rename from lib/wysiwyg_sanitizer.rb rename to app/lib/wysiwyg_sanitizer.rb diff --git a/app/models/custom/setting.rb b/app/models/custom/setting.rb index d6c6dff6a..d4fa3a51f 100644 --- a/app/models/custom/setting.rb +++ b/app/models/custom/setting.rb @@ -1,4 +1,4 @@ -require_dependency Rails.root.join("app", "models", "setting").to_s +load Rails.root.join("app", "models", "setting.rb") class Setting class << self diff --git a/app/models/debate.rb b/app/models/debate.rb index 4316b4777..c4ca74af0 100644 --- a/app/models/debate.rb +++ b/app/models/debate.rb @@ -1,5 +1,3 @@ -require "numeric" - class Debate < ApplicationRecord include Flaggable include Taggable diff --git a/app/models/verification/sms.rb b/app/models/verification/sms.rb index 4e8e07f71..ad23dda00 100644 --- a/app/models/verification/sms.rb +++ b/app/models/verification/sms.rb @@ -24,7 +24,7 @@ class Verification::Sms end def send_sms - SMSApi.new.sms_deliver(user.unconfirmed_phone, user.sms_confirmation_code) + SmsApi.new.sms_deliver(user.unconfirmed_phone, user.sms_confirmation_code) end def verified? diff --git a/config/application.rb b/config/application.rb index a2cf9bfde..a4cc6006b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -32,10 +32,6 @@ module Consul # in any CONSUL DEMOCRACY installations config.active_support.use_authenticated_message_encryption = false - # Keep using the classic autoloader until we decide how custom classes - # should work with zeitwerk - config.autoloader = :classic - # Don't enable has_many_inversing because it doesn't seem to currently # work with the _count database columns we use for caching purposes config.active_record.has_many_inversing = false @@ -125,8 +121,6 @@ module Consul config.assets.paths << Rails.root.join("node_modules", "jquery-ui", "themes", "base") config.assets.paths << Rails.root.join("node_modules") - # Add lib to the autoload path - config.autoload_paths << Rails.root.join("lib") config.active_job.queue_adapter = :delayed_job # CONSUL DEMOCRACY specific custom overrides @@ -134,12 +128,19 @@ module Consul # * English: https://github.com/consuldemocracy/consuldemocracy/blob/master/CUSTOMIZE_EN.md # * Spanish: https://github.com/consuldemocracy/consuldemocracy/blob/master/CUSTOMIZE_ES.md # - config.autoload_paths << "#{Rails.root}/app/components/custom" - config.autoload_paths << "#{Rails.root}/app/controllers/custom" - config.autoload_paths << "#{Rails.root}/app/graphql/custom" - config.autoload_paths << "#{Rails.root}/app/mailers/custom" - config.autoload_paths << "#{Rails.root}/app/models/custom" - config.autoload_paths << "#{Rails.root}/app/models/custom/concerns" + + [ + "app/components/custom", + "app/controllers/custom", + "app/graphql/custom", + "app/lib/custom", + "app/mailers/custom", + "app/models/custom", + "app/models/custom/concerns" + ].each do |path| + config.autoload_paths << Rails.root.join(path) + config.eager_load_paths << Rails.root.join(path) + end config.paths["app/views"].unshift(Rails.root.join("app", "views", "custom")) diff --git a/config/environments/development.rb b/config/environments/development.rb index 704a1e63e..df04c5583 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -72,6 +72,7 @@ Rails.application.configure do # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + config.eager_load_paths << "#{Rails.root}/spec/mailers/previews" config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews" # Limit size of local logs diff --git a/config/environments/production.rb b/config/environments/production.rb index 1b200d1ab..57ba25c25 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -12,11 +12,6 @@ Rails.application.configure do # Rake tasks automatically ignore this option for performance. config.eager_load = true - # Because autoloading is disabled in production environments with Rails 5, - # using autoload_paths will not load needed classes from specified paths. - # The solution to this, is to ask Rails to eager load classes. - config.eager_load_paths += ["#{config.root}/lib"] - # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true diff --git a/config/environments/test.rb b/config/environments/test.rb index 530286e6c..369978ed2 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -20,7 +20,7 @@ Rails.application.configure do # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true diff --git a/config/initializers/acts_as_taggable_on.rb b/config/initializers/acts_as_taggable_on.rb index 7dea4aafc..af1045a80 100644 --- a/config/initializers/acts_as_taggable_on.rb +++ b/config/initializers/acts_as_taggable_on.rb @@ -7,6 +7,12 @@ ActsAsTaggableOn.setup do |config| # config.base_class = "ApplicationRecord" end +Rails.application.reloader.to_prepare do + ActsAsTaggableOn::Tag.class_eval do + include Graphqlable + end +end + module ActsAsTaggableOn Tagging.class_eval do after_create :increment_tag_custom_counter @@ -39,8 +45,6 @@ module ActsAsTaggableOn kind == "category" end - include Graphqlable - scope :public_for_api, -> do where( kind: [nil, "category"], diff --git a/config/initializers/age.rb b/config/initializers/age.rb deleted file mode 100644 index d0928527e..000000000 --- a/config/initializers/age.rb +++ /dev/null @@ -1 +0,0 @@ -require "age" diff --git a/config/initializers/audited.rb b/config/initializers/audited.rb index 14de509e8..13e1e0793 100644 --- a/config/initializers/audited.rb +++ b/config/initializers/audited.rb @@ -1,4 +1,4 @@ Audited.config do |config| - config.audit_class = ::Audit + config.audit_class = "::Audit" config.ignored_default_callbacks = [:touch] end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 23d2d0a6a..9baa69960 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -1,4 +1,4 @@ -require Rails.root.join("lib", "omniauth_wordpress") +require Rails.root.join("lib", "omni_auth", "strategies", "wordpress") # Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. @@ -270,23 +270,22 @@ Devise.setup do |config| config.omniauth :twitter, Rails.application.secrets.twitter_key, Rails.application.secrets.twitter_secret, - setup: OmniauthTenantSetup.twitter + setup: ->(env) { OmniauthTenantSetup.twitter(env) } config.omniauth :facebook, Rails.application.secrets.facebook_key, Rails.application.secrets.facebook_secret, scope: "email", info_fields: "email,name,verified", - setup: OmniauthTenantSetup.facebook + setup: ->(env) { OmniauthTenantSetup.facebook(env) } config.omniauth :google_oauth2, Rails.application.secrets.google_oauth2_key, Rails.application.secrets.google_oauth2_secret, - setup: OmniauthTenantSetup.google_oauth2 + setup: ->(env) { OmniauthTenantSetup.google_oauth2(env) } config.omniauth :wordpress_oauth2, Rails.application.secrets.wordpress_oauth2_key, Rails.application.secrets.wordpress_oauth2_secret, - strategy_class: OmniAuth::Strategies::Wordpress, client_options: { site: Rails.application.secrets.wordpress_oauth2_site }, - setup: OmniauthTenantSetup.wordpress_oauth2 + setup: ->(env) { OmniauthTenantSetup.wordpress_oauth2(env) } # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/initializers/disable_active_storage_uploads.rb b/config/initializers/disable_active_storage_uploads.rb index fa5a52a91..f7bf09fb0 100644 --- a/config/initializers/disable_active_storage_uploads.rb +++ b/config/initializers/disable_active_storage_uploads.rb @@ -1,11 +1,13 @@ -ActiveStorage::DirectUploadsController.class_eval do - def create - head :unauthorized +Rails.application.reloader.to_prepare do + ActiveStorage::DirectUploadsController.class_eval do + def create + head :unauthorized + end end -end -ActiveStorage::DiskController.class_eval do - def update - head :unauthorized + ActiveStorage::DiskController.class_eval do + def update + head :unauthorized + end end end diff --git a/config/initializers/globalize.rb b/config/initializers/globalize.rb index 0a63e4d71..9f098a9b0 100644 --- a/config/initializers/globalize.rb +++ b/config/initializers/globalize.rb @@ -1,3 +1,9 @@ +Rails.application.reloader.to_prepare do + Globalize::ActiveRecord::Translation.class_eval do + include SkipValidation + end +end + module Globalize module ActiveRecord module InstanceMethods @@ -9,10 +15,6 @@ module Globalize end end end - - class Translation - include SkipValidation - end end end diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index e95cdbca7..17b2717d6 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -18,5 +18,6 @@ ActiveSupport::Inflector.inflections(:en) do |inflect| inflect.plural(/^(\d+)$/i, '\1') inflect.acronym "SDG" + inflect.acronym "WYSIWYG" inflect.irregular "organización", "organizaciones" end diff --git a/config/initializers/vote_extensions.rb b/config/initializers/vote_extensions.rb index c70392250..080610432 100644 --- a/config/initializers/vote_extensions.rb +++ b/config/initializers/vote_extensions.rb @@ -1,6 +1,10 @@ -ActsAsVotable::Vote.class_eval do - include Graphqlable +Rails.application.reloader.to_prepare do + ActsAsVotable::Vote.class_eval do + include Graphqlable + end +end +ActsAsVotable::Vote.class_eval do belongs_to :signature belongs_to :budget_investment, foreign_key: "votable_id", class_name: "Budget::Investment" diff --git a/lib/numeric.rb b/lib/numeric.rb deleted file mode 100644 index ab9b212b9..000000000 --- a/lib/numeric.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Numeric - def percent_of(n) - (to_f / n * 100).to_i - end -end diff --git a/lib/omniauth_wordpress.rb b/lib/omni_auth/strategies/wordpress.rb similarity index 95% rename from lib/omniauth_wordpress.rb rename to lib/omni_auth/strategies/wordpress.rb index dc0ec1f6c..acc1bfa7e 100644 --- a/lib/omniauth_wordpress.rb +++ b/lib/omni_auth/strategies/wordpress.rb @@ -5,7 +5,7 @@ require "omniauth-oauth2" module OmniAuth module Strategies class Wordpress < OmniAuth::Strategies::OAuth2 - option :name, "wordpress_oauth2" + option :name, :wordpress_oauth2 option :client_options, {} diff --git a/spec/components/layout/common_html_attributes_component_spec.rb b/spec/components/layout/common_html_attributes_component_spec.rb index ded22103c..ecdc6187b 100644 --- a/spec/components/layout/common_html_attributes_component_spec.rb +++ b/spec/components/layout/common_html_attributes_component_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" -describe Layout::CommonHTMLAttributesComponent do - let(:component) { Layout::CommonHTMLAttributesComponent.new } +describe Layout::CommonHtmlAttributesComponent do + let(:component) { Layout::CommonHtmlAttributesComponent.new } context "with multitenancy disabled" do before { allow(Rails.application.config).to receive(:multitenancy).and_return(false) } diff --git a/spec/lib/document_parser_spec.rb b/spec/lib/document_parser_spec.rb index 6162bc9e7..be8b254ae 100644 --- a/spec/lib/document_parser_spec.rb +++ b/spec/lib/document_parser_spec.rb @@ -1,35 +1,44 @@ require "rails_helper" -include DocumentParser describe DocumentParser do + before do + dummy_class = Class.new do + include DocumentParser + end + + stub_const("DummyClass", dummy_class) + end + + let(:dummy) { DummyClass.new } + describe "#get_document_number_variants" do it "returns no variants when document_number is not defined" do - expect(DocumentParser.get_document_number_variants("1", "")).to be_empty + expect(dummy.get_document_number_variants("1", "")).to be_empty end it "trims and cleans up entry" do - expect(DocumentParser.get_document_number_variants(2, " 1 2@ 34")).to eq(["1234"]) + expect(dummy.get_document_number_variants(2, " 1 2@ 34")).to eq(["1234"]) end it "returns only one try for passports & residence cards" do - expect(DocumentParser.get_document_number_variants(2, "1234")).to eq(["1234"]) - expect(DocumentParser.get_document_number_variants(3, "1234")).to eq(["1234"]) + expect(dummy.get_document_number_variants(2, "1234")).to eq(["1234"]) + expect(dummy.get_document_number_variants(3, "1234")).to eq(["1234"]) end it "takes only the last 8 digits for dnis and resicence cards" do - expect(DocumentParser.get_document_number_variants(1, "543212345678")).to eq(["12345678"]) + expect(dummy.get_document_number_variants(1, "543212345678")).to eq(["12345678"]) end it "tries all the dni variants padding with zeroes" do - expect(DocumentParser.get_document_number_variants(1, "0123456")) + expect(dummy.get_document_number_variants(1, "0123456")) .to eq(["123456", "0123456", "00123456"]) - expect(DocumentParser.get_document_number_variants(1, "00123456")) + expect(dummy.get_document_number_variants(1, "00123456")) .to eq(["123456", "0123456", "00123456"]) end it "adds upper and lowercase letter when the letter is present" do - expect(DocumentParser.get_document_number_variants(1, "1234567A")) + expect(dummy.get_document_number_variants(1, "1234567A")) .to eq(%w[1234567 01234567 1234567a 1234567A 01234567a 01234567A]) end end diff --git a/spec/models/machine_learning_spec.rb b/spec/models/machine_learning_spec.rb index 1a0dd1735..a004b3fc9 100644 --- a/spec/models/machine_learning_spec.rb +++ b/spec/models/machine_learning_spec.rb @@ -378,6 +378,10 @@ describe MachineLearning do end describe "#run_machine_learning_scripts" do + let!(:original_fork_mode) { DEBUGGER__::CONFIG[:fork_mode] } + before { DEBUGGER__::CONFIG[:fork_mode] = "parent" } + after { DEBUGGER__::CONFIG[:fork_mode] = original_fork_mode } + it "returns true if python script executed correctly" do machine_learning = MachineLearning.new(job) diff --git a/spec/system/admin/homepage/homepage_spec.rb b/spec/system/admin/homepage/homepage_spec.rb index f0f1bec38..274c537bf 100644 --- a/spec/system/admin/homepage/homepage_spec.rb +++ b/spec/system/admin/homepage/homepage_spec.rb @@ -178,16 +178,15 @@ describe "Homepage", :admin do link_text: "Link1 text", link_url: "consul1.dev") - # TODO: uncomment again after switching to zeitwerk - # card2 = create(:widget_card, label: "Card2 label", - # title: "Card2 text", - # description: "Card2 description", - # link_text: "Link2 text", - # link_url: "consul2.dev") + card2 = create(:widget_card, label: "Card2 label", + title: "Card2 text", + description: "Card2 description", + link_text: "Link2 text", + link_url: "consul2.dev") visit root_path - expect(page).to have_css(".card", count: 1) # TODO: change to `count: 2 after switching to zeitwerk + expect(page).to have_css(".card", count: 2) within("#widget_card_#{card1.id}") do expect(page).to have_content("CARD1 LABEL") @@ -198,15 +197,14 @@ describe "Homepage", :admin do expect(page).to have_css("img[alt='#{card1.image.title}']") end - # TODO: uncomment again after switching to zeitwerk - # within("#widget_card_#{card2.id}") do - # expect(page).to have_content("CARD2 LABEL") - # expect(page).to have_content("CARD2 TEXT") - # expect(page).to have_content("Card2 description") - # expect(page).to have_content("Link2 text") - # expect(page).to have_link(href: "consul2.dev") - # expect(page).to have_css("img[alt='#{card2.image.title}']") - # end + within("#widget_card_#{card2.id}") do + expect(page).to have_content("CARD2 LABEL") + expect(page).to have_content("CARD2 TEXT") + expect(page).to have_content("Card2 description") + expect(page).to have_content("Link2 text") + expect(page).to have_link(href: "consul2.dev") + expect(page).to have_css("img[alt='#{card2.image.title}']") + end end scenario "Recomendations" do diff --git a/spec/system/admin/widgets/cards_spec.rb b/spec/system/admin/widgets/cards_spec.rb index 4f5043ae7..d753f1489 100644 --- a/spec/system/admin/widgets/cards_spec.rb +++ b/spec/system/admin/widgets/cards_spec.rb @@ -59,16 +59,14 @@ describe "Cards", :admin do scenario "Show" do card_1 = create(:widget_card, title: "Card homepage large", columns: 8) - # TODO: uncomment after switching to zeitwerk - # card_2 = create(:widget_card, title: "Card homepage medium", columns: 4) - # card_3 = create(:widget_card, title: "Card homepage small", columns: 2) + card_2 = create(:widget_card, title: "Card homepage medium", columns: 4) + card_3 = create(:widget_card, title: "Card homepage small", columns: 2) visit root_path expect(page).to have_css("#widget_card_#{card_1.id}.medium-8") - # TODO: uncomment after switching to zeitwerk - # expect(page).to have_css("#widget_card_#{card_2.id}.medium-4") - # expect(page).to have_css("#widget_card_#{card_3.id}.medium-2") + expect(page).to have_css("#widget_card_#{card_2.id}.medium-4") + expect(page).to have_css("#widget_card_#{card_3.id}.medium-2") end scenario "Edit" do diff --git a/spec/system/polls/polls_spec.rb b/spec/system/polls/polls_spec.rb index bf00eb20a..19dad5252 100644 --- a/spec/system/polls/polls_spec.rb +++ b/spec/system/polls/polls_spec.rb @@ -26,7 +26,7 @@ describe "Polls" do end scenario "Polls can be listed" do - polls = [create(:poll, :with_image)] # TODO: generate a list again after switching to zeitwerk + polls = create_list(:poll, 3, :with_image) visit polls_path @@ -210,24 +210,23 @@ describe "Polls" do expect("Second question").to appear_before("Third question") end - # TODO: uncomment after switching to zeitwerk - # scenario "Buttons to slide through images work back and forth" do - # question = create(:poll_question, :yes_no, poll: poll) - # create(:image, imageable: question.question_answers.last, title: "The no movement") - # create(:image, imageable: question.question_answers.last, title: "No movement planning") + scenario "Buttons to slide through images work back and forth" do + question = create(:poll_question, :yes_no, poll: poll) + create(:image, imageable: question.question_answers.last, title: "The no movement") + create(:image, imageable: question.question_answers.last, title: "No movement planning") - # visit poll_path(poll) + visit poll_path(poll) - # within(".orbit-bullets") do - # find("[data-slide='1']").click + within(".orbit-bullets") do + find("[data-slide='1']").click - # expect(page).to have_css ".is-active[data-slide='1']" + expect(page).to have_css ".is-active[data-slide='1']" - # find("[data-slide='0']").click + find("[data-slide='0']").click - # expect(page).to have_css ".is-active[data-slide='0']" - # end - # end + expect(page).to have_css ".is-active[data-slide='0']" + end + end scenario "Non-logged in users" do create(:poll_question, :yes_no, poll: poll)