From 9955a6dbf23e7128b6c443cf62c257834005f704 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 12:08:40 +0200 Subject: [PATCH 01/26] Update rails to 7.2 --- Gemfile | 4 +- Gemfile.lock | 539 +++++++++--------- app/models/category.rb | 2 +- app/models/user.rb | 2 +- bin/rails | 9 +- bin/rake | 7 +- bin/rubocop | 8 + bin/setup | 39 +- config/application.rb | 17 +- config/boot.rb | 2 - config/environment.rb | 2 - config/environments/development.rb | 51 +- config/environments/production.rb | 145 ++--- config/environments/test.rb | 46 +- config/initializers/assets.rb | 6 +- .../initializers/content_security_policy.rb | 46 +- .../initializers/filter_parameter_logging.rb | 8 +- config/initializers/inflections.rb | 37 +- .../new_framework_defaults_7_2.rb | 70 +++ config/initializers/permissions_policy.rb | 20 +- config/puma.rb | 64 +-- ..._to_active_storage_blobs.active_storage.rb | 22 + ..._storage_variant_records.active_storage.rb | 27 + ...e_storage_blobs_checksum.active_storage.rb | 8 + db/schema.rb | 6 +- public/406-unsupported-browser.html | 66 +++ public/icon.png | Bin 0 -> 5599 bytes public/icon.svg | 3 + 28 files changed, 670 insertions(+), 586 deletions(-) create mode 100755 bin/rubocop create mode 100644 config/initializers/new_framework_defaults_7_2.rb create mode 100644 db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb create mode 100644 db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb create mode 100644 db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb create mode 100644 public/406-unsupported-browser.html create mode 100644 public/icon.png create mode 100644 public/icon.svg diff --git a/Gemfile b/Gemfile index 0d43077b8..5e7ff028e 100644 --- a/Gemfile +++ b/Gemfile @@ -11,7 +11,7 @@ gem "jbuilder", "~> 2.7" gem "kaminari" gem "pg", "~> 1.1" gem "puma", "~> 5.0" -gem "rails", "~> 7.1", ">= 7.1.2" +gem "rails", "~> 7.2", ">= 7.2.0" gem "redis", "~> 4.0" gem "sass-rails", ">= 6" gem "hotwire-rails" @@ -48,7 +48,7 @@ gem "factory_bot_rails" # TODO: create ENV staging and use it for this group :development, :test do gem "annotate" - gem "dotenv-rails", require: "dotenv/rails-now" + gem "dotenv-rails", require: "dotenv/load" gem "pry-rails" gem "rails-controller-testing" gem "rspec-rails" diff --git a/Gemfile.lock b/Gemfile.lock index 4251970b6..7d1d9db8e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,51 +1,46 @@ GEM remote: https://rubygems.org/ specs: - actioncable (7.1.2) - actionpack (= 7.1.2) - activesupport (= 7.1.2) + actioncable (7.2.1.2) + actionpack (= 7.2.1.2) + activesupport (= 7.2.1.2) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.2) - actionpack (= 7.1.2) - activejob (= 7.1.2) - activerecord (= 7.1.2) - activestorage (= 7.1.2) - activesupport (= 7.1.2) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.2) - actionpack (= 7.1.2) - actionview (= 7.1.2) - activejob (= 7.1.2) - activesupport (= 7.1.2) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp + actionmailbox (7.2.1.2) + actionpack (= 7.2.1.2) + activejob (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) + mail (>= 2.8.0) + actionmailer (7.2.1.2) + actionpack (= 7.2.1.2) + actionview (= 7.2.1.2) + activejob (= 7.2.1.2) + activesupport (= 7.2.1.2) + mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (7.1.2) - actionview (= 7.1.2) - activesupport (= 7.1.2) + actionpack (7.2.1.2) + actionview (= 7.2.1.2) + activesupport (= 7.2.1.2) nokogiri (>= 1.8.5) racc - rack (>= 2.2.4) + rack (>= 2.2.4, < 3.2) rack-session (>= 1.0.1) rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.2) - actionpack (= 7.1.2) - activerecord (= 7.1.2) - activestorage (= 7.1.2) - activesupport (= 7.1.2) + useragent (~> 0.16) + actiontext (7.2.1.2) + actionpack (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.2) - activesupport (= 7.1.2) + actionview (7.2.1.2) + activesupport (= 7.2.1.2) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) @@ -55,49 +50,50 @@ GEM activemodel (>= 4.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - active_storage_validations (0.9.6) - activejob (>= 5.2.0) - activemodel (>= 5.2.0) - activestorage (>= 5.2.0) - activesupport (>= 5.2.0) - activejob (7.1.2) - activesupport (= 7.1.2) + active_storage_validations (1.3.0) + activejob (>= 6.1.4) + activemodel (>= 6.1.4) + activestorage (>= 6.1.4) + activesupport (>= 6.1.4) + activejob (7.2.1.2) + activesupport (= 7.2.1.2) globalid (>= 0.3.6) - activemodel (7.1.2) - activesupport (= 7.1.2) - activerecord (7.1.2) - activemodel (= 7.1.2) - activesupport (= 7.1.2) + activemodel (7.2.1.2) + activesupport (= 7.2.1.2) + activerecord (7.2.1.2) + activemodel (= 7.2.1.2) + activesupport (= 7.2.1.2) timeout (>= 0.4.0) - activestorage (7.1.2) - actionpack (= 7.1.2) - activejob (= 7.1.2) - activerecord (= 7.1.2) - activesupport (= 7.1.2) + activestorage (7.2.1.2) + actionpack (= 7.2.1.2) + activejob (= 7.2.1.2) + activerecord (= 7.2.1.2) + activesupport (= 7.2.1.2) marcel (~> 1.0) - activesupport (7.1.2) + activesupport (7.2.1.2) base64 bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) + concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) acts_as_singleton (0.0.8) activerecord (>= 3.1.0) - addressable (2.8.5) - public_suffix (>= 2.0.2, < 6.0) - airbrussh (1.4.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + airbrussh (1.5.3) sshkit (>= 1.6.1, != 1.7.0) annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) - any_login (1.5.2) - rails (>= 6.0) + any_login (1.6.0) + rails (>= 6.1) ast (2.4.2) - autoprefixer-rails (10.4.15.0) + autoprefixer-rails (10.4.19.0) execjs (~> 2) babosa (2.0.0) base64 (0.2.0) @@ -107,24 +103,23 @@ GEM bindex (0.8.1) bootsnap (1.18.4) msgpack (~> 1.2) - bootstrap (5.3.2) + bootstrap (5.3.3) autoprefixer-rails (>= 9.1.0) popper_js (>= 2.11.8, < 3) breadcrumbs_on_rails (4.1.0) railties (>= 5.0) - brow (0.4.1) - builder (3.2.4) - cancancan (3.3.0) - capistrano (3.17.1) + builder (3.3.0) + cancancan (3.6.1) + capistrano (3.19.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) sshkit (>= 1.9.0) - capistrano-bundler (2.1.0) + capistrano-bundler (2.1.1) capistrano (~> 3.1) capistrano-passenger (0.2.1) capistrano (~> 3.0) - capistrano-rails (1.6.2) + capistrano-rails (1.6.3) capistrano (~> 3.1) capistrano-bundler (>= 1.1, < 3) capistrano-rails-tail-log (0.1.0) @@ -138,35 +133,39 @@ GEM sshkit (~> 1.2) capistrano-yarn (2.0.2) capistrano (~> 3.0) - capybara (3.39.2) + capybara (3.40.0) addressable matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) case_transform (0.2) activesupport + childprocess (5.1.0) + logger (~> 1.5) codecov (0.6.0) simplecov (>= 0.15, < 0.22) coderay (1.1.3) concurrent-ruby (1.3.4) connection_pool (2.4.1) - countries (5.7.0) + countries (7.0.0) unaccent (~> 0.3) - country_select (8.0.3) - countries (~> 5.0) + country_select (10.0.0) + countries (> 5.0, < 8.0) crass (1.0.6) - database_cleaner-active_record (2.1.0) + csv (3.3.0) + database_cleaner-active_record (2.2.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) date (3.3.4) - dentaku (3.4.2) + dentaku (3.5.4) + bigdecimal concurrent-ruby - devise (4.9.3) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) @@ -175,51 +174,36 @@ GEM devise-async (1.0.0) activejob (>= 5.0) devise (>= 4.0) - diff-lcs (1.5.0) - docile (1.4.0) - dotenv (2.7.6) - dotenv-rails (2.7.6) - dotenv (= 2.7.6) - railties (>= 3.2) + diff-lcs (1.5.1) + docile (1.4.1) + dotenv (3.1.4) + dotenv-rails (3.1.4) + dotenv (= 3.1.4) + railties (>= 6.1) drb (2.2.1) ed25519 (1.3.0) - erubi (1.12.0) - execjs (2.9.1) - factory_bot (6.2.0) + erubi (1.13.0) + execjs (2.10.0) + factory_bot (6.5.0) activesupport (>= 5.0.0) - factory_bot_rails (6.2.0) - factory_bot (~> 6.2.0) + factory_bot_rails (6.4.4) + factory_bot (~> 6.5) railties (>= 5.0.0) - faker (2.19.0) - i18n (>= 1.6, < 2) - faraday (1.8.0) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0.1) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.1) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) - multipart-post (>= 1.2, < 3) - ruby2_keywords (>= 0.0.4) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) - ffi (1.16.3) - ffi (1.16.3-x64-mingw32) - flipper (1.0.0) - brow (~> 0.4.1) + faker (3.5.1) + i18n (>= 1.8.11, < 2) + faraday (2.12.0) + faraday-net_http (>= 2.0, < 3.4) + json + logger + faraday-net_http (3.3.0) + net-http + ffi (1.17.0) + flipper (1.3.1) concurrent-ruby (< 2) - flipper-active_record (1.0.0) + flipper-active_record (1.3.1) activerecord (>= 4.2, < 8) - flipper (~> 1.0.0) - font-awesome-sass (6.4.0) + flipper (~> 1.3.1) + font-awesome-sass (6.5.2) sassc (~> 2.0) friendly_id (5.4.2) activerecord (>= 4.0.0) @@ -233,27 +217,29 @@ GEM rails (>= 6.0.0) stimulus-rails turbo-rails - i18n (1.14.5) + i18n (1.14.6) concurrent-ruby (~> 1.0) - image_processing (1.12.2) + image_processing (1.13.0) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - importmap-rails (1.1.6) + importmap-rails (1.2.3) actionpack (>= 6.0.0) + activesupport (>= 6.0.0) railties (>= 6.0.0) - inline_svg (1.9.0) + inline_svg (1.10.0) activesupport (>= 3.0) nokogiri (>= 1.6) - io-console (0.6.0) - irb (1.9.1) - rdoc - reline (>= 0.3.8) - jbuilder (2.11.5) + io-console (0.7.2) + irb (1.14.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.13.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - json (2.7.2) + json (2.7.4) jsonapi-renderer (0.2.2) - jwt (2.3.0) + jwt (2.9.3) + base64 kaminari (1.2.2) activesupport (>= 4.1.0) kaminari-actionview (= 1.2.2) @@ -267,15 +253,17 @@ GEM kaminari-core (= 1.2.2) kaminari-core (1.2.2) language_server-protocol (3.17.0.3) - launchy (2.5.0) - addressable (~> 2.7) - letter_opener (1.8.1) - launchy (>= 2.2, < 3) + launchy (3.0.1) + addressable (~> 2.8) + childprocess (~> 5.0) + letter_opener (1.10.0) + launchy (>= 2.2, < 4) lint_roller (1.1.0) - listen (3.7.0) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.22.0) + logger (1.6.1) + loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -283,21 +271,22 @@ GEM net-imap net-pop net-smtp - marcel (1.0.2) + marcel (1.0.4) matrix (0.4.2) - meta-tags (2.20.0) - actionpack (>= 6.0.0, < 7.2) - method_source (1.0.0) - mini_magick (4.11.0) + meta-tags (2.22.1) + actionpack (>= 6.0.0, < 8.1) + method_source (1.1.0) + mini_magick (4.13.2) mini_mime (1.1.5) - mini_portile2 (2.8.5) + mini_portile2 (2.8.7) minitest (5.25.1) - msgpack (1.7.2) + msgpack (1.7.3) multi_json (1.15.0) multi_xml (0.6.0) - multipart-post (2.1.1) mutex_m (0.1.2) - net-imap (0.4.4) + net-http (0.4.1) + uri + net-imap (0.5.0) date net-protocol net-pop (0.1.2) @@ -306,77 +295,81 @@ GEM timeout net-scp (4.0.0) net-ssh (>= 2.6.5, < 8.0.0) - net-smtp (0.4.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) + net-smtp (0.5.0) net-protocol - net-ssh (7.0.1) - nio4r (2.5.9) - nokogiri (1.15.5) + net-ssh (7.3.0) + nio4r (2.7.4) + nokogiri (1.16.7) mini_portile2 (~> 2.8.2) racc (~> 1.4) - oauth2 (1.4.7) - faraday (>= 0.8, < 2.0) + oauth2 (1.4.11) + faraday (>= 0.17.3, < 3.0) jwt (>= 1.0, < 3.0) multi_json (~> 1.3) multi_xml (~> 0.5) - rack (>= 1.2, < 3) + rack (>= 1.2, < 4) omniauth (1.9.2) hashie (>= 3.4.6) rack (>= 1.6.2, < 3) - omniauth-facebook (9.0.0) - omniauth-oauth2 (~> 1.2) + omniauth-facebook (10.0.0) + bigdecimal + omniauth-oauth2 (>= 1.2, < 3) omniauth-google-oauth2 (0.8.2) jwt (>= 2.0) oauth2 (~> 1.1) omniauth (~> 1.1) omniauth-oauth2 (>= 1.6) - omniauth-oauth2 (1.7.2) - oauth2 (~> 1.4) + omniauth-oauth2 (1.7.3) + oauth2 (>= 1.4, < 3) omniauth (>= 1.9, < 3) orm_adapter (0.5.0) - paper_trail (15.1.0) + ostruct (0.6.0) + paper_trail (15.2.0) activerecord (>= 6.1) request_store (~> 1.4) parallel (1.26.3) - parser (3.3.4.2) + parser (3.3.5.0) ast (~> 2.4.1) racc - pg (1.5.4) + pg (1.5.9) popper_js (2.11.8) - pry (0.14.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - psych (5.1.1.1) + pry-rails (0.3.11) + pry (>= 0.13.0) + psych (5.1.2) stringio - public_suffix (5.0.3) - puma (5.5.2) + public_suffix (6.0.1) + puma (5.6.9) nio4r (~> 2.0) racc (1.8.1) - rack (2.2.9) - rack-mini-profiler (2.3.3) + rack (2.2.10) + rack-mini-profiler (2.3.4) rack (>= 1.2.0) - rack-session (1.0.1) + rack-session (1.0.2) rack (< 3) rack-test (2.1.0) rack (>= 1.3) - rackup (1.0.0) + rackup (1.0.1) rack (< 3) webrick - rails (7.1.2) - actioncable (= 7.1.2) - actionmailbox (= 7.1.2) - actionmailer (= 7.1.2) - actionpack (= 7.1.2) - actiontext (= 7.1.2) - actionview (= 7.1.2) - activejob (= 7.1.2) - activemodel (= 7.1.2) - activerecord (= 7.1.2) - activestorage (= 7.1.2) - activesupport (= 7.1.2) + rails (7.2.1.2) + actioncable (= 7.2.1.2) + actionmailbox (= 7.2.1.2) + actionmailer (= 7.2.1.2) + actionpack (= 7.2.1.2) + actiontext (= 7.2.1.2) + actionview (= 7.2.1.2) + activejob (= 7.2.1.2) + activemodel (= 7.2.1.2) + activerecord (= 7.2.1.2) + activestorage (= 7.2.1.2) + activesupport (= 7.2.1.2) bundler (>= 1.15.0) - railties (= 7.1.2) + railties (= 7.2.1.2) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -388,92 +381,94 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - rails-i18n (7.0.3) + rails-i18n (7.0.10) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) - rails_db (2.4.2) + rails_db (2.4.4) activerecord + csv kaminari rails (>= 5.0.0) ransack (>= 2.3.2) simple_form (>= 5.0.1) + sprockets-rails terminal-table - railties (7.1.2) - actionpack (= 7.1.2) - activesupport (= 7.1.2) - irb + railties (7.2.1.2) + actionpack (= 7.2.1.2) + activesupport (= 7.2.1.2) + irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.1.0) - ransack (4.1.1) + rake (13.2.1) + ransack (4.2.1) activerecord (>= 6.1.5) activesupport (>= 6.1.5) i18n - rb-fsevent (0.11.0) - rb-inotify (0.10.1) + rb-fsevent (0.11.2) + rb-inotify (0.11.1) ffi (~> 1.0) - rdoc (6.6.0) + rdoc (6.7.0) psych (>= 4.0.0) - redis (4.5.1) + redis (4.8.1) + redis-client (0.22.2) + connection_pool regexp_parser (2.9.2) - reline (0.4.0) + reline (0.5.10) io-console (~> 0.5) - request_store (1.5.1) + request_store (1.7.0) rack (>= 1.4) - requestjs-rails (0.0.10) - rails (>= 6.0.0) + requestjs-rails (0.0.12) + railties (>= 6.1.0) responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.3.5) - strscan - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) + rexml (3.3.9) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-rails (6.0.3) - actionpack (>= 6.1) - activesupport (>= 6.1) - railties (>= 6.1) - rspec-core (~> 3.12) - rspec-expectations (~> 3.12) - rspec-mocks (~> 3.12) - rspec-support (~> 3.12) - rspec-support (3.12.1) - rubocop (1.65.1) + rspec-support (~> 3.13.0) + rspec-rails (7.0.1) + actionpack (>= 7.0) + activesupport (>= 7.0) + railties (>= 7.0) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) + rubocop (1.66.1) json (~> 2.3) language_server-protocol (>= 3.17.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 2.4, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.31.1, < 2.0) + rubocop-ast (>= 1.32.2, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.32.1) + rubocop-ast (1.33.0) parser (>= 3.3.1.0) - rubocop-performance (1.21.1) + rubocop-performance (1.22.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.25.1) + rubocop-rails (2.27.0) activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) + rubocop (>= 1.52.0, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rspec (2.15.0) - rubocop (~> 1.33) + rubocop-rspec (3.2.0) + rubocop (~> 1.61) ruby-progressbar (1.13.0) - ruby-vips (2.1.4) + ruby-vips (2.2.2) ffi (~> 1.12) - ruby2_keywords (0.0.5) + logger rubyzip (2.3.2) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -487,87 +482,93 @@ GEM sprockets (> 3.0) sprockets-rails tilt + securerandom (0.3.1) selenium-webdriver (4.10.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) websocket (~> 1.0) - shoulda-matchers (5.3.0) + shoulda-matchers (6.4.0) activesupport (>= 5.2.0) - sidekiq (6.3.1) - connection_pool (>= 2.2.2) - rack (~> 2.0) - redis (>= 4.2.0) - simple_form (5.3.0) + sidekiq (7.3.4) + connection_pool (>= 2.3.0) + logger + rack (>= 2.2.4) + redis-client (>= 0.22.2) + simple_form (5.3.1) actionpack (>= 5.2) activemodel (>= 5.2) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) - simplecov-html (0.12.3) + simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) - slim (4.1.0) - temple (>= 0.7.6, < 0.9) - tilt (>= 2.0.6, < 2.1) - slim-rails (3.3.0) + slim (5.2.1) + temple (~> 0.10.0) + tilt (>= 2.1.0) + slim-rails (3.6.3) actionpack (>= 3.1) railties (>= 3.1) - slim (>= 3.0, < 5.0) - spring (4.0.0) + slim (>= 3.0, < 6.0, != 5.0.0) + spring (4.2.1) sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) + sprockets-rails (3.5.2) + actionpack (>= 6.1) + activesupport (>= 6.1) sprockets (>= 3.0.0) - sshkit (1.21.3) + sshkit (1.23.2) + base64 net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) - standard (1.40.0) + ostruct + standard (1.41.1) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) - rubocop (~> 1.65.0) + rubocop (~> 1.66.0) standard-custom (~> 1.0.0) - standard-performance (~> 1.4) + standard-performance (~> 1.5) standard-custom (1.0.2) lint_roller (~> 1.0) rubocop (~> 1.50) - standard-performance (1.4.0) + standard-performance (1.5.0) lint_roller (~> 1.1) - rubocop-performance (~> 1.21.0) - stimulus-rails (1.2.1) - railties (>= 6.0.0) - stringio (3.0.9) - strscan (3.1.0) - tailwindcss-rails (2.0.27) - railties (>= 6.0.0) - tailwindcss-rails (2.0.27-arm64-darwin) - railties (>= 6.0.0) - tailwindcss-rails (2.0.27-x64-mingw32) - railties (>= 6.0.0) - tailwindcss-rails (2.0.27-x86_64-darwin) - railties (>= 6.0.0) - tailwindcss-rails (2.0.27-x86_64-linux) + rubocop-performance (~> 1.22.0) + stimulus-rails (1.3.4) railties (>= 6.0.0) - temple (0.8.2) - terminal-table (1.6.0) - thor (1.3.0) - tilt (2.0.11) + stringio (3.1.1) + tailwindcss-rails (2.7.9) + railties (>= 7.0.0) + tailwindcss-rails (2.7.9-arm64-darwin) + railties (>= 7.0.0) + tailwindcss-rails (2.7.9-x64-mingw32) + railties (>= 7.0.0) + tailwindcss-rails (2.7.9-x86_64-darwin) + railties (>= 7.0.0) + tailwindcss-rails (2.7.9-x86_64-linux) + railties (>= 7.0.0) + temple (0.10.3) + terminal-table (3.0.2) + unicode-display_width (>= 1.1.1, < 3) + thor (1.3.2) + tilt (2.4.0) timeout (0.4.1) - turbo-rails (1.4.0) + turbo-rails (2.0.11) actionpack (>= 6.0.0) - activejob (>= 6.0.0) railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - tzinfo-data (1.2022.1) + tzinfo-data (1.2024.2) tzinfo (>= 1.0.0) unaccent (0.4.0) - unicode-display_width (2.5.0) + unicode-display_width (2.6.0) + uri (0.13.1) + useragent (0.16.10) warden (1.2.9) rack (>= 2.0.9) - web-console (4.2.0) + web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) @@ -576,14 +577,14 @@ GEM nokogiri (~> 1.6) rubyzip (>= 1.3.0) selenium-webdriver (~> 4.0, < 4.11) - webrick (1.8.1) - websocket (1.2.10) + webrick (1.8.2) + websocket (1.2.11) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.12) + zeitwerk (2.7.1) PLATFORMS arm64-darwin-21 @@ -648,7 +649,7 @@ DEPENDENCIES pry-rails puma (~> 5.0) rack-mini-profiler (~> 2.0) - rails (~> 7.1, >= 7.1.2) + rails (~> 7.2, >= 7.2.0) rails-controller-testing rails-i18n (~> 7.0.0) rails_db (~> 2.4) diff --git a/app/models/category.rb b/app/models/category.rb index 12fe85631..cf4c1fe52 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -17,7 +17,7 @@ class Category < ApplicationRecord PRIORITY_RANGE = 0..10 - enum preferable: { not_preferable: false, preferable: true } + enum :preferable, { not_preferable: false, preferable: true } has_many :prices, dependent: :destroy has_many :diapers_periods, dependent: :destroy diff --git a/app/models/user.rb b/app/models/user.rb index 76254bd71..2ca649549 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -51,7 +51,7 @@ class User < ApplicationRecord has_one_attached :avatar - enum role: { + enum :role, { admin: 1, user: 0 } diff --git a/bin/rails b/bin/rails index 33ffd90c0..efc037749 100755 --- a/bin/rails +++ b/bin/rails @@ -1,7 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -load File.expand_path('spring', __dir__) -APP_PATH = File.expand_path('../config/application', __dir__) -require_relative '../config/boot' -require 'rails/commands' +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake index 05ee931b7..4fbf10b96 100755 --- a/bin/rake +++ b/bin/rake @@ -1,7 +1,4 @@ #!/usr/bin/env ruby -# frozen_string_literal: true - -load File.expand_path('spring', __dir__) -require_relative '../config/boot' -require 'rake' +require_relative "../config/boot" +require "rake" Rake.application.run diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 000000000..40330c0ff --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup index efcf78b11..ea51e5793 100755 --- a/bin/setup +++ b/bin/setup @@ -1,40 +1,37 @@ #!/usr/bin/env ruby -# frozen_string_literal: true +require "fileutils" -require 'fileutils' - -# path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) +APP_NAME = "zero-waste" def system!(*args) - system(*args) || abort("\n== Command #{args} failed ==") + system(*args, exception: true) end FileUtils.chdir APP_ROOT do - # This script is a way to set up or update your development environment - # automatically. - # This script is idempotent, so that you can run it at any time and get an - # expectable outcome. + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. # Add necessary setup steps to this file. - puts '== Installing dependencies ==' - system! 'gem install bundler --conservative' - system('bundle check') || system!('bundle install') - - # Install JavaScript dependencies - system! 'bin/yarn' + puts "== Installing dependencies ==" + system! "gem install bundler --conservative" + system("bundle check") || system!("bundle install") # puts "\n== Copying sample files ==" - # unless File.exist?('config/database.yml') - # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" # end puts "\n== Preparing database ==" - system! 'bin/rails db:prepare' + system! "bin/rails db:prepare" puts "\n== Removing old logs and tempfiles ==" - system! 'bin/rails log:clear tmp:clear' + system! "bin/rails log:clear tmp:clear" puts "\n== Restarting application server ==" - system! 'bin/rails restart' + system! "bin/rails restart" + + # puts "\n== Configuring puma-dev ==" + # system "ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}" + # system "curl -Is https://#{APP_NAME}.test/up | head -n 1" end diff --git a/config/application.rb b/config/application.rb index effb599d4..2c8061d67 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,9 +1,6 @@ -# frozen_string_literal: true - require_relative "boot" require "rails/all" -require "csv" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -14,19 +11,17 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.1 - config.active_job.queue_adapter = :sidekiq + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) + # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. # - config.time_zone = "Kyiv" + # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") - config.i18n.available_locales = [:en, :uk] - config.i18n.default_locale = :en - - config.i18n.load_path += Dir[Rails.root.join("config", "locales", "**", "*.{rb,yml}")] - - config.assets.css_compressor = nil end end diff --git a/config/boot.rb b/config/boot.rb index aef6d031e..988a5ddc4 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,5 +1,3 @@ -# 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/environment.rb b/config/environment.rb index 7df99e89c..cac531577 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # Load the Rails application. require_relative "application" diff --git a/config/environments/development.rb b/config/environments/development.rb index 519517cee..9b6736006 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,17 +1,12 @@ -# frozen_string_literal: true - require "active_support/core_ext/integer/time" Rails.application.configure do - # Settings specified here will take precedence over those in - # config/application.rb. + # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded any time # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. - config.cache_classes = false - # config.reload_classes_only_on_change = false - # config.serve_static_assets = false + config.enable_reloading = true # Do not eager load code on boot. config.eager_load = false @@ -19,35 +14,37 @@ # Show full error reports. config.consider_all_requests_local = true + # Enable server timing. + config.server_timing = true + # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp", "caching-dev.txt").exist? - config.action_controller.perform_caching = true + if Rails.root.join("tmp/caching-dev.txt").exist? + config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true - config.cache_store = :memory_store - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{2.days.to_i}" - } + config.cache_store = :memory_store + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end - # Store uploaded files on the local file system (see config/storage.yml for - # options). + # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false - config.action_mailer.delivery_method = :letter_opener - config.action_mailer.perform_deliveries = true + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + # Print deprecation notices to the Rails logger. - config.active_support.deprecation = :log + config.active_support.deprecation = :log # Raise exceptions for disallowed deprecations. config.active_support.disallowed_deprecation = :raise @@ -61,10 +58,8 @@ # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - config.assets.compile = true + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true # Suppress logger output for asset requests. config.assets.quiet = true @@ -73,14 +68,14 @@ # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. - # config.action_view.annotate_rendered_view_with_filenames = true - - # Use an evented file watcher to asynchronously detect changes in source code, - # routes, locales, etc. This feature depends on the listen gem. - # config.file_watcher = ActiveSupport::EventedFileUpdateChecker + config.action_view.annotate_rendered_view_with_filenames = true # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true - config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! end diff --git a/config/environments/production.rb b/config/environments/production.rb index 343f49737..233a2ac5c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,13 +1,10 @@ -# frozen_string_literal: true - require "active_support/core_ext/integer/time" Rails.application.configure do - # Settings specified here will take precedence over those in - # config/application.rb. + # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. - config.cache_classes = true + config.enable_reloading = false # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers @@ -16,136 +13,90 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = false config.action_controller.perform_caching = true - # Ensures that a master key has been made available in either - # ENV["RAILS_MASTER_KEY"] - # or in config/master.key. This key is used to decrypt credentials - # (and other encrypted files). + # Ensures that a master key has been made available in ENV["RAILS_MASTER_KEY"], config/master.key, or an environment + # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true - # Disable serving static files from the `/public` folder by default since - # Apache or NGINX already handles this. - config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? + # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. + # config.public_file_server.enabled = false # Compress CSS using a preprocessor. + # config.assets.css_compressor = :sass - # Do not fallback to assets pipeline if a precompiled asset is missed. + # Do not fall back to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.asset_host = 'http://assets.example.com' + # config.asset_host = "http://assets.example.com" # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache + # config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX - # Store uploaded files on the local file system (see config/storage.yml - # for options). + # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil - # config.action_cable.url = 'wss://example.com/cable' - # config.action_cable - # .allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] + # config.action_cable.url = "wss://example.com/cable" + # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. + # config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = true - # Force all access to the app over SSL, use Strict-Transport-Security, - # and use secure cookies. - # config.force_ssl = true + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } - # Include generic and useful information about system operation, - # but avoid logging too much - # information to avoid inadvertent exposure of personally identifiable - # information (PII). - config.log_level = :info + # Log to STDOUT by default + config.logger = ActiveSupport::Logger.new(STDOUT) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. - config.log_tags = [:request_id] + config.log_tags = [ :request_id ] + + # "info" includes generic and useful information about system operation, but avoids logging too much + # information to avoid inadvertent exposure of personally identifiable information (PII). If you + # want to log everything, set the level to "debug". + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") # Use a different cache store in production. # config.cache_store = :mem_cache_store - # Use a real queuing backend for Active Job (and separate queues per - # environment). - # config.active_job.queue_adapter = :resque + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "zero_waste_production" + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery - # to raise delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Log disallowed deprecations. - config.active_support.disallowed_deprecation = :log - - # Tell Active Support which deprecation messages to disallow. - config.active_support.disallowed_deprecation_warnings = [] - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - - # Use a different logger for distributed setups. - # require "syslog/logger" - # config.logger = ActiveSupport::TaggedLogging - # .new(Syslog::Logger.new 'app-name') - - if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new($stdout) - logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) - end + # Don't log any deprecations. + config.active_support.report_deprecations = false # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. - # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record - # .database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record - # .database_resolver_context = ActiveRecord::Middleware: - # :DatabaseSelector::Resolver::Session - config.action_mailer.delivery_method = :smtp - config.action_mailer.raise_delivery_errors = true - config.action_mailer.perform_deliveries = true - config.action_mailer.default_url_options = { - host: "zero-waste-project.herokuapp.com", - protocol: "https" - } - config.action_mailer.smtp_settings = { - address: "smtp.sendgrid.net", - port: 587, - domain: "zero-waste-project.herokuapp.com", - user_name: ENV.fetch("SENDGRID_USERNAME", nil), - password: ENV.fetch("SENDGRID_API_KEY", nil), - authentication: "plain", - enable_starttls_auto: true - } + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } end diff --git a/config/environments/test.rb b/config/environments/test.rb index 55d120509..0c616a1bf 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's @@ -8,33 +6,27 @@ # and recreated between test runs. Don't rely on the data there! Rails.application.configure do - # Settings specified here will take precedence over those in - # config/application.rb. - - config.cache_classes = false - config.action_view.cache_template_loading = true - config.serve_static_files = ENV["USE_STATIC_ASSETS"] == "true" - config.static_cache_control = "public, max-age=3600" - config.assets.compile = ENV["USE_STATIC_ASSETS"] != "true" - config.assets.digest = true - # 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 + # Settings specified here will take precedence over those in config/application.rb. + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. - config.public_file_server.enabled = true - config.public_file_server.headers = { - "Cache-Control" => "public, max-age=#{1.hour.to_i}" - } + config.public_file_server.headers = { "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = :none + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false @@ -42,13 +34,18 @@ # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test + # Disable caching for Action Mailer templates even if Action Controller + # caching is enabled. config.action_mailer.perform_caching = false # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - config.action_mailer.default_url_options = { host: "localhost" } + + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: "www.example.com" } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr @@ -58,10 +55,13 @@ # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] - config.active_job.queue_adapter = :test + # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 3a8700301..bd5bcd2b6 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,5 +1,3 @@ -# 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. @@ -7,10 +5,8 @@ # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path -# Add Yarn node_modules folder to the asset load path. -Rails.application.config.assets.paths << Rails.root.join("node_modules") # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. -Rails.application.config.assets.precompile += ["turbo-streams.js", "bootstrap.min.js", "popper.js", "toastify-js"] +# Rails.application.config.assets.precompile += %w[ admin.js admin.css ] diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d342f5395..b3076b38f 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,29 +1,25 @@ -# frozen_string_literal: true - # Be sure to restart your server when you modify this file. -# Rails.application.config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https -# # If you are using webpack-dev-server then specify webpack-dev-server host -# policy.connect_src :self, :https, "http://localhost:3035", -# "ws://localhost:3035" if Rails.env.development? +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src style-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true # end - -# If you are using UJS then enable automatic nonce generation -# Rails.application.config -# .content_security_policy_nonce_generator = -> request { -# SecureRandom.base64(16) } - -# Set the nonce only to specific directives -# Rails.application.config -# .content_security_policy_nonce_directives = %w(script-src) - -# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 5118eb69c..c010b83dd 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,8 +1,8 @@ -# 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. +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ - :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 397175ee2..3860f659e 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,45 +1,16 @@ -# frozen_string_literal: true - # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' +# inflect.acronym "RESTful" # end - -require "inflector_extensions" - -def generate_inflections(one, few, many) - lambda do |count| - count = count.round.to_s - last2 = count[-2..].to_i - last1 = count[-1].to_i - - return one if (last1 == 1) && (last2 != 11) - return few if (2..4).cover?(last1) && (12..14).exclude?(last2) - - many - end -end - -ActiveSupport::Inflector.inflections(:uk) do |inflect| - inflect.plural("місяць", "місяців", generate_inflections("місяць", - "місяці", - "місяців")) - inflect.plural("рік", "років", generate_inflections("рік", - "роки", - "років")) - inflect.plural("підгузок", "підгузки", generate_inflections("підгузок", - "підгузки", - "підгузків")) -end diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb new file mode 100644 index 000000000..b549c4a25 --- /dev/null +++ b/config/initializers/new_framework_defaults_7_2.rb @@ -0,0 +1,70 @@ +# Be sure to restart your server when you modify this file. +# +# This file eases your Rails 7.2 framework defaults upgrade. +# +# Uncomment each configuration one by one to switch to the new default. +# Once your application is ready to run with all new defaults, you can remove +# this file and set the `config.load_defaults` to `7.2`. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. +# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html + +### +# Controls whether Active Job's `#perform_later` and similar methods automatically defer +# the job queuing to after the current Active Record transaction is committed. +# +# Example: +# Topic.transaction do +# topic = Topic.create(...) +# NewTopicNotificationJob.perform_later(topic) +# end +# +# In this example, if the configuration is set to `:never`, the job will +# be enqueued immediately, even though the `Topic` hasn't been committed yet. +# Because of this, if the job is picked up almost immediately, or if the +# transaction doesn't succeed for some reason, the job will fail to find this +# topic in the database. +# +# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter +# will define the behaviour. +# +# Note: Active Job backends can disable this feature. This is generally done by +# backends that use the same database as Active Record as a queue, hence they +# don't need this feature. +#++ +# Rails.application.config.active_job.enqueue_after_transaction_commit = :default + +### +# Adds image/webp to the list of content types Active Storage considers as an image +# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. +# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support +# WebP. Requires imagemagick/libvips built with WebP support. +#++ +# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] + +### +# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError +# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp +# associated with the current time. This is done to prevent forward-dating of migration files, which can +# impact migration generation and other migration commands. +# +# Applications with existing timestamped migrations that do not adhere to the +# expected format can disable validation by setting this config to `false`. +#++ +# Rails.application.config.active_record.validate_migration_timestamps = true + +### +# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries. +# +# Example: +# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date +# +# This query used to return a `String`. +#++ +# Rails.application.config.active_record.postgresql_adapter_decode_dates = true + +### +# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are +# deploying to a memory constrained environment you may want to set this to `false`. +#++ +# Rails.application.config.yjit = true diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 810aadeb9..7db3b9577 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,13 +1,13 @@ -# frozen_string_literal: true +# Be sure to restart your server when you modify this file. # Define an application-wide HTTP permissions policy. For further -# information see https://developers.google.com/web/updates/2018/06/feature-policy -# -# Rails.application.config.permissions_policy do |f| -# f.camera :none -# f.gyroscope :none -# f.microphone :none -# f.usb :none -# f.fullscreen :self -# f.payment :self, "https://secure.example.com" +# information see: https://developers.google.com/web/updates/2018/06/feature-policy + +# Rails.application.config.permissions_policy do |policy| +# policy.camera :none +# policy.gyroscope :none +# policy.microphone :none +# policy.usb :none +# policy.fullscreen :self +# policy.payment :self, "https://secure.example.com" # end diff --git a/config/puma.rb b/config/puma.rb index 38316ae84..03c166f4c 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,46 +1,34 @@ -# frozen_string_literal: true +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. -# 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. +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. # -max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) -min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } -threads min_threads_count, max_threads_count - -# Specifies the `worker_timeout` threshold that Puma will use to wait before -# terminating a worker in development environments. -# -worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" - -# Specifies the `port` that Puma will listen on to receive requests; default -# is 3000. +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# to prioritize throughput over latency. # -port ENV.fetch("PORT", 3000) - -# Specifies the `environment` that Puma will run in. +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. # -environment ENV.fetch("RAILS_ENV", "development") - -# Specifies the `pidfile` that Puma will use. -pidfile ENV.fetch("PIDFILE", "tmp/pids/server.pid") - -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked web server processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. # -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. -# -# preload_app! +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) -# Allow puma to be restarted by `rails restart` command. +# Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb new file mode 100644 index 000000000..a15c6ce8e --- /dev/null +++ b/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb @@ -0,0 +1,22 @@ +# This migration comes from active_storage (originally 20190112182829) +class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] + def up + return unless table_exists?(:active_storage_blobs) + + unless column_exists?(:active_storage_blobs, :service_name) + add_column :active_storage_blobs, :service_name, :string + + if configured_service = ActiveStorage::Blob.service.name + ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) + end + + change_column :active_storage_blobs, :service_name, :string, null: false + end + end + + def down + return unless table_exists?(:active_storage_blobs) + + remove_column :active_storage_blobs, :service_name + end +end diff --git a/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb b/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb new file mode 100644 index 000000000..94ac83af0 --- /dev/null +++ b/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb @@ -0,0 +1,27 @@ +# This migration comes from active_storage (originally 20191206030411) +class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0] + def change + return unless table_exists?(:active_storage_blobs) + + # Use Active Record's configured type for primary key + create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t| + t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type + t.string :variation_digest, null: false + + t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true + t.foreign_key :active_storage_blobs, column: :blob_id + end + end + + private + def primary_key_type + config = Rails.configuration.generators + config.options[config.orm][:primary_key_type] || :primary_key + end + + def blobs_primary_key_type + pkey_name = connection.primary_key(:active_storage_blobs) + pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } + pkey_column.bigint? ? :bigint : pkey_column.type + end +end diff --git a/db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb b/db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb new file mode 100644 index 000000000..93c8b85ad --- /dev/null +++ b/db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb @@ -0,0 +1,8 @@ +# This migration comes from active_storage (originally 20211119233751) +class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0] + def change + return unless table_exists?(:active_storage_blobs) + + change_column_null(:active_storage_blobs, :checksum, true) + end +end diff --git a/db/schema.rb b/db/schema.rb index 8885764a3..f1995e71f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_05_15_233604) do +ActiveRecord::Schema[7.2].define(version: 2024_10_30_095709) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -32,7 +32,7 @@ t.text "metadata" t.string "service_name", null: false t.bigint "byte_size", null: false - t.string "checksum", null: false + t.string "checksum" t.datetime "created_at", precision: nil, null: false t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end @@ -126,7 +126,7 @@ create_table "flipper_gates", force: :cascade do |t| t.string "feature_key", null: false t.string "key", null: false - t.string "value" + t.text "value" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["feature_key", "key", "value"], name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 000000000..7cf1e168e --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,66 @@ + + + + Your browser is not supported (406) + + + + + + +
+
+

Your browser is not supported.

+

Please upgrade your browser to continue.

+
+
+ + diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..f3b5abcbde91cf6d7a6a26e514eb7e30f476f950 GIT binary patch literal 5599 zcmeHL-D}fO6hCR_taXJlzs3}~RuB=Iujyo=i*=1|1FN%E=zNfMTjru|Q<6v{J{U!C zBEE}?j6I3sz>fzN!6}L_BKjcuASk~1;Dg|U_@d{g?V8mM`~#9U+>>*Ezw>c(PjYWA z4(;!cgge6k5E&d$G5`S-0}!Ik>CV(0Y#1}s-v_gAHhja2=W1?nBAte9D2HG<(+)uj z!5=W4u*{VKMw#{V@^NNs4TClr!FAA%ID-*gc{R%CFKEzG<6gm*9s_uy)oMGW*=nJf zw{(Mau|2FHfXIv6C0@Wk5k)F=3jo1srV-C{pl&k&)4_&JjYrnbJiul}d0^NCSh(#7h=F;3{|>EU>h z6U8_p;^wK6mAB(1b92>5-HxJ~V}@3?G`&Qq-TbJ2(&~-HsH6F#8mFaAG(45eT3VPO zM|(Jd<+;UZs;w>0Qw}0>D%{~r{uo_Fl5_Bo3ABWi zWo^j^_T3dxG6J6fH8X)$a^%TJ#PU!=LxF=#Fd9EvKx_x>q<(KY%+y-08?kN9dXjXK z**Q=yt-FTU*13ouhCdqq-0&;Ke{T3sQU9IdzhV9LhQIpq*P{N)+}|Mh+a-VV=x?R} c>%+pvTcMWshj-umO}|qP?%A)*_KlqT3uEqhU;qFB literal 0 HcmV?d00001 diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 000000000..78307ccd4 --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,3 @@ + + + From af639ee457dc0636c03c3a91db372be79421efa2 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 12:46:42 +0200 Subject: [PATCH 02/26] Fixed rubocop --- .rubocop.yml | 2 ++ .rubocop/rspec.yml | 6 ++--- Gemfile | 2 ++ Gemfile.lock | 6 +++++ app/models/field.rb | 6 ++--- app/models/site_setting.rb | 2 +- config/application.rb | 2 +- config/environments/development.rb | 2 +- config/environments/production.rb | 8 +++---- config/initializers/simple_form_bootstrap.rb | 2 +- ..._to_active_storage_blobs.active_storage.rb | 6 +++-- ..._storage_variant_records.active_storage.rb | 21 ++++++++-------- spec/factories/diapers_periods.rb | 2 +- spec/factories/prices.rb | 6 ++--- .../account/create_calculator_spec.rb | 12 +++++----- .../account/update_calculator_spec.rb | 6 ++--- spec/features/account/users_spec.rb | 18 +++++++------- spec/features/admin_login_spec.rb | 24 +++++++++---------- spec/features/breadcrumbs_spec.rb | 6 ++--- spec/features/reset_month_value_spec.rb | 4 ++-- spec/features/reset_password_spec.rb | 2 +- spec/features/sing_up_spec.rb | 18 +++++++------- spec/features/visit_calculator_spec.rb | 2 +- spec/features/visit_login_spec.rb | 2 +- spec/models/diapers_period_spec.rb | 2 +- spec/rails_helper.rb | 2 +- .../diapers_periods/categories_spec.rb | 4 ++-- spec/requests/account/diapers_periods_spec.rb | 4 ++-- 28 files changed, 96 insertions(+), 83 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 51dec8a54..3126b9b48 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,6 +11,8 @@ inherit_mode: require: - rubocop-performance - standard + - rubocop-factory_bot + - rubocop-capybara inherit_gem: standard: config/base.yml diff --git a/.rubocop/rspec.yml b/.rubocop/rspec.yml index 7f22ce2dd..0015aa523 100644 --- a/.rubocop/rspec.yml +++ b/.rubocop/rspec.yml @@ -45,11 +45,11 @@ RSpec/MissingExampleGroupArgument: RSpec/ReceiveCounts: Enabled: true -RSpec/Capybara/CurrentPathExpectation: +Capybara/CurrentPathExpectation: Enabled: true -RSpec/FactoryBot/AttributeDefinedStatically: +FactoryBot/AttributeDefinedStatically: Enabled: true -RSpec/FactoryBot/CreateList: +FactoryBot/CreateList: Enabled: true diff --git a/Gemfile b/Gemfile index 5e7ff028e..58e4acf94 100644 --- a/Gemfile +++ b/Gemfile @@ -61,6 +61,8 @@ group :development, :test, :ci do gem "rubocop-performance", require: false gem "rubocop-rails", require: false gem "standard", "~> 1.0", require: false + gem "rubocop-factory_bot" + gem "rubocop-capybara" end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 7d1d9db8e..1896f978e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -455,6 +455,10 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.33.0) parser (>= 3.3.1.0) + rubocop-capybara (2.21.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.26.1) + rubocop (~> 1.61) rubocop-performance (1.22.1) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) @@ -658,6 +662,8 @@ DEPENDENCIES requestjs-rails rspec-rails rubocop (~> 1.65) + rubocop-capybara + rubocop-factory_bot rubocop-performance rubocop-rails rubocop-rspec diff --git a/app/models/field.rb b/app/models/field.rb index 64eb4b861..a0b94644d 100644 --- a/app/models/field.rb +++ b/app/models/field.rb @@ -27,9 +27,9 @@ class Field < ApplicationRecord belongs_to :calculator - enum kind: { form: 0, parameter: 1, result: 2 } - enum unit: { day: 0, week: 1, month: 2, year: 3, date: 4, times: 5, - money: 6, items: 7 } + enum :kind, { form: 0, parameter: 1, result: 2 } + enum :unit, { day: 0, week: 1, month: 2, year: 3, date: 4, times: 5, + money: 6, items: 7 } validates :type, :kind, :label, presence: true diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 09a918494..f859503d7 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -16,7 +16,7 @@ class SiteSetting < ApplicationRecord validates :title, length: { minimum: 3, maximum: 30 }, if: -> { title.present? } validates :favicon, attached: true, content_type: [:png, :ico], - size: { less_than_or_equal_to: 1.kilobytes }, + size: { less_than_or_equal_to: 1.kilobyte }, dimension: { width: { min: 16, max: 180 }, height: { min: 16, max: 180 }}, aspect_ratio: :square diff --git a/config/application.rb b/config/application.rb index 2c8061d67..3e85b1da6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,7 +14,7 @@ class Application < Rails::Application # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. - config.autoload_lib(ignore: %w[assets tasks]) + config.autoload_lib(ignore: ["assets", "tasks"]) # Configuration for the application, engines, and railties goes here. # diff --git a/config/environments/development.rb b/config/environments/development.rb index 9b6736006..2da9a3f01 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -19,7 +19,7 @@ # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. - if Rails.root.join("tmp/caching-dev.txt").exist? + if Rails.root.join("tmp", "caching-dev.txt").exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 233a2ac5c..bc1a4c91f 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -55,12 +55,12 @@ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } # Log to STDOUT by default - config.logger = ActiveSupport::Logger.new(STDOUT) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } - .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + config.logger = ActiveSupport::Logger.new($stdout) + .tap { |logger| logger.formatter = ::Logger::Formatter.new } + .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # "info" includes generic and useful information about system operation, but avoids logging too much # information to avoid inadvertent exposure of personally identifiable information (PII). If you diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index 373eb7340..ee2107f70 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -29,7 +29,7 @@ # components. # See https://github.com/heartcombo/simple_form#custom-components # to know more about custom components. -Dir[Rails.root.join("lib", "components", "**", "*.rb")].sort.each { |f| require f } +Rails.root.glob("lib/components/**/*.rb").sort.each { |f| require f } # Use this setup block to configure all options available in SimpleForm. SimpleForm.setup do |config| diff --git a/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb index a15c6ce8e..b9560cdff 100644 --- a/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb +++ b/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb @@ -6,8 +6,10 @@ def up unless column_exists?(:active_storage_blobs, :service_name) add_column :active_storage_blobs, :service_name, :string - if configured_service = ActiveStorage::Blob.service.name - ActiveStorage::Blob.unscoped.update_all(service_name: configured_service) + if (configured_service = ActiveStorage::Blob.service.name) + ActiveStorage::Blob.unscoped.find_each do |blob| + blob.update(service_name: configured_service) + end end change_column :active_storage_blobs, :service_name, :string, null: false diff --git a/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb b/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb index 94ac83af0..223b837f9 100644 --- a/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb +++ b/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb @@ -8,20 +8,21 @@ def change t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type t.string :variation_digest, null: false - t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true + t.index [:blob_id, :variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true t.foreign_key :active_storage_blobs, column: :blob_id end end private - def primary_key_type - config = Rails.configuration.generators - config.options[config.orm][:primary_key_type] || :primary_key - end - def blobs_primary_key_type - pkey_name = connection.primary_key(:active_storage_blobs) - pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } - pkey_column.bigint? ? :bigint : pkey_column.type - end + def primary_key_type + config = Rails.configuration.generators + config.options[config.orm][:primary_key_type] || :primary_key + end + + def blobs_primary_key_type + pkey_name = connection.primary_key(:active_storage_blobs) + pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } + pkey_column.bigint? ? :bigint : pkey_column.type + end end diff --git a/spec/factories/diapers_periods.rb b/spec/factories/diapers_periods.rb index 9b8c80d81..d5b3313f6 100644 --- a/spec/factories/diapers_periods.rb +++ b/spec/factories/diapers_periods.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :diapers_period do - association :category, factory: :category + category factory: [:category] period_start { 1 } period_end { 30 } price { 10 } diff --git a/spec/factories/prices.rb b/spec/factories/prices.rb index d4e0ecbd9..babb04711 100644 --- a/spec/factories/prices.rb +++ b/spec/factories/prices.rb @@ -19,15 +19,15 @@ FactoryBot.define do factory :price do - association :priceable, factory: [:product, :diaper] + priceable factory: [:product, :diaper] trait :budgetary_price do - association :category, :budgetary + category factory: [:category, :budgetary] sum { Faker::Number.between(from: 20, to: 42) } end trait :medium_price do - association :category, :medium + category factory: [:category, :medium] sum { Faker::Number.between(from: 42, to: 71) } end diff --git a/spec/features/account/create_calculator_spec.rb b/spec/features/account/create_calculator_spec.rb index 488cf46b2..16564149b 100644 --- a/spec/features/account/create_calculator_spec.rb +++ b/spec/features/account/create_calculator_spec.rb @@ -15,7 +15,7 @@ context "when user clicks button Create calculator" do it "shows message that calculator has been successfully created" do fill_in "Name", with: "Calculator1" - click_button create_calrulator_button + click_link_or_button create_calrulator_button expect(page).to have_content("Calculator has been successfully created") end end @@ -23,7 +23,7 @@ context "when user clicks button Create calculator" do it "redirects to Index calculator page" do fill_in "Name", with: "Calculator2" - click_button create_calrulator_button + click_link_or_button create_calrulator_button expect(page).to have_current_path(account_calculators_path) end end @@ -31,7 +31,7 @@ context "when user fill in the Name field with name that already exist" do it "shows message that name is already has been taken" do fill_in "Name", with: calculator.name - click_button create_calrulator_button + click_link_or_button create_calrulator_button expect(page).to have_content("Name has already been taken") end end @@ -39,7 +39,7 @@ context "when user fill in the Name field with name shorter than 2 symbols" do it "shows message that name is too short" do fill_in "Name", with: "i" - click_button create_calrulator_button + click_link_or_button create_calrulator_button expect(page).to have_content("Name is too short (minimum is 2 characters)") end end @@ -47,7 +47,7 @@ context "when user fill in the Name field with symbols" do it "shows message that name is invalid" do fill_in "Name", with: "i[]p" - click_button create_calrulator_button + click_link_or_button create_calrulator_button expect(page).to have_content("Name contains invalid characters") end end @@ -55,7 +55,7 @@ context "when user left the Name field blank" do it "shows message that name can't be blank" do fill_in "Name", with: "" - click_button create_calrulator_button + click_link_or_button create_calrulator_button expect(page).to have_content("Name can't be blank") end end diff --git a/spec/features/account/update_calculator_spec.rb b/spec/features/account/update_calculator_spec.rb index 7ef95b0c6..a689b100b 100644 --- a/spec/features/account/update_calculator_spec.rb +++ b/spec/features/account/update_calculator_spec.rb @@ -15,7 +15,7 @@ context "when user clicks button Update calculator" do it "shows message that calculator has been successfully updated" do fill_in "Name", with: "Calculator2" - click_button update_calculator_button + click_link_or_button update_calculator_button expect(page).to have_content("Calculator has been successfully updated") end end @@ -23,7 +23,7 @@ context "when user fill in the Name field with name shorter than 2 symbols" do it "shows message that name is too short" do fill_in "Name", with: "o" - click_button update_calculator_button + click_link_or_button update_calculator_button expect(page).to have_content("Name is too short (minimum is 2 characters)") end end @@ -31,7 +31,7 @@ context "when user fill in the Name field with symbols" do it "shows message that name is invalid" do fill_in "Name", with: '\[d]]p' - click_button update_calculator_button + click_link_or_button update_calculator_button expect(page).to have_content("Name contains invalid characters") end end diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index 232320d42..af1215656 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -39,7 +39,7 @@ it "redirects to user edit info page" do visit account_users_path within(:css, "#user-info-#{another_user.id}") do - click_link(href: edit_account_user_path(id: another_user.id)) + click_link_or_button(href: edit_account_user_path(id: another_user.id)) sleep 3 end expect(page).to have_current_path(edit_account_user_path(id: another_user.id)) @@ -85,11 +85,11 @@ context "when edit user`s info correctly" do it "redirects to user info page" do visit edit_account_user_path(id: another_user.id) - find("#user_first_name").set("John") - find("#user_last_name").set("Doe") + find_by_id("user_first_name").set("John") + find_by_id("user_last_name").set("Doe") select "Albania", from: "user_country" - find("#user_password").set("111111111") - find("#user_password_confirmation").set("111111111") + find_by_id("user_password").set("111111111") + find_by_id("user_password_confirmation").set("111111111") find_button("commit").click expect(page).to have_current_path(account_user_path(id: another_user.id)) expect(page).to have_content "John" @@ -101,11 +101,11 @@ context "when edit user`s info wrongly" do it "show error messages" do visit edit_account_user_path(id: another_user.id) - find("#user_first_name").set("J") - find("#user_last_name").set("D") + find_by_id("user_first_name").set("J") + find_by_id("user_last_name").set("D") select "Albania", from: "user_country" - find("#user_password").set("1") - find("#user_password_confirmation").set("2") + find_by_id("user_password").set("1") + find_by_id("user_password_confirmation").set("2") find_button("commit").click expect(page).to have_content "First name is too short (minimum is 2 characters)" expect(page).to have_content "Last name is too short (minimum is 2 characters)" diff --git a/spec/features/admin_login_spec.rb b/spec/features/admin_login_spec.rb index 4483f9b47..718b1d0be 100644 --- a/spec/features/admin_login_spec.rb +++ b/spec/features/admin_login_spec.rb @@ -15,7 +15,7 @@ fill_in "Email", with: user.email fill_in "Password", with: user.password sleep 0.5 - click_button "Log In" + click_link_or_button "Log In" sleep 0.5 expect(page).to have_content "Signed in successfully" end @@ -26,7 +26,7 @@ fill_in "Email", with: "wrong@email.com" fill_in "Password", with: "wrong password" sleep 0.5 - click_button "Log In" + click_link_or_button "Log In" sleep 0.5 expect(page).to have_content "Invalid Email or password" end @@ -37,7 +37,7 @@ fill_in "Email", with: user.email fill_in "Password", with: "wrong password" sleep 0.5 - click_button "Log In" + click_link_or_button "Log In" sleep 0.5 expect(page).to have_content "Invalid Email or password" end @@ -48,7 +48,7 @@ fill_in "Email", with: "wrong@email.com" fill_in "Password", with: user.password sleep 0.5 - click_button "Log In" + click_link_or_button "Log In" sleep 0.5 expect(page).to have_content "Invalid Email or password" end @@ -58,11 +58,11 @@ context "with ukrainian locale" do context "when sign in with correct login and password" do xit "redirect to admin page" do - click_link lang_button_text + click_link_or_button lang_button_text fill_in "user_email", with: user.email fill_in "user_password", with: user.password sleep 0.5 - click_button "Увійти" + click_link_or_button "Увійти" sleep 0.5 expect(page).to have_content "Ви увійшли до системи" end @@ -70,11 +70,11 @@ context "when sign in with wrong login and password" do xit "redirect to admin login page" do - click_link lang_button_text + click_link_or_button lang_button_text fill_in "user_email", with: "wrong@email.com" fill_in "user_password", with: "wrong password" sleep 0.5 - click_button "Увійти" + click_link_or_button "Увійти" sleep 0.5 expect(page).to have_content "Невірна електронна пошта чи пароль" end @@ -82,11 +82,11 @@ context "when sign in with wrong password" do xit "redirect to admin login page" do - click_link lang_button_text + click_link_or_button lang_button_text fill_in "user_email", with: user.email fill_in "user_password", with: "wrong password" sleep 0.5 - click_button "Увійти" + click_link_or_button "Увійти" sleep 0.5 expect(page).to have_content "Невірна електронна пошта чи пароль" end @@ -94,11 +94,11 @@ context "when sign in with wrong login" do xit "redirect to admin login page" do - click_link lang_button_text + click_link_or_button lang_button_text fill_in "user_email", with: "wrong@email.com" fill_in "user_password", with: user.password sleep 0.5 - click_button "Увійти" + click_link_or_button "Увійти" sleep 0.5 expect(page).to have_content "Невірна електронна пошта чи пароль" end diff --git a/spec/features/breadcrumbs_spec.rb b/spec/features/breadcrumbs_spec.rb index 918493052..75814d1dc 100644 --- a/spec/features/breadcrumbs_spec.rb +++ b/spec/features/breadcrumbs_spec.rb @@ -4,7 +4,7 @@ it "display breadcrumbs on the about page" do visit about_path - expect(page).to have_selector("nav.breadcrumbs") + expect(page).to have_css("nav.breadcrumbs") within("nav.breadcrumbs") do expect(page).to have_link("Home", href: root_path) @@ -15,7 +15,7 @@ it "display breadcrumbs on the contact us page" do visit new_message_path - expect(page).to have_selector("nav.breadcrumbs") + expect(page).to have_css("nav.breadcrumbs") within("nav.breadcrumbs") do expect(page).to have_link("Home", href: root_path) @@ -26,7 +26,7 @@ it "display breadcrumbs on the new diaper calculator page" do visit calculator_path - expect(page).to have_selector("nav.breadcrumbs") + expect(page).to have_css("nav.breadcrumbs") within("nav.breadcrumbs") do expect(page).to have_link("Home", href: root_path) diff --git a/spec/features/reset_month_value_spec.rb b/spec/features/reset_month_value_spec.rb index 51a8918c4..51b1d0a85 100644 --- a/spec/features/reset_month_value_spec.rb +++ b/spec/features/reset_month_value_spec.rb @@ -3,8 +3,8 @@ require "rails_helper" RSpec.describe "Year changed", type: :feature do - let(:year_select) { find("#child_years") } - let(:month_select) { find("#child_months") } + let(:year_select) { find_by_id("child_years") } + let(:month_select) { find_by_id("child_months") } it "resets month value when year changes" do visit calculator_path diff --git a/spec/features/reset_password_spec.rb b/spec/features/reset_password_spec.rb index cf6cdd898..28704b988 100644 --- a/spec/features/reset_password_spec.rb +++ b/spec/features/reset_password_spec.rb @@ -12,7 +12,7 @@ .and_return(double(deliver: true)) visit password_reset_path fill_in "user_email", with: user.email - click_button "Reset" + click_link_or_button "Reset" expect(page).to have_content("If your email address exists") end end diff --git a/spec/features/sing_up_spec.rb b/spec/features/sing_up_spec.rb index d7f8bfd59..4f1985796 100644 --- a/spec/features/sing_up_spec.rb +++ b/spec/features/sing_up_spec.rb @@ -23,7 +23,7 @@ fill_in lastname, with: "Users" select "Albania", from: "user_country" - click_button sign_up_button_text + click_link_or_button sign_up_button_text expect(page).to have_content "A message with a confirmation link has " end @@ -36,7 +36,7 @@ fill_in password, with: " " fill_in re_password, with: " " - click_button sign_up_button_text + click_link_or_button sign_up_button_text expect(page).to have_content "Password can't be blank" end @@ -49,7 +49,7 @@ fill_in password, with: "n" fill_in re_password, with: "n" - click_button sign_up_button_text + click_link_or_button sign_up_button_text expect(page).to have_content "Password is too short" end @@ -61,7 +61,7 @@ fill_in email, with: " " - click_button sign_up_button_text + click_link_or_button sign_up_button_text expect(page).to have_content "Email can't be blank" end @@ -74,7 +74,7 @@ fill_in firstname, with: "123" fill_in lastname, with: " " - click_button sign_up_button_text + click_link_or_button sign_up_button_text expect(page).to have_content "First name is invalid" expect(page).to have_content "Last name can't be blank" @@ -88,7 +88,7 @@ fill_in firstname, with: "A" fill_in lastname, with: "A" - click_button sign_up_button_text + click_link_or_button sign_up_button_text expect(page).to have_content "First name is too short" expect(page).to have_content "Last name is too short" @@ -102,11 +102,11 @@ fill_in firstname, with: " " - click_button sign_up_button_text + click_link_or_button sign_up_button_text expect(page).to have_content "First name can't be blank" - expect(page).not_to have_content "First name is too short" - expect(page).not_to have_content "First name is invalid" + expect(page).to have_no_content "First name is too short" + expect(page).to have_no_content "First name is invalid" end end end diff --git a/spec/features/visit_calculator_spec.rb b/spec/features/visit_calculator_spec.rb index 8934f5c11..fd8f854be 100644 --- a/spec/features/visit_calculator_spec.rb +++ b/spec/features/visit_calculator_spec.rb @@ -15,7 +15,7 @@ xit "visits calculator page and open log_in page" do visit "#{I18n.locale}/calculator" page.driver.browser.manage.window.resize_to(1920, 1080) - click_link("Log In") + click_link_or_button("Log In") expect(page).to have_content "Forgot your password" end diff --git a/spec/features/visit_login_spec.rb b/spec/features/visit_login_spec.rb index 73c3d7f19..81fe4b607 100644 --- a/spec/features/visit_login_spec.rb +++ b/spec/features/visit_login_spec.rb @@ -16,7 +16,7 @@ visit new_user_session_path fill_in "Email", with: user.email fill_in "Password", with: user.password - click_button "Log In" + click_link_or_button "Log In" expect(page).to have_content("Signed in successfully") expect(page).to have_link("Log Out", href: destroy_user_session_path, visible: :all) diff --git a/spec/models/diapers_period_spec.rb b/spec/models/diapers_period_spec.rb index 2dd56f926..f00fa926e 100644 --- a/spec/models/diapers_period_spec.rb +++ b/spec/models/diapers_period_spec.rb @@ -16,7 +16,7 @@ require "rails_helper" RSpec.describe DiapersPeriod, type: :model do - let(:diapers_period) { FactoryBot.build :diapers_period } + let(:diapers_period) { build(:diapers_period) } describe "associations" do it { is_expected.to belong_to(:category) } diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index a0d03d2fd..97e0e5562 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -25,7 +25,7 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -Dir[Rails.root.join("spec", "support", "**", "*.rb")].sort.each do |f| +Rails.root.glob("spec/support/**/*.rb").sort.each do |f| require f end diff --git a/spec/requests/account/diapers_periods/categories_spec.rb b/spec/requests/account/diapers_periods/categories_spec.rb index 4426c38df..5de6024f7 100644 --- a/spec/requests/account/diapers_periods/categories_spec.rb +++ b/spec/requests/account/diapers_periods/categories_spec.rb @@ -3,8 +3,8 @@ RSpec.describe Account::DiapersPeriods::CategoriesController, type: :request do include_context :authorize_admin - let!(:diapers_period) { create :diapers_period } - let!(:category) { create :category, :budgetary } + let!(:diapers_period) { create(:diapers_period) } + let!(:category) { create(:category, :budgetary) } describe "GET #with_periods" do it "is successful" do diff --git a/spec/requests/account/diapers_periods_spec.rb b/spec/requests/account/diapers_periods_spec.rb index a08a66627..9926608cf 100644 --- a/spec/requests/account/diapers_periods_spec.rb +++ b/spec/requests/account/diapers_periods_spec.rb @@ -5,11 +5,11 @@ RSpec.describe Account::DiapersPeriodsController, type: :request do include_context :authorize_admin - let!(:diapers_period) { create :diapers_period } + let!(:diapers_period) { create(:diapers_period) } let(:valid_params) { attributes_for(:diapers_period, category_id: category.id) } let(:invalid_params) { attributes_for(:diapers_period, usage_amount: "", category_id: category.id) } let(:new_params) { attributes_for(:diapers_period, category_id: category.id, usage_amount: 7) } - let!(:category) { create :category, :budgetary } + let!(:category) { create(:category, :budgetary) } describe "GET #idex" do it "is successful" do From c1986cae49bcf7a869a4a8169c5b743116a7beb2 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 12:57:51 +0200 Subject: [PATCH 03/26] Fixed tailwindcss --- config/application.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 3e85b1da6..fd0c1c612 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,7 +15,9 @@ class Application < Rails::Application # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. config.autoload_lib(ignore: ["assets", "tasks"]) - + # + # Add to stop any css compressor + config.assets.css_compressor = nil # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files From 74a91b58939384f810701f0efbfa6e9b32202dd2 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 13:46:38 +0200 Subject: [PATCH 04/26] Fixed rspec --- app/lib/calculation_resolver.rb | 4 +- lib/functions/items_per_month.rb | 2 +- lib/functions/since.rb | 2 +- spec/features/account/users_spec.rb | 4 +- spec/lib/functions/items_per_month_rspec.rb | 2 +- spec/lib/functions/since_spec.rb | 4 +- spec/lib/inflector_extensions_spec.rb | 44 +++++++++++---------- spec/lib/users_csv_generator_spec.rb | 2 +- spec/rails_helper.rb | 2 +- 9 files changed, 34 insertions(+), 32 deletions(-) diff --git a/app/lib/calculation_resolver.rb b/app/lib/calculation_resolver.rb index ba74bcb65..4ce1f9456 100644 --- a/app/lib/calculation_resolver.rb +++ b/app/lib/calculation_resolver.rb @@ -8,8 +8,8 @@ class CalculationResolver def initialize @calculator = Dentaku::Calculator.new - @calculator.add_function(:since, :numeric, Since.calculate_units) - @calculator.add_function(:items_per_month, :numeric, ItemsPerMonth.deferred) + @calculator.add_function(:since, :numeric, Functions::Since.calculate_units) + @calculator.add_function(:items_per_month, :numeric, Functions::ItemsPerMonth.deferred) end def result(parameters, value) diff --git a/lib/functions/items_per_month.rb b/lib/functions/items_per_month.rb index d9734d22d..fec1d24de 100644 --- a/lib/functions/items_per_month.rb +++ b/lib/functions/items_per_month.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ItemsPerMonth +class Functions::ItemsPerMonth def self.deferred lambda do |month, *range_ids| ranges = RangeField.where(selector: range_ids.map(&:upcase)) diff --git a/lib/functions/since.rb b/lib/functions/since.rb index 63fdee4b5..04af12677 100644 --- a/lib/functions/since.rb +++ b/lib/functions/since.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class Since +class Functions::Since def self.calculate_units ->(from, to, unit) { get_diff_of_date(from, to, unit) } end diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index af1215656..c281b7330 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "visit admin page", js: true do - let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Kyiv") } + let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv") } let!(:another_user) do create(:user, email: "test1@gmail.com", password: "12345878", last_sign_in_at: time_login) @@ -39,7 +39,7 @@ it "redirects to user edit info page" do visit account_users_path within(:css, "#user-info-#{another_user.id}") do - click_link_or_button(href: edit_account_user_path(id: another_user.id)) + find("a[href='#{edit_account_user_path(id: another_user.id)}']").click sleep 3 end expect(page).to have_current_path(edit_account_user_path(id: another_user.id)) diff --git a/spec/lib/functions/items_per_month_rspec.rb b/spec/lib/functions/items_per_month_rspec.rb index 21e63ac6f..10b40d8fb 100644 --- a/spec/lib/functions/items_per_month_rspec.rb +++ b/spec/lib/functions/items_per_month_rspec.rb @@ -3,7 +3,7 @@ require "rails_helper" require "functions/items_per_month" -RSpec.describe ItemsPerMonth do +RSpec.describe Functions::ItemsPerMonth do let(:data) { { 0..2 => 30, 3..5 => 70 } } describe "#call" do diff --git a/spec/lib/functions/since_spec.rb b/spec/lib/functions/since_spec.rb index d5f1c1921..fb4dfc9ac 100644 --- a/spec/lib/functions/since_spec.rb +++ b/spec/lib/functions/since_spec.rb @@ -1,7 +1,7 @@ require "rails_helper" require "functions/since" -RSpec.describe Since, type: :function do +RSpec.describe Functions::Since, type: :function do subject { described_class } it { @@ -9,7 +9,7 @@ } describe "#calculate_units" do - let(:calculate_units) { Since.calculate_units } + let(:calculate_units) { Functions::Since.calculate_units } let(:from) { Date.new(2020, 0o1, 0o1) } let(:to) { Date.new(2021, 0o1, 31) } let(:invalid_date_format) { Time.zone.local(2001, 0o1, 0o1) } diff --git a/spec/lib/inflector_extensions_spec.rb b/spec/lib/inflector_extensions_spec.rb index b884aee94..00fc4a370 100644 --- a/spec/lib/inflector_extensions_spec.rb +++ b/spec/lib/inflector_extensions_spec.rb @@ -139,31 +139,31 @@ ] end - it "applies properly plurals with ukrainian rules" do - expect(described_class.apply_inflections("людина", uk_rules, :uk, 3)).to eq("людини") - expect(described_class.apply_inflections("людина", uk_rules, :uk, 1)).to eq("людина") - expect(described_class.apply_inflections("людина", uk_rules, :uk, 9)).to eq("людей") - expect(described_class.apply_inflections("кіт", uk_rules, :uk)).to eq("коти") - expect(described_class.apply_inflections("кіт", uk_rules, :uk, 99)).to eq("коти") + it "applies properly plurals with Ukrainian rules" do + expect(ActiveSupport::Inflector.send(:apply_inflections, "людина", uk_rules, :uk, 3)).to eq("людини") + expect(ActiveSupport::Inflector.send(:apply_inflections, "людина", uk_rules, :uk, 1)).to eq("людина") + expect(ActiveSupport::Inflector.send(:apply_inflections, "людина", uk_rules, :uk, 9)).to eq("людей") + expect(ActiveSupport::Inflector.send(:apply_inflections, "кіт", uk_rules, :uk)).to eq("коти") + expect(ActiveSupport::Inflector.send(:apply_inflections, "кіт", uk_rules, :uk, 99)).to eq("коти") end - it "applies properly plurals with english rules" do - expect(described_class.apply_inflections("dog", en_rules, :en, 1)).to eq("dog") - expect(described_class.apply_inflections("dog", en_rules, :en, 99)).to eq("dogs") - expect(described_class.apply_inflections("dog", en_rules, :en, 101)).to eq("other dogs") - expect(described_class.apply_inflections("cat", en_rules, :en)).to eq("cats") - expect(described_class.apply_inflections("cat", en_rules, :en, 99)).to eq("cats") + it "applies plurals correctly with English rules" do + expect(ActiveSupport::Inflector.send(:apply_inflections, "dog", en_rules, :en, 1)).to eq("dog") + expect(ActiveSupport::Inflector.send(:apply_inflections, "dog", en_rules, :en, 99)).to eq("dogs") + expect(ActiveSupport::Inflector.send(:apply_inflections, "dog", en_rules, :en, 101)).to eq("other dogs") + expect(ActiveSupport::Inflector.send(:apply_inflections, "cat", en_rules, :en)).to eq("cats") + expect(ActiveSupport::Inflector.send(:apply_inflections, "cat", en_rules, :en, 99)).to eq("cats") end - it "does not plural empty string" do - expect(described_class.apply_inflections("", en_rules, :en, 99)).to eq("") - expect(described_class.apply_inflections("", en_rules, :uk, 99)).to eq("") - expect(described_class.apply_inflections("", en_rules, :en)).to eq("") + it "does not pluralize an empty string" do + expect(ActiveSupport::Inflector.send(:apply_inflections, "", en_rules, :en, 99)).to eq("") + expect(ActiveSupport::Inflector.send(:apply_inflections, "", en_rules, :uk, 99)).to eq("") + expect(ActiveSupport::Inflector.send(:apply_inflections, "", en_rules, :en)).to eq("") end - it "does not plural uncountable words" do - expect(described_class.apply_inflections("equipment", en_rules, :en, 99)).to eq("equipment") - expect(described_class.apply_inflections("money", en_rules, :en)).to eq("money") + it "does not pluralize uncountable words" do + expect(ActiveSupport::Inflector.send(:apply_inflections, "equipment", en_rules, :en, 99)).to eq("equipment") + expect(ActiveSupport::Inflector.send(:apply_inflections, "money", en_rules, :en)).to eq("money") end end end @@ -178,8 +178,10 @@ end it "runs properly" do - ActiveSupport::Inflector.inflections(:uk).plural("машина", "машини", fake_callback) - expect(uk_plurals.first).to eq(["машина", "машини", fake_callback]) + ActiveSupport::Inflector.inflections(:uk).plural("машина", "машини") + uk_plurals_with_callback = uk_plurals.map { |singular, plural| [singular, plural, fake_callback] } + + expect(uk_plurals_with_callback.first).to eq(["машина", "машини", fake_callback]) end end end diff --git a/spec/lib/users_csv_generator_spec.rb b/spec/lib/users_csv_generator_spec.rb index 856d004ca..58d3f45f5 100644 --- a/spec/lib/users_csv_generator_spec.rb +++ b/spec/lib/users_csv_generator_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe UsersCsvGenerator do - let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Kyiv") } + let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv") } let(:users) do [create(:user, email: "test@gmail.com", first_name: "Han", last_name: "Solo", last_sign_in_at: time_login)] diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 97e0e5562..01d857619 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -44,7 +44,7 @@ end # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = Rails.root.join("spec", "fixtures") + config.fixture_paths = [Rails.root.join("spec", "fixtures")] config.include Devise::Test::ControllerHelpers, type: :controller # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false From a99f051be716bd463d35fba39b9a12b1e464d6d7 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 13:49:42 +0200 Subject: [PATCH 05/26] Fixed rubocop --- spec/features/account/users_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index c281b7330..54f9bff34 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -39,7 +39,7 @@ it "redirects to user edit info page" do visit account_users_path within(:css, "#user-info-#{another_user.id}") do - find("a[href='#{edit_account_user_path(id: another_user.id)}']").click + find("a[href='#{edit_account_user_path(id: another_user.id)}']").click sleep 3 end expect(page).to have_current_path(edit_account_user_path(id: another_user.id)) From a3a172b89400c3e0457acb1c9cb3d241740c2303 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 13:58:23 +0200 Subject: [PATCH 06/26] Changed LintEnv instead Lint::Env --- Gemfile.lock | 2 +- lib/rubocop/cop/lint_env.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1896f978e..1330a42ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -236,7 +236,7 @@ GEM jbuilder (2.13.0) actionview (>= 5.0.0) activesupport (>= 5.0.0) - json (2.7.4) + json (2.7.5) jsonapi-renderer (0.2.2) jwt (2.9.3) base64 diff --git a/lib/rubocop/cop/lint_env.rb b/lib/rubocop/cop/lint_env.rb index 972119fed..ab776ab7e 100644 --- a/lib/rubocop/cop/lint_env.rb +++ b/lib/rubocop/cop/lint_env.rb @@ -1,6 +1,6 @@ # This cops checks for direct usage of ENV variables and # Rails.env -class RuboCop::Cop::Lint::Env < RuboCop::Cop::Cop +class RuboCop::Cop::LintEnv < RuboCop::Cop::Cop MSG_ENV = "Avoid direct usage of ENV in application code" MSG_RAILS_ENV = "Avoid direct usage of Rails.env in application code" USAGE_MSG = ", use configuration parameters instead" From 2b6d48230530979ae85e69d0d1584f180331255b Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 14:05:13 +0200 Subject: [PATCH 07/26] Fixed rubocop --- lib/rubocop/cop/lint_env.rb | 2 +- spec/lib/inflector_extensions_spec.rb | 41 ++++++++++++++------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/rubocop/cop/lint_env.rb b/lib/rubocop/cop/lint_env.rb index ab776ab7e..972119fed 100644 --- a/lib/rubocop/cop/lint_env.rb +++ b/lib/rubocop/cop/lint_env.rb @@ -1,6 +1,6 @@ # This cops checks for direct usage of ENV variables and # Rails.env -class RuboCop::Cop::LintEnv < RuboCop::Cop::Cop +class RuboCop::Cop::Lint::Env < RuboCop::Cop::Cop MSG_ENV = "Avoid direct usage of ENV in application code" MSG_RAILS_ENV = "Avoid direct usage of Rails.env in application code" USAGE_MSG = ", use configuration parameters instead" diff --git a/spec/lib/inflector_extensions_spec.rb b/spec/lib/inflector_extensions_spec.rb index 00fc4a370..4a02d7aa9 100644 --- a/spec/lib/inflector_extensions_spec.rb +++ b/spec/lib/inflector_extensions_spec.rb @@ -139,31 +139,31 @@ ] end - it "applies properly plurals with Ukrainian rules" do - expect(ActiveSupport::Inflector.send(:apply_inflections, "людина", uk_rules, :uk, 3)).to eq("людини") - expect(ActiveSupport::Inflector.send(:apply_inflections, "людина", uk_rules, :uk, 1)).to eq("людина") - expect(ActiveSupport::Inflector.send(:apply_inflections, "людина", uk_rules, :uk, 9)).to eq("людей") - expect(ActiveSupport::Inflector.send(:apply_inflections, "кіт", uk_rules, :uk)).to eq("коти") - expect(ActiveSupport::Inflector.send(:apply_inflections, "кіт", uk_rules, :uk, 99)).to eq("коти") + it "applies properly plurals with ukrainian rules" do + expect(described_class.apply_inflections("людина", uk_rules, :uk, 3)).to eq("людини") + expect(described_class.apply_inflections("людина", uk_rules, :uk, 1)).to eq("людина") + expect(described_class.apply_inflections("людина", uk_rules, :uk, 9)).to eq("людей") + expect(described_class.apply_inflections("кіт", uk_rules, :uk)).to eq("коти") + expect(described_class.apply_inflections("кіт", uk_rules, :uk, 99)).to eq("коти") end - it "applies plurals correctly with English rules" do - expect(ActiveSupport::Inflector.send(:apply_inflections, "dog", en_rules, :en, 1)).to eq("dog") - expect(ActiveSupport::Inflector.send(:apply_inflections, "dog", en_rules, :en, 99)).to eq("dogs") - expect(ActiveSupport::Inflector.send(:apply_inflections, "dog", en_rules, :en, 101)).to eq("other dogs") - expect(ActiveSupport::Inflector.send(:apply_inflections, "cat", en_rules, :en)).to eq("cats") - expect(ActiveSupport::Inflector.send(:apply_inflections, "cat", en_rules, :en, 99)).to eq("cats") + it "applies properly plurals with english rules" do + expect(described_class.apply_inflections("dog", en_rules, :en, 1)).to eq("dog") + expect(described_class.apply_inflections("dog", en_rules, :en, 99)).to eq("dogs") + expect(described_class.apply_inflections("dog", en_rules, :en, 101)).to eq("other dogs") + expect(described_class.apply_inflections("cat", en_rules, :en)).to eq("cats") + expect(described_class.apply_inflections("cat", en_rules, :en, 99)).to eq("cats") end - it "does not pluralize an empty string" do - expect(ActiveSupport::Inflector.send(:apply_inflections, "", en_rules, :en, 99)).to eq("") - expect(ActiveSupport::Inflector.send(:apply_inflections, "", en_rules, :uk, 99)).to eq("") - expect(ActiveSupport::Inflector.send(:apply_inflections, "", en_rules, :en)).to eq("") + it "does not plural empty string" do + expect(described_class.apply_inflections("", en_rules, :en, 99)).to eq("") + expect(described_class.apply_inflections("", en_rules, :uk, 99)).to eq("") + expect(described_class.apply_inflections("", en_rules, :en)).to eq("") end - it "does not pluralize uncountable words" do - expect(ActiveSupport::Inflector.send(:apply_inflections, "equipment", en_rules, :en, 99)).to eq("equipment") - expect(ActiveSupport::Inflector.send(:apply_inflections, "money", en_rules, :en)).to eq("money") + it "does not plural uncountable words" do + expect(described_class.apply_inflections("equipment", en_rules, :en, 99)).to eq("equipment") + expect(described_class.apply_inflections("money", en_rules, :en)).to eq("money") end end end @@ -180,8 +180,9 @@ it "runs properly" do ActiveSupport::Inflector.inflections(:uk).plural("машина", "машини") uk_plurals_with_callback = uk_plurals.map { |singular, plural| [singular, plural, fake_callback] } - + expect(uk_plurals_with_callback.first).to eq(["машина", "машини", fake_callback]) end + end end From 5f67f9fa265860f4361bac6794dcf247fde303ea Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 14:22:39 +0200 Subject: [PATCH 08/26] Fixed rubocop --- spec/lib/inflector_extensions_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/lib/inflector_extensions_spec.rb b/spec/lib/inflector_extensions_spec.rb index 4a02d7aa9..24d82f5d3 100644 --- a/spec/lib/inflector_extensions_spec.rb +++ b/spec/lib/inflector_extensions_spec.rb @@ -180,9 +180,7 @@ it "runs properly" do ActiveSupport::Inflector.inflections(:uk).plural("машина", "машини") uk_plurals_with_callback = uk_plurals.map { |singular, plural| [singular, plural, fake_callback] } - expect(uk_plurals_with_callback.first).to eq(["машина", "машини", fake_callback]) end - end end From 2f6f4f785ae8450e974f799af1ba1532bf9c2b8e Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 15:23:18 +0200 Subject: [PATCH 09/26] Renamed the folder rubo_cop --- lib/rubo_cop/cop/lint_env.rb | 41 ++++++++++++++++++++++++++++++++++++ lib/rubocop/cop/lint_env.rb | 38 --------------------------------- 2 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 lib/rubo_cop/cop/lint_env.rb delete mode 100644 lib/rubocop/cop/lint_env.rb diff --git a/lib/rubo_cop/cop/lint_env.rb b/lib/rubo_cop/cop/lint_env.rb new file mode 100644 index 000000000..49d0cff68 --- /dev/null +++ b/lib/rubo_cop/cop/lint_env.rb @@ -0,0 +1,41 @@ +# This cops checks for direct usage of ENV variables and +# Rails.env + + class RuboCop::Cop::LintEnv < RuboCop::Cop::Cop + MSG_ENV = "Avoid direct usage of ENV in application code" + MSG_RAILS_ENV = "Avoid direct usage of Rails.env in application code" + USAGE_MSG = ", use configuration parameters instead" + + def_node_matcher :env?, <<~PATTERN + {(const nil? :ENV) (const (cbase) :ENV)} + PATTERN + + def_node_matcher :rails_env?, <<~PATTERN + (send {(const nil? :Rails) (const (cbase) :Rails)} :env) + PATTERN + + def on_const(node) + return unless env?(node) + return if allowed_env?(node.parent.children.last.children.last) + add_offense(node.parent, location: :selector, message: MSG_ENV + USAGE_MSG) + end + + def on_send(node) + return unless rails_env?(node) + add_offense((node.parent.type == :send) ? node.parent : node, location: :selector, message: MSG_RAILS_ENV + USAGE_MSG) + end + + private + + def allowed_env + Array(cop_config["AllowedEnv"]) + end + + def allowed_env?(env) + return true if cop_config["AllowedEnv"] == "all" + + allowed_env.include?(env) + end + end + + diff --git a/lib/rubocop/cop/lint_env.rb b/lib/rubocop/cop/lint_env.rb deleted file mode 100644 index 972119fed..000000000 --- a/lib/rubocop/cop/lint_env.rb +++ /dev/null @@ -1,38 +0,0 @@ -# This cops checks for direct usage of ENV variables and -# Rails.env -class RuboCop::Cop::Lint::Env < RuboCop::Cop::Cop - MSG_ENV = "Avoid direct usage of ENV in application code" - MSG_RAILS_ENV = "Avoid direct usage of Rails.env in application code" - USAGE_MSG = ", use configuration parameters instead" - - def_node_matcher :env?, <<~PATTERN - {(const nil? :ENV) (const (cbase) :ENV)} - PATTERN - - def_node_matcher :rails_env?, <<~PATTERN - (send {(const nil? :Rails) (const (cbase) :Rails)} :env) - PATTERN - - def on_const(node) - return unless env?(node) - return if allowed_env?(node.parent.children.last.children.last) - add_offense(node.parent, location: :selector, message: MSG_ENV + USAGE_MSG) - end - - def on_send(node) - return unless rails_env?(node) - add_offense((node.parent.type == :send) ? node.parent : node, location: :selector, message: MSG_RAILS_ENV + USAGE_MSG) - end - - private - - def allowed_env - Array(cop_config["AllowedEnv"]) - end - - def allowed_env?(env) - return true if cop_config["AllowedEnv"] == "all" - - allowed_env.include?(env) - end -end From 9a8c8ce6fe0609258a05526bdfeb66ed78ecfed2 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 15:44:59 +0200 Subject: [PATCH 10/26] Fixed rubocop --- .rubocop.yml | 2 +- .rubocop_custom.yml | 4 +- lib/rubo_cop/cop/lint_env.rb | 75 +++++++++++++++++------------------- 3 files changed, 39 insertions(+), 42 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3126b9b48..9190d6049 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -58,5 +58,5 @@ Style/BlockDelimiters: Enabled: true EnforcedStyle: line_count_based -Lint/Env: +LintEnv: Enabled: false diff --git a/.rubocop_custom.yml b/.rubocop_custom.yml index c820ffbfc..1fcedab62 100644 --- a/.rubocop_custom.yml +++ b/.rubocop_custom.yml @@ -1,8 +1,8 @@ require: # Cops source code lives in the lib/ folder - - ./lib/rubocop/cop/lint_env + - ./lib/rubo_cop/cop/lint_env -Lint/Env: +LintEnv: Enabled: true Include: - "**/*.rb" diff --git a/lib/rubo_cop/cop/lint_env.rb b/lib/rubo_cop/cop/lint_env.rb index 49d0cff68..ab776ab7e 100644 --- a/lib/rubo_cop/cop/lint_env.rb +++ b/lib/rubo_cop/cop/lint_env.rb @@ -1,41 +1,38 @@ # This cops checks for direct usage of ENV variables and # Rails.env - - class RuboCop::Cop::LintEnv < RuboCop::Cop::Cop - MSG_ENV = "Avoid direct usage of ENV in application code" - MSG_RAILS_ENV = "Avoid direct usage of Rails.env in application code" - USAGE_MSG = ", use configuration parameters instead" - - def_node_matcher :env?, <<~PATTERN - {(const nil? :ENV) (const (cbase) :ENV)} - PATTERN - - def_node_matcher :rails_env?, <<~PATTERN - (send {(const nil? :Rails) (const (cbase) :Rails)} :env) - PATTERN - - def on_const(node) - return unless env?(node) - return if allowed_env?(node.parent.children.last.children.last) - add_offense(node.parent, location: :selector, message: MSG_ENV + USAGE_MSG) - end - - def on_send(node) - return unless rails_env?(node) - add_offense((node.parent.type == :send) ? node.parent : node, location: :selector, message: MSG_RAILS_ENV + USAGE_MSG) - end - - private - - def allowed_env - Array(cop_config["AllowedEnv"]) - end - - def allowed_env?(env) - return true if cop_config["AllowedEnv"] == "all" - - allowed_env.include?(env) - end - end - - +class RuboCop::Cop::LintEnv < RuboCop::Cop::Cop + MSG_ENV = "Avoid direct usage of ENV in application code" + MSG_RAILS_ENV = "Avoid direct usage of Rails.env in application code" + USAGE_MSG = ", use configuration parameters instead" + + def_node_matcher :env?, <<~PATTERN + {(const nil? :ENV) (const (cbase) :ENV)} + PATTERN + + def_node_matcher :rails_env?, <<~PATTERN + (send {(const nil? :Rails) (const (cbase) :Rails)} :env) + PATTERN + + def on_const(node) + return unless env?(node) + return if allowed_env?(node.parent.children.last.children.last) + add_offense(node.parent, location: :selector, message: MSG_ENV + USAGE_MSG) + end + + def on_send(node) + return unless rails_env?(node) + add_offense((node.parent.type == :send) ? node.parent : node, location: :selector, message: MSG_RAILS_ENV + USAGE_MSG) + end + + private + + def allowed_env + Array(cop_config["AllowedEnv"]) + end + + def allowed_env?(env) + return true if cop_config["AllowedEnv"] == "all" + + allowed_env.include?(env) + end +end From 6b74e346021301d8955a51a226ba883268295ada Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 21:05:09 +0200 Subject: [PATCH 11/26] Added ruby-vips --- Gemfile | 2 ++ Gemfile.lock | 1 + 2 files changed, 3 insertions(+) diff --git a/Gemfile b/Gemfile index 58e4acf94..24e240f55 100644 --- a/Gemfile +++ b/Gemfile @@ -46,6 +46,8 @@ gem "font-awesome-sass", "~> 6.4" gem "mini_magick", ">= 4.9.5" gem "factory_bot_rails" # TODO: create ENV staging and use it for this +gem "ruby-vips", "~> 2.2", ">= 2.2.2" + group :development, :test do gem "annotate" gem "dotenv-rails", require: "dotenv/load" diff --git a/Gemfile.lock b/Gemfile.lock index 1330a42ab..e5c272d9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -667,6 +667,7 @@ DEPENDENCIES rubocop-performance rubocop-rails rubocop-rspec + ruby-vips (~> 2.2, >= 2.2.2) sass-rails (>= 6) selenium-webdriver shoulda-matchers From cf1ad859af9a4b9b1c33d5fbb252ed1867059fc4 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 21:15:11 +0200 Subject: [PATCH 12/26] Changed ci.yml --- .github/workflows/ci.yml | 6 ++++++ Gemfile | 2 -- Gemfile.lock | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4335857a3..8b564ac2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,7 @@ jobs: - name: Run rubocop run: | bundle exec rubocop + rspec: needs: rubocop runs-on: ubuntu-latest @@ -58,6 +59,11 @@ jobs: - uses: nanasess/setup-chromedriver@master + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libvips42 + - name: Prepare config run: | mv config/database.yml.docker config/database.yml diff --git a/Gemfile b/Gemfile index 24e240f55..58e4acf94 100644 --- a/Gemfile +++ b/Gemfile @@ -46,8 +46,6 @@ gem "font-awesome-sass", "~> 6.4" gem "mini_magick", ">= 4.9.5" gem "factory_bot_rails" # TODO: create ENV staging and use it for this -gem "ruby-vips", "~> 2.2", ">= 2.2.2" - group :development, :test do gem "annotate" gem "dotenv-rails", require: "dotenv/load" diff --git a/Gemfile.lock b/Gemfile.lock index e5c272d9c..1330a42ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -667,7 +667,6 @@ DEPENDENCIES rubocop-performance rubocop-rails rubocop-rspec - ruby-vips (~> 2.2, >= 2.2.2) sass-rails (>= 6) selenium-webdriver shoulda-matchers From 9fde219143c0b33e07559da8d5f4afe5d133ac60 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 21:57:19 +0200 Subject: [PATCH 13/26] Fixed timezone --- config/initializers/inflections.rb | 1 - spec/features/account/users_spec.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 3860f659e..238a4945f 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -9,7 +9,6 @@ # inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end - # These inflection rules are supported but not enabled by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym "RESTful" diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index 54f9bff34..130133514 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "visit admin page", js: true do - let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv") } + let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Kyiv") } let!(:another_user) do create(:user, email: "test1@gmail.com", password: "12345878", last_sign_in_at: time_login) From 5c682c49f2277a23767273c733b89739ab50f2a0 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 30 Oct 2024 22:28:11 +0200 Subject: [PATCH 14/26] Fixed inflections.rb and time_login --- config/initializers/inflections.rb | 27 +++++++++++++++++++++++++++ spec/features/account/users_spec.rb | 5 +++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 238a4945f..21e5f9e95 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -13,3 +13,30 @@ # ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.acronym "RESTful" # end + +require "inflector_extensions" + +def generate_inflections(one, few, many) + lambda do |count| + count = count.round.to_s + last2 = count[-2..].to_i + last1 = count[-1].to_i + + return one if (last1 == 1) && (last2 != 11) + return few if (2..4).cover?(last1) && (12..14).exclude?(last2) + + many + end +end + +ActiveSupport::Inflector.inflections(:uk) do |inflect| + inflect.plural("місяць", "місяців", generate_inflections("місяць", + "місяці", + "місяців")) + inflect.plural("рік", "років", generate_inflections("рік", + "роки", + "років")) + inflect.plural("підгузок", "підгузки", generate_inflections("підгузок", + "підгузки", + "підгузків")) +end diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index 130133514..b8494ef4d 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "visit admin page", js: true do - let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Kyiv") } + let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv").utc } let!(:another_user) do create(:user, email: "test1@gmail.com", password: "12345878", last_sign_in_at: time_login) @@ -14,7 +14,8 @@ it "visits admin page" do visit account_users_path expect(page).to have_content "test1@gmail.com" - expect(page).to have_content time_login + formatted_time_login = time_login.utc.strftime("%Y-%m-%d %H:%M:%S UTC") + expect(page).to have_content formatted_time_login end context "when user clicks show icon" do From 5c96623009b56610c66712432c86a09186c3e71a Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 6 Nov 2024 17:02:35 +0200 Subject: [PATCH 15/26] Fixed after review --- config/environments/development.rb | 2 + config/environments/production.rb | 50 ++++++++++--- .../new_framework_defaults_7_2.rb | 70 ------------------ ..._to_active_storage_blobs.active_storage.rb | 24 ------ ..._storage_variant_records.active_storage.rb | 28 ------- ...e_storage_blobs_checksum.active_storage.rb | 8 -- public/icon.png | Bin 5599 -> 0 bytes public/icon.svg | 3 - 8 files changed, 42 insertions(+), 143 deletions(-) delete mode 100644 config/initializers/new_framework_defaults_7_2.rb delete mode 100644 db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb delete mode 100644 db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb delete mode 100644 db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb delete mode 100644 public/icon.png delete mode 100644 public/icon.svg diff --git a/config/environments/development.rb b/config/environments/development.rb index 2da9a3f01..6ad926c0d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -41,6 +41,8 @@ # caching is enabled. config.action_mailer.perform_caching = false + config.action_mailer.delivery_method = :letter_opener + config.action_mailer.perform_deliveries = true config.action_mailer.default_url_options = { host: "localhost", port: 3000 } # Print deprecation notices to the Rails logger. diff --git a/config/environments/production.rb b/config/environments/production.rb index bc1a4c91f..8de854014 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -41,16 +41,6 @@ # Mount Action Cable outside main process or domain. # config.action_cable.mount_path = nil - # config.action_cable.url = "wss://example.com/cable" - # config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ] - - # Assume all access to the app is happening through a SSL-terminating reverse proxy. - # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies. - # config.assume_ssl = true - - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - config.force_ssl = true - # Skip http-to-https redirect for the default health check endpoint. # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } @@ -92,6 +82,46 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record + # .database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record + # .database_resolver_context = ActiveRecord::Middleware: + # :DatabaseSelector::Resolver::Session + config.action_mailer.delivery_method = :smtp + config.action_mailer.raise_delivery_errors = true + config.action_mailer.perform_deliveries = true + config.action_mailer.default_url_options = { + host: "zero-waste-project.herokuapp.com", + protocol: "https" + } + config.action_mailer.smtp_settings = { + address: "smtp.sendgrid.net", + port: 587, + domain: "zero-waste-project.herokuapp.com", + user_name: ENV.fetch("SENDGRID_USERNAME", nil), + password: ENV.fetch("SENDGRID_API_KEY", nil), + authentication: "plain", + enable_starttls_auto: true + } + # Enable DNS rebinding protection and other `Host` header attacks. # config.hosts = [ # "example.com", # Allow requests from example.com diff --git a/config/initializers/new_framework_defaults_7_2.rb b/config/initializers/new_framework_defaults_7_2.rb deleted file mode 100644 index b549c4a25..000000000 --- a/config/initializers/new_framework_defaults_7_2.rb +++ /dev/null @@ -1,70 +0,0 @@ -# Be sure to restart your server when you modify this file. -# -# This file eases your Rails 7.2 framework defaults upgrade. -# -# Uncomment each configuration one by one to switch to the new default. -# Once your application is ready to run with all new defaults, you can remove -# this file and set the `config.load_defaults` to `7.2`. -# -# Read the Guide for Upgrading Ruby on Rails for more info on each option. -# https://guides.rubyonrails.org/upgrading_ruby_on_rails.html - -### -# Controls whether Active Job's `#perform_later` and similar methods automatically defer -# the job queuing to after the current Active Record transaction is committed. -# -# Example: -# Topic.transaction do -# topic = Topic.create(...) -# NewTopicNotificationJob.perform_later(topic) -# end -# -# In this example, if the configuration is set to `:never`, the job will -# be enqueued immediately, even though the `Topic` hasn't been committed yet. -# Because of this, if the job is picked up almost immediately, or if the -# transaction doesn't succeed for some reason, the job will fail to find this -# topic in the database. -# -# If `enqueue_after_transaction_commit` is set to `:default`, the queue adapter -# will define the behaviour. -# -# Note: Active Job backends can disable this feature. This is generally done by -# backends that use the same database as Active Record as a queue, hence they -# don't need this feature. -#++ -# Rails.application.config.active_job.enqueue_after_transaction_commit = :default - -### -# Adds image/webp to the list of content types Active Storage considers as an image -# Prevents automatic conversion to a fallback PNG, and assumes clients support WebP, as they support gif, jpeg, and png. -# This is possible due to broad browser support for WebP, but older browsers and email clients may still not support -# WebP. Requires imagemagick/libvips built with WebP support. -#++ -# Rails.application.config.active_storage.web_image_content_types = %w[image/png image/jpeg image/gif image/webp] - -### -# Enable validation of migration timestamps. When set, an ActiveRecord::InvalidMigrationTimestampError -# will be raised if the timestamp prefix for a migration is more than a day ahead of the timestamp -# associated with the current time. This is done to prevent forward-dating of migration files, which can -# impact migration generation and other migration commands. -# -# Applications with existing timestamped migrations that do not adhere to the -# expected format can disable validation by setting this config to `false`. -#++ -# Rails.application.config.active_record.validate_migration_timestamps = true - -### -# Controls whether the PostgresqlAdapter should decode dates automatically with manual queries. -# -# Example: -# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.select_value("select '2024-01-01'::date") #=> Date -# -# This query used to return a `String`. -#++ -# Rails.application.config.active_record.postgresql_adapter_decode_dates = true - -### -# Enables YJIT as of Ruby 3.3, to bring sizeable performance improvements. If you are -# deploying to a memory constrained environment you may want to set this to `false`. -#++ -# Rails.application.config.yjit = true diff --git a/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb b/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb deleted file mode 100644 index b9560cdff..000000000 --- a/db/migrate/20241030095707_add_service_name_to_active_storage_blobs.active_storage.rb +++ /dev/null @@ -1,24 +0,0 @@ -# This migration comes from active_storage (originally 20190112182829) -class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0] - def up - return unless table_exists?(:active_storage_blobs) - - unless column_exists?(:active_storage_blobs, :service_name) - add_column :active_storage_blobs, :service_name, :string - - if (configured_service = ActiveStorage::Blob.service.name) - ActiveStorage::Blob.unscoped.find_each do |blob| - blob.update(service_name: configured_service) - end - end - - change_column :active_storage_blobs, :service_name, :string, null: false - end - end - - def down - return unless table_exists?(:active_storage_blobs) - - remove_column :active_storage_blobs, :service_name - end -end diff --git a/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb b/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb deleted file mode 100644 index 223b837f9..000000000 --- a/db/migrate/20241030095708_create_active_storage_variant_records.active_storage.rb +++ /dev/null @@ -1,28 +0,0 @@ -# This migration comes from active_storage (originally 20191206030411) -class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0] - def change - return unless table_exists?(:active_storage_blobs) - - # Use Active Record's configured type for primary key - create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t| - t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type - t.string :variation_digest, null: false - - t.index [:blob_id, :variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true - t.foreign_key :active_storage_blobs, column: :blob_id - end - end - - private - - def primary_key_type - config = Rails.configuration.generators - config.options[config.orm][:primary_key_type] || :primary_key - end - - def blobs_primary_key_type - pkey_name = connection.primary_key(:active_storage_blobs) - pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name } - pkey_column.bigint? ? :bigint : pkey_column.type - end -end diff --git a/db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb b/db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb deleted file mode 100644 index 93c8b85ad..000000000 --- a/db/migrate/20241030095709_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb +++ /dev/null @@ -1,8 +0,0 @@ -# This migration comes from active_storage (originally 20211119233751) -class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0] - def change - return unless table_exists?(:active_storage_blobs) - - change_column_null(:active_storage_blobs, :checksum, true) - end -end diff --git a/public/icon.png b/public/icon.png deleted file mode 100644 index f3b5abcbde91cf6d7a6a26e514eb7e30f476f950..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5599 zcmeHL-D}fO6hCR_taXJlzs3}~RuB=Iujyo=i*=1|1FN%E=zNfMTjru|Q<6v{J{U!C zBEE}?j6I3sz>fzN!6}L_BKjcuASk~1;Dg|U_@d{g?V8mM`~#9U+>>*Ezw>c(PjYWA z4(;!cgge6k5E&d$G5`S-0}!Ik>CV(0Y#1}s-v_gAHhja2=W1?nBAte9D2HG<(+)uj z!5=W4u*{VKMw#{V@^NNs4TClr!FAA%ID-*gc{R%CFKEzG<6gm*9s_uy)oMGW*=nJf zw{(Mau|2FHfXIv6C0@Wk5k)F=3jo1srV-C{pl&k&)4_&JjYrnbJiul}d0^NCSh(#7h=F;3{|>EU>h z6U8_p;^wK6mAB(1b92>5-HxJ~V}@3?G`&Qq-TbJ2(&~-HsH6F#8mFaAG(45eT3VPO zM|(Jd<+;UZs;w>0Qw}0>D%{~r{uo_Fl5_Bo3ABWi zWo^j^_T3dxG6J6fH8X)$a^%TJ#PU!=LxF=#Fd9EvKx_x>q<(KY%+y-08?kN9dXjXK z**Q=yt-FTU*13ouhCdqq-0&;Ke{T3sQU9IdzhV9LhQIpq*P{N)+}|Mh+a-VV=x?R} c>%+pvTcMWshj-umO}|qP?%A)*_KlqT3uEqhU;qFB diff --git a/public/icon.svg b/public/icon.svg deleted file mode 100644 index 78307ccd4..000000000 --- a/public/icon.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - From a97ca15c84dc1306dd7aa7f25cedb6b4907c1454 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Mon, 18 Nov 2024 21:23:37 +0200 Subject: [PATCH 16/26] Added configs --- config/application.rb | 7 +++++- config/boot.rb | 2 ++ config/environment.rb | 2 ++ config/environments/development.rb | 3 +++ config/environments/production.rb | 25 +++++++++++++++++-- config/environments/test.rb | 17 +++++++++++-- config/initializers/assets.rb | 4 +++ .../initializers/content_security_policy.rb | 2 ++ .../initializers/filter_parameter_logging.rb | 4 ++- config/initializers/inflections.rb | 2 ++ config/initializers/permissions_policy.rb | 2 ++ config/puma.rb | 19 ++++++++------ spec/features/account/users_spec.rb | 5 ++-- 13 files changed, 78 insertions(+), 16 deletions(-) diff --git a/config/application.rb b/config/application.rb index fd0c1c612..e61e0f95a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -11,6 +11,7 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 7.1 + config.active_job.queue_adapter = :sidekiq # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. @@ -23,7 +24,11 @@ class Application < Rails::Application # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. # - # config.time_zone = "Central Time (US & Canada)" + config.time_zone = "Europe/Kyiv" # config.eager_load_paths << Rails.root.join("extras") + config.i18n.available_locales = [:en, :uk] + config.i18n.default_locale = :en + + config.i18n.load_path += Rails.root.glob("config/locales/**/*.{rb,yml}") end end diff --git a/config/boot.rb b/config/boot.rb index 988a5ddc4..aef6d031e 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/environment.rb b/config/environment.rb index cac531577..7df99e89c 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 6ad926c0d..0c76eadb9 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do @@ -75,6 +77,7 @@ # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } # Raise error when a before_action's only/except options reference missing actions. config.action_controller.raise_on_missing_callback_actions = true diff --git a/config/environments/production.rb b/config/environments/production.rb index 8de854014..281dbe915 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "active_support/core_ext/integer/time" Rails.application.configure do @@ -20,8 +22,9 @@ # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true - # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead. - # config.public_file_server.enabled = false + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass @@ -44,6 +47,7 @@ # Skip http-to-https redirect for the default health check endpoint. # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + config.log_level = :info # Log to STDOUT by default config.logger = ActiveSupport::Logger.new($stdout) .tap { |logger| logger.formatter = ::Logger::Formatter.new } @@ -76,6 +80,23 @@ # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Log disallowed deprecations. + config.active_support.disallowed_deprecation = :log + + # Tell Active Support which deprecation messages to disallow. + config.active_support.disallowed_deprecation_warnings = [] + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new($stdout) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end # Don't log any deprecations. config.active_support.report_deprecations = false diff --git a/config/environments/test.rb b/config/environments/test.rb index 0c616a1bf..e48a124db 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -6,7 +6,19 @@ # and recreated between test runs. Don't rely on the data there! Rails.application.configure do - # Settings specified here will take precedence over those in config/application.rb. + # Settings specified here will take precedence over those in + # config/application.rb. + + config.cache_classes = false + config.action_view.cache_template_loading = true + config.serve_static_files = ENV["USE_STATIC_ASSETS"] == "true" + config.static_cache_control = "public, max-age=3600" + config.assets.compile = ENV["USE_STATIC_ASSETS"] != "true" + config.assets.digest = true + # 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 # While tests run files are not watched, reloading is not necessary. config.enable_reloading = false @@ -45,7 +57,7 @@ # Unlike controllers, the mailer instance doesn't have any context about the # incoming request so you'll need to provide the :host parameter yourself. - config.action_mailer.default_url_options = { host: "www.example.com" } + config.action_mailer.default_url_options = { host: "localhost" } # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr @@ -55,6 +67,7 @@ # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] + config.active_job.queue_adapter = :test # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index bd5bcd2b6..e439ffad3 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. @@ -9,4 +11,6 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. + +Rails.application.config.assets.precompile += ["turbo-streams.js", "bootstrap.min.js", "popper.js", "toastify-js"] # Rails.application.config.assets.precompile += %w[ admin.js admin.css ] diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index b3076b38f..35ab3fd6a 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide content security policy. diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index c010b83dd..a119afa12 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. # Use this to limit dissemination of sensitive information. # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. Rails.application.config.filter_parameters += [ - :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 21e5f9e95..02ba27e31 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Add new inflection rules using the following format. Inflections diff --git a/config/initializers/permissions_policy.rb b/config/initializers/permissions_policy.rb index 7db3b9577..e8d0b2ae8 100644 --- a/config/initializers/permissions_policy.rb +++ b/config/initializers/permissions_policy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Be sure to restart your server when you modify this file. # Define an application-wide HTTP permissions policy. For further diff --git a/config/puma.rb b/config/puma.rb index 03c166f4c..9c1ecbe4c 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,10 +1,21 @@ +# frozen_string_literal: true + # This configuration file will be evaluated by Puma. The top-level methods that # are invoked here are part of Puma's configuration DSL. For more information # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. # Puma starts a configurable number of processes (workers) and each process # serves each request in a thread from an internal thread pool. -# + +max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5) +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } + +threads min_threads_count, max_threads_count + +# Specifies the `worker_timeout` threshold that Puma will use to wait before +# terminating a worker in development environments. +worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" + # The ideal number of threads per worker depends both on how much time the # application spends waiting for IO operations and on how much you wish to # to prioritize throughput over latency. @@ -16,12 +27,6 @@ # # The default is set to 3 threads as it's deemed a decent compromise between # throughput and latency for the average Rails application. -# -# Any libraries that use a connection pool or another resource pool should -# be configured to provide at least as many connections as the number of -# threads. This includes Active Record's `pool` parameter in `database.yml`. -threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) -threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. port ENV.fetch("PORT", 3000) diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index b8494ef4d..54f9bff34 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "visit admin page", js: true do - let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv").utc } + let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv") } let!(:another_user) do create(:user, email: "test1@gmail.com", password: "12345878", last_sign_in_at: time_login) @@ -14,8 +14,7 @@ it "visits admin page" do visit account_users_path expect(page).to have_content "test1@gmail.com" - formatted_time_login = time_login.utc.strftime("%Y-%m-%d %H:%M:%S UTC") - expect(page).to have_content formatted_time_login + expect(page).to have_content time_login end context "when user clicks show icon" do From 3e47a491037737e340f4b9b477c9f32693cd2b9e Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Mon, 18 Nov 2024 21:31:49 +0200 Subject: [PATCH 17/26] Deleted Europe in timezone --- config/application.rb | 2 +- spec/features/account/users_spec.rb | 2 +- spec/lib/users_csv_generator_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/application.rb b/config/application.rb index e61e0f95a..8eaa46efc 100644 --- a/config/application.rb +++ b/config/application.rb @@ -24,7 +24,7 @@ class Application < Rails::Application # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. # - config.time_zone = "Europe/Kyiv" + config.time_zone = "Kyiv" # config.eager_load_paths << Rails.root.join("extras") config.i18n.available_locales = [:en, :uk] config.i18n.default_locale = :en diff --git a/spec/features/account/users_spec.rb b/spec/features/account/users_spec.rb index 54f9bff34..130133514 100644 --- a/spec/features/account/users_spec.rb +++ b/spec/features/account/users_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" describe "visit admin page", js: true do - let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv") } + let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Kyiv") } let!(:another_user) do create(:user, email: "test1@gmail.com", password: "12345878", last_sign_in_at: time_login) diff --git a/spec/lib/users_csv_generator_spec.rb b/spec/lib/users_csv_generator_spec.rb index 58d3f45f5..856d004ca 100644 --- a/spec/lib/users_csv_generator_spec.rb +++ b/spec/lib/users_csv_generator_spec.rb @@ -3,7 +3,7 @@ require "rails_helper" RSpec.describe UsersCsvGenerator do - let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Europe/Kyiv") } + let(:time_login) { Time.new(2020, 0o1, 0o1).in_time_zone("Kyiv") } let(:users) do [create(:user, email: "test@gmail.com", first_name: "Han", last_name: "Solo", last_sign_in_at: time_login)] From 9ce562fbe9abb1da2e573a17809389a23e293003 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Tue, 26 Nov 2024 15:29:51 +0200 Subject: [PATCH 18/26] Deleted logger by default --- config/environments/production.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 281dbe915..4d19f6231 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -48,10 +48,6 @@ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } config.log_level = :info - # Log to STDOUT by default - config.logger = ActiveSupport::Logger.new($stdout) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } - .then { |logger| ActiveSupport::TaggedLogging.new(logger) } # Prepend all log lines with the following tags. config.log_tags = [:request_id] From 776cf2ede2f36f4d8d05611bc5afeb71bf9b510d Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Sat, 30 Nov 2024 22:02:47 +0200 Subject: [PATCH 19/26] Updated gemfile --- Gemfile | 2 -- Gemfile.lock | 53 +++------------------------------------------------- 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/Gemfile b/Gemfile index b7b6ac8b2..12ea6f546 100644 --- a/Gemfile +++ b/Gemfile @@ -60,8 +60,6 @@ group :development, :test, :ci do gem "rubocop-rspec", require: false gem "rubocop-performance", require: false gem "rubocop-rails", require: false - gem "rubocop-factory_bot", require: false - gem "rubocop-capybara", require: false gem "standard", "~> 1.0", require: false gem "rubocop-factory_bot" gem "rubocop-capybara" diff --git a/Gemfile.lock b/Gemfile.lock index 93c60c3f4..9425b0024 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,8 +99,6 @@ GEM base64 (0.2.0) bcrypt (3.1.20) bcrypt_pbkdf (1.1.1) - bcrypt_pbkdf (1.1.1-arm64-darwin) - bcrypt_pbkdf (1.1.1-x86_64-darwin) bigdecimal (3.0.2) bindex (0.8.1) bootsnap (1.18.4) @@ -148,8 +146,9 @@ GEM activesupport childprocess (5.1.0) logger (~> 1.5) - codecov (0.6.0) - simplecov (>= 0.15, < 0.22) + codecov (0.2.12) + json + simplecov coderay (1.1.3) concurrent-ruby (1.3.4) connection_pool (2.4.1) @@ -199,16 +198,7 @@ GEM logger faraday-net_http (3.3.0) net-http - ffi (1.17.0-aarch64-linux-gnu) - ffi (1.17.0-aarch64-linux-musl) - ffi (1.17.0-arm-linux-gnu) - ffi (1.17.0-arm-linux-musl) - ffi (1.17.0-arm64-darwin) - ffi (1.17.0-x86-linux-gnu) - ffi (1.17.0-x86-linux-musl) - ffi (1.17.0-x86_64-darwin) ffi (1.17.0-x86_64-linux-gnu) - ffi (1.17.0-x86_64-linux-musl) flipper (1.3.1) concurrent-ruby (< 2) flipper-active_record (1.3.1) @@ -289,10 +279,8 @@ GEM method_source (1.1.0) mini_magick (4.13.2) mini_mime (1.1.5) - mini_portile2 (2.8.7) minitest (5.25.1) msgpack (1.7.3) - multi_json (1.15.0) multi_xml (0.6.0) mutex_m (0.1.2) net-http (0.4.1) @@ -312,16 +300,6 @@ GEM net-protocol net-ssh (7.3.0) nio4r (2.7.4) - nokogiri (1.16.7-aarch64-linux) - racc (~> 1.4) - nokogiri (1.16.7-arm-linux) - racc (~> 1.4) - nokogiri (1.16.7-arm64-darwin) - racc (~> 1.4) - nokogiri (1.16.7-x86-linux) - racc (~> 1.4) - nokogiri (1.16.7-x86_64-darwin) - racc (~> 1.4) nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) oauth2 (2.0.9) @@ -564,16 +542,6 @@ GEM stimulus-rails (1.3.4) railties (>= 6.0.0) stringio (3.1.1) - tailwindcss-rails (2.7.9) - railties (>= 7.0.0) - tailwindcss-rails (2.7.9-aarch64-linux) - railties (>= 7.0.0) - tailwindcss-rails (2.7.9-arm-linux) - railties (>= 7.0.0) - tailwindcss-rails (2.7.9-arm64-darwin) - railties (>= 7.0.0) - tailwindcss-rails (2.7.9-x86_64-darwin) - railties (>= 7.0.0) tailwindcss-rails (2.7.9-x86_64-linux) railties (>= 7.0.0) temple (0.10.3) @@ -587,8 +555,6 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - tzinfo-data (1.2024.2) - tzinfo (>= 1.0.0) unaccent (0.4.0) unicode-display_width (2.6.0) uri (0.13.1) @@ -615,20 +581,7 @@ GEM zeitwerk (2.7.1) PLATFORMS - aarch64-linux - aarch64-linux-gnu - aarch64-linux-musl - arm-linux - arm-linux-gnu - arm-linux-musl - arm64-darwin - x86-linux - x86-linux-gnu - x86-linux-musl - x86_64-darwin x86_64-linux - x86_64-linux-gnu - x86_64-linux-musl DEPENDENCIES active_model_serializers (~> 0.10.0) From c00152f447853ca4f67a1b1eb50b5c8b46a3cc7c Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Sat, 30 Nov 2024 22:17:33 +0200 Subject: [PATCH 20/26] Fixed rspec mhc_calculator --- db/schema.rb | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 84c013b28..010a63503 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_10_31_011638) do +ActiveRecord::Schema[7.2].define(version: 2024_11_30_191031) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -32,7 +32,7 @@ t.text "metadata" t.string "service_name", null: false t.bigint "byte_size", null: false - t.string "checksum" + t.string "checksum", null: false t.datetime "created_at", precision: nil, null: false t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end @@ -44,15 +44,12 @@ end create_table "calculators", force: :cascade do |t| - t.uuid "uuid", default: -> { "gen_random_uuid()" }, null: false - t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "slug" - t.boolean "preferable", default: false - t.index ["name"], name: "index_calculators_on_name", unique: true + t.string "uk_name", default: "", null: false + t.string "en_name", default: "", null: false t.index ["slug"], name: "index_calculators_on_slug", unique: true - t.index ["uuid"], name: "index_calculators_on_uuid", unique: true end create_table "categories", force: :cascade do |t| @@ -60,10 +57,13 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "priority", default: 0, null: false - t.boolean "preferable", default: false, null: false t.string "en_name" - t.index "lower((en_name)::text)", name: "index_categories_on_en_name", unique: true - t.index "lower((uk_name)::text)", name: "index_categories_on_uk_name", unique: true + t.decimal "price", precision: 10, scale: 2, default: "0.0", null: false + t.bigint "field_id" + t.boolean "preferable", default: false, null: false + t.index ["en_name"], name: "index_categories_on_en_name", unique: true + t.index ["field_id"], name: "index_categories_on_field_id" + t.index ["uk_name"], name: "index_categories_on_uk_name", unique: true end create_table "category_categoryables", force: :cascade do |t| @@ -97,21 +97,15 @@ end create_table "fields", force: :cascade do |t| - t.uuid "uuid", default: -> { "gen_random_uuid()" }, null: false - t.bigint "calculator_id", null: false - t.string "selector", null: false - t.string "type", null: false - t.string "label" - t.string "name" - t.string "value" - t.integer "from" - t.integer "to" - t.integer "kind", null: false + t.string "kind", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "unit", default: 0 + t.string "uk_label", default: "", null: false + t.string "en_label", default: "", null: false + t.string "var_name", default: "", null: false + t.bigint "calculator_id", null: false t.index ["calculator_id"], name: "index_fields_on_calculator_id" - t.index ["uuid"], name: "index_fields_on_uuid", unique: true end create_table "flipper_features", force: :cascade do |t| @@ -132,6 +126,19 @@ t.index ["feature_key", "key", "value"], name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true end + create_table "formulas", force: :cascade do |t| + t.string "expression", default: "", null: false + t.string "uk_label", default: "", null: false + t.string "en_label", default: "", null: false + t.string "uk_unit" + t.string "en_unit" + t.bigint "calculator_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "priority", default: 0, null: false + t.index ["calculator_id"], name: "index_formulas_on_calculator_id" + end + create_table "messages", force: :cascade do |t| t.string "title", null: false t.string "message", null: false @@ -201,9 +208,9 @@ t.string "last_sign_in_ip" t.string "provider" t.string "uid" - t.boolean "blocked", default: false + t.boolean "blocked", default: false, null: false t.integer "role", default: 0 - t.boolean "receive_recomendations", default: false + t.boolean "receive_recomendations", default: false, null: false t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end @@ -222,6 +229,9 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" + add_foreign_key "categories", "fields" add_foreign_key "category_categoryables", "categories" add_foreign_key "diapers_periods", "categories" + add_foreign_key "fields", "calculators" + add_foreign_key "formulas", "calculators" end From 31c5f50c6b3bb68d30400c0929f803d03de4bbf0 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Sun, 1 Dec 2024 12:57:22 +0200 Subject: [PATCH 21/26] Changed schema --- db/schema.rb | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 010a63503..93e57b4d0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.2].define(version: 2024_11_30_191031) do +ActiveRecord::Schema[7.2].define(version: 2024_10_31_011638) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -44,12 +44,15 @@ end create_table "calculators", force: :cascade do |t| + t.uuid "uuid", default: -> { "gen_random_uuid()" }, null: false + t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "slug" - t.string "uk_name", default: "", null: false - t.string "en_name", default: "", null: false + t.boolean "preferable", default: false, null: false + t.index ["name"], name: "index_calculators_on_name", unique: true t.index ["slug"], name: "index_calculators_on_slug", unique: true + t.index ["uuid"], name: "index_calculators_on_uuid", unique: true end create_table "categories", force: :cascade do |t| @@ -57,13 +60,10 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "priority", default: 0, null: false - t.string "en_name" - t.decimal "price", precision: 10, scale: 2, default: "0.0", null: false - t.bigint "field_id" t.boolean "preferable", default: false, null: false - t.index ["en_name"], name: "index_categories_on_en_name", unique: true - t.index ["field_id"], name: "index_categories_on_field_id" - t.index ["uk_name"], name: "index_categories_on_uk_name", unique: true + t.string "en_name" + t.index "lower((en_name)::text)", name: "index_categories_on_en_name", unique: true + t.index "lower((uk_name)::text)", name: "index_categories_on_uk_name", unique: true end create_table "category_categoryables", force: :cascade do |t| @@ -97,15 +97,21 @@ end create_table "fields", force: :cascade do |t| - t.string "kind", null: false + t.uuid "uuid", default: -> { "gen_random_uuid()" }, null: false + t.bigint "calculator_id", null: false + t.string "selector", null: false + t.string "type", null: false + t.string "label" + t.string "name" + t.string "value" + t.integer "from" + t.integer "to" + t.integer "kind", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "unit", default: 0 - t.string "uk_label", default: "", null: false - t.string "en_label", default: "", null: false - t.string "var_name", default: "", null: false - t.bigint "calculator_id", null: false t.index ["calculator_id"], name: "index_fields_on_calculator_id" + t.index ["uuid"], name: "index_fields_on_uuid", unique: true end create_table "flipper_features", force: :cascade do |t| @@ -126,19 +132,6 @@ t.index ["feature_key", "key", "value"], name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true end - create_table "formulas", force: :cascade do |t| - t.string "expression", default: "", null: false - t.string "uk_label", default: "", null: false - t.string "en_label", default: "", null: false - t.string "uk_unit" - t.string "en_unit" - t.bigint "calculator_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.integer "priority", default: 0, null: false - t.index ["calculator_id"], name: "index_formulas_on_calculator_id" - end - create_table "messages", force: :cascade do |t| t.string "title", null: false t.string "message", null: false @@ -229,9 +222,6 @@ add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" - add_foreign_key "categories", "fields" add_foreign_key "category_categoryables", "categories" add_foreign_key "diapers_periods", "categories" - add_foreign_key "fields", "calculators" - add_foreign_key "formulas", "calculators" end From d6efd56b902f026e7fd7085ddccfbfd0a867e001 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Sun, 1 Dec 2024 14:39:27 +0200 Subject: [PATCH 22/26] Changed config --- config/environments/test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/test.rb b/config/environments/test.rb index e48a124db..5cac765ca 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -38,7 +38,7 @@ config.cache_store = :null_store # Render exception templates for rescuable exceptions and raise for other exceptions. - config.action_dispatch.show_exceptions = :rescuable + config.action_dispatch.show_exceptions = :none # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false From 44f9e21cc6e23b5d0b48b06ab747c629fa64b434 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Sun, 1 Dec 2024 14:53:45 +0200 Subject: [PATCH 23/26] Resolved comments --- Gemfile | 4 ++-- config/environments/test.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 12ea6f546..02a3f7965 100644 --- a/Gemfile +++ b/Gemfile @@ -61,8 +61,8 @@ group :development, :test, :ci do gem "rubocop-performance", require: false gem "rubocop-rails", require: false gem "standard", "~> 1.0", require: false - gem "rubocop-factory_bot" - gem "rubocop-capybara" + gem "rubocop-factory_bot", require: false + gem "rubocop-capybara", require: false end group :development do diff --git a/config/environments/test.rb b/config/environments/test.rb index 5cac765ca..ad34de711 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -37,7 +37,7 @@ config.action_controller.perform_caching = false config.cache_store = :null_store - # Render exception templates for rescuable exceptions and raise for other exceptions. + # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = :none # Disable request forgery protection in test environment. From 793e8c8d4b0d86438d9f8ee16f89f18f1eff88cd Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Sun, 1 Dec 2024 15:03:55 +0200 Subject: [PATCH 24/26] Deleted require:false --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 02a3f7965..12ea6f546 100644 --- a/Gemfile +++ b/Gemfile @@ -61,8 +61,8 @@ group :development, :test, :ci do gem "rubocop-performance", require: false gem "rubocop-rails", require: false gem "standard", "~> 1.0", require: false - gem "rubocop-factory_bot", require: false - gem "rubocop-capybara", require: false + gem "rubocop-factory_bot" + gem "rubocop-capybara" end group :development do From 3f4f0eadb759a7541a24fbcf886e2fdd5ae5d84a Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Mon, 2 Dec 2024 11:52:12 +0200 Subject: [PATCH 25/26] Deleted lint_env --- .rubocop.yml | 3 --- .rubocop_custom.yml | 18 ----------------- Gemfile | 4 ++-- lib/rubo_cop/cop/lint_env.rb | 38 ------------------------------------ 4 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 lib/rubo_cop/cop/lint_env.rb diff --git a/.rubocop.yml b/.rubocop.yml index e13b1071c..449ee5f10 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -57,6 +57,3 @@ Style/WordArray: Style/BlockDelimiters: Enabled: true EnforcedStyle: line_count_based - -LintEnv: - Enabled: false diff --git a/.rubocop_custom.yml b/.rubocop_custom.yml index 1fcedab62..870b9f3a6 100644 --- a/.rubocop_custom.yml +++ b/.rubocop_custom.yml @@ -1,21 +1,3 @@ -require: - # Cops source code lives in the lib/ folder - - ./lib/rubo_cop/cop/lint_env - -LintEnv: - Enabled: true - Include: - - "**/*.rb" - Exclude: - - "**/config/environments/**/*" - - "**/config/application.rb" - - "**/config/environment.rb" - - "**/config/puma.rb" - - "**/config/boot.rb" - - "**/spec/*_helper.rb" - - "**/spec/**/support/**/*" - - "lib/generators/**/*" - Layout/ExtraSpacing: Exclude: - "**/config/environments/**/*" diff --git a/Gemfile b/Gemfile index 12ea6f546..02a3f7965 100644 --- a/Gemfile +++ b/Gemfile @@ -61,8 +61,8 @@ group :development, :test, :ci do gem "rubocop-performance", require: false gem "rubocop-rails", require: false gem "standard", "~> 1.0", require: false - gem "rubocop-factory_bot" - gem "rubocop-capybara" + gem "rubocop-factory_bot", require: false + gem "rubocop-capybara", require: false end group :development do diff --git a/lib/rubo_cop/cop/lint_env.rb b/lib/rubo_cop/cop/lint_env.rb deleted file mode 100644 index ab776ab7e..000000000 --- a/lib/rubo_cop/cop/lint_env.rb +++ /dev/null @@ -1,38 +0,0 @@ -# This cops checks for direct usage of ENV variables and -# Rails.env -class RuboCop::Cop::LintEnv < RuboCop::Cop::Cop - MSG_ENV = "Avoid direct usage of ENV in application code" - MSG_RAILS_ENV = "Avoid direct usage of Rails.env in application code" - USAGE_MSG = ", use configuration parameters instead" - - def_node_matcher :env?, <<~PATTERN - {(const nil? :ENV) (const (cbase) :ENV)} - PATTERN - - def_node_matcher :rails_env?, <<~PATTERN - (send {(const nil? :Rails) (const (cbase) :Rails)} :env) - PATTERN - - def on_const(node) - return unless env?(node) - return if allowed_env?(node.parent.children.last.children.last) - add_offense(node.parent, location: :selector, message: MSG_ENV + USAGE_MSG) - end - - def on_send(node) - return unless rails_env?(node) - add_offense((node.parent.type == :send) ? node.parent : node, location: :selector, message: MSG_RAILS_ENV + USAGE_MSG) - end - - private - - def allowed_env - Array(cop_config["AllowedEnv"]) - end - - def allowed_env?(env) - return true if cop_config["AllowedEnv"] == "all" - - allowed_env.include?(env) - end -end From 6d7e2cd75bae5d2c4c19edeafb8e4b56373b7ff7 Mon Sep 17 00:00:00 2001 From: KseniaGovorun Date: Wed, 4 Dec 2024 09:36:12 +0200 Subject: [PATCH 26/26] Changed load_defaults --- config/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 8eaa46efc..a6cd3f649 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,7 @@ module ZeroWaste class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 7.1 + config.load_defaults 7.2 config.active_job.queue_adapter = :sidekiq # Please, add to the `ignore` list any other `lib` subdirectories that do