diff --git a/backend/.gitignore b/backend/.gitignore index dd116f5..c591125 100644 --- a/backend/.gitignore +++ b/backend/.gitignore @@ -20,6 +20,8 @@ /node_modules /yarn-error.log +/vendor + .byebug_history /.idea diff --git a/backend/Dockerfile b/backend/Dockerfile index fbaebd5..a02901b 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -6,7 +6,7 @@ RUN apk add --update tzdata && \ RUN apk add --update --virtual runtime-deps nodejs libffi-dev readline sqlite sqlite-dev -RUN apk add --update --virtual build-deps build-base libc-dev linux-headers libxml2-dev libxslt-dev readline-dev +RUN apk add --update --virtual build-deps build-base libc-dev linux-headers libxml2-dev libxslt-dev readline-dev ruby-dev WORKDIR /tmp ADD /Gemfile* ./ diff --git a/backend/Gemfile b/backend/Gemfile index 05d70e8..1a761fe 100644 --- a/backend/Gemfile +++ b/backend/Gemfile @@ -6,61 +6,61 @@ git_source(:github) do |repo_name| end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' -gem 'rails', '~> 5.2', '>= 5.2.2' -gem 'railties', '~> 5.2', '>= 5.2.2' -gem 'bootsnap', '~> 1.4', '>= 1.4.1' +gem 'rails', '~> 6.0' +gem 'railties', '~> 6.0' +gem 'bootsnap', '~> 1.4', '>= 1.4.5' # Use sqlite3 as the database for Active Record -gem 'sqlite3', '~> 1.3.13' +gem 'sqlite3', '~> 1.4', '>= 1.4.1' # Use Puma as the app server -gem 'puma', '~> 3.7' +gem 'puma', '~> 4.1', '>= 4.1.1' # Use SCSS for stylesheets -gem 'sass-rails', '~> 5.0' +gem 'sass-rails', '~> 6.0' # Use Uglifier as compressor for JavaScript assets -gem 'uglifier', '>= 1.3.0' +gem 'uglifier', '~> 4.1', '>= 4.1.20' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby # Use CoffeeScript for .coffee assets and views -gem 'coffee-rails', '~> 4.2' +gem 'coffee-rails', '~> 5.0' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks -gem 'turbolinks', '~> 5' +gem 'turbolinks', '~> 5.2' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder -gem 'jbuilder', '~> 2.5' +gem 'jbuilder', '~> 2.9', '>= 2.9.1' # Use Redis adapter to run Action Cable in production -gem 'redis', '~> 3.0' +gem 'redis', '~> 4.1', '>= 4.1.2' # Use ActiveModel has_secure_password -gem 'bcrypt', '~> 3.1.7' +gem 'bcrypt', '~> 3.1', '>= 3.1.13' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development -gem 'rack-cors', :require => 'rack/cors' +gem 'rack-cors', '~> 1.0', '>= 1.0.3' -gem 'mongoid', '~> 6.1.0' +gem 'mongoid', '~> 7.1', '>= 7.1.2' -gem 'devise', '~> 4.6', '>= 4.6.1' +gem 'devise', '~> 4.7', '>= 4.7.1' gem 'gen-data', '~> 0.3.11' -gem 'rest-client', '~> 2.0', '>= 2.0.2' +gem 'rest-client', '~> 2.1' -gem 'jwt', '~> 1.5', '>= 1.5.4' +gem 'jwt', '~> 2.2', '>= 2.2.1' 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] # Adds support for Capybara system testing and selenium driver - gem 'capybara', '~> 2.13' + gem 'capybara', '~> 3.29' gem 'selenium-webdriver' end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. - gem 'web-console', '>= 3.3.0' - gem 'listen', '>= 3.0.5', '< 3.2' + gem 'web-console', '~> 4.0', '>= 4.0.1' + gem 'listen', '~> 3.1', '>= 3.1.5' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' - gem 'spring-watcher-listen', '~> 2.0.0' + gem 'spring', '~> 2.1' + gem 'spring-watcher-listen', '~> 2.0', '>= 2.0.1' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/backend/bin/setup b/backend/bin/setup index a334d86..0e39e8c 100755 --- a/backend/bin/setup +++ b/backend/bin/setup @@ -1,6 +1,5 @@ #!/usr/bin/env ruby require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -9,8 +8,9 @@ def system!(*args) system(*args) || abort("\n== Command #{args} failed ==") end -chdir APP_ROOT do - # This script is a starting point to setup your application. +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. # Add necessary setup steps to this file. puts '== Installing dependencies ==' @@ -19,11 +19,11 @@ chdir APP_ROOT do # puts "\n== Copying sample files ==" # unless File.exist?('config/database.yml') - # cp 'config/database.yml.sample', 'config/database.yml' + # FileUtils.cp 'config/database.yml.sample', 'config/database.yml' # end puts "\n== Preparing database ==" - system! 'bin/rails db:setup' + system! 'bin/rails db:prepare' puts "\n== Removing old logs and tempfiles ==" system! 'bin/rails log:clear tmp:clear' diff --git a/backend/bin/yarn b/backend/bin/yarn deleted file mode 100755 index 460dd56..0000000 --- a/backend/bin/yarn +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env ruby -APP_ROOT = File.expand_path('..', __dir__) -Dir.chdir(APP_ROOT) do - begin - exec "yarnpkg", *ARGV - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end -end diff --git a/backend/config/application.rb b/backend/config/application.rb index 17e32ba..3c0e138 100644 --- a/backend/config/application.rb +++ b/backend/config/application.rb @@ -8,6 +8,8 @@ require "active_storage/engine" require "action_controller/railtie" require "action_mailer/railtie" +require "action_mailbox/engine" +require "action_text/engine" require "action_view/railtie" require "action_cable/engine" # require "sprockets/railtie" @@ -24,7 +26,7 @@ class Application < Rails::Application # Skip views, helpers and assets when generating a new resource. config.api_only = true # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 5.1 + config.load_defaults 6.0 config.generators do |g| g.orm :mongoid end diff --git a/backend/config/environments/development.rb b/backend/config/environments/development.rb index d52ec9e..698f159 100644 --- a/backend/config/environments/development.rb +++ b/backend/config/environments/development.rb @@ -15,8 +15,6 @@ # 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 - config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" @@ -27,7 +25,7 @@ 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. @@ -45,7 +43,7 @@ config.active_record.verbose_query_logs = true - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true # Use an evented file watcher to asynchronously detect changes in source code, diff --git a/backend/config/environments/production.rb b/backend/config/environments/production.rb index 9797559..40450b8 100644 --- a/backend/config/environments/production.rb +++ b/backend/config/environments/production.rb @@ -12,7 +12,6 @@ # Full error reports are disabled and caching is turned on. 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). @@ -29,10 +28,10 @@ # 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 + # 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.*/ ] @@ -50,9 +49,9 @@ # 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) + # 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 = "backend_#{Rails.env}" + # config.active_job.queue_name_prefix = "backend_production" config.action_mailer.perform_caching = false @@ -82,4 +81,25 @@ # 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/backend/config/environments/test.rb b/backend/config/environments/test.rb index 0a38fd3..de83a77 100644 --- a/backend/config/environments/test.rb +++ b/backend/config/environments/test.rb @@ -1,11 +1,12 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# 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. - - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true + + config.cache_classes = false # 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 @@ -21,6 +22,7 @@ # 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 = false @@ -28,7 +30,7 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false - # Store uploaded files on the local file system in a temporary directory + # Store uploaded files on the local file system in a temporary directory. config.active_storage.service = :test config.action_mailer.perform_caching = false @@ -41,6 +43,6 @@ # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr - # Raises error for missing translations + # Raises error for missing translations. # config.action_view.raise_on_missing_translations = true end diff --git a/backend/config/initializers/new_framework_defaults_6_0.rb b/backend/config/initializers/new_framework_defaults_6_0.rb new file mode 100644 index 0000000..92240ef --- /dev/null +++ b/backend/config/initializers/new_framework_defaults_6_0.rb @@ -0,0 +1,45 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 6.0 upgrade. +# +# Once upgraded flip defaults one by one to migrate to the new default. +# +# Read the Guide for Upgrading Ruby on Rails for more info on each option. + +# Don't force requests from old versions of IE to be UTF-8 encoded. +# Rails.application.config.action_view.default_enforce_utf8 = false + +# Embed purpose and expiry metadata inside signed and encrypted +# cookies for increased security. +# +# This option is not backwards compatible with earlier Rails versions. +# It's best enabled when your entire app is migrated and stable on 6.0. +# Rails.application.config.action_dispatch.use_cookies_with_metadata = true + +# Change the return value of `ActionDispatch::Response#content_type` to Content-Type header without modification. +# Rails.application.config.action_dispatch.return_only_media_type_on_content_type = false + +# Return false instead of self when enqueuing is aborted from a callback. +# Rails.application.config.active_job.return_false_on_aborted_enqueue = true + +# Send Active Storage analysis and purge jobs to dedicated queues. +# Rails.application.config.active_storage.queues.analysis = :active_storage_analysis +# Rails.application.config.active_storage.queues.purge = :active_storage_purge + +# When assigning to a collection of attachments declared via `has_many_attached`, replace existing +# attachments instead of appending. Use #attach to add new attachments without replacing existing ones. +# Rails.application.config.active_storage.replace_on_assign_to_many = true + +# Use ActionMailer::MailDeliveryJob for sending parameterized and normal mail. +# +# The default delivery jobs (ActionMailer::Parameterized::DeliveryJob, ActionMailer::DeliveryJob), +# will be removed in Rails 6.1. This setting is not backwards compatible with earlier Rails versions. +# If you send mail in the background, job workers need to have a copy of +# MailDeliveryJob to ensure all delivery jobs are processed properly. +# Make sure your entire app is migrated and stable on 6.0 before using this setting. +# Rails.application.config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" + +# Enable the same cache key to be reused when the object being cached of type +# `ActiveRecord::Relation` changes by moving the volatile information (max updated at and count) +# of the relation's cache key into the cache version to support recycling cache key. +# Rails.application.config.active_record.collection_cache_versioning = true diff --git a/backend/config/locales/en.yml b/backend/config/locales/en.yml index decc5a8..cf9b342 100644 --- a/backend/config/locales/en.yml +++ b/backend/config/locales/en.yml @@ -27,7 +27,7 @@ # 'true': 'foo' # # To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. +# available at https://guides.rubyonrails.org/i18n.html. en: hello: "Hello world" diff --git a/backend/config/puma.rb b/backend/config/puma.rb index a5eccf8..5f7c4bd 100644 --- a/backend/config/puma.rb +++ b/backend/config/puma.rb @@ -4,8 +4,9 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } -threads threads_count, threads_count +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 `port` that Puma will listen on to receive requests; default is 3000. # @@ -15,8 +16,11 @@ # environment ENV.fetch("RAILS_ENV") { "development" } +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/web.pid" } + # Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together +# 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). diff --git a/backend/config/spring.rb b/backend/config/spring.rb index 9fa7863..db5bf13 100644 --- a/backend/config/spring.rb +++ b/backend/config/spring.rb @@ -1,6 +1,6 @@ -%w[ - .ruby-version - .rbenv-vars - tmp/restart.txt - tmp/caching-dev.txt -].each { |path| Spring.watch(path) } +Spring.watch( + ".ruby-version", + ".rbenv-vars", + "tmp/restart.txt", + "tmp/caching-dev.txt" +) diff --git a/backend/db/migrate/20190915013425_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb b/backend/db/migrate/20190915013425_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb new file mode 100644 index 0000000..ff5d72c --- /dev/null +++ b/backend/db/migrate/20190915013425_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb @@ -0,0 +1,10 @@ +# This migration comes from active_storage (originally 20180723000244) +class AddForeignKeyConstraintToActiveStorageAttachmentsForBlobId < ActiveRecord::Migration[6.0] + def up + return if foreign_key_exists?(:active_storage_attachments, column: :blob_id) + + if table_exists?(:active_storage_blobs) + add_foreign_key :active_storage_attachments, :active_storage_blobs, column: :blob_id + end + end +end diff --git a/backend/db/schema.rb b/backend/db/schema.rb index 52ab025..ae2335e 100644 --- a/backend/db/schema.rb +++ b/backend/db/schema.rb @@ -2,14 +2,14 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 0) do +ActiveRecord::Schema.define(version: 2019_09_15_013425) do end diff --git a/backend/test/controllers/auth_controller_test.rb b/backend/test/controllers/auth_controller_test.rb index fb5b088..50b0ae8 100644 --- a/backend/test/controllers/auth_controller_test.rb +++ b/backend/test/controllers/auth_controller_test.rb @@ -10,7 +10,7 @@ class AuthControllerTest < ActionDispatch::IntegrationTest opt = [{ 'login' => '' }, { 'token' => '' }, { 'password' => '' }, { 'guid' => '' }] # generate combinations and send post requests Gen::Data.shuffle_options(opt).map do |params| - response = RestClient.post (Backend::Application.config.host + '/login'), params + response = RestClient.post((Backend::Application.config.host + '/login'), params) assert_equal false, JSON.parse(response)['success'] end @@ -18,7 +18,7 @@ class AuthControllerTest < ActionDispatch::IntegrationTest User.all.includes(:tokens).each do |u| u.tokens.each do |t| opt = { 'guid' => u.id.to_s, 'token' => t.token } - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) assert_equal true, JSON.parse(response)['success'] end end @@ -29,14 +29,14 @@ class AuthControllerTest < ActionDispatch::IntegrationTest response = {} if i < p opt = { 'guid' => u.id.to_s, 'token' => (srand 1234).to_s} - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) else if i < (p * 2) opt = { 'guid' => (srand 1234).to_s, 'token' => (srand 1234).to_s} - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) else u.tokens.each do |t| opt = { 'guid' => (srand 1234).to_s, 'token' => t.token} - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) end end end @@ -46,21 +46,21 @@ class AuthControllerTest < ActionDispatch::IntegrationTest # (nil guid and/or nil token) auth User.all.includes(:tokens).each do |u| opt = { 'guid' => u.id.to_s, 'token' => nil} - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) assert_equal false, JSON.parse(response)['success'] u.tokens.each do |t| opt = { 'guid' => nil, 'token' => t.token} - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) assert_equal false, JSON.parse(response)['success'] end opt = { 'guid' => nil, 'token' => nil} - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) assert_equal false, JSON.parse(response)['success'] end # (login && password) auth opt = { 'login' => 'test1', 'password' => 'test' } - response = RestClient.post (Backend::Application.config.host + '/login'), opt + response = RestClient.post((Backend::Application.config.host + '/login'), opt) assert_equal true, JSON.parse(response)['success'] end @@ -91,7 +91,7 @@ class AuthControllerTest < ActionDispatch::IntegrationTest 1.times do s_rand = OpenSSL::Random.random_bytes(10).unpack('H*').join opt = { 'login' => s_rand, 'password' => s_rand, 're_password' => s_rand } - response = RestClient.post (Backend::Application.config.host + '/reg'), opt + response = RestClient.post((Backend::Application.config.host + '/reg'), opt) assert_equal true, JSON.parse(response)['success'] end end diff --git a/backend/vendor/.keep b/backend/vendor/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/docker-compose.yml b/docker-compose.yml index 66a326a..fb91467 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,8 +44,6 @@ services: ports: - "3000:3000" depends_on: - - mongodb - - rabbitmq - sock sock: build: ./backend