From 0b33fbb66e9db9b366c97dfa80fa59cc422dcf48 Mon Sep 17 00:00:00 2001 From: glacials Date: Fri, 19 Aug 2016 17:01:57 -0700 Subject: [PATCH] Upgrade to Rails 5 proper Also do a bunch of v4 API stuff --- Gemfile | 20 +- Gemfile.lock | 413 +++++++++--------- app/assets/javascripts/application.js | 2 +- app/assets/javascripts/darkmode.coffee | 5 +- .../api/v4/application_controller.rb | 16 +- app/controllers/api/v4/converts_controller.rb | 5 +- .../v4/games/categories/runs_controller.rb | 37 -- .../api/v4/games/categories_controller.rb | 8 - .../api/v4/runners/pbs_controller.rb | 14 + .../v4/{users => runners}/runs_controller.rb | 6 +- app/controllers/api/v4/runners_controller.rb | 9 - .../api/v4/runs/splits_controller.rb | 4 +- .../users/games/categories/pbs_controller.rb | 18 - .../categories/predictions_controller.rb | 45 -- .../users/games/categories/runs_controller.rb | 16 - .../api/v4/users/pbs_controller.rb | 20 - app/controllers/api/v4/users_controller.rb | 15 - app/controllers/concerns/.keep | 0 app/controllers/games/aliases_controller.rb | 1 - .../leaderboards/sum_of_bests_controller.rb | 18 +- .../games/categories_controller.rb | 17 +- .../runs/application_controller.rb | 1 - app/controllers/runs/stats_controller.rb | 1 - app/models/application_record.rb | 3 + app/models/category.rb | 4 +- app/models/concerns/twitch_user.rb | 18 +- app/models/game.rb | 8 +- app/models/game/alias.rb | 2 +- app/models/rivalry.rb | 2 +- app/models/run.rb | 12 +- app/models/run_file.rb | 2 +- app/models/user.rb | 6 +- app/serializers/api/v4/run_serializer.rb | 14 +- app/serializers/api/v4/split_serializer.rb | 3 - .../api/v4/split_with_history_serializer.rb | 9 - config/application.rb | 2 + config/routes.rb | 36 +- config/unicorn.rb | 8 +- db/schema.rb | 1 - lib/parsers/llanfair.rb | 10 +- lib/twitch.rb | 4 +- 41 files changed, 362 insertions(+), 473 deletions(-) delete mode 100644 app/controllers/api/v4/games/categories/runs_controller.rb create mode 100644 app/controllers/api/v4/runners/pbs_controller.rb rename app/controllers/api/v4/{users => runners}/runs_controller.rb (51%) delete mode 100644 app/controllers/api/v4/users/games/categories/pbs_controller.rb delete mode 100644 app/controllers/api/v4/users/games/categories/predictions_controller.rb delete mode 100644 app/controllers/api/v4/users/games/categories/runs_controller.rb delete mode 100644 app/controllers/api/v4/users/pbs_controller.rb delete mode 100644 app/controllers/api/v4/users_controller.rb delete mode 100644 app/controllers/concerns/.keep create mode 100644 app/models/application_record.rb delete mode 100644 app/serializers/api/v4/split_serializer.rb delete mode 100644 app/serializers/api/v4/split_with_history_serializer.rb diff --git a/Gemfile b/Gemfile index 7253b339..ba0907f2 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ ruby '2.2.5' group :test do # tests gem 'factory_girl_rails', require: false - gem 'rspec-rails', '3.5.0.beta3', require: false + gem 'rspec-rails', require: false gem 'simplecov', require: false end @@ -37,21 +37,22 @@ group :production do end # api -gem 'active_model_serializers', github: 'rails-api/active_model_serializers' +gem 'active_model_serializers' gem 'api-pagination' gem 'jbuilder' # authentication gem 'authie', github: 'glacials/authie' -gem 'omniauth', '~> 1.2.2' +gem 'omniauth' gem 'omniauth-twitch' -gem 'omniauth-oauth2', '~> 1.3.0' +gem 'omniauth-oauth2' # authorization gem 'cancancan' # db -gem 'arel', github: 'rails/arel' +gem 'arel' +gem 'aws-sdk-rails' gem 'pg' # errors+logging @@ -67,8 +68,8 @@ gem 'platform-api' # javascript gem 'coffee-rails' gem 'jquery-rails' -gem 'jquery-cookie-rails' gem 'jquery-ui-rails' +gem 'js_cookie_rails' gem 'numeraljs-rails' gem 'spinjs-rails' gem 'tipsy-rails' @@ -77,8 +78,7 @@ gem 'momentjs-rails' gem 'd3-rails', '~> 3.5.17' gem 'c3-rails' -# models/db -gem 'aws-sdk-rails' +# models gem 'has_secure_token' gem 'nilify_blanks' @@ -92,7 +92,7 @@ gem 'xml-simple' # server/environment gem 'figaro' -gem 'rails', github: 'rails/rails' +gem 'rails', '~> 5' gem 'thin' gem 'unicorn' @@ -106,7 +106,7 @@ gem 'bootstrap-sass' gem 'flat-ui-rails' gem 'gon' gem 'htmlentities' -gem 'purecss-rails' +gem 'purecss-rails', github: 'glacials/purecss-rails' gem 'sass-rails' gem 'slim' gem 'uglifier' diff --git a/Gemfile.lock b/Gemfile.lock index def9ad9b..fae4d6fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,97 +13,77 @@ GIT numerizer (~> 0.1.1) GIT - remote: git://github.com/rails-api/active_model_serializers.git - revision: 35fb9de3104336fde07df093a4bd7765ac9ea0fa + remote: git://github.com/glacials/purecss-rails.git + revision: a4c7a6c05bf438465a0d02f75c5bd6063023ca52 specs: - active_model_serializers (0.10.0.rc1) - activemodel (>= 4.0) + purecss-rails (0.6.0) + railties (>= 3.2.6) GIT - remote: git://github.com/rails/arel.git - revision: 4767bb11c280f97262d221c47af8d39ab4fd583f + remote: git://github.com/rails/turbolinks.git + revision: 37a7c296232d20a61bd1946f600da7f2009189db specs: - arel (7.0.0.alpha) + turbolinks (3.0.0) + coffee-rails -GIT - remote: git://github.com/rails/rails.git - revision: ee372bdcebf9ce978152c353ecfd5608dc05038a +GEM + remote: https://rubygems.org/ specs: - actionmailer (5.0.0.alpha) - actionpack (= 5.0.0.alpha) - actionview (= 5.0.0.alpha) - activejob (= 5.0.0.alpha) + actioncable (5.0.0.1) + actionpack (= 5.0.0.1) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.0.1) + actionpack (= 5.0.0.1) + actionview (= 5.0.0.1) + activejob (= 5.0.0.1) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 1.0, >= 1.0.5) - actionpack (5.0.0.alpha) - actionview (= 5.0.0.alpha) - activesupport (= 5.0.0.alpha) - rack (~> 1.6) + rails-dom-testing (~> 2.0) + actionpack (5.0.0.1) + actionview (= 5.0.0.1) + activesupport (= 5.0.0.1) + rack (~> 2.0) 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) - actionview (5.0.0.alpha) - activesupport (= 5.0.0.alpha) + actionview (5.0.0.1) + activesupport (= 5.0.0.1) 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.2) - activejob (5.0.0.alpha) - activesupport (= 5.0.0.alpha) - globalid (>= 0.3.0) - activemodel (5.0.0.alpha) - activesupport (= 5.0.0.alpha) - builder (~> 3.1) - activerecord (5.0.0.alpha) - activemodel (= 5.0.0.alpha) - activesupport (= 5.0.0.alpha) - arel (= 7.0.0.alpha) - activesupport (5.0.0.alpha) + active_model_serializers (0.10.2) + actionpack (>= 4.1, < 6) + activemodel (>= 4.1, < 6) + jsonapi (~> 0.1.1.beta2) + railties (>= 4.1, < 6) + activejob (5.0.0.1) + activesupport (= 5.0.0.1) + globalid (>= 0.3.6) + activemodel (5.0.0.1) + activesupport (= 5.0.0.1) + activerecord (5.0.0.1) + activemodel (= 5.0.0.1) + activesupport (= 5.0.0.1) + arel (~> 7.0) + activesupport (5.0.0.1) + concurrent-ruby (~> 1.0, >= 1.0.2) i18n (~> 0.7) - json (~> 1.7, >= 1.7.7) minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - rails (5.0.0.alpha) - actionmailer (= 5.0.0.alpha) - actionpack (= 5.0.0.alpha) - actionview (= 5.0.0.alpha) - activejob (= 5.0.0.alpha) - activemodel (= 5.0.0.alpha) - activerecord (= 5.0.0.alpha) - activesupport (= 5.0.0.alpha) - bundler (>= 1.3.0, < 2.0) - railties (= 5.0.0.alpha) - sprockets-rails - railties (5.0.0.alpha) - actionpack (= 5.0.0.alpha) - activesupport (= 5.0.0.alpha) - method_source - rake (>= 0.8.7) - thor (>= 0.18.1, < 2.0) - -GIT - remote: git://github.com/rails/turbolinks.git - revision: 63c78377985245704f89cb847a1758c357731257 - specs: - turbolinks (3.0.0) - coffee-rails - -GEM - remote: https://rubygems.org/ - specs: - api-pagination (4.1.1) - ast (2.2.0) - autoprefixer-rails (6.3.4) + api-pagination (4.3.0) + arel (7.1.1) + ast (2.3.0) + autoprefixer-rails (6.4.0.2) execjs - awesome_print (1.6.1) - aws-sdk-core (2.5.4) + awesome_print (1.7.0) + aws-sdk-core (2.5.5) jmespath (~> 1.0) aws-sdk-rails (1.0.1) aws-sdk-resources (~> 2) railties (>= 3) - aws-sdk-resources (2.5.4) - aws-sdk-core (= 2.5.4) + aws-sdk-resources (2.5.5) + aws-sdk-core (= 2.5.5) babel_bridge (0.5.4) better_errors (2.1.1) coderay (>= 1.0.0) @@ -111,79 +91,82 @@ GEM rack (>= 0.9.0) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) - blockenspiel (0.4.5) - bootstrap-sass (3.3.6) + blockenspiel (0.5.0) + bootstrap-sass (3.3.7) autoprefixer-rails (>= 5.2.1) sass (>= 3.3.4) builder (3.2.2) c3-rails (0.4.11) callsite (0.0.11) - cancancan (1.13.1) + cancancan (1.15.0) choice (0.2.0) coderay (1.1.1) - coffee-rails (4.1.0) + coffee-rails (4.2.1) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.0) + railties (>= 4.0.0, < 5.2.x) coffee-script (2.4.1) coffee-script-source execjs - coffee-script-source (1.9.1.1) - concurrent-ruby (1.0.1) + coffee-script-source (1.10.0) + concurrent-ruby (1.0.2) d3-rails (3.5.17) railties (>= 3.1) - daemons (1.2.2) + daemons (1.2.4) dalli (2.7.6) debug_inspector (0.0.2) - delayed_job (4.0.6) - activesupport (>= 3.0, < 5.0) - delayed_job_active_record (4.0.3) - activerecord (>= 3.0, < 5.0) - delayed_job (>= 3.0, < 4.1) + delayed_job (4.1.2) + activesupport (>= 3.0, < 5.1) + delayed_job_active_record (4.1.1) + activerecord (>= 3.0, < 5.1) + delayed_job (>= 3.0, < 5) diff-lcs (1.2.5) docile (1.1.5) - domain_name (0.5.24) + domain_name (0.5.20160615) unf (>= 0.0.5, < 1.0.0) erubis (2.7.0) - eventmachine (1.0.8) - excon (0.45.3) - execjs (2.6.0) - factory_girl (4.5.0) + eventmachine (1.2.0.1) + excon (0.51.0) + execjs (2.7.0) + factory_girl (4.7.0) activesupport (>= 3.0.0) - factory_girl_rails (4.6.0) - factory_girl (~> 4.5.0) + factory_girl_rails (4.7.0) + factory_girl (~> 4.7.0) railties (>= 3.0.0) faraday (0.9.2) multipart-post (>= 1.2, < 3) - ffi (1.9.10) + ffi (1.9.14) figaro (1.1.1) thor (~> 0.14) flat-ui-rails (0.0.2) - foreman (0.78.0) + foreman (0.82.0) thor (~> 0.19.1) formatador (0.2.5) - globalid (0.3.5) + globalid (0.3.7) activesupport (>= 4.1.0) - gon (6.0.1) + gon (6.1.0) actionpack (>= 3.0) json multi_json request_store (>= 1.0) - guard (2.13.0) + guard (2.14.0) formatador (>= 0.2.4) - listen (>= 2.7, <= 4.0) + listen (>= 2.7, < 4.0) lumberjack (~> 1.0) nenv (~> 0.1) notiffany (~> 0.0) pry (>= 0.9.12) shellany (~> 0.0) thor (>= 0.18.1) - guard-rspec (1.2.2) - guard (>= 1.1) + guard-compat (1.2.1) + guard-rspec (4.7.3) + guard (~> 2.1) + guard-compat (~> 1.1) + rspec (>= 2.99.0, < 4.0) has_secure_token (1.0.0) activerecord (>= 3.0) - hashie (3.4.3) - heroics (0.0.14) - erubis (~> 2.7.0) + hashie (3.4.4) + heroics (0.0.17) + erubis (~> 2.0) excon moneta multi_json (>= 1.9.2) @@ -191,18 +174,15 @@ GEM htmlentities (4.3.4) http-cookie (1.0.2) domain_name (~> 0.5) - httparty (0.13.5) - json (~> 1.8) + httparty (0.14.0) multi_xml (>= 0.5.2) i18n (0.7.0) - jbuilder (2.2.16) - activesupport (>= 3.0.0, < 5) + jbuilder (2.6.0) + activesupport (>= 3.0.0, < 5.1) multi_json (~> 1.2) jmespath (1.3.1) - jquery-cookie-rails (1.3.1.1) - railties (>= 3.2.0, < 5.0) - jquery-rails (4.0.3) - rails-dom-testing (~> 1.0) + jquery-rails (4.2.1) + rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) jquery-turbolinks (2.1.0) @@ -210,25 +190,32 @@ GEM turbolinks jquery-ui-rails (5.0.5) railties (>= 3.2.16) + js_cookie_rails (2.1.2) + railties (>= 3.1) json (1.8.3) - jwt (1.5.1) - kgio (2.9.3) - listen (3.0.6) - rb-fsevent (>= 0.9.3) - rb-inotify (>= 0.9.7) + jsonapi (0.1.1.beta2) + json (~> 1.8) + jwt (1.5.4) + kgio (2.10.0) + listen (3.1.5) + rb-fsevent (~> 0.9, >= 0.9.4) + rb-inotify (~> 0.9, >= 0.9.7) + ruby_dep (~> 1.2) loofah (2.0.3) nokogiri (>= 1.5.9) lumberjack (1.0.10) - mail (2.6.3) - mime-types (>= 1.16, < 3) - meta_request (0.3.4) + mail (2.6.4) + mime-types (>= 1.16, < 4) + meta_request (0.4.0) callsite (~> 0.0, >= 0.0.11) rack-contrib (~> 1.1) - railties (>= 3.0.0, < 5.0.0) + railties (>= 3.0.0, < 5.1.0) method_source (0.8.2) - mime-types (2.6.1) - mini_portile2 (2.0.0) - minitest (5.8.4) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.0) momentjs-rails (2.11.1) railties (>= 3.1) moneta (0.8.0) @@ -237,59 +224,69 @@ GEM multi_xml (0.5.5) multipart-post (2.0.0) nenv (0.3.0) - netrc (0.10.3) - newrelic_rpm (3.15.0.314) + netrc (0.11.0) + newrelic_rpm (3.16.1.320) nilify_blanks (1.2.1) activerecord (>= 3.0.0) activesupport (>= 3.0.0) - nokogiri (1.6.7.2) - mini_portile2 (~> 2.0.0.rc2) - notiffany (0.0.8) + nio4r (1.2.1) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + notiffany (0.1.1) nenv (~> 0.1) shellany (~> 0.0) numeraljs-rails (1.4.5.0) numerizer (0.1.1) - oauth2 (1.1.0) + oauth2 (1.2.0) faraday (>= 0.8, < 0.10) - jwt (~> 1.0, < 1.5.2) + jwt (~> 1.0) multi_json (~> 1.3) multi_xml (~> 0.5) rack (>= 1.2, < 3) - omniauth (1.2.2) + omniauth (1.3.1) hashie (>= 1.2, < 4) - rack (~> 1.0) - omniauth-oauth2 (1.3.1) + rack (>= 1.0, < 3) + omniauth-oauth2 (1.4.0) oauth2 (~> 1.0) omniauth (~> 1.2) - omniauth-twitch (0.1.2) + omniauth-twitch (0.2.0) omniauth-oauth2 (~> 1.1) - parser (2.3.0.6) + parser (2.3.1.2) ast (~> 2.2) pg (0.18.4) - platform-api (0.2.0) - heroics (~> 0.0.10) + pkg-config (1.1.7) + platform-api (0.8.0) + heroics (~> 0.0.17) powerpack (0.1.1) - pry (0.10.3) + pry (0.10.4) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) pry-rails (0.3.4) pry (>= 0.9.10) - ptools (1.3.2) - purecss-rails (0.6.0) - railties (>= 3.2.6, < 5) - rack (1.6.4) + ptools (1.3.3) + rack (2.0.1) rack-contrib (1.2.0) rack (>= 0.9.1) rack-test (0.6.3) rack (>= 1.0) - rails-deprecated_sanitizer (1.0.3) - activesupport (>= 4.2.0.alpha) - rails-dom-testing (1.0.7) - activesupport (>= 4.2.0.beta, < 5.0) + rails (5.0.0.1) + actioncable (= 5.0.0.1) + actionmailer (= 5.0.0.1) + actionpack (= 5.0.0.1) + actionview (= 5.0.0.1) + activejob (= 5.0.0.1) + activemodel (= 5.0.0.1) + activerecord (= 5.0.0.1) + activesupport (= 5.0.0.1) + bundler (>= 1.3.0, < 2.0) + railties (= 5.0.0.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.1) + activesupport (>= 4.2.0, < 6.0) nokogiri (~> 1.6.0) - rails-deprecated_sanitizer (>= 1.0.1) - rails-erd (1.4.0) + rails-erd (1.5.0) activerecord (>= 3.2) activesupport (>= 3.2) choice (~> 0.2.0) @@ -299,99 +296,111 @@ GEM rails_12factor (0.0.3) rails_serve_static_assets rails_stdout_logging - rails_serve_static_assets (0.0.4) - rails_stdout_logging (0.0.3) + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) + railties (5.0.0.1) + actionpack (= 5.0.0.1) + activesupport (= 5.0.0.1) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) rainbow (2.1.0) - raindrops (0.13.0) - rake (11.1.2) + raindrops (0.17.0) + rake (11.2.2) rb-fsevent (0.9.7) rb-inotify (0.9.7) ffi (>= 0.5.0) - request_store (1.3.0) - rest-client (1.8.0) + request_store (1.3.1) + rest-client (2.0.0) http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 3.0) - netrc (~> 0.7) + mime-types (>= 1.16, < 4.0) + netrc (~> 0.8) rollbar (2.12.0) multi_json - rspec-core (3.5.0.beta3) - rspec-support (= 3.5.0.beta3) - rspec-expectations (3.5.0.beta3) + rspec (3.5.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-core (3.5.2) + rspec-support (~> 3.5.0) + rspec-expectations (3.5.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (= 3.5.0.beta3) - rspec-mocks (3.5.0.beta3) + rspec-support (~> 3.5.0) + rspec-mocks (3.5.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (= 3.5.0.beta3) - rspec-rails (3.5.0.beta3) + rspec-support (~> 3.5.0) + rspec-rails (3.5.1) actionpack (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (= 3.5.0.beta3) - rspec-expectations (= 3.5.0.beta3) - rspec-mocks (= 3.5.0.beta3) - rspec-support (= 3.5.0.beta3) - rspec-support (3.5.0.beta3) - rubocop (0.38.0) - parser (>= 2.3.0.6, < 3.0) + rspec-core (~> 3.5.0) + rspec-expectations (~> 3.5.0) + rspec-mocks (~> 3.5.0) + rspec-support (~> 3.5.0) + rspec-support (3.5.0) + rubocop (0.42.0) + parser (>= 2.3.1.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) unicode-display_width (~> 1.0, >= 1.0.1) ruby-graphviz (1.2.2) - ruby-progressbar (1.7.5) - sass (3.4.21) - sass-rails (5.0.4) - railties (>= 4.0.0, < 5.0) + ruby-progressbar (1.8.1) + ruby_dep (1.4.0) + sass (3.4.22) + sass-rails (5.0.6) + railties (>= 4.0.0, < 6) sass (~> 3.1) sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) shellany (0.0.1) - simplecov (0.11.2) + simplecov (0.12.0) docile (~> 1.1.0) - json (~> 1.8) + json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) - slim (3.0.6) - temple (~> 0.7.3) + slim (3.0.7) + temple (~> 0.7.6) tilt (>= 1.3.3, < 2.1) slop (3.6.0) spinjs-rails (1.4) rails (>= 3.1) - sprockets (3.5.2) + sprockets (3.7.0) concurrent-ruby (~> 1.0) rack (> 1, < 3) - sprockets-rails (3.0.4) + sprockets-rails (3.1.1) actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) - temple (0.7.6) - thin (1.6.3) + temple (0.7.7) + thin (1.7.0) daemons (~> 1.0, >= 1.0.9) - eventmachine (~> 1.0) - rack (~> 1.0) + eventmachine (~> 1.0, >= 1.0.4) + rack (>= 1, < 3) thor (0.19.1) thread_safe (0.3.5) - tilt (2.0.2) + tilt (2.0.5) tipsy-rails (1.0.5) railties (>= 3.0) sass-rails tzinfo (1.2.2) thread_safe (~> 0.1) - uglifier (2.7.2) - execjs (>= 0.3.0) - json (>= 1.8.0) - underscore-rails (1.8.2) + uglifier (3.0.1) + execjs (>= 0.3.0, < 3) + underscore-rails (1.8.3) unf (0.1.4) unf_ext - unf_ext (0.0.7.1) - unicode-display_width (1.0.2) - unicorn (4.9.0) + unf_ext (0.0.7.2) + unicode-display_width (1.1.0) + unicorn (5.1.0) kgio (~> 2.6) - rack raindrops (~> 0.7) - versionomy (0.4.4) - blockenspiel (>= 0.4.5) + versionomy (0.5.0) + blockenspiel (~> 0.5) + websocket-driver (0.6.4) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) will_paginate (3.1.0) xml-simple (1.1.5) @@ -399,9 +408,9 @@ PLATFORMS ruby DEPENDENCIES - active_model_serializers! + active_model_serializers api-pagination - arel! + arel authie! awesome_print aws-sdk-rails @@ -427,31 +436,31 @@ DEPENDENCIES htmlentities httparty jbuilder - jquery-cookie-rails jquery-rails jquery-turbolinks jquery-ui-rails + js_cookie_rails meta_request momentjs-rails moving_average newrelic_rpm nilify_blanks numeraljs-rails - omniauth (~> 1.2.2) - omniauth-oauth2 (~> 1.3.0) + omniauth + omniauth-oauth2 omniauth-twitch pg platform-api pry-rails ptools - purecss-rails - rails! + purecss-rails! + rails (~> 5) rails-erd rails_12factor rails_stdout_logging rest-client rollbar - rspec-rails (= 3.5.0.beta3) + rspec-rails rubocop sass-rails simplecov diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 048368ef..a07a1746 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,9 +12,9 @@ // //= require jquery //= require jquery.turbolinks -//= require jquery.cookie //= require jquery_ujs //= require jquery-ui/draggable +//= require js.cookie //= require bootstrap //= require numeral //= require spin diff --git a/app/assets/javascripts/darkmode.coffee b/app/assets/javascripts/darkmode.coffee index c8f80142..88f41a66 100644 --- a/app/assets/javascripts/darkmode.coffee +++ b/app/assets/javascripts/darkmode.coffee @@ -1,3 +1,6 @@ window.toggleDarkmode = -> - $.cookie "darkmode", (if $.cookie("darkmode") is "1" then "0" else "1") + if Cookies.get('darkmode') is '1' + Cookies.remove('darkmode') + else + Cookies.set('darkmode', '1') location.reload() diff --git a/app/controllers/api/v4/application_controller.rb b/app/controllers/api/v4/application_controller.rb index efdd04a3..77bca2d6 100644 --- a/app/controllers/api/v4/application_controller.rb +++ b/app/controllers/api/v4/application_controller.rb @@ -52,26 +52,26 @@ class Api::V4::ApplicationController < ActionController::Base end def set_category - @category = Category.find(params[:category_id] || params[:id]) + @category = Category.find(params[:category]) rescue ActiveRecord::RecordNotFound - render not_found(:category, params[:category_id] || params[:id]) + render not_found(:category, params[:category]) end def set_game - @game = Game.find_by!(shortname: params[:game_id] || params[:id]) + @game = Game.find_by!(shortname: params[:game]) rescue ActiveRecord::RecordNotFound - render not_found(:game, params[:game_id] || params[:id]) + render not_found(:game, params[:game]) end def set_runner - @runner = User.with_runs.find(params[:runner_id] || params[:id]) + @runner = User.with_runs.find(params[:runner]) rescue ActiveRecord::RecordNotFound - render not_found(:runner, params[:runner_id] || params[:id]) + render not_found(:runner, params[:runner]) end def set_run - @run = Run.find36(params[:run_id] || params[:id]) + @run = Run.find36(params[:run]) rescue ActiveRecord::RecordNotFound - render not_found(:run, params[:run_id] || params[:id]) + render not_found(:run, params[:run]) end end diff --git a/app/controllers/api/v4/converts_controller.rb b/app/controllers/api/v4/converts_controller.rb index 600fdeff..445a90e5 100644 --- a/app/controllers/api/v4/converts_controller.rb +++ b/app/controllers/api/v4/converts_controller.rb @@ -1,11 +1,10 @@ class Api::V4::ConvertsController < Api::V4::ApplicationController - before_action :check_parameters, only: [:create] def create run_file = RunFile.for_convert(params[:file]) - @run = Run.new(run_file: run_file, user: nil) + @run = Run.new(run_file: run_file) unless @run.parses?(fast: params[:historic] != "1", convert: true) render status: 400, json: { status: 400, @@ -47,7 +46,5 @@ class Api::V4::ConvertsController < Api::V4::ApplicationController status: 400, message: "Missing 'file' or 'format' parameter. Make sure to include both in your request." } - return end - end diff --git a/app/controllers/api/v4/games/categories/runs_controller.rb b/app/controllers/api/v4/games/categories/runs_controller.rb deleted file mode 100644 index 23cc5c87..00000000 --- a/app/controllers/api/v4/games/categories/runs_controller.rb +++ /dev/null @@ -1,37 +0,0 @@ -class Api::V4::Games::Categories::RunsController < Api::V4::ApplicationController - before_action :set_game, only: [:index] - before_action :set_category, only: [:index] - before_action :set_runs, only: [:index] - - def index - paginate json: @runs, each_serializer: Api::V4::RunSerializer - end - - def create - # TODO: Tokens, not cookies - run_file = RunFile.for_file(params.require(:file)) - @record = Run.new(run_file: run_file, user: current_user, image_url: params[:image_url]).tap do |run| - # TODO: Move this error handling into a before_action or a rescue - unless run.parses? - render status: 400, json: { - status: 400, - message: "Can't parse that file. We support #{Run.programs.to_sentence}." - } - return - end - run.save - end - head 201, location: api_v4_run_url(@record) - rescue ActionController::ParameterMissing - render status: 400, json: { - status: 400, - message: "No run file received. Make sure you're including a 'file' parameter in your request." - } - end - - private - - def set_runs - @runs = @category.runs.includes(:game, :category, :user) - end -end diff --git a/app/controllers/api/v4/games/categories_controller.rb b/app/controllers/api/v4/games/categories_controller.rb index 49da3c79..7520c399 100644 --- a/app/controllers/api/v4/games/categories_controller.rb +++ b/app/controllers/api/v4/games/categories_controller.rb @@ -9,12 +9,4 @@ class Api::V4::Games::CategoriesController < Api::V4::ApplicationController def show render json: @category, serializer: Api::V4::CategorySerializer end - - private - - def set_category - @category = @game.categories.find(params[:id]) - rescue ActiveRecord::RecordNotFound - render not_found(:category, params[:id]) - end end diff --git a/app/controllers/api/v4/runners/pbs_controller.rb b/app/controllers/api/v4/runners/pbs_controller.rb new file mode 100644 index 00000000..72637fcd --- /dev/null +++ b/app/controllers/api/v4/runners/pbs_controller.rb @@ -0,0 +1,14 @@ +class Api::V4::Runners::PBsController < Api::V4::ApplicationController + before_action :set_runner + before_action :set_pbs, only: [:index] + + def index + paginate json: @pbs, each_serializer: Api::V4::RunSerializer + end + + private + + def set_pbs + @pbs = @runner.pbs.includes(:game, :category) + end +end diff --git a/app/controllers/api/v4/users/runs_controller.rb b/app/controllers/api/v4/runners/runs_controller.rb similarity index 51% rename from app/controllers/api/v4/users/runs_controller.rb rename to app/controllers/api/v4/runners/runs_controller.rb index 08867388..76ce8fc1 100644 --- a/app/controllers/api/v4/users/runs_controller.rb +++ b/app/controllers/api/v4/runners/runs_controller.rb @@ -1,5 +1,5 @@ -class Api::V4::Users::RunsController < Api::V4::ApplicationController - before_action :set_user +class Api::V4::Runners::RunsController < Api::V4::ApplicationController + before_action :set_runner before_action :set_runs, only: [:index] def index @@ -9,6 +9,6 @@ class Api::V4::Users::RunsController < Api::V4::ApplicationController private def set_runs - @runs = @user.runs.includes(:game, :category) + @runs = @runner.runs.includes(:game, :category) end end diff --git a/app/controllers/api/v4/runners_controller.rb b/app/controllers/api/v4/runners_controller.rb index 2e300c8a..2b411e5e 100644 --- a/app/controllers/api/v4/runners_controller.rb +++ b/app/controllers/api/v4/runners_controller.rb @@ -18,13 +18,4 @@ class Api::V4::RunnersController < Api::V4::ApplicationController def runs end - - private - - def set_runner - @runner = User.with_runs.find_by!(name: params[:id]) - rescue ActiveRecord::RecordNotFound - render not_found(:runner, params[:id]) - end - end diff --git a/app/controllers/api/v4/runs/splits_controller.rb b/app/controllers/api/v4/runs/splits_controller.rb index 7549fd92..f22f198c 100644 --- a/app/controllers/api/v4/runs/splits_controller.rb +++ b/app/controllers/api/v4/runs/splits_controller.rb @@ -3,9 +3,9 @@ class Api::V4::Runs::SplitsController < Api::V4::ApplicationController def index if params[:historic] == '1' - render json: @run.parse(fast: false)[:splits], each_serializer: Api::V4::SplitWithHistorySerializer + render json: @run.parse(fast: false)[:splits] else - render json: @run.parse[:splits], each_serializer: Api::V4::SplitSerializer + render json: @run.parse[:splits] end end end diff --git a/app/controllers/api/v4/users/games/categories/pbs_controller.rb b/app/controllers/api/v4/users/games/categories/pbs_controller.rb deleted file mode 100644 index 2c3b4233..00000000 --- a/app/controllers/api/v4/users/games/categories/pbs_controller.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Api::V4::Users::Games::Categories::PbsController < Api::V4::ApplicationController - before_action :set_user, only: [:show] - before_action :set_game, only: [:show] - before_action :set_category, only: [:show] - before_action :set_pb, only: [:show] - - def show - render json: @pb, serializer: Api::V4::RunSerializer - end - - private - - def set_pb - unless @pb = @user.pb_for(@category) - render not_found(:run, :pb) - end - end -end diff --git a/app/controllers/api/v4/users/games/categories/predictions_controller.rb b/app/controllers/api/v4/users/games/categories/predictions_controller.rb deleted file mode 100644 index 3a24efdc..00000000 --- a/app/controllers/api/v4/users/games/categories/predictions_controller.rb +++ /dev/null @@ -1,45 +0,0 @@ -class Api::V4::Users::Games::Categories::PredictionsController < Api::V4::ApplicationController - before_action :set_user, only: [:show] - before_action :set_game, only: [:show] - before_action :set_category, only: [:show] - before_action :set_prediction, only: [:show] - - def show - most_recent_run = @user.runs.where(category: @category).order(:created_at).last - @prediction.merge!( - id: nil, - path: nil, - name: most_recent_run.name, - program: most_recent_run.program, - image_url: nil, - created_at: Time.now, - updated_at: Time.now, - user: Api::V4::UserSerializer.new(@user, root: false), - game: Api::V4::GameSerializer.new(@game, root: false), - category: Api::V4::CategorySerializer.new(@category, root: false), - time: 0 - ) - @prediction[:splits] = most_recent_run.splits.map do |split| - Run::Split.new( - best: split.best, - name: split.name, - finish_time: @prediction[:time] += (split.history + [split.duration]).reject { |duration| duration == 0 }.smma.round(6), - duration: (split.history + [split.duration]).reject { |duration| duration == 0 }.smma.round(6), - gold?: false, - skipped?: rand(0.99) < split.history.map { |time| time.nil? ? 1 : 0 }.smma - ) - end - render json: {prediction: @prediction} - rescue MovingAverage::Errors::InvalidTailError - render status: 404, json: {status: 404, message: "Not enough data on #{@user.name} to make a prediction."} - end - - private - - def set_prediction - unless @user.runs?(@category) - render not_found(:run, :prediction) - end - @prediction = {} - end -end diff --git a/app/controllers/api/v4/users/games/categories/runs_controller.rb b/app/controllers/api/v4/users/games/categories/runs_controller.rb deleted file mode 100644 index ef01cfd8..00000000 --- a/app/controllers/api/v4/users/games/categories/runs_controller.rb +++ /dev/null @@ -1,16 +0,0 @@ -class Api::V4::Users::Games::Categories::RunsController < Api::V4::ApplicationController - before_action :set_user, only: [:index] - before_action :set_game, only: [:index] - before_action :set_category, only: [:index] - before_action :set_runs, only: [:index] - - def index - paginate json: @runs, each_serializer: Api::V4::RunSerializer - end - - private - - def set_runs - @runs = @user.runs.where(category: @category) - end -end diff --git a/app/controllers/api/v4/users/pbs_controller.rb b/app/controllers/api/v4/users/pbs_controller.rb deleted file mode 100644 index 31429e26..00000000 --- a/app/controllers/api/v4/users/pbs_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -class Api::V4::Users::PbsController < Api::V4::ApplicationController - before_action :set_user - before_action :set_pbs, only: [:index] - - def index - paginate json: @pbs, each_serializer: Api::V4::RunSerializer - end - - private - - def set_user - @user = User.find_by(name: params[:user_id]) || User.find(params[:user_id]) - rescue ActiveRecord::RecordNotFound - render not_found(:user, params[:user_id]) - end - - def set_pbs - @pbs = @user.pbs.includes(:game, :category) - end -end diff --git a/app/controllers/api/v4/users_controller.rb b/app/controllers/api/v4/users_controller.rb deleted file mode 100644 index 4274bc58..00000000 --- a/app/controllers/api/v4/users_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Api::V4::UsersController < Api::V4::ApplicationController - before_action :set_user, only: [:show] - - def show - render json: @user, serializer: Api::V4::UserSerializer - end - - private - - def set_user - @user = User.find_by!(name: params[:id]) - rescue ActiveRecord::RecordNotFound - render not_found(:user, params[:id]) - end -end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/controllers/games/aliases_controller.rb b/app/controllers/games/aliases_controller.rb index 2b30b994..68cc91a8 100644 --- a/app/controllers/games/aliases_controller.rb +++ b/app/controllers/games/aliases_controller.rb @@ -41,7 +41,6 @@ class Games::AliasesController < ApplicationController def authorize if cannot?(:edit, @game) || cannot?(:edit, @game_to_merge) redirect_to game_path(@game), alert: "You don't have permission to do that." - return end end diff --git a/app/controllers/games/categories/leaderboards/sum_of_bests_controller.rb b/app/controllers/games/categories/leaderboards/sum_of_bests_controller.rb index 92d52fed..4fb3da3e 100644 --- a/app/controllers/games/categories/leaderboards/sum_of_bests_controller.rb +++ b/app/controllers/games/categories/leaderboards/sum_of_bests_controller.rb @@ -8,14 +8,20 @@ class Games::Categories::Leaderboards::SumOfBestsController < ApplicationControl private def set_game - @game = Game.find_by(shortname: params[:game_id]) || Game.find(params[:game_id]) - rescue ActiveRecord::RecordNotFound - render status: 404, file: "#{Rails.root}/public/404.html" + @game = Game.where(shortname: params[:game_id]).or(Game.where(id: params[:game_id])).first + + if @game.nil? + render status: 404, file: "#{Rails.root}/public/404.html" + end end def set_category - @category = @game.categories.find(params[:category_id]) - rescue ActiveRecord::RecordNotFound - render status: 404, file: "#{Rails.root}/public/404.html" + @category = @game.categories.where(shortname: params[:category_id]).or( + @game.categories.where(id: params[:category_id]) + ).first + + if @category.nil? + render status: 404, file: "#{Rails.root}/public/404.html" + end end end diff --git a/app/controllers/games/categories_controller.rb b/app/controllers/games/categories_controller.rb index 15a41e29..05dfb84e 100644 --- a/app/controllers/games/categories_controller.rb +++ b/app/controllers/games/categories_controller.rb @@ -8,13 +8,20 @@ class Games::CategoriesController < ApplicationController private def set_game - @game = Game.find_by(shortname: params[:game_id]) - redirect_to game_path(params[:game_id]) if @game.nil? + @game = Game.where(shortname: params[:game_id]).or(Game.where(id: params[:game_id])).first + + if @game.nil? + render status: 404, file: "#{Rails.root}/public/404.html" + end end def set_category - @category = @game.categories.find_by(shortname: params[:id]) || - @game.categories.find_by(id: params[:id]) - redirect_to game_path(params[:game_id]) if @category.nil? + @category = @game.categories.where(shortname: params[:category_id]).or( + @game.categories.where(id: params[:category_id]) + ).first + + if @category.nil? + render status: 404, file: "#{Rails.root}/public/404.html" + end end end diff --git a/app/controllers/runs/application_controller.rb b/app/controllers/runs/application_controller.rb index fa9be31f..b8dd4aee 100644 --- a/app/controllers/runs/application_controller.rb +++ b/app/controllers/runs/application_controller.rb @@ -8,5 +8,4 @@ class Runs::ApplicationController < ApplicationController rescue ActionController::UnknownFormat, ActiveRecord::RecordNotFound not_found end - end diff --git a/app/controllers/runs/stats_controller.rb b/app/controllers/runs/stats_controller.rb index 9b6baeb0..f4c22c27 100644 --- a/app/controllers/runs/stats_controller.rb +++ b/app/controllers/runs/stats_controller.rb @@ -12,6 +12,5 @@ class Runs::StatsController < Runs::ApplicationController program: @run.program, } gon.scale_to = @run.time - end end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 00000000..10a4cba8 --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + self.abstract_class = true +end diff --git a/app/models/category.rb b/app/models/category.rb index 4f967af7..4c7f8f6b 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -1,4 +1,4 @@ -class Category < ActiveRecord::Base +class Category < ApplicationRecord belongs_to :game has_many :runs has_many :rivalries, dependent: :destroy @@ -51,7 +51,7 @@ class Category < ActiveRecord::Base # merge_into! changes ownership of all of this category's runs and rivalries to the given category, then destroys this # category. def merge_into!(category) - ActiveRecord::Base.transaction do + ApplicationRecord.transaction do runs.update_all(category_id: category.id) rivalries.update_all(category_id: category.id) destroy diff --git a/app/models/concerns/twitch_user.rb b/app/models/concerns/twitch_user.rb index b35f76ff..0690bcca 100644 --- a/app/models/concerns/twitch_user.rb +++ b/app/models/concerns/twitch_user.rb @@ -11,18 +11,24 @@ module TwitchUser end end - def update_avatar! - body = Twitch::User.find(name).get + def twitch_sync! + body = Twitch::User.get(name) - avatar = JSON.parse(body)['logo'] - return if avatar.blank? + basic_info = JSON.parse(body) + + twitch_id = basic_info['_id'] + name = basic_info['name'] + avatar = basic_info['logo'] uri = URI.parse(avatar).tap do |uri| uri.scheme = 'https' end - return if avatar == uri.to_s - update(avatar: uri.to_s) + update( + twitch_id: twitch_id, + name: name, + avatar: uri.to_s + ) rescue RestClient::ResourceNotFound nil end diff --git a/app/models/game.rb b/app/models/game.rb index f746f8ee..05eed3b9 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -1,6 +1,6 @@ require 'speedrunslive' -class Game < ActiveRecord::Base +class Game < ApplicationRecord include SRLGame validates :name, presence: true @@ -22,13 +22,13 @@ class Game < ActiveRecord::Base def self.from_name(name) name = name.strip return nil if name.blank? - joins(:aliases).where(aliases: {name: name}).first + joins(:aliases).where(game_aliases: {name: name}).first end def self.from_name!(name) name = name.strip return nil if name.blank? - joins(:aliases).where(aliases: {name: name}).first_or_create(name: name) + joins(:aliases).where(game_aliases: {name: name}).first_or_create(name: name) end def to_param @@ -58,7 +58,7 @@ class Game < ActiveRecord::Base # merge_into! changes ownership of all of this game's categories and aliases to the given game, then destroys this # game. def merge_into!(game) - ActiveRecord::Base.transaction do + ApplicationRecord.transaction do aliases.update_all(game_id: game.id) categories.each do |category| diff --git a/app/models/game/alias.rb b/app/models/game/alias.rb index 7cb63a7a..62c3bacf 100644 --- a/app/models/game/alias.rb +++ b/app/models/game/alias.rb @@ -10,7 +10,7 @@ # # if you need to, which performs two queries. It is safe to expect that a Game#name will also be represented as a # Game::Alias#name. -class Game::Alias < ActiveRecord::Base +class Game::Alias < ApplicationRecord belongs_to :game, dependent: :destroy validates_uniqueness_of :name diff --git a/app/models/rivalry.rb b/app/models/rivalry.rb index ec578d43..fc82ae99 100644 --- a/app/models/rivalry.rb +++ b/app/models/rivalry.rb @@ -1,4 +1,4 @@ -class Rivalry < ActiveRecord::Base +class Rivalry < ApplicationRecord validates_uniqueness_of :category, scope: :from_user_id belongs_to :category diff --git a/app/models/run.rb b/app/models/run.rb index e3e71ba1..bfba4af7 100644 --- a/app/models/run.rb +++ b/app/models/run.rb @@ -1,6 +1,6 @@ Dir['./lib/parsers/*'].each { |file| require file } -class Run < ActiveRecord::Base +class Run < ApplicationRecord include PadawanRun include ForgetfulPersonsRun include SRDCRun @@ -78,10 +78,6 @@ class Run < ActiveRecord::Base user.present? && self.user == user end - def runners - [user] - end - def time_since_upload time_ago_in_words(created_at).sub('about ', '') end @@ -200,7 +196,11 @@ class Run < ActiveRecord::Base end def original_file - program.to_sym == :llanfair ? RunFile.pack_binary(file) : file + if program.to_sym == :llanfair && file.is_a?(Array) + RunFile.pack_binary(file) + else + file + end end def destroy_run_file_if_orphaned diff --git a/app/models/run_file.rb b/app/models/run_file.rb index 409d24ef..207a3026 100644 --- a/app/models/run_file.rb +++ b/app/models/run_file.rb @@ -1,4 +1,4 @@ -class RunFile < ActiveRecord::Base +class RunFile < ApplicationRecord has_many :runs, dependent: :restrict_with_exception, primary_key: :digest, foreign_key: :run_file_digest validates :digest, presence: true, uniqueness: true diff --git a/app/models/user.rb b/app/models/user.rb index 614cbe04..7a790338 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,4 @@ -class User < ActiveRecord::Base +class User < ApplicationRecord include AuthenticatingUser include RivalUser include TwitchUser @@ -24,6 +24,10 @@ class User < ActiveRecord::Base end def avatar + if read_attribute(:avatar).nil? + return nil + end + URI.parse(read_attribute(:avatar) || '').tap do |uri| uri.scheme = 'https' end.to_s diff --git a/app/serializers/api/v4/run_serializer.rb b/app/serializers/api/v4/run_serializer.rb index f6b810e0..c6032843 100644 --- a/app/serializers/api/v4/run_serializer.rb +++ b/app/serializers/api/v4/run_serializer.rb @@ -1,13 +1,19 @@ class Api::V4::RunSerializer < Api::V4::ApplicationSerializer + attributes :id, :srdc_id, :name, :time, :program, :attempts, :image_url, :created_at, :updated_at, :video_url + has_one :game, serializer: Api::V4::GameSerializer has_one :category, serializer: Api::V4::CategorySerializer has_many :runners, serializer: Api::V4::RunnerSerializer - attributes :id, :srdc_id, :name, :time, :program, :attempts, :image_url, :created_at, :updated_at, :video_url - - private - def id object.id36 end + + def runners + if object.user.nil? + [] + else + [object.user] + end + end end diff --git a/app/serializers/api/v4/split_serializer.rb b/app/serializers/api/v4/split_serializer.rb deleted file mode 100644 index f614a629..00000000 --- a/app/serializers/api/v4/split_serializer.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Api::V4::SplitSerializer < Api::V4::ApplicationSerializer - has_one :name, :duration, :best, :finish_time, :gold, :skipped -end diff --git a/app/serializers/api/v4/split_with_history_serializer.rb b/app/serializers/api/v4/split_with_history_serializer.rb deleted file mode 100644 index 3bfb9207..00000000 --- a/app/serializers/api/v4/split_with_history_serializer.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Api::V4::SplitWithHistorySerializer < Api::V4::SplitSerializer - attributes :history - - private - - def history - object.history || [] - end -end diff --git a/config/application.rb b/config/application.rb index 9ff9fb02..e9756505 100644 --- a/config/application.rb +++ b/config/application.rb @@ -13,6 +13,8 @@ module SplitsIO config.active_job.queue_adapter = :delayed_job config.assets.precompile += ['darkmode.css'] + + ActiveSupport.halt_callback_chains_on_return_false = false end end diff --git a/config/routes.rb b/config/routes.rb index 32936c91..1ab113ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -70,23 +70,33 @@ SplitsIO::Application.routes.draw do namespace :api do namespace :v4 do match '(/*a(/*b(/*c(/*d))))', via: [:options], to: 'application#options' - resources :categories, only: [:show] do - resources :runners, :runs, only: :index, module: :categories - end - resources :games, only: [:index, :show] do - resources :categories, :runners, :runs, only: :index, module: :games - end + get '/games', to: 'games#index' + get '/games/:game', to: 'games#show', as: 'game' - resources :runners, only: [:show] do - resources :categories, :games, :pbs, :predictions, :runs, only: :index, module: :runners - end + get '/games/:game/categories', to: 'games/categories#index' + get '/games/:game/runners', to: 'games/runners#index' + get '/games/:game/runs', to: 'games/runs#index' - resources :runs, only: [:create, :show, :update, :destroy] do - resources :splits, only: :index, module: :runs - end + get '/categories/:category', to: 'categories#show', as: 'category' + + get '/categories/:category/:runners', to: 'categories/runners#index' + + get '/runners/:runner', to: 'runners#show', as: 'runner' + + get '/runners/:runner/pbs', to: 'runners/pbs#index' + get '/runners/:runner/runs', to: 'runners/runs#index' + get '/runners/:runner/games', to: 'runners/games#index' + get '/runners/:runner/categories', to: 'runners/categories#index' + + post '/runs', to: 'runs#create' + get '/runs/:run', to: 'runs#show', as: 'run' + put '/runs/:run', to: 'runs#update' + delete '/runs/:run', to: 'runs#destroy' + + get '/runs/:run/splits', to: 'runs/splits#index' - post '/convert', to: 'converts#create', as: :api_convert + post '/convert', to: 'converts#create' end namespace :v3 do diff --git a/config/unicorn.rb b/config/unicorn.rb index f6e59b8f..2e4cf71d 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -8,8 +8,8 @@ before_fork do |server, worker| Process.kill 'QUIT', Process.pid end - defined?(ActiveRecord::Base) and - ActiveRecord::Base.connection.disconnect! + defined?(ApplicationRecord) and + ApplicationRecord.connection.disconnect! end after_fork do |server, worker| @@ -17,6 +17,6 @@ after_fork do |server, worker| puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' end - defined?(ActiveRecord::Base) and - ActiveRecord::Base.establish_connection + defined?(ApplicationRecord) and + ApplicationRecord.establish_connection end diff --git a/db/schema.rb b/db/schema.rb index e5aadbb0..ec3e80cf 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. diff --git a/lib/parsers/llanfair.rb b/lib/parsers/llanfair.rb index 14570f98..27ad89ea 100644 --- a/lib/parsers/llanfair.rb +++ b/lib/parsers/llanfair.rb @@ -17,9 +17,15 @@ module Llanfair class Parser < BabelBridge::Parser def parse(character_array, options = {}) - # Convert the array of character from string form to an actual array + # Convert the array of characters from string form to an actual array # Then pack the characters back to the original bytes - file = RunFile.pack_binary(character_array) + # We don't need to do this if the file is from S3; it's already binary + if character_array.is_a? Array + file = RunFile.pack_binary(character_array) + else + file = character_array + end + run = {} run[:time] = 0 # A port of Nitrofski's import llanfair files function for wsplit diff --git a/lib/twitch.rb b/lib/twitch.rb index af23b9bc..3fefde07 100644 --- a/lib/twitch.rb +++ b/lib/twitch.rb @@ -6,12 +6,12 @@ class Twitch module User def self.login_from_url(twitch_url) - %r{^https?://(?:www\.)?twitch\.tv/([^/]+)(?:.*)$}.match(twitch_url)[1] + %r{^https?://(?:www\.)?twitch\.tv/([^/]+)(?:.*)$}.match(twitch_url)[1].downcase end class << self def get(login) - route(login).get + route(login.downcase).get end def route(login) -- knotmirror 0.0.1