From 95a2fe41ec3b185ef5722a5efefd495e60e3ca3c Mon Sep 17 00:00:00 2001 From: Alex Baldwin Date: Fri, 3 Jun 2022 20:20:42 -0400 Subject: [PATCH] Upgrade to Rails 7 Upgrade to Rails 7 with `rails new` default project scaffolding Fixes #11 Content Policy prevented stimulus controller from loading which caused message input to not clear on submit --- Gemfile | 84 ++--- Gemfile.lock | 302 ++++++++++-------- app/assets/config/manifest.js | 3 +- app/assets/javascripts/importmap.json.erb | 5 - app/assets/stylesheets/application.css | 5 +- app/assets/stylesheets/scaffolds.scss | 65 ---- app/channels/application_cable/channel.rb | 4 + app/channels/application_cable/connection.rb | 4 + .../.gitkeep => controllers/concerns/.keep} | 0 app/helpers/messages_helper.rb | 2 + app/helpers/rooms_helper.rb | 2 + app/javascript/application.js | 3 + app/javascript/controllers/application.js | 9 + .../controllers/hello_controller.js | 7 + app/javascript/controllers/index.js | 11 + .../controllers/reset_form_controller.js | 2 +- app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 2 +- app/models/concerns/.keep | 0 app/views/layouts/application.html.erb | 6 +- app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + bin/bundle | 16 +- bin/importmap | 4 + bin/rails | 3 +- bin/rake | 1 - bin/setup | 19 +- bin/spring | 10 - config/application.rb | 2 +- config/boot.rb | 2 +- config/credentials.yml.enc | 2 +- config/database.yml | 2 +- config/environments/development.rb | 16 +- config/environments/production.rb | 45 +-- config/environments/test.rb | 14 +- config/importmap.rb | 7 + .../application_controller_renderer.rb | 8 - config/initializers/assets.rb | 2 +- config/initializers/backtrace_silencers.rb | 8 - .../initializers/content_security_policy.rb | 45 ++- config/initializers/cookies_serializer.rb | 5 - .../initializers/filter_parameter_logging.rb | 4 +- config/initializers/inflections.rb | 8 +- config/initializers/mime_types.rb | 4 - config/initializers/wrap_parameters.rb | 14 - config/locales/en.yml | 6 +- config/puma.rb | 2 +- config/spring.rb | 6 - config/storage.yml | 10 +- ...ooms.rb => 20220603235340_create_rooms.rb} | 2 +- ...s.rb => 20220603235402_create_messages.rb} | 2 +- db/schema.rb | 11 +- db/seeds.rb | 4 +- .../application_cable/connection_test.rb | 11 + test/controllers/messages_controller_test.rb | 48 +++ test/controllers/rooms_controller_test.rb | 4 +- test/system/messages_test.rb | 43 +++ test/system/rooms_test.rb | 18 +- test/test_helper.rb | 2 +- vendor/javascript/.keep | 0 60 files changed, 493 insertions(+), 451 deletions(-) delete mode 100644 app/assets/javascripts/importmap.json.erb delete mode 100644 app/assets/stylesheets/scaffolds.scss create mode 100644 app/channels/application_cable/channel.rb create mode 100644 app/channels/application_cable/connection.rb rename app/{assets/javascripts/libraries/.gitkeep => controllers/concerns/.keep} (100%) create mode 100644 app/helpers/messages_helper.rb create mode 100644 app/helpers/rooms_helper.rb create mode 100644 app/javascript/application.js create mode 100644 app/javascript/controllers/application.js create mode 100644 app/javascript/controllers/hello_controller.js create mode 100644 app/javascript/controllers/index.js rename app/{assets/javascripts => javascript}/controllers/reset_form_controller.js (64%) create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100755 bin/importmap delete mode 100755 bin/spring create mode 100644 config/importmap.rb delete mode 100644 config/initializers/application_controller_renderer.rb delete mode 100644 config/initializers/backtrace_silencers.rb delete mode 100644 config/initializers/cookies_serializer.rb delete mode 100644 config/initializers/mime_types.rb delete mode 100644 config/initializers/wrap_parameters.rb delete mode 100644 config/spring.rb rename db/migrate/{20201220113420_create_rooms.rb => 20220603235340_create_rooms.rb} (67%) rename db/migrate/{20201220113435_create_messages.rb => 20220603235402_create_messages.rb} (75%) create mode 100644 test/channels/application_cable/connection_test.rb create mode 100644 test/controllers/messages_controller_test.rb create mode 100644 test/system/messages_test.rb create mode 100644 vendor/javascript/.keep diff --git a/Gemfile b/Gemfile index 45d4dce..66abc40 100644 --- a/Gemfile +++ b/Gemfile @@ -1,62 +1,72 @@ -source 'https://rubygems.org' +source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '2.7.1' +ruby "3.1.2" -# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 6.1.3' +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 7.0.3" + +# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] +gem "sprockets-rails" # Use sqlite3 as the database for Active Record -gem 'sqlite3', '~> 1.4' +gem "sqlite3", "~> 1.4" + +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", "~> 5.0" -# Use Puma as the app server -gem 'puma', '~> 5.0' +# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] +gem "importmap-rails" -# Use SCSS for stylesheets -gem 'sass-rails', '>= 6' +# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] +gem "turbo-rails" -# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.7' +# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] +gem "stimulus-rails" -# Use Hotwire for the frontend -gem 'hotwire-rails' +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem "jbuilder" -# Use Redis for Action Cable -gem 'redis', '~> 4.0' +# Use Redis adapter to run Action Cable in production +gem "redis", "~> 4.0" -# Use Active Model has_secure_password -# gem 'bcrypt', '~> 3.1.7' +# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis] +# gem "kredis" -# Use Active Storage variant -# gem 'image_processing', '~> 1.2' +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ] # Reduces boot times through caching; required in config/boot.rb -gem 'bootsnap', '>= 1.4.4', require: false +gem "bootsnap", require: false + +# Use Sass to process CSS +# gem "sassc-rails" + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" group :development, :test do - # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem "debug", platforms: %i[ mri mingw x64_mingw ] end group :development do - # Access an interactive console on exception pages or by calling 'console' anywhere in the code. - gem 'web-console', '>= 4.1.0' - - # Display performance information such as SQL time and flame graphs for each request in your browser. - # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md - # gem 'rack-mini-profiler', '~> 2.0' + # Use console on exceptions pages [https://github.com/rails/web-console] + gem "web-console" - gem 'listen', '~> 3.3' + # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler] + # gem "rack-mini-profiler" - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' + # Speed up commands on slow machines / big apps [https://github.com/rails/spring] + # gem "spring" end group :test do - # Adds support for Capybara system testing and selenium driver - gem 'capybara', '>= 3.26' - gem 'selenium-webdriver' - - # Easy installation and use of web drivers to run system tests with browsers - gem 'webdrivers' + # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] + gem "capybara" + gem "selenium-webdriver" + gem "webdrivers" end diff --git a/Gemfile.lock b/Gemfile.lock index 7f51b35..658b275 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,221 +1,239 @@ GEM remote: https://rubygems.org/ specs: - actioncable (6.1.3.1) - actionpack (= 6.1.3.1) - activesupport (= 6.1.3.1) + actioncable (7.0.3) + actionpack (= 7.0.3) + activesupport (= 7.0.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.3.1) - actionpack (= 6.1.3.1) - activejob (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + actionmailbox (7.0.3) + actionpack (= 7.0.3) + activejob (= 7.0.3) + activerecord (= 7.0.3) + activestorage (= 7.0.3) + activesupport (= 7.0.3) mail (>= 2.7.1) - actionmailer (6.1.3.1) - actionpack (= 6.1.3.1) - actionview (= 6.1.3.1) - activejob (= 6.1.3.1) - activesupport (= 6.1.3.1) + net-imap + net-pop + net-smtp + actionmailer (7.0.3) + actionpack (= 7.0.3) + actionview (= 7.0.3) + activejob (= 7.0.3) + activesupport (= 7.0.3) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (6.1.3.1) - actionview (= 6.1.3.1) - activesupport (= 6.1.3.1) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.3) + actionview (= 7.0.3) + activesupport (= 7.0.3) + rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.3.1) - actionpack (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + actiontext (7.0.3) + actionpack (= 7.0.3) + activerecord (= 7.0.3) + activestorage (= 7.0.3) + activesupport (= 7.0.3) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.3.1) - activesupport (= 6.1.3.1) + actionview (7.0.3) + activesupport (= 7.0.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.3.1) - activesupport (= 6.1.3.1) + activejob (7.0.3) + activesupport (= 7.0.3) globalid (>= 0.3.6) - activemodel (6.1.3.1) - activesupport (= 6.1.3.1) - activerecord (6.1.3.1) - activemodel (= 6.1.3.1) - activesupport (= 6.1.3.1) - activestorage (6.1.3.1) - actionpack (= 6.1.3.1) - activejob (= 6.1.3.1) - activerecord (= 6.1.3.1) - activesupport (= 6.1.3.1) - marcel (~> 1.0.0) - mini_mime (~> 1.0.2) - activesupport (6.1.3.1) + activemodel (7.0.3) + activesupport (= 7.0.3) + activerecord (7.0.3) + activemodel (= 7.0.3) + activesupport (= 7.0.3) + activestorage (7.0.3) + actionpack (= 7.0.3) + activejob (= 7.0.3) + activerecord (= 7.0.3) + activesupport (= 7.0.3) + marcel (~> 1.0) + mini_mime (>= 1.1.0) + activesupport (7.0.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.7.0) + addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) bindex (0.8.1) - bootsnap (1.5.1) - msgpack (~> 1.0) + bootsnap (1.12.0) + msgpack (~> 1.2) builder (3.2.4) - byebug (11.1.3) - capybara (3.34.0) + capybara (3.37.1) addressable + matrix mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) rack-test (>= 0.6.3) - regexp_parser (~> 1.5) + regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - childprocess (3.0.0) - concurrent-ruby (1.1.8) + childprocess (4.1.0) + concurrent-ruby (1.1.10) crass (1.0.6) + debug (1.5.0) + irb (>= 1.3.6) + reline (>= 0.2.7) + digest (3.1.0) erubi (1.10.0) - ffi (1.14.2) - globalid (0.4.2) - activesupport (>= 4.2.0) - hotwire-rails (0.1.2) - rails (>= 6.0.0) - stimulus-rails - turbo-rails - i18n (1.8.10) + globalid (1.0.0) + activesupport (>= 5.0) + i18n (1.10.0) concurrent-ruby (~> 1.0) - jbuilder (2.10.1) + importmap-rails (1.1.0) + actionpack (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.5.11) + irb (1.4.1) + reline (>= 0.3.0) + jbuilder (2.11.5) + actionview (>= 5.0.0) activesupport (>= 5.0.0) - listen (3.3.3) - rb-fsevent (~> 0.10, >= 0.10.3) - rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.9.0) + loofah (2.18.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (1.0.0) + marcel (1.0.2) + matrix (0.4.2) method_source (1.0.0) - mini_mime (1.0.3) - mini_portile2 (2.5.0) - minitest (5.14.4) - msgpack (1.3.3) - nio4r (2.5.7) - nokogiri (1.11.2) - mini_portile2 (~> 2.5.0) + mini_mime (1.1.2) + minitest (5.15.0) + msgpack (1.5.2) + net-imap (0.2.3) + digest + net-protocol + strscan + net-pop (0.1.1) + digest + net-protocol + timeout + net-protocol (0.1.3) + timeout + net-smtp (0.3.1) + digest + net-protocol + timeout + nio4r (2.5.8) + nokogiri (1.13.6-x86_64-darwin) racc (~> 1.4) - public_suffix (4.0.6) - puma (5.1.1) + public_suffix (4.0.7) + puma (5.6.4) nio4r (~> 2.0) - racc (1.5.2) - rack (2.2.3) + racc (1.6.0) + rack (2.2.3.1) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (6.1.3.1) - actioncable (= 6.1.3.1) - actionmailbox (= 6.1.3.1) - actionmailer (= 6.1.3.1) - actionpack (= 6.1.3.1) - actiontext (= 6.1.3.1) - actionview (= 6.1.3.1) - activejob (= 6.1.3.1) - activemodel (= 6.1.3.1) - activerecord (= 6.1.3.1) - activestorage (= 6.1.3.1) - activesupport (= 6.1.3.1) + rails (7.0.3) + actioncable (= 7.0.3) + actionmailbox (= 7.0.3) + actionmailer (= 7.0.3) + actionpack (= 7.0.3) + actiontext (= 7.0.3) + actionview (= 7.0.3) + activejob (= 7.0.3) + activemodel (= 7.0.3) + activerecord (= 7.0.3) + activestorage (= 7.0.3) + activesupport (= 7.0.3) bundler (>= 1.15.0) - railties (= 6.1.3.1) - sprockets-rails (>= 2.0.0) + railties (= 7.0.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.3.0) + rails-html-sanitizer (1.4.2) loofah (~> 2.3) - railties (6.1.3.1) - actionpack (= 6.1.3.1) - activesupport (= 6.1.3.1) + railties (7.0.3) + actionpack (= 7.0.3) + activesupport (= 7.0.3) method_source - rake (>= 0.8.7) + rake (>= 12.2) thor (~> 1.0) - rake (13.0.3) - rb-fsevent (0.10.4) - rb-inotify (0.10.1) - ffi (~> 1.0) - redis (4.2.5) - regexp_parser (1.8.2) - rubyzip (2.3.0) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - selenium-webdriver (3.142.7) - childprocess (>= 0.5, < 4.0) - rubyzip (>= 1.2.2) - spring (2.1.1) - sprockets (4.0.2) + zeitwerk (~> 2.5) + rake (13.0.6) + redis (4.6.0) + regexp_parser (2.5.0) + reline (0.3.1) + io-console (~> 0.5) + rexml (3.2.5) + rubyzip (2.3.2) + selenium-webdriver (4.2.1) + childprocess (>= 0.5, < 5.0) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 3.0) + websocket (~> 1.0) + sprockets (4.0.3) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.2.2) - actionpack (>= 4.0) - activesupport (>= 4.0) + sprockets-rails (3.4.2) + actionpack (>= 5.2) + activesupport (>= 5.2) sprockets (>= 3.0.0) sqlite3 (1.4.2) - stimulus-rails (0.1.2) - rails (>= 6.0.0) - thor (1.1.0) - tilt (2.0.10) - turbo-rails (0.5.2) - rails (>= 6.0.0) + stimulus-rails (1.0.4) + railties (>= 6.0.0) + strscan (3.0.3) + thor (1.2.1) + timeout (0.3.0) + turbo-rails (1.1.1) + actionpack (>= 6.0.0) + activejob (>= 6.0.0) + railties (>= 6.0.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - web-console (4.1.0) + web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webdrivers (4.4.2) + webdrivers (5.0.0) nokogiri (~> 1.6) rubyzip (>= 1.3.0) - selenium-webdriver (>= 3.0, < 4.0) - websocket-driver (0.7.3) + selenium-webdriver (~> 4.0) + websocket (1.2.9) + websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.4.2) + zeitwerk (2.5.4) PLATFORMS - ruby + x86_64-darwin-21 DEPENDENCIES - bootsnap (>= 1.4.4) - byebug - capybara (>= 3.26) - hotwire-rails - jbuilder (~> 2.7) - listen (~> 3.3) + bootsnap + capybara + debug + importmap-rails + jbuilder puma (~> 5.0) - rails (~> 6.1.3) + rails (~> 7.0.3) redis (~> 4.0) - sass-rails (>= 6) selenium-webdriver - spring + sprockets-rails sqlite3 (~> 1.4) - web-console (>= 4.1.0) + stimulus-rails + turbo-rails + tzinfo-data + web-console webdrivers RUBY VERSION - ruby 2.7.1p83 + ruby 3.1.2p20 BUNDLED WITH - 2.1.4 + 2.3.15 diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index 61d8236..ddd546a 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -1,3 +1,4 @@ //= link_tree ../images //= link_directory ../stylesheets .css -//= link_tree ../javascripts +//= link_tree ../../javascript .js +//= link_tree ../../../vendor/javascript .js diff --git a/app/assets/javascripts/importmap.json.erb b/app/assets/javascripts/importmap.json.erb deleted file mode 100644 index 125fc14..0000000 --- a/app/assets/javascripts/importmap.json.erb +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - <%= importmap_list_with_stimulus_from "app/assets/javascripts/controllers", "app/assets/javascripts/libraries" %> - } -} diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index a2db5b1..f5b42c6 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -2,17 +2,18 @@ * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * Any CSS (and SCSS, if configured) file within this directory, lib/assets/stylesheets, or any plugin's * vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * compiled file so the styles you add here take precedence over styles defined in any other CSS * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * *= require_tree . *= require_self */ + turbo-frame { display: block; border: 1px solid blue; diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss deleted file mode 100644 index bb2597f..0000000 --- a/app/assets/stylesheets/scaffolds.scss +++ /dev/null @@ -1,65 +0,0 @@ -body { - background-color: #fff; - color: #333; - margin: 33px; } - -body, p, ol, ul, td { - font-family: verdana, arial, helvetica, sans-serif; - font-size: 13px; - line-height: 18px; } - -pre { - background-color: #eee; - padding: 10px; - font-size: 11px; } - -a { - color: #000; } - -a:visited { - color: #666; } - -a:hover { - color: #fff; - background-color: #000; } - -th { - padding-bottom: 5px; } - -td { - padding: 0 5px 7px; } - -div.field, -div.actions { - margin-bottom: 10px; } - -#notice { - color: green; } - -.field_with_errors { - padding: 2px; - background-color: red; - display: table; } - -#error_explanation { - width: 450px; - border: 2px solid red; - padding: 7px 7px 0; - margin-bottom: 20px; - background-color: #f0f0f0; } - -#error_explanation h2 { - text-align: left; - font-weight: bold; - padding: 5px 5px 5px 15px; - font-size: 12px; - margin: -7px -7px 0; - background-color: #c00; - color: #fff; } - -#error_explanation ul li { - font-size: 12px; - list-style: square; } - -label { - display: block; } diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb new file mode 100644 index 0000000..d672697 --- /dev/null +++ b/app/channels/application_cable/channel.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Channel < ActionCable::Channel::Base + end +end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb new file mode 100644 index 0000000..0ff5442 --- /dev/null +++ b/app/channels/application_cable/connection.rb @@ -0,0 +1,4 @@ +module ApplicationCable + class Connection < ActionCable::Connection::Base + end +end diff --git a/app/assets/javascripts/libraries/.gitkeep b/app/controllers/concerns/.keep similarity index 100% rename from app/assets/javascripts/libraries/.gitkeep rename to app/controllers/concerns/.keep diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb new file mode 100644 index 0000000..f1bca9f --- /dev/null +++ b/app/helpers/messages_helper.rb @@ -0,0 +1,2 @@ +module MessagesHelper +end diff --git a/app/helpers/rooms_helper.rb b/app/helpers/rooms_helper.rb new file mode 100644 index 0000000..1d0f4c7 --- /dev/null +++ b/app/helpers/rooms_helper.rb @@ -0,0 +1,2 @@ +module RoomsHelper +end diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..0d7b494 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1,3 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +import "@hotwired/turbo-rails" +import "controllers" diff --git a/app/javascript/controllers/application.js b/app/javascript/controllers/application.js new file mode 100644 index 0000000..1213e85 --- /dev/null +++ b/app/javascript/controllers/application.js @@ -0,0 +1,9 @@ +import { Application } from "@hotwired/stimulus" + +const application = Application.start() + +// Configure Stimulus development experience +application.debug = false +window.Stimulus = application + +export { application } diff --git a/app/javascript/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js new file mode 100644 index 0000000..5975c07 --- /dev/null +++ b/app/javascript/controllers/hello_controller.js @@ -0,0 +1,7 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + connect() { + this.element.textContent = "Hello World!" + } +} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js new file mode 100644 index 0000000..54ad4ca --- /dev/null +++ b/app/javascript/controllers/index.js @@ -0,0 +1,11 @@ +// Import and register all your controllers from the importmap under controllers/* + +import { application } from "controllers/application" + +// Eager load all controllers defined in the import map under controllers/**/*_controller +import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading" +eagerLoadControllersFrom("controllers", application) + +// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!) +// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading" +// lazyLoadControllersFrom("controllers", application) diff --git a/app/assets/javascripts/controllers/reset_form_controller.js b/app/javascript/controllers/reset_form_controller.js similarity index 64% rename from app/assets/javascripts/controllers/reset_form_controller.js rename to app/javascript/controllers/reset_form_controller.js index 148dde4..185e1bb 100644 --- a/app/assets/javascripts/controllers/reset_form_controller.js +++ b/app/javascript/controllers/reset_form_controller.js @@ -1,4 +1,4 @@ -import { Controller } from "stimulus" +import { Controller } from "@hotwired/stimulus" export default class extends Controller { reset() { diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..3c34c81 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba..b63caeb 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,3 @@ class ApplicationRecord < ActiveRecord::Base - self.abstract_class = true + primary_abstract_class end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index a481ba3..bbb856d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,10 +6,8 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all' %> - <%= yield :head %> - <%= turbo_include_tags %> - <%= stimulus_include_tags %> + <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> + <%= javascript_importmap_tags %> diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..cbd34d2 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/bin/bundle b/bin/bundle index a71368e..981e650 100755 --- a/bin/bundle +++ b/bin/bundle @@ -41,7 +41,7 @@ m = Module.new do gemfile = ENV["BUNDLE_GEMFILE"] return gemfile if gemfile && !gemfile.empty? - File.expand_path("../../Gemfile", __FILE__) + File.expand_path("../Gemfile", __dir__) end def lockfile @@ -60,20 +60,20 @@ m = Module.new do Regexp.last_match(1) end - def bundler_version - @bundler_version ||= + def bundler_requirement + @bundler_requirement ||= env_var_version || cli_arg_version || - lockfile_version + bundler_requirement_for(lockfile_version) end - def bundler_requirement - return "#{Gem::Requirement.default}.a" unless bundler_version + def bundler_requirement_for(version) + return "#{Gem::Requirement.default}.a" unless version - bundler_gem_version = Gem::Version.new(bundler_version) + bundler_gem_version = Gem::Version.new(version) requirement = bundler_gem_version.approximate_recommendation - return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + return requirement unless Gem.rubygems_version < Gem::Version.new("2.7.0") requirement += ".a" if bundler_gem_version.prerelease? diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 0000000..36502ab --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/bin/rails b/bin/rails index 21d3e02..efc0377 100755 --- a/bin/rails +++ b/bin/rails @@ -1,5 +1,4 @@ #!/usr/bin/env ruby -load File.expand_path("spring", __dir__) -APP_PATH = File.expand_path('../config/application', __dir__) +APP_PATH = File.expand_path("../config/application", __dir__) require_relative "../config/boot" require "rails/commands" diff --git a/bin/rake b/bin/rake index 7327f47..4fbf10b 100755 --- a/bin/rake +++ b/bin/rake @@ -1,5 +1,4 @@ #!/usr/bin/env ruby -load File.expand_path("spring", __dir__) require_relative "../config/boot" require "rake" Rake.application.run diff --git a/bin/setup b/bin/setup index 864be37..ec47b79 100755 --- a/bin/setup +++ b/bin/setup @@ -2,7 +2,7 @@ require "fileutils" # path to your application root. -APP_ROOT = File.expand_path('..', __dir__) +APP_ROOT = File.expand_path("..", __dir__) def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") @@ -13,16 +13,21 @@ FileUtils.chdir APP_ROOT do # 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') + 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" + # 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" end diff --git a/bin/spring b/bin/spring deleted file mode 100755 index 89f6161..0000000 --- a/bin/spring +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env ruby -if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) - # Load Spring without loading other gems in the Gemfile, for speed. - require "bundler" - Bundler.locked_gems.specs.find { |spec| spec.name == "spring" }&.tap do |spring| - Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path - gem "spring", spring.version - require "spring/binstub" - end -end diff --git a/config/application.rb b/config/application.rb index d3b063a..c2f78f1 100644 --- a/config/application.rb +++ b/config/application.rb @@ -9,7 +9,7 @@ module Chat class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.1 + config.load_defaults 7.0 # Configuration for the application, engines, and railties goes here. # diff --git a/config/boot.rb b/config/boot.rb index 3cda23b..988a5dd 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,4 +1,4 @@ -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" # Set up gems listed in the Gemfile. require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index f7543df..d241d7f 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -reF6bGkOCuBLYp9rs64qkPya4KdAGjdBM5XunLm9xkDztzViWWsLWNjTHDPuoTOabAlKStRH2Wu7an3Ykso1YCRSgHeOHeCRiIUwhb9PAZB0pKqYI24LLOsyB8cyWcW6RSZfjIQApVWj3op5067i8tqN57mRZ9Zhk9VTQ2hkGMNhiis+llgzsT6jiskvhverbOfZRl2nexiQLP1gkGkLQ3veeAmVNB34K1Tjsg7/v6V61iWYhimbjFAdOqLgfM8PEwUMb11eyPzNK5jBToZ5yM/rgE3VdjrFf6jgBQL7+zKEH9zK/vJjBT/hH6vl4ES6zWJSDtyux1+MND0y2WDII9Is+p+4sjLypvlVivPk/+X2Z1Ngv1hC9BoYaIlK/6/jrCmJ/EU5HOH8jR0TwNObmC3UEkkWzeGPCFUJ--S2Wu3X6ooz17sLQZ--WmhhK3i6ofMT2/ZuHJyeEw== \ No newline at end of file +OkipgazXOiKz/mYCSnCaLFU9ldfh1z4GXot7QQe0HCwiHS95lp4J3lbgXMuAz2Fu9C2UYOiy6BW+R8e42eCsr0pmndBdNtIsqxBuRVVqy2Z6qbKiZTYn8tRUW+GDUj45+SZe4hS61jsf23exEUL/FylRA14LuYZY8nD2Y2IeUknUcg/8VbGI2LjhZ1oMUgekiv1Faj/1IniIlNG39oYbyHPy3yI6A/ihM0Syqh8N996jcFITcb21+e9Wb6R59aDi/9OeGNtvXgvgqaYSMBE4tOuydSQAMJ+PHZmBnb0HKdNRnhbz2sBjHce+TCEMCoP3v/K0I0CKd1o2f+PFnNwc6w9nmGguSv5JZM3gaN9LxE+zbwegy+NOC4y/6e5Py1POu/dYZpv5W37Ps7YJr17ZJvk/UZsHCFj33LJE--uIyoeU1/a3WdBCsB--iU/cwV7UOQA6AoXWhBUPtA== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml index 4a8a1b2..fcba57f 100644 --- a/config/database.yml +++ b/config/database.yml @@ -2,7 +2,7 @@ # gem install sqlite3 # # Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' +# gem "sqlite3" # default: &default adapter: sqlite3 diff --git a/config/environments/development.rb b/config/environments/development.rb index bbaa7ff..8500f45 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,15 +14,18 @@ # 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? + 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}" + "Cache-Control" => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -53,11 +56,6 @@ # 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.debug = true - # Suppress logger output for asset requests. config.assets.quiet = true @@ -67,10 +65,6 @@ # 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 - # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true end diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c6045d..e64a06c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -22,7 +22,7 @@ # 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? + config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present? # Compress CSS using a preprocessor. # config.assets.css_compressor = :sass @@ -31,19 +31,19 @@ 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). 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.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true @@ -72,21 +72,15 @@ # 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 = [] + # Don't log any deprecations. + config.active_support.report_deprecations = false # 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') + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) @@ -96,25 +90,4 @@ # 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 end diff --git a/config/environments/test.rb b/config/environments/test.rb index 93ed4f1..6ea4d1e 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,18 +8,18 @@ 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 + # Turn false under Spring and add config.action_view.cache_template_loading = true. + config.cache_classes = 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 + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way 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}" + "Cache-Control" => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 0000000..8dce42d --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,7 @@ +# Pin npm packages by running ./bin/importmap + +pin "application", preload: true +pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true +pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true +pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true +pin_all_from "app/javascript/controllers", under: "controllers" diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb deleted file mode 100644 index 89d2efa..0000000 --- a/config/initializers/application_controller_renderer.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# ActiveSupport::Reloader.to_prepare do -# ApplicationController.renderer.defaults.merge!( -# http_host: 'example.org', -# https: false -# ) -# end diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index fe48fc3..2eeef96 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1,7 +1,7 @@ # 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. -Rails.application.config.assets.version = '1.0' +Rails.application.config.assets.version = "1.0" # Add additional assets to the asset load path. # Rails.application.config.assets.paths << Emoji.images_path diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb deleted file mode 100644 index 33699c3..0000000 --- a/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,8 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| /my_noisy_library/.match?(line) } - -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code -# by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". -Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index 41c4301..54f47cf 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,28 +1,25 @@ # Be sure to restart your server when you modify this file. -# Define an application-wide content security policy -# For further information see the following documentation -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy +# 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 -# 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 - -# # 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 and inline scripts +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-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) - -# Report CSP violations to a specified URI -# For further information see the following documentation: -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only -# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/cookies_serializer.rb b/config/initializers/cookies_serializer.rb deleted file mode 100644 index 5a6a32d..0000000 --- a/config/initializers/cookies_serializer.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Specify a serializer for the signed and encrypted cookie jars. -# Valid options are :json, :marshal, and :hybrid. -Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4b34a03..adc6568 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,6 +1,8 @@ # 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 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 ] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf..3860f65 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -4,13 +4,13 @@ # 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 diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb deleted file mode 100644 index dc18996..0000000 --- a/config/initializers/mime_types.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb deleted file mode 100644 index bbfc396..0000000 --- a/config/initializers/wrap_parameters.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# This file contains settings for ActionController::ParamsWrapper which -# is enabled by default. - -# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] -end - -# To enable root element in JSON for ActiveRecord objects. -# ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true -# end diff --git a/config/locales/en.yml b/config/locales/en.yml index cf9b342..8ca56fc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,11 +4,11 @@ # # To use the locales, use `I18n.t`: # -# I18n.t 'hello' +# I18n.t "hello" # # In views, this is aliased to just `t`: # -# <%= t('hello') %> +# <%= t("hello") %> # # To use a different locale, set it with `I18n.locale`: # @@ -24,7 +24,7 @@ # Instead, surround them with single quotes. # # en: -# 'true': 'foo' +# "true": "foo" # # To learn more, please read the Rails Internationalization guide # available at https://guides.rubyonrails.org/i18n.html. diff --git a/config/puma.rb b/config/puma.rb index d9b3e83..daaf036 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -39,5 +39,5 @@ # # preload_app! -# Allow puma to be restarted by `rails restart` command. +# Allow puma to be restarted by `bin/rails restart` command. plugin :tmp_restart diff --git a/config/spring.rb b/config/spring.rb deleted file mode 100644 index db5bf13..0000000 --- a/config/spring.rb +++ /dev/null @@ -1,6 +0,0 @@ -Spring.watch( - ".ruby-version", - ".rbenv-vars", - "tmp/restart.txt", - "tmp/caching-dev.txt" -) diff --git a/config/storage.yml b/config/storage.yml index d32f76e..4942ab6 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -6,27 +6,27 @@ local: service: Disk root: <%= Rails.root.join("storage") %> -# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) # amazon: # service: S3 # access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> # secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> # region: us-east-1 -# bucket: your_own_bucket +# bucket: your_own_bucket-<%= Rails.env %> # Remember not to checkin your GCS keyfile to a repository # google: # service: GCS # project: your_project # credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> -# bucket: your_own_bucket +# bucket: your_own_bucket-<%= Rails.env %> -# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) # microsoft: # service: AzureStorage # storage_account_name: your_account_name # storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> -# container: your_container_name +# container: your_container_name-<%= Rails.env %> # mirror: # service: Mirror diff --git a/db/migrate/20201220113420_create_rooms.rb b/db/migrate/20220603235340_create_rooms.rb similarity index 67% rename from db/migrate/20201220113420_create_rooms.rb rename to db/migrate/20220603235340_create_rooms.rb index ea043b3..b869a1f 100644 --- a/db/migrate/20201220113420_create_rooms.rb +++ b/db/migrate/20220603235340_create_rooms.rb @@ -1,4 +1,4 @@ -class CreateRooms < ActiveRecord::Migration[6.1] +class CreateRooms < ActiveRecord::Migration[7.0] def change create_table :rooms do |t| t.string :name diff --git a/db/migrate/20201220113435_create_messages.rb b/db/migrate/20220603235402_create_messages.rb similarity index 75% rename from db/migrate/20201220113435_create_messages.rb rename to db/migrate/20220603235402_create_messages.rb index 9f0fd83..9af7b47 100644 --- a/db/migrate/20201220113435_create_messages.rb +++ b/db/migrate/20220603235402_create_messages.rb @@ -1,4 +1,4 @@ -class CreateMessages < ActiveRecord::Migration[6.1] +class CreateMessages < ActiveRecord::Migration[7.0] def change create_table :messages do |t| t.references :room, null: false, foreign_key: true diff --git a/db/schema.rb b/db/schema.rb index f5287f1..347746f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,20 +10,19 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_12_20_113435) do - +ActiveRecord::Schema[7.0].define(version: 2022_06_03_235402) do create_table "messages", force: :cascade do |t| t.integer "room_id", null: false t.text "content" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["room_id"], name: "index_messages_on_room_id" end create_table "rooms", force: :cascade do |t| t.string "name" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end add_foreign_key "messages", "rooms" diff --git a/db/seeds.rb b/db/seeds.rb index f3a0480..bc25fce 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -3,5 +3,5 @@ # # Examples: # -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) -# Character.create(name: 'Luke', movie: movies.first) +# movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }]) +# Character.create(name: "Luke", movie: movies.first) diff --git a/test/channels/application_cable/connection_test.rb b/test/channels/application_cable/connection_test.rb new file mode 100644 index 0000000..800405f --- /dev/null +++ b/test/channels/application_cable/connection_test.rb @@ -0,0 +1,11 @@ +require "test_helper" + +class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase + # test "connects with cookies" do + # cookies.signed[:user_id] = 42 + # + # connect + # + # assert_equal connection.user_id, "42" + # end +end diff --git a/test/controllers/messages_controller_test.rb b/test/controllers/messages_controller_test.rb new file mode 100644 index 0000000..6c7802a --- /dev/null +++ b/test/controllers/messages_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class MessagesControllerTest < ActionDispatch::IntegrationTest + setup do + @message = messages(:one) + end + + test "should get index" do + get messages_url + assert_response :success + end + + test "should get new" do + get new_message_url + assert_response :success + end + + test "should create message" do + assert_difference("Message.count") do + post messages_url, params: { message: { content: @message.content, room_id: @message.room_id } } + end + + assert_redirected_to message_url(Message.last) + end + + test "should show message" do + get message_url(@message) + assert_response :success + end + + test "should get edit" do + get edit_message_url(@message) + assert_response :success + end + + test "should update message" do + patch message_url(@message), params: { message: { content: @message.content, room_id: @message.room_id } } + assert_redirected_to message_url(@message) + end + + test "should destroy message" do + assert_difference("Message.count", -1) do + delete message_url(@message) + end + + assert_redirected_to messages_url + end +end diff --git a/test/controllers/rooms_controller_test.rb b/test/controllers/rooms_controller_test.rb index cb591d5..6f227a8 100644 --- a/test/controllers/rooms_controller_test.rb +++ b/test/controllers/rooms_controller_test.rb @@ -16,7 +16,7 @@ class RoomsControllerTest < ActionDispatch::IntegrationTest end test "should create room" do - assert_difference('Room.count') do + assert_difference("Room.count") do post rooms_url, params: { room: { name: @room.name } } end @@ -39,7 +39,7 @@ class RoomsControllerTest < ActionDispatch::IntegrationTest end test "should destroy room" do - assert_difference('Room.count', -1) do + assert_difference("Room.count", -1) do delete room_url(@room) end diff --git a/test/system/messages_test.rb b/test/system/messages_test.rb new file mode 100644 index 0000000..0b30ea2 --- /dev/null +++ b/test/system/messages_test.rb @@ -0,0 +1,43 @@ +require "application_system_test_case" + +class MessagesTest < ApplicationSystemTestCase + setup do + @message = messages(:one) + end + + test "visiting the index" do + visit messages_url + assert_selector "h1", text: "Messages" + end + + test "should create message" do + visit messages_url + click_on "New message" + + fill_in "Content", with: @message.content + fill_in "Room", with: @message.room_id + click_on "Create Message" + + assert_text "Message was successfully created" + click_on "Back" + end + + test "should update Message" do + visit message_url(@message) + click_on "Edit this message", match: :first + + fill_in "Content", with: @message.content + fill_in "Room", with: @message.room_id + click_on "Update Message" + + assert_text "Message was successfully updated" + click_on "Back" + end + + test "should destroy Message" do + visit message_url(@message) + click_on "Destroy this message", match: :first + + assert_text "Message was successfully destroyed" + end +end diff --git a/test/system/rooms_test.rb b/test/system/rooms_test.rb index 9e8a243..3186389 100644 --- a/test/system/rooms_test.rb +++ b/test/system/rooms_test.rb @@ -10,9 +10,9 @@ class RoomsTest < ApplicationSystemTestCase assert_selector "h1", text: "Rooms" end - test "creating a Room" do + test "should create room" do visit rooms_url - click_on "New Room" + click_on "New room" fill_in "Name", with: @room.name click_on "Create Room" @@ -21,9 +21,9 @@ class RoomsTest < ApplicationSystemTestCase click_on "Back" end - test "updating a Room" do - visit rooms_url - click_on "Edit", match: :first + test "should update Room" do + visit room_url(@room) + click_on "Edit this room", match: :first fill_in "Name", with: @room.name click_on "Update Room" @@ -32,11 +32,9 @@ class RoomsTest < ApplicationSystemTestCase click_on "Back" end - test "destroying a Room" do - visit rooms_url - page.accept_confirm do - click_on "Destroy", match: :first - end + test "should destroy Room" do + visit room_url(@room) + click_on "Destroy this room", match: :first assert_text "Room was successfully destroyed" end diff --git a/test/test_helper.rb b/test/test_helper.rb index 47b598d..d713e37 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,4 @@ -ENV['RAILS_ENV'] ||= 'test' +ENV["RAILS_ENV"] ||= "test" require_relative "../config/environment" require "rails/test_help" diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 0000000..e69de29