1
0
mirror of https://github.com/projekteuler/projekteuler.git synced 2025-12-10 08:46:41 +01:00

Update rails and code

This commit is contained in:
Philipp Fischbeck 2017-11-23 13:52:13 +01:00
parent 8334baff99
commit 95bb01b440
30 changed files with 340 additions and 152 deletions

View File

@ -2,7 +2,7 @@ source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5' gem 'rails', '5.1.4'
# Use sqlite3 as the database for Active Record # Use sqlite3 as the database for Active Record
gem 'sqlite3', '~> 1.3.13' gem 'sqlite3', '~> 1.3.13'
# Use SCSS for stylesheets # Use SCSS for stylesheets
@ -14,6 +14,8 @@ gem 'coffee-rails', '~> 4.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes # See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby # gem 'therubyracer', platforms: :ruby
gem 'rails-controller-testing'
# Use jquery as the JavaScript library # Use jquery as the JavaScript library
gem 'jquery-rails', '~> 4.3.1' gem 'jquery-rails', '~> 4.3.1'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
@ -23,10 +25,7 @@ gem 'jbuilder', '~> 2.7.0'
# bundle exec rake doc:rails generates the API under doc/api. # bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.2', group: :doc gem 'sdoc', '~> 0.4.2', group: :doc
gem 'web-console', '~> 2.0', group: :development gem 'web-console', '~> 3.5.1', group: :development
gem 'quiet_assets', '~> 1.1.0', group: :development
# Use Coveralls for coverage documentation # Use Coveralls for coverage documentation
gem 'coveralls', '~> 0.8.21', require: false gem 'coveralls', '~> 0.8.21', require: false

View File

@ -1,50 +1,51 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
actionmailer (4.2.5) actioncable (5.1.4)
actionpack (= 4.2.5) actionpack (= 5.1.4)
actionview (= 4.2.5) nio4r (~> 2.0)
activejob (= 4.2.5) websocket-driver (~> 0.6.1)
actionmailer (5.1.4)
actionpack (= 5.1.4)
actionview (= 5.1.4)
activejob (= 5.1.4)
mail (~> 2.5, >= 2.5.4) mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 2.0)
actionpack (4.2.5) actionpack (5.1.4)
actionview (= 4.2.5) actionview (= 5.1.4)
activesupport (= 4.2.5) activesupport (= 5.1.4)
rack (~> 1.6) rack (~> 2.0)
rack-test (~> 0.6.2) rack-test (>= 0.6.3)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.2)
actionview (4.2.5) actionview (5.1.4)
activesupport (= 4.2.5) activesupport (= 5.1.4)
builder (~> 3.1) builder (~> 3.1)
erubis (~> 2.7.0) erubi (~> 1.4)
rails-dom-testing (~> 1.0, >= 1.0.5) rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.2) rails-html-sanitizer (~> 1.0, >= 1.0.3)
activejob (4.2.5) activejob (5.1.4)
activesupport (= 4.2.5) activesupport (= 5.1.4)
globalid (>= 0.3.0) globalid (>= 0.3.6)
activemodel (4.2.5) activemodel (5.1.4)
activesupport (= 4.2.5) activesupport (= 5.1.4)
builder (~> 3.1) activerecord (5.1.4)
activerecord (4.2.5) activemodel (= 5.1.4)
activemodel (= 4.2.5) activesupport (= 5.1.4)
activesupport (= 4.2.5) arel (~> 8.0)
arel (~> 6.0) activesupport (5.1.4)
activesupport (4.2.5) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7) i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
arel (6.0.3) arel (8.0.0)
autoprefixer-rails (7.1.6) autoprefixer-rails (7.1.6)
execjs execjs
bcrypt (3.1.11-x86-mingw32) bcrypt (3.1.11-x86-mingw32)
bh (1.3.6) bh (1.3.6)
actionpack actionpack
activesupport activesupport
binding_of_caller (0.7.2) bindex (0.5.0)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.3.7) bootstrap-sass (3.3.7)
autoprefixer-rails (>= 5.2.1) autoprefixer-rails (>= 5.2.1)
sass (>= 3.3.4) sass (>= 3.3.4)
@ -66,7 +67,6 @@ GEM
thor (~> 0.19.4) thor (~> 0.19.4)
tins (~> 1.6) tins (~> 1.6)
crass (1.0.3) crass (1.0.3)
debug_inspector (0.0.2)
devise (4.3.0) devise (4.3.0)
bcrypt (~> 3.0) bcrypt (~> 3.0)
orm_adapter (~> 0.1) orm_adapter (~> 0.1)
@ -75,10 +75,10 @@ GEM
warden (~> 1.2.3) warden (~> 1.2.3)
devise-bootstrap-views (0.0.11) devise-bootstrap-views (0.0.11)
docile (1.1.5) docile (1.1.5)
erubis (2.7.0) erubi (1.7.0)
execjs (2.7.0) execjs (2.7.0)
globalid (0.3.6) globalid (0.4.1)
activesupport (>= 4.1.0) activesupport (>= 4.2.0)
i18n (0.9.1) i18n (0.9.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
jbuilder (2.7.0) jbuilder (2.7.0)
@ -92,44 +92,47 @@ GEM
loofah (2.1.1) loofah (2.1.1)
crass (~> 1.0.2) crass (~> 1.0.2)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.3) mail (2.7.0)
mime-types (>= 1.16, < 3) mini_mime (>= 0.1.1)
mathjax-rails (2.6.1) mathjax-rails (2.6.1)
railties (>= 3.0) railties (>= 3.0)
mime-types (2.99) method_source (0.9.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0) mini_portile2 (2.3.0)
minitest (5.10.3) minitest (5.10.3)
multi_json (1.12.2) multi_json (1.12.2)
nio4r (2.1.0)
nokogiri (1.8.1-x86-mingw32) nokogiri (1.8.1-x86-mingw32)
mini_portile2 (~> 2.3.0) mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0) orm_adapter (0.5.0)
quiet_assets (1.1.0) rack (2.0.3)
railties (>= 3.1, < 5.0) rack-test (0.8.2)
rack (1.6.8) rack (>= 1.0, < 3)
rack-test (0.6.3) rails (5.1.4)
rack (>= 1.0) actioncable (= 5.1.4)
rails (4.2.5) actionmailer (= 5.1.4)
actionmailer (= 4.2.5) actionpack (= 5.1.4)
actionpack (= 4.2.5) actionview (= 5.1.4)
actionview (= 4.2.5) activejob (= 5.1.4)
activejob (= 4.2.5) activemodel (= 5.1.4)
activemodel (= 4.2.5) activerecord (= 5.1.4)
activerecord (= 4.2.5) activesupport (= 5.1.4)
activesupport (= 4.2.5) bundler (>= 1.3.0)
bundler (>= 1.3.0, < 2.0) railties (= 5.1.4)
railties (= 4.2.5) sprockets-rails (>= 2.0.0)
sprockets-rails rails-controller-testing (1.0.2)
rails-deprecated_sanitizer (1.0.3) actionpack (~> 5.x, >= 5.0.1)
activesupport (>= 4.2.0.alpha) actionview (~> 5.x, >= 5.0.1)
rails-dom-testing (1.0.8) activesupport (~> 5.x)
activesupport (>= 4.2.0.beta, < 5.0) rails-dom-testing (2.0.3)
nokogiri (~> 1.6) activesupport (>= 4.2.0)
rails-deprecated_sanitizer (>= 1.0.1) nokogiri (>= 1.6)
rails-html-sanitizer (1.0.3) rails-html-sanitizer (1.0.3)
loofah (~> 2.0) loofah (~> 2.0)
railties (4.2.5) railties (5.1.4)
actionpack (= 4.2.5) actionpack (= 5.1.4)
activesupport (= 4.2.5) activesupport (= 5.1.4)
method_source
rake (>= 0.8.7) rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0) thor (>= 0.18.1, < 2.0)
rake (12.3.0) rake (12.3.0)
@ -176,11 +179,14 @@ GEM
execjs (>= 0.3.0, < 3) execjs (>= 0.3.0, < 3)
warden (1.2.7) warden (1.2.7)
rack (>= 1.0) rack (>= 1.0)
web-console (2.2.1) web-console (3.5.1)
activemodel (>= 4.0) actionview (>= 5.0)
binding_of_caller (>= 0.7.2) activemodel (>= 5.0)
railties (>= 4.0) bindex (>= 0.4.0)
sprockets-rails (>= 2.0, < 4.0) railties (>= 5.0)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
will-paginate-i18n (0.1.15) will-paginate-i18n (0.1.15)
will_paginate (3.1.6) will_paginate (3.1.6)
will_paginate-bootstrap (1.0.1) will_paginate-bootstrap (1.0.1)
@ -201,15 +207,15 @@ DEPENDENCIES
jbuilder (~> 2.7.0) jbuilder (~> 2.7.0)
jquery-rails (~> 4.3.1) jquery-rails (~> 4.3.1)
mathjax-rails (~> 2.6.1) mathjax-rails (~> 2.6.1)
quiet_assets (~> 1.1.0) rails (= 5.1.4)
rails (= 4.2.5) rails-controller-testing
sass-rails (~> 5.0.7) sass-rails (~> 5.0.7)
sdoc (~> 0.4.2) sdoc (~> 0.4.2)
sqlite3 (~> 1.3.13) sqlite3 (~> 1.3.13)
turbolinks (~> 5.0.1) turbolinks (~> 5.0.1)
tzinfo-data tzinfo-data
uglifier (~> 3.2.0) uglifier (~> 3.2.0)
web-console (~> 2.0) web-console (~> 3.5.1)
will-paginate-i18n (~> 0.1.15) will-paginate-i18n (~> 0.1.15)
will_paginate (~> 3.1.6) will_paginate (~> 3.1.6)
will_paginate-bootstrap (~> 1.0.1) will_paginate-bootstrap (~> 1.0.1)

View File

@ -0,0 +1,2 @@
class ApplicationJob < ActiveJob::Base
end

View File

@ -1,4 +1,4 @@
class Admin < ActiveRecord::Base class Admin < ApplicationRecord
# Include default devise modules. Others available are: # Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable # :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, devise :database_authenticatable,

View File

@ -0,0 +1,3 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@ -1,6 +1,6 @@
class Problem < ActiveRecord::Base class Problem < ApplicationRecord
# TODO Check whether there is a better relation for this # TODO Check whether there is a better relation for this
belongs_to :translation belongs_to :translation, optional: true
delegate :title, :content, to: :translation delegate :title, :content, to: :translation
has_many :translations, inverse_of: :problem has_many :translations, inverse_of: :problem

View File

@ -1,4 +1,4 @@
class Translation < ActiveRecord::Base class Translation < ApplicationRecord
belongs_to :problem, inverse_of: :translations belongs_to :problem, inverse_of: :translations
validates :title, :content, :problem_id, presence: true validates :title, :content, :problem_id, presence: true

View File

@ -1,4 +1,4 @@
#!/usr/bin/env ruby.exe #!/usr/bin/env ruby.exe
APP_PATH = File.expand_path('../../config/application', __FILE__) APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot' require_relative '../config/boot'
require 'rails/commands' require 'rails/commands'

View File

@ -1,29 +1,38 @@
#!/usr/bin/env ruby.exe #!/usr/bin/env ruby.exe
require 'pathname' require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root. # path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
Dir.chdir APP_ROOT do 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. # This script is a starting point to setup your application.
# Add necessary setup steps to this file: # Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# Install JavaScript dependencies if using Yarn
# system('bin/yarn')
puts "== Installing dependencies =="
system "gem install bundler --conservative"
system "bundle check || bundle install"
# puts "\n== Copying sample files ==" # puts "\n== Copying sample files =="
# unless File.exist?("config/database.yml") # unless File.exist?('config/database.yml')
# system "cp config/database.yml.sample config/database.yml" # cp 'config/database.yml.sample', 'config/database.yml'
# end # end
puts "\n== Preparing database ==" puts "\n== Preparing database =="
system "bin/rake db:setup" system! 'bin/rails db:setup'
puts "\n== Removing old logs and tempfiles ==" puts "\n== Removing old logs and tempfiles =="
system "rm -f log/*" system! 'bin/rails log:clear tmp:clear'
system "rm -rf tmp/cache"
puts "\n== Restarting application server ==" puts "\n== Restarting application server =="
system "touch tmp/restart.txt" system! 'bin/rails restart'
end end

29
bin/update Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby.exe
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
puts "\n== Updating database =="
system! 'bin/rails db:migrate'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end

11
bin/yarn Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env ruby.exe
VENDOR_PATH = File.expand_path('..', __dir__)
Dir.chdir(VENDOR_PATH) do
begin
exec "yarnpkg #{ARGV.join(" ")}"
rescue Errno::ENOENT
$stderr.puts "Yarn executable was not detected in the system."
$stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
exit 1
end
end

View File

@ -1,4 +1,4 @@
require File.expand_path('../boot', __FILE__) require_relative 'boot'
require 'rails/all' require 'rails/all'
@ -8,6 +8,9 @@ Bundler.require(*Rails.groups)
module Projekteuler module Projekteuler
class Application < Rails::Application class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded. # -- all .rb files in that directory are automatically loaded.
@ -20,8 +23,5 @@ module Projekteuler
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s] config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
config.i18n.available_locales = :de config.i18n.available_locales = :de
config.i18n.default_locale = :de config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end end
end end

View File

@ -1,3 +1,3 @@
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' # Set up gems listed in the Gemfile. require 'bundler/setup' # Set up gems listed in the Gemfile.

10
config/cable.yml Normal file
View File

@ -0,0 +1,10 @@
development:
adapter: async
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: projekteuler_production

View File

@ -1,5 +1,5 @@
# Load the Rails application. # Load the Rails application.
require File.expand_path('../application', __FILE__) require_relative 'application'
# Initialize the Rails application. # Initialize the Rails application.
Rails.application.initialize! Rails.application.initialize!

View File

@ -9,13 +9,28 @@ Rails.application.configure do
# Do not eager load code on boot. # Do not eager load code on boot.
config.eager_load = false config.eager_load = false
# Show full error reports and disable caching. # Show full error reports.
config.consider_all_requests_local = true config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Enable/disable caching. By default caching is disabled.
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.seconds.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send. # Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger. # Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log config.active_support.deprecation = :log
@ -27,15 +42,13 @@ Rails.application.configure do
# number of complex assets. # number of complex assets.
config.assets.debug = true config.assets.debug = true
# Asset digests allow you to set far-future HTTP expiration dates on all assets, # Suppress logger output for asset requests.
# yet still be able to expire them through the digest params. config.assets.quiet = true
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true
# Raises error for missing translations # Raises error for missing translations
config.action_view.raise_on_missing_translations = true config.action_view.raise_on_missing_translations = 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
end end

View File

@ -14,15 +14,14 @@ Rails.application.configure do
config.consider_all_requests_local = false config.consider_all_requests_local = false
config.action_controller.perform_caching = true config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application # Attempt to read encrypted secrets from `config/secrets.yml.enc`.
# Add `rack-cache` to your Gemfile before enabling this. # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or
# For large-scale production use, consider using a caching reverse proxy like # `config/secrets.yml.key`.
# NGINX, varnish or squid. config.read_encrypted_secrets = true
# config.action_dispatch.rack_cache = true
# Disable serving static files from the `/public` folder by default since # Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this. # Apache or NGINX already handles this.
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
# Compress JavaScripts and CSS. # Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier config.assets.js_compressor = :uglifier
@ -31,16 +30,20 @@ Rails.application.configure do
# Do not fallback to assets pipeline if a precompiled asset is missed. # Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false config.assets.compile = false
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files. # 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-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# 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.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true # config.force_ssl = true
@ -49,16 +52,15 @@ Rails.application.configure do
config.log_level = :debug config.log_level = :debug
# Prepend all log lines with the following tags. # Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ] config.log_tags = [ :request_id ]
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production. # Use a different cache store in production.
# config.cache_store = :mem_cache_store # config.cache_store = :mem_cache_store
# Enable serving of images, stylesheets, and JavaScripts from an asset server. # Use a real queuing backend for Active Job (and separate queues per environment)
# config.action_controller.asset_host = 'http://assets.example.com' # config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "projekteuler_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors. # 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.
@ -74,6 +76,16 @@ Rails.application.configure do
# Use default logging formatter so that PID and timestamp are not suppressed. # Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new 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
# Do not dump schema after migrations. # Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false
end end

View File

@ -12,9 +12,11 @@ Rails.application.configure do
# preloads Rails for running tests, you may have to set it to true. # preloads Rails for running tests, you may have to set it to true.
config.eager_load = false config.eager_load = false
# Configure static file server for tests with Cache-Control for performance. # Configure public file server for tests with Cache-Control for performance.
config.serve_static_files = true config.public_file_server.enabled = true
config.static_cache_control = 'public, max-age=3600' config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}"
}
# Show full error reports and disable caching. # Show full error reports and disable caching.
config.consider_all_requests_local = true config.consider_all_requests_local = true
@ -25,15 +27,13 @@ Rails.application.configure do
# Disable request forgery protection in test environment. # Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false config.action_controller.allow_forgery_protection = false
config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world. # Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the # The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array. # ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test config.action_mailer.delivery_method = :test
# Randomize the order test cases are executed.
config.active_support.test_order = :random
# Print deprecation notices to the stderr. # Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr config.active_support.deprecation = :stderr

View File

@ -0,0 +1,8 @@
# 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

View File

@ -3,9 +3,12 @@
# Version of your assets, change this if you want to expire all your assets. # 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 # Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_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. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # application.js, application.css, and all non-JS/CSS in the app/assets
# Rails.application.config.assets.precompile += %w( search.js ) # folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

View File

@ -1,3 +1,5 @@
# Be sure to restart your server when you modify this file. # 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 Rails.application.config.action_dispatch.cookies_serializer = :json

View File

@ -0,0 +1,14 @@
# Be sure to restart your server when you modify this file.
#
# This file contains migration options to ease your Rails 5.1 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.
# Make `form_with` generate non-remote forms.
Rails.application.config.action_view.form_with_generates_remote_forms = false
# Unknown asset fallback will return the path passed in when the given
# asset is not present in the asset pipeline.
# Rails.application.config.assets.unknown_asset_fallback = false

View File

@ -5,10 +5,10 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json] if respond_to?(:wrap_parameters) wrap_parameters format: [:json]
end end
# To enable root element in JSON for ActiveRecord objects. # To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do # ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true # self.include_root_in_json = true
# end # end

56
config/puma.rb Normal file
View File

@ -0,0 +1,56 @@
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# 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).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# 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. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!
# If you are preloading your application and using Active Record, it's
# recommended that you close any connections to the database before workers
# are forked to prevent connection leakage.
#
# before_fork do
# ActiveRecord::Base.connection_pool.disconnect! if defined?(ActiveRecord)
# end
# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted, this block will be run. If you are using the `preload_app!`
# option, you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, as Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
#
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart

View File

@ -66,4 +66,5 @@ Rails.application.routes.draw do
# # (app/controllers/admin/products_controller.rb) # # (app/controllers/admin/products_controller.rb)
# resources :products # resources :products
# end # end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end end

View File

@ -5,18 +5,28 @@
# Make sure the secret is at least 30 characters and all random, # Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks. # no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key. # You can use `rails secret` to generate a secure secret key.
# Make sure the secrets in this file are kept private # Make sure the secrets in this file are kept private
# if you're sharing your code publicly. # if you're sharing your code publicly.
# Shared secrets are available across all environments.
# shared:
# api_key: a1B2c3D4e5F6
# Environmental secrets are only available for that specific environment.
development: development:
secret_key_base: 6c2640a4cd5352d96caea5bfb073ec7b827ad609f5a5a99680dbd56f2506dc0aecfe568404a0a63fc19529f7c7a38ac403635f83497580b3dec2afc16b7972b4 secret_key_base: ceb25f25a0e73150d84c213c7b303dc7091b6eaea001bc986067e5bf6642913c2d0e83c8c93b1e975cae11f2812d05602e1341e9a48687b7b23bed7976992890
test: test:
secret_key_base: 1b2d1b8c35dc3bcc8327819d95a1e635c64ae5038d25c4630463514a945c710da4923f2b8489f81021511fb59ee258e19735e50fb0df3c7efc3f06dc294c748f secret_key_base: eb1a45af35f2aa8c17790252820d8071be124f6a50f1e3112c873fe9d0e4aa49159c53759f381fe224e22aead60623bd82455fba509eb99e07117b98bcd41d4d
# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
# Or, use `bin/rails secrets:setup` to configure encrypted secrets
# and move the `production:` environment over there.
# Do not keep production secrets in the repository,
# instead read values from the environment.
production: production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

View File

@ -13,13 +13,13 @@ class Admin::DashboardControllerTest < ActionController::TestCase
end end
test "should post new problem count" do test "should post new problem count" do
post :update_problem_count, problem_count: 15 post :update_problem_count, params: { problem_count: 15 }
assert_redirected_to controller: 'admin/dashboard', action: 'index' assert_redirected_to controller: 'admin/dashboard', action: 'index'
assert_equal 15, Problem.count assert_equal 15, Problem.count
end end
test "should fail incorrect problem count" do test "should fail incorrect problem count" do
post :update_problem_count, problem_count: 2 post :update_problem_count, params: { problem_count: 2 }
assert_redirected_to controller: 'admin/dashboard', action: 'index' assert_redirected_to controller: 'admin/dashboard', action: 'index'
assert_equal 3, Problem.count assert_equal 3, Problem.count
end end

View File

@ -14,7 +14,7 @@ class Admin::TranslationsControllerTest < ActionController::TestCase
end end
test "should show translation" do test "should show translation" do
get :show, id: @translation get :show, params: { id: @translation }
assert_response :success assert_response :success
end end

View File

@ -9,12 +9,12 @@ class ProblemsControllerTest < ActionController::TestCase
end end
test "should get show" do test "should get show" do
get :show, id: 1 get :show, params: { id: 1 }
assert_response :success assert_response :success
end end
test "should get untranslated problem" do test "should get untranslated problem" do
get :show, id: 3 get :show, params: { id: 3 }
assert_response :success assert_response :success
end end

View File

@ -15,18 +15,18 @@ class TranslationsControllerTest < ActionController::TestCase
end end
test "should get new for translated problem" do test "should get new for translated problem" do
get :new, problem_id: 1 get :new, params: { problem_id: 1 }
assert_response :success assert_response :success
end end
test "should get new for untranslated problem" do test "should get new for untranslated problem" do
get :new, problem_id: 3 get :new, params: { problem_id: 3 }
assert_response :success assert_response :success
end end
test "should create translation" do test "should create translation" do
assert_difference('Translation.count') do assert_difference('Translation.count') do
post :create, problem_id: 1, translation: @update post :create, params: { problem_id: 1, translation: @update }
end end
assert_redirected_to problem_path(id: 1) assert_redirected_to problem_path(id: 1)
@ -34,7 +34,7 @@ class TranslationsControllerTest < ActionController::TestCase
test "should not create incorrect translation" do test "should not create incorrect translation" do
assert_no_difference('Translation.count') do assert_no_difference('Translation.count') do
post :create, problem_id: 1, translation: @incorrect post :create, params: { problem_id: 1, translation: @incorrect }
end end
end end
end end