diff --git a/Gemfile b/Gemfile index f6bcf542f..90a01033b 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby ">= 2.4.10", "< 2.5" -gem "rails", "~> 4.2" +gem "rails", "~> 5.0.7.2" gem "devise", "~> 4.0" gem "psych", "~> 2.0.2" # part of stdlib, need newer version for safe_load @@ -24,10 +24,10 @@ gem "loofah", "<= 2.20.0" gem "whenever", require: false # for cron jobs gem "tilt" gem "simple-navigation", "3.11.0" -gem "simple_form", "3.2.1" +gem "simple_form", "3.3.1" gem "render_anywhere" gem "pygments.rb", "~> 2.0" -gem "ranked-model", "< 0.4.3" # pinned because 0.4.3-0.4.4 are broken (see https://github.com/brendon/ranked-model/issues/139; we also need the fix in https://github.com/brendon/ranked-model/pull/152); we can't update to 0.4.5 yet because it requires activerecord >= 4.2 +gem "ranked-model" gem "pdf-reader" gem "mechanize" gem "prawn" @@ -43,6 +43,8 @@ gem "ruby-duration" gem "pg" gem "backup" +gem "activemodel-serializers-xml" + # Redis and Background Processing gem "redis" gem "qless", github: "Shopify/qless" @@ -79,7 +81,7 @@ group :development, :test do gem "standard" - gem "test_after_commit", "~> 1.2" + gem "rails-controller-testing", "~> 1.0" end # Gems used only for assets and not required diff --git a/Gemfile.lock b/Gemfile.lock index 094ed9103..fc406a35d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,45 +16,52 @@ GIT GEM remote: https://rubygems.org/ specs: - Ascii85 (1.0.2) - actionmailer (4.2.11.3) - actionpack (= 4.2.11.3) - actionview (= 4.2.11.3) - activejob (= 4.2.11.3) + Ascii85 (1.1.1) + actioncable (5.0.7.2) + actionpack (= 5.0.7.2) + nio4r (>= 1.2, < 3.0) + websocket-driver (~> 0.6.1) + actionmailer (5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (4.2.11.3) - actionview (= 4.2.11.3) - activesupport (= 4.2.11.3) - rack (~> 1.6) - rack-test (~> 0.6.2) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) + actionpack (5.0.7.2) + actionview (= 5.0.7.2) + activesupport (= 5.0.7.2) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (4.2.11.3) - activesupport (= 4.2.11.3) + actionview (5.0.7.2) + activesupport (= 5.0.7.2) builder (~> 3.1) erubis (~> 2.7.0) - rails-dom-testing (~> 1.0, >= 1.0.5) + rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (4.2.11.3) - activesupport (= 4.2.11.3) - globalid (>= 0.3.0) - activemodel (4.2.11.3) - activesupport (= 4.2.11.3) + activejob (5.0.7.2) + activesupport (= 5.0.7.2) + globalid (>= 0.3.6) + activemodel (5.0.7.2) + activesupport (= 5.0.7.2) + activemodel-serializers-xml (1.0.3) + activemodel (>= 5.0.0.a) + activesupport (>= 5.0.0.a) builder (~> 3.1) - activerecord (4.2.11.3) - activemodel (= 4.2.11.3) - activesupport (= 4.2.11.3) - arel (~> 6.0) - activesupport (4.2.11.3) - i18n (~> 0.7) + activerecord (5.0.7.2) + activemodel (= 5.0.7.2) + activesupport (= 5.0.7.2) + arel (~> 7.0) + activesupport (5.0.7.2) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 0.7, < 2) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.8.1) - public_suffix (>= 2.0.2, < 6.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) afm (0.2.2) - arel (6.0.4) + arel (7.1.4) ast (2.4.3) atomic (1.1.101) avl_tree (1.2.1) @@ -62,24 +69,26 @@ GEM backup (3.4.0) open4 (~> 1.3.0) thor (>= 0.15.4, < 2) + base64 (0.2.0) bcrypt (3.1.20) - better_errors (2.9.1) - coderay (>= 1.0.0) + better_errors (2.10.1) erubi (>= 1.0.0) rack (>= 0.9.0) - binding_of_caller (0.7.3) - debug_inspector (>= 0.0.1) - builder (3.2.4) - byebug (9.1.0) - capybara (2.17.0) + rouge (>= 1.0.0) + binding_of_caller (1.0.1) + debug_inspector (>= 1.2.0) + builder (3.3.0) + byebug (11.1.3) + capybara (3.32.2) addressable mini_mime (>= 0.1.3) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - xpath (>= 2.0, < 4.0) - capybara-email (2.5.0) - capybara (~> 2.4) + nokogiri (~> 1.8) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (~> 1.5) + xpath (~> 3.2) + capybara-email (3.0.2) + capybara (>= 2.4, < 4.0) mail carrierwave (1.3.2) activemodel (>= 4.0.0) @@ -87,8 +96,7 @@ GEM mime-types (>= 1.16) ssrf_filter (~> 1.0) chronic (0.10.2) - chunky_png (1.3.8) - coderay (1.1.3) + chunky_png (1.4.0) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -96,39 +104,38 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.2.2) - connection_pool (2.2.1) - countries (2.1.3) - i18n_data (~> 0.8.0) - money (~> 6.9) + concurrent-ruby (1.3.5) + connection_pool (2.2.5) + countries (3.1.0) + i18n_data (~> 0.11.0) sixarm_ruby_unaccent (~> 1.1) unicode_utils (~> 1.4) - country_select (3.1.1) - countries (~> 2.0) + country_select (4.0.0) + countries (~> 3.0) sort_alphabetical (~> 1.0) - crass (1.0.5) + crass (1.0.6) daemons (1.4.1) - debug_inspector (0.0.3) - devise (4.9.3) + debug_inspector (1.2.0) + devise (4.9.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) - diff-lcs (1.5.0) + diff-lcs (1.6.1) docile (1.3.5) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - erubi (1.12.0) + erubi (1.13.1) erubis (2.7.0) eventmachine (1.2.7) - execjs (2.7.0) - factory_bot (4.11.1) - activesupport (>= 3.0.0) - factory_bot_rails (4.11.1) - factory_bot (~> 4.11.1) - railties (>= 3.0.0) - faraday (1.10.3) + execjs (2.9.0) + factory_bot (5.2.0) + activesupport (>= 4.2.0) + factory_bot_rails (5.2.0) + factory_bot (~> 5.2.0) + railties (>= 4.2.0) + faraday (1.10.4) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -144,33 +151,33 @@ GEM faraday-em_synchrony (1.0.0) faraday-excon (1.1.0) faraday-httpclient (1.0.1) - faraday-multipart (1.0.4) - multipart-post (~> 2) - faraday-net_http (1.0.1) + faraday-multipart (1.1.0) + multipart-post (~> 2.0) + faraday-net_http (1.0.2) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) faraday-retry (1.0.3) - ffi (1.12.2) - foreman (0.84.0) - thor (~> 0.19.1) + ffi (1.15.5) + foreman (0.88.1) globalid (0.4.2) activesupport (>= 4.2.0) has_scope (0.7.2) actionpack (>= 4.1) activesupport (>= 4.1) hashery (2.1.2) - hashie (3.5.7) + hashie (5.0.0) hitimes (1.3.1) - http-cookie (1.0.5) + http-cookie (1.0.8) domain_name (~> 0.5) - i18n (0.9.5) + i18n (1.14.7) concurrent-ruby (~> 1.0) - i18n_data (0.8.0) - iso8601 (0.10.1) + i18n_data (0.11.0) + iso8601 (0.13.0) json (2.7.6) libv8-node (15.14.0.1) - loofah (2.3.1) + logger (1.5.3) + loofah (2.20.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -185,28 +192,32 @@ GEM ntlm-http (~> 0.1, >= 0.1.1) webrick (~> 1.7) webrobots (>= 0.0.9, < 0.2) + method_source (1.1.0) metriks (0.9.9.8) atomic (~> 1.0) avl_tree (~> 1.2.0) hitimes (~> 1.1) - mime-types (3.4.1) + mime-types (3.6.2) + logger mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) + mime-types-data (3.2025.0415) mini_mime (1.1.2) mini_portile2 (2.4.0) mini_racer (0.4.0) libv8-node (~> 15.14.0.0) minitest (5.15.0) - money (6.10.1) - i18n (>= 0.6.4, < 1.0) multipart-post (2.3.0) + mustermann (2.0.2) + ruby2_keywords (~> 0.0.1) net-http-digest_auth (1.4.1) - net-http-persistent (4.0.1) + net-http-persistent (4.0.5) connection_pool (~> 2.2) - newrelic_rpm (4.7.1.340) + newrelic_rpm (9.18.0) + nio4r (2.7.3) nokogiri (1.10.10) mini_portile2 (~> 2.4.0) ntlm-http (0.1.1) + observer (0.1.2) open4 (1.3.4) orm_adapter (0.5.0) parallel (1.20.1) @@ -214,15 +225,15 @@ GEM ast (~> 2.4.1) racc pdf-core (0.7.0) - pdf-reader (2.0.0) - Ascii85 (~> 1.0.0) + pdf-reader (2.14.1) + Ascii85 (>= 1.0, < 3.0, != 2.0.0) afm (~> 0.2.1) hashery (~> 2.0) ruby-rc4 ttfunk - pdfkit (0.8.2) - pg (0.21.0) - pkg-config (1.5.1) + pdfkit (0.8.4.3.2) + pg (1.2.3) + pkg-config (1.6.1) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) @@ -232,57 +243,65 @@ GEM activesupport (>= 3.0.0) pygments.rb (2.3.1) racc (1.5.2) - rack (1.6.13) - rack-protection (1.5.5) + rack (2.2.13) + rack-protection (2.2.3) rack rack-test (0.6.3) rack (>= 1.0) - rails (4.2.11.3) - actionmailer (= 4.2.11.3) - actionpack (= 4.2.11.3) - actionview (= 4.2.11.3) - activejob (= 4.2.11.3) - activemodel (= 4.2.11.3) - activerecord (= 4.2.11.3) - activesupport (= 4.2.11.3) - bundler (>= 1.3.0, < 2.0) - railties (= 4.2.11.3) - sprockets-rails - rails-deprecated_sanitizer (1.0.4) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.9) - activesupport (>= 4.2.0, < 5.0) - nokogiri (~> 1.6) - rails-deprecated_sanitizer (>= 1.0.1) - rails-html-sanitizer (1.4.3) - loofah (~> 2.3) - railties (4.2.11.3) - actionpack (= 4.2.11.3) - activesupport (= 4.2.11.3) + rails (5.0.7.2) + actioncable (= 5.0.7.2) + actionmailer (= 5.0.7.2) + actionpack (= 5.0.7.2) + actionview (= 5.0.7.2) + activejob (= 5.0.7.2) + activemodel (= 5.0.7.2) + activerecord (= 5.0.7.2) + activesupport (= 5.0.7.2) + bundler (>= 1.3.0) + railties (= 5.0.7.2) + sprockets-rails (>= 2.0.0) + rails-controller-testing (1.0.5) + actionpack (>= 5.0.1.rc1) + actionview (>= 5.0.1.rc1) + activesupport (>= 5.0.1.rc1) + rails-dom-testing (2.1.1) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.5.0) + loofah (~> 2.19, >= 2.19.1) + railties (5.0.7.2) + actionpack (= 5.0.7.2) + activesupport (= 5.0.7.2) + method_source rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (3.1.1) - rake (13.1.0) - ranked-model (0.4.0) - activerecord (>= 3.1.12) - rb-fsevent (0.10.2) - rb-inotify (0.9.10) - ffi (>= 0.5.0, < 2) - recaptcha (4.6.3) + rake (13.2.1) + ranked-model (0.4.8) + activerecord (>= 4.2) + rb-fsevent (0.11.2) + rb-inotify (0.10.1) + ffi (~> 1.0) + recaptcha (5.9.0) json - redcarpet (3.2.3) + redcarpet (3.6.1) redis (4.4.0) - regexp_parser (2.10.0) + regexp_parser (1.8.2) render_anywhere (0.0.12) rails (>= 3.0.7) - responders (2.4.1) - actionpack (>= 4.2.0, < 6.0) - railties (>= 4.2.0, < 6.0) + responders (3.0.1) + actionpack (>= 5.0) + railties (>= 5.0) rexml (3.2.5) - rmagick (5.1.0) + rmagick (5.5.0) + observer (~> 0.1) pkg-config (~> 1.4) - rqrcode (0.10.1) + rouge (3.30.0) + rqrcode (2.1.2) chunky_png (~> 1.0) + rqrcode_core (~> 1.0) + rqrcode_core (1.2.0) rspec-core (3.9.3) rspec-support (~> 3.9.3) rspec-expectations (3.9.4) @@ -323,88 +342,94 @@ GEM ruby2_keywords (0.0.5) rubyzip (1.3.0) rusage (0.2.0) - sass (3.5.5) + sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sass-rails (5.0.7) - railties (>= 4.0.0, < 6) - sass (~> 3.1) - sprockets (>= 2.8, < 4.0) - sprockets-rails (>= 2.0, < 4.0) - tilt (>= 1.1, < 3) + 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 sentry-raven (3.1.2) faraday (>= 1.0) simple-navigation (3.11.0) activesupport (>= 2.3.2) - simple_form (3.2.1) + simple_form (3.3.1) actionpack (> 4, < 5.1) activemodel (> 4, < 5.1) simplecov (0.18.5) docile (~> 1.1) simplecov-html (~> 0.11) - simplecov-html (0.12.3) - sinatra (1.4.8) - rack (~> 1.5) - rack-protection (~> 1.4) - tilt (>= 1.3, < 3) - sixarm_ruby_unaccent (1.2.0) + simplecov-html (0.13.1) + sinatra (2.2.3) + mustermann (~> 2.0) + rack (~> 2.2) + rack-protection (= 2.2.3) + tilt (~> 2.0) + sixarm_ruby_unaccent (1.2.2) sort_alphabetical (1.1.0) unicode_utils (>= 1.2.2) - spring (1.7.2) - sprockets (3.7.2) + spring (2.1.1) + sprockets (3.7.5) + base64 concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (2.3.3) - actionpack (>= 3.0) - activesupport (>= 3.0) - sprockets (>= 2.8, < 4.0) + sprockets-rails (3.2.2) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) ssrf_filter (1.0.8) standard (1.0.5) rubocop (= 1.12.1) rubocop-performance (= 1.10.1) statsd-ruby (1.5.0) superfish-rails (1.6.0.1) - test_after_commit (1.2.2) - activerecord (>= 3.2, < 5.0) thin (1.8.2) daemons (~> 1.0, >= 1.0.9) eventmachine (~> 1.0, >= 1.0.4) rack (>= 1, < 3) - thor (0.19.4) + thor (1.2.2) thread_safe (0.3.6) - tilt (2.0.8) - ttfunk (1.5.1) + tilt (2.6.0) + ttfunk (1.6.2.1) tzinfo (1.2.11) thread_safe (~> 0.1) - uglifier (4.1.2) + uglifier (4.2.1) execjs (>= 0.3.0, < 3) - unf (0.1.4) - unf_ext - unf_ext (0.0.8.2) + unf (0.2.0) unicode-display_width (2.6.0) unicode_utils (1.4.0) vegas (0.1.11) rack (>= 1.0.0) - warden (1.2.7) - rack (>= 1.0) - webrick (1.7.0) + warden (1.2.9) + rack (>= 2.0.9) + webrick (1.9.1) webrobots (0.1.2) - whenever (0.10.0) + websocket-driver (0.6.5) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + whenever (1.0.0) chronic (>= 0.6.3) - will_paginate (3.1.6) - world-flags (0.6.5) + will_paginate (4.0.1) + world-flags (0.6.6) hashie (>= 1.2) i18n (>= 0.6) - xpath (2.1.0) - nokogiri (~> 1.3) + xpath (3.2.0) + nokogiri (~> 1.8) yui-compressor (0.12.0) PLATFORMS ruby DEPENDENCIES + activemodel-serializers-xml backup better_errors binding_of_caller @@ -433,8 +458,9 @@ DEPENDENCIES pundit (~> 1.1.0) pygments.rb (~> 2.0) qless! - rails (~> 4.2) - ranked-model (< 0.4.3) + rails (~> 5.0.7.2) + rails-controller-testing (~> 1.0) + ranked-model recaptcha redcarpet redis @@ -449,13 +475,12 @@ DEPENDENCIES sass-rails sentry-raven simple-navigation (= 3.11.0) - simple_form (= 3.2.1) + simple_form (= 3.3.1) simplecov sinatra spring standard superfish-rails (~> 1.6.0) - test_after_commit (~> 1.2) tilt uglifier (>= 1.0.3) whenever diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cf8424911..cc696d42d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,14 +4,14 @@ class ApplicationController < ActionController::Base layout "scaffold" + protect_from_forgery + before_filter :update_last_seen_at before_filter :update_contest_checkin before_filter :read_settings before_filter :check_su_loss before_filter :configure_permitted_parameters, if: :devise_controller? - protect_from_forgery - # helper ApplicationHelper # helper ProblemsHelper # helper Accounts::RequestsHelper diff --git a/app/models/request.rb b/app/models/request.rb index 63fde6e89..ec2432f9f 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -31,8 +31,7 @@ class Request < ActiveRecord::Base scope :pending, -> { status_pending.merge(not_past_expiry) } scope :expired, -> { status_pending.merge(past_expiry) } - # TODO(Rails5): Convert to where.not(pending).or(past_expiry) - scope :closed, -> { where("status != ? OR expired_at <= ?", STATUS[:pending], DateTime.now) } + scope :closed, -> { where.not(pending).or(past_expiry) } def pending? status == STATUS[:pending] && (expired_at == Float::INFINITY || expired_at > DateTime.now) diff --git a/bin/bundle b/bin/bundle new file mode 100755 index 000000000..66e9889e8 --- /dev/null +++ b/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails new file mode 100755 index 000000000..073966023 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/bin/rake b/bin/rake new file mode 100755 index 000000000..17240489f --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/bin/setup b/bin/setup new file mode 100755 index 000000000..e620b4dad --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +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 starting point to setup your application. + # Add necessary setup steps to this file. + + 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') + # cp 'config/database.yml.sample', 'config/database.yml' + # end + + puts "\n== Preparing database ==" + system! 'bin/rails db:setup' + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/bin/update b/bin/update new file mode 100755 index 000000000..a8e4462f2 --- /dev/null +++ b/bin/update @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +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 diff --git a/config/boot.rb b/config/boot.rb index edf778b45..282011619 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,6 +1,3 @@ -require "rubygems" +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -# Set up gems listed in the Gemfile. -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) - -require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) +require "bundler/setup" # Set up gems listed in the Gemfile. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 000000000..0bbde6f74 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,9 @@ +development: + adapter: async + +test: + adapter: async + +production: + adapter: redis + url: redis://localhost:6379/1 diff --git a/config/environment.rb b/config/environment.rb index 2c9f09cfd..cac531577 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,5 +1,5 @@ -# Load the rails application -require File.expand_path("../application", __FILE__) +# Load the Rails application. +require_relative "application" -# Initialize the rails application -NZTrain::Application.initialize! +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/production.rb b/config/environments/production.rb index a3d5c60e5..fc621db9b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -22,8 +22,8 @@ # If you have no front-end server that supports something like X-Sendfile, # just comment this out and Rails will serve the files - # See everything in the log (default is :info) - # config.log_level = :debug + # Change to "debug" to log everything (including potentially personally-identifiable information!). + config.log_level = :info # Use a different logger for distributed setups # config.logger = SyslogLogger.new diff --git a/config/initializers/application_controller_renderer.rb b/config/initializers/application_controller_renderer.rb new file mode 100644 index 000000000..89d2efab2 --- /dev/null +++ b/config/initializers/application_controller_renderer.rb @@ -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 diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 000000000..0838adaa2 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# 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" + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 000000000..4a994e1e7 --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 9e8b0131f..ac033bf9d 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -1,10 +1,16 @@ # Be sure to restart your server when you modify this file. -# Add new inflection rules using the following format -# (all these examples are active by default): -# ActiveSupport::Inflector.inflections do |inflect| +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb new file mode 100644 index 000000000..cbf423a81 --- /dev/null +++ b/config/initializers/new_framework_defaults.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains migration options to ease your Rails 5.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. + +Rails.application.config.action_controller.raise_on_unfiltered_parameters = true + +# Enable per-form CSRF tokens. Previous versions had false. +Rails.application.config.action_controller.per_form_csrf_tokens = false + +# Enable origin-checking CSRF mitigation. Previous versions had false. +Rails.application.config.action_controller.forgery_protection_origin_check = false + +# Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. +# Previous versions had false. +ActiveSupport.to_time_preserves_timezone = false + +# Require `belongs_to` associations by default. Previous versions had false. +Rails.application.config.active_record.belongs_to_required_by_default = false + +# Do not halt callback chains when a callback returns false. Previous versions had true. +ActiveSupport.halt_callback_chains_on_return_false = true diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb new file mode 100644 index 000000000..bbfc3961b --- /dev/null +++ b/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# 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/puma.rb b/config/puma.rb new file mode 100644 index 000000000..59d2d1881 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,47 @@ +# 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).to_i +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! + +# 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 `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, 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 diff --git a/config/secrets.yml b/config/secrets.yml new file mode 100644 index 000000000..b920e28f9 --- /dev/null +++ b/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rails secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: 60daf0d06bb2646d9c60f5036ac363a9a4b48c08f02abe474610e58edfa030f944fa7ab17f7a6b06e26327258ef3727c5f95c9634548f475e1347e5f74d2ffe7 + +test: + secret_key_base: b40cbeae7b7995d6e308b6bba2c95d2c3c9701ba9a02b46aea044becb636bd4ecfb32d8078c99f3cf12642ef210cb5dadb2000da184a7b6c241d717f5f714e00 + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/config/spring.rb b/config/spring.rb new file mode 100644 index 000000000..9fa7863f9 --- /dev/null +++ b/config/spring.rb @@ -0,0 +1,6 @@ +%w[ + .ruby-version + .rbenv-vars + tmp/restart.txt + tmp/caching-dev.txt +].each { |path| Spring.watch(path) } diff --git a/db/schema.rb b/db/schema.rb index 8128e87c9..e5a82dd07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -34,12 +33,11 @@ t.integer "school_year" t.integer "supervisor_id" t.boolean "checked_in", default: false + t.index ["contest_id", "score", "time_taken"], name: "index_contest_relations_on_contest_id_and_score_and_time_taken", order: { score: :desc }, using: :btree + t.index ["contest_id", "user_id"], name: "index_contest_relations_on_contest_id_and_user_id", unique: true, using: :btree + t.index ["user_id", "started_at"], name: "index_contest_relations_on_user_id_and_started_at", using: :btree end - add_index "contest_relations", ["contest_id", "score", "time_taken"], name: "index_contest_relations_on_contest_id_and_score_and_time_taken", order: {"score"=>:desc}, using: :btree - add_index "contest_relations", ["contest_id", "user_id"], name: "index_contest_relations_on_contest_id_and_user_id", unique: true, using: :btree - add_index "contest_relations", ["user_id", "started_at"], name: "index_contest_relations_on_user_id_and_started_at", using: :btree - create_table "contest_scores", force: :cascade do |t| t.integer "contest_relation_id", null: false t.integer "problem_id", null: false @@ -48,10 +46,9 @@ t.integer "attempt" t.integer "submission_id" t.datetime "updated_at" + t.index ["contest_relation_id", "problem_id"], name: "index_contest_scores_on_contest_relation_id_and_problem_id", using: :btree end - add_index "contest_scores", ["contest_relation_id", "problem_id"], name: "index_contest_scores_on_contest_relation_id_and_problem_id", using: :btree - create_table "contest_supervisors", force: :cascade do |t| t.integer "contest_id" t.integer "user_id" @@ -111,19 +108,17 @@ t.string "filepath", limit: 255 t.string "root_type", limit: 255 t.integer "visibility", limit: 2, default: 0 + t.index ["file_attachment_id"], name: "index_filelinks_on_file_attachment_id", using: :btree + t.index ["root_id", "filepath"], name: "index_filelinks_on_root_id_and_filepath", using: :btree end - add_index "filelinks", ["file_attachment_id"], name: "index_filelinks_on_file_attachment_id", using: :btree - add_index "filelinks", ["root_id", "filepath"], name: "index_filelinks_on_root_id_and_filepath", using: :btree - create_table "group_contests", force: :cascade do |t| t.integer "group_id" t.integer "contest_id" + t.index ["contest_id", "group_id"], name: "index_group_contests_on_contest_id_and_group_id", using: :btree + t.index ["group_id", "contest_id"], name: "index_group_contests_on_group_id_and_contest_id", using: :btree end - add_index "group_contests", ["contest_id", "group_id"], name: "index_group_contests_on_contest_id_and_group_id", using: :btree - add_index "group_contests", ["group_id", "contest_id"], name: "index_group_contests_on_group_id_and_contest_id", using: :btree - create_table "group_memberships", force: :cascade do |t| t.integer "group_id" t.integer "member_id" @@ -134,11 +129,10 @@ t.integer "group_id" t.integer "problem_set_id" t.string "name", limit: 255 + t.index ["group_id", "problem_set_id"], name: "index_group_problem_sets_on_group_id_and_problem_set_id", using: :btree + t.index ["problem_set_id", "group_id"], name: "index_group_problem_sets_on_problem_set_id_and_group_id", using: :btree end - add_index "group_problem_sets", ["group_id", "problem_set_id"], name: "index_group_problem_sets_on_group_id_and_problem_set_id", using: :btree - add_index "group_problem_sets", ["problem_set_id", "group_id"], name: "index_group_problem_sets_on_problem_set_id_and_group_id", using: :btree - create_table "groups", force: :cascade do |t| t.string "name", limit: 255 t.datetime "created_at" @@ -177,10 +171,9 @@ t.integer "current_language_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["identifier"], name: "index_language_groups_on_identifier", unique: true, using: :btree end - add_index "language_groups", ["identifier"], name: "index_language_groups_on_identifier", unique: true, using: :btree - create_table "languages", force: :cascade do |t| t.string "identifier", limit: 255 t.string "compiler", limit: 255 @@ -198,10 +191,9 @@ t.string "interpreter", limit: 255 t.string "interpreter_command", limit: 255 t.integer "processes", default: 1 + t.index ["identifier"], name: "index_languages_on_identifier", unique: true, using: :btree end - add_index "languages", ["identifier"], name: "index_languages_on_identifier", unique: true, using: :btree - create_table "organisations", force: :cascade do |t| end @@ -217,11 +209,10 @@ t.integer "problem_id" t.integer "problem_set_order" t.integer "weighting", default: 100 + t.index ["problem_id", "problem_set_id"], name: "index_problem_set_problems_on_problem_id_and_problem_set_id", using: :btree + t.index ["problem_set_id", "problem_id"], name: "index_problem_set_problems_on_problem_set_id_and_problem_id", using: :btree end - add_index "problem_set_problems", ["problem_id", "problem_set_id"], name: "index_problem_set_problems_on_problem_id_and_problem_set_id", using: :btree - add_index "problem_set_problems", ["problem_set_id", "problem_id"], name: "index_problem_set_problems_on_problem_set_id_and_problem_id", using: :btree - create_table "problem_sets", force: :cascade do |t| t.string "name", limit: 255 t.integer "owner_id" @@ -248,10 +239,10 @@ end create_table "products", force: :cascade do |t| - t.string "name", limit: 255 - t.integer "gtin", limit: 8 - t.text "description" - t.string "image", limit: 255 + t.string "name", limit: 255 + t.bigint "gtin" + t.text "description" + t.string "image", limit: 255 end create_table "requests", force: :cascade do |t| @@ -289,19 +280,17 @@ t.text "data" t.datetime "created_at" t.datetime "updated_at" + t.index ["created_at"], name: "index_sessions_on_created_at", using: :btree + t.index ["session_id"], name: "index_sessions_on_session_id", using: :btree + t.index ["updated_at"], name: "index_sessions_on_updated_at", using: :btree end - add_index "sessions", ["created_at"], name: "index_sessions_on_created_at", using: :btree - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree - add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree - create_table "settings", force: :cascade do |t| t.string "key", limit: 255 t.string "value", limit: 255 + t.index ["key"], name: "index_settings_on_key", unique: true, using: :btree end - add_index "settings", ["key"], name: "index_settings_on_key", unique: true, using: :btree - create_table "submissions", force: :cascade do |t| t.text "source" t.integer "score" @@ -321,21 +310,19 @@ t.float "evaluation" t.decimal "points" t.integer "maximum_points" + t.index ["problem_id", "created_at"], name: "index_submissions_on_problem_id_and_created_at", using: :btree + t.index ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree end - add_index "submissions", ["problem_id", "created_at"], name: "index_submissions_on_problem_id_and_created_at", using: :btree - add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree - create_table "test_case_relations", force: :cascade do |t| t.integer "test_case_id" t.integer "test_set_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["test_case_id"], name: "index_test_case_relations_on_test_case_id", using: :btree + t.index ["test_set_id"], name: "index_test_case_relations_on_test_set_id", using: :btree end - add_index "test_case_relations", ["test_case_id"], name: "index_test_case_relations_on_test_case_id", using: :btree - add_index "test_case_relations", ["test_set_id"], name: "index_test_case_relations_on_test_set_id", using: :btree - create_table "test_cases", force: :cascade do |t| t.text "input" t.text "output" @@ -345,10 +332,9 @@ t.integer "problem_id" t.boolean "sample", default: false t.integer "problem_order" + t.index ["problem_id", "name"], name: "index_test_cases_on_problem_id_and_name", unique: true, using: :btree end - add_index "test_cases", ["problem_id", "name"], name: "index_test_cases_on_problem_id_and_name", unique: true, using: :btree - create_table "test_sets", force: :cascade do |t| t.integer "problem_id" t.integer "points" @@ -357,10 +343,9 @@ t.datetime "updated_at" t.boolean "prerequisite", default: false t.integer "problem_order" + t.index ["problem_id", "name"], name: "index_test_sets_on_problem_id_and_name", unique: true, using: :btree end - add_index "test_sets", ["problem_id", "name"], name: "index_test_sets_on_problem_id_and_name", unique: true, using: :btree - create_table "user_problem_relations", force: :cascade do |t| t.integer "problem_id" t.integer "user_id" @@ -372,11 +357,10 @@ t.datetime "first_viewed_at" t.datetime "created_at" t.datetime "updated_at" + t.index ["problem_id", "ranked_score"], name: "index_user_problem_relations_on_problem_id_and_ranked_score", using: :btree + t.index ["user_id", "problem_id"], name: "index_user_problem_relations_on_user_id_and_problem_id", unique: true, using: :btree end - add_index "user_problem_relations", ["problem_id", "ranked_score"], name: "index_user_problem_relations_on_problem_id_and_ranked_score", using: :btree - add_index "user_problem_relations", ["user_id", "problem_id"], name: "index_user_problem_relations_on_user_id_and_problem_id", unique: true, using: :btree - create_table "users", force: :cascade do |t| t.string "email", limit: 255, default: "", null: false t.string "encrypted_password", limit: 255, default: "", null: false @@ -403,10 +387,10 @@ t.integer "school_id" t.string "country_code", limit: 3 t.date "school_graduation" + t.index "lower((username)::text)", name: "index_users_on_username", unique: true, using: :btree + t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree + t.index ["email"], name: "index_users_on_email", unique: true, using: :btree + t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree end - add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree - add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree - add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree - end diff --git a/spec/controllers/problems_controller_spec.rb b/spec/controllers/problems_controller_spec.rb index 460dffbbd..e852fefce 100644 --- a/spec/controllers/problems_controller_spec.rb +++ b/spec/controllers/problems_controller_spec.rb @@ -39,7 +39,7 @@ it "can post submit for group problem" do expect_any_instance_of(Submission).to receive(:judge) # post multi-part form - post :submit, id: group_problem.id, submission: {language_id: LanguageGroup.find_by_identifier("c++").current_language, source_file: fixture_file_upload("/files/adding.cpp", "text/plain")} + post :submit, id: group_problem.id, submission: {language_id: LanguageGroup.find_by_identifier("c++").current_language.id, source_file: fixture_file_upload("/files/adding.cpp", "text/plain")} expect(response).to redirect_to submission_path(assigns(:submission)) expect(assigns(:submission).problem_id).to eq(group_problem.id) expect(assigns(:submission).user_id).to eq(user.id)