From 322001f8d34fb1d653e83e5328d5ab0d6aa4b721 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Sun, 15 Mar 2020 20:31:46 +0200 Subject: [PATCH] Rails 4 fixes Update to ruby 2.3.8 Update gems Fix tests --- DEVELOPMENT.md | 8 ++ Dockerfile.dev | 12 +-- Gemfile | 64 +++++++++------ Gemfile.lock | 81 +++++++------------ app/models/group.rb | 2 +- app/models/user.rb | 4 +- config/application.rb | 1 + config/environments/development.rb | 4 +- config/routes.rb | 6 +- lib/plugins/acts_as_readable/README | 47 ----------- .../acts_as_readable_migration_generator.rb | 11 --- .../templates/migration.rb | 14 ---- lib/plugins/acts_as_readable/init.rb | 3 - .../acts_as_readable/lib/acts_as_readable.rb | 43 ---------- lib/plugins/acts_as_readable/lib/reading.rb | 7 -- .../lib/user_with_readings.rb | 3 - 16 files changed, 94 insertions(+), 216 deletions(-) create mode 100644 DEVELOPMENT.md delete mode 100644 lib/plugins/acts_as_readable/README delete mode 100644 lib/plugins/acts_as_readable/generators/acts_as_readable_migration/acts_as_readable_migration_generator.rb delete mode 100644 lib/plugins/acts_as_readable/generators/acts_as_readable_migration/templates/migration.rb delete mode 100644 lib/plugins/acts_as_readable/init.rb delete mode 100644 lib/plugins/acts_as_readable/lib/acts_as_readable.rb delete mode 100644 lib/plugins/acts_as_readable/lib/reading.rb delete mode 100644 lib/plugins/acts_as_readable/lib/user_with_readings.rb diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..212a40c --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,8 @@ +# Development + +Currently buggy. + +# Handy commands + +`docker-compose -f docker-compose.dev.yml exec -u web web /bin/bash` +`docker-compose -f docker-compose.dev.yml restart web` \ No newline at end of file diff --git a/Dockerfile.dev b/Dockerfile.dev index c216b6b..64f720e 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,4 @@ -FROM ruby:2.2.10 +FROM ruby:2.3.8 ENV RAILS_ENV development @@ -6,20 +6,20 @@ ENV RAILS_ENV development RUN adduser web --home /home/web --shell /bin/bash --disabled-password --gecos "" RUN apt-get update && apt-get -y upgrade \ - && apt-get -y install mysql-client libmysqlclient-dev memcached nodejs firefox-esr \ - && service memcached start + && apt-get -y install libmariadb-dev libmariadb-dev-compat nodejs \ + zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev \ + libxslt1-dev imagemagick libmagickwand-dev # Separate Gemfile ADD so that `bundle install` can be cached more effectively - ADD Gemfile Gemfile.lock /var/www/ RUN mkdir -p /var/bundle && chown -R web:web /var/bundle && chown -R web:web /var/www -RUN su -c "bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4" -s /bin/bash -l web WORKDIR /var/www USER web -RUN bundle config github.https true; cd /var/www && bundle install --path /var/bundle --jobs 4 +RUN bundle config github.https true && \ +bundle install --path /var/bundle --jobs 8 USER root CMD ["/var/www/script/entry.sh"] diff --git a/Gemfile b/Gemfile index 790dfa1..84bad64 100644 --- a/Gemfile +++ b/Gemfile @@ -1,34 +1,47 @@ source 'http://rubygems.org' -ruby '2.2.10' +ruby '2.3.8' -gem 'dotenv-rails' gem 'rails', '~> 4.1.16' -gem 'mysql2', '~> 0.3.18' -gem 'dalli', '~> 2.7.0' -gem 'puma', '~> 2.11.1' -gem 'i18n-js' -gem 'exceptional', '~> 2.0.33' -gem 'oj', '~> 2.5.5' +# Dotenv +gem 'dotenv-rails' + +# DB +# Fixme: using this bc puma startup problem +gem 'mysql2', '0.3.18' +gem 'dalli', '~> 2.7.0' +gem 'active_record_union' + +# Web server +gem 'puma' gem 'faraday', '~> 0.9.0' + +# Model plugins +# FIXME: using this b/c ruby 2.4 not supported +gem 'unread', '0.10.1' + +# View helper gems gem 'nokogiri', '~> 1.9.0' gem 'bbcoder', '~> 1.0.1' gem 'sanitize', '~> 2.1.0' gem 'carrierwave', '~> 0.10.0' gem 'bluecloth', '~> 2.2.0' -gem 'newrelic_rpm', '~> 3.13.0.299' +gem 'rmagick' gem 'will_paginate', '~> 3.0.5' gem 'dynamic_form', '~> 1.1.4' +gem 'active_link_to', '~> 1.0.2' gem 'country_select', require: 'country_select_without_sort_alphabetical' gem 'i18n_country_select' -gem 'active_link_to', '~> 1.0.2' -gem 'rmagick', '~> 2.13.4', require: false -gem 'test-unit', '~> 3.1.3' +gem 'public_suffix', '~> 3.1.1' + +# External APIs gem 'google-api-client', '~> 0.10.3' gem 'steam-condenser', github: 'koraktor/steam-condenser-ruby' -gem 'public_suffix', '~> 3.1.1' -gem 'active_record_union' + +# Legacy feature shims +gem 'protected_attributes', '~> 1.1.3' +gem 'rails_autolink', '~> 1.1.5' # Dependency version fix gem 'signet', '0.11.0' @@ -36,34 +49,32 @@ gem 'signet', '0.11.0' # Please install nodejs locally. #gem 'therubyracer', '~> 0.12.1' if RUBY_PLATFORM == 'x86_64-linux' +# Move these to assets group gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails', '~> 2.0.2' gem 'tinymce-rails', '~> 3.5.9' gem 'sass-rails', '~> 5.0.3' - gem 'font-awesome-sass', '~> 4.1.0.0' gem 'bourbon', '~> 3.1.8' gem 'neat', '~> 1.6.0' gem 'haml', '~> 4.0.5' -gem 'rails_autolink', '~> 1.1.5' gem 'uglifier', '~> 2.5.0' +gem 'i18n-js' -# Legacy feature shims -gem 'protected_attributes', '~> 1.1.3' +group :production do + gem 'newrelic_rpm', '~> 3.13.0.299' +end group :development do - gem 'capistrano', '~> 3.1.0' - gem 'capistrano-rbenv', '~> 2.0.2' - gem 'capistrano-bundler', '~> 1.1.2' - gem 'capistrano-rails', '~> 1.1' - gem 'better_errors', '~> 1.1.0' - gem 'binding_of_caller', '~> 0.7.2' - gem 'annotate', '~> 2.6.2' - gem 'quiet_assets', '~> 1.0.2' + gem 'better_errors' + gem 'binding_of_caller' + gem 'annotate' + gem 'quiet_assets' gem 'web-console' end group :test do +# gem 'spring' gem 'simplecov', '~> 0.7.1', require: false gem 'codeclimate-test-reporter', '~> 0.3.0', require: nil gem 'database_cleaner', '~> 1.2.0' @@ -74,6 +85,7 @@ group :test do gem 'factory_bot_rails' gem 'timecop', '~> 0.7.1' gem 'rspec' + gem 'test-unit', '~> 3.1.3' end group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 1dffafb..3fe14f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,15 +42,16 @@ GEM tzinfo (~> 1.1) addressable (2.7.0) public_suffix (>= 2.0.2, < 5.0) - annotate (2.6.10) - activerecord (>= 3.2, <= 4.3) - rake (~> 10.4) + annotate (3.1.0) + activerecord (>= 3.2, < 7.0) + rake (>= 10.4, < 14.0) arel (5.0.1.20140414130214) bbcoder (1.0.1) - better_errors (1.1.0) + better_errors (2.6.0) coderay (>= 1.0.0) - erubis (>= 2.6.6) - binding_of_caller (0.7.3) + erubi (>= 1.0.0) + rack (>= 0.9.0) + binding_of_caller (0.8.0) debug_inspector (>= 0.0.1) bluecloth (2.2.0) bourbon (3.1.8) @@ -60,19 +61,6 @@ GEM byebug (2.7.0) columnize (~> 0.3) debugger-linecache (~> 1.2) - capistrano (3.1.0) - i18n - rake (>= 10.0.0) - sshkit (~> 1.3) - capistrano-bundler (1.1.4) - capistrano (~> 3.1) - sshkit (~> 1.2) - capistrano-rails (1.4.0) - capistrano (~> 3.1) - capistrano-bundler (~> 1.1) - capistrano-rbenv (2.0.4) - capistrano (~> 3.1) - sshkit (~> 1.3) capybara (2.4.4) mime-types (>= 1.16) nokogiri (>= 1.3.3) @@ -113,13 +101,13 @@ GEM declarative (0.0.10) declarative-option (0.1.0) diff-lcs (1.3) - dotenv (0.10.0) - dotenv-rails (0.10.0) - dotenv (= 0.10.0) + dotenv (2.7.5) + dotenv-rails (2.7.5) + dotenv (= 2.7.5) + railties (>= 3.2, < 6.1) dynamic_form (1.1.4) + erubi (1.9.0) erubis (2.7.0) - exceptional (2.0.33) - rack execjs (2.7.0) factory_bot (4.11.1) activesupport (>= 3.0.0) @@ -186,17 +174,14 @@ GEM multi_json (1.14.1) multi_xml (0.6.0) multipart-post (2.1.1) - mysql2 (0.3.21) + mysql2 (0.3.18) neat (1.6.0) bourbon (>= 3.1) sass (>= 3.3) - net-scp (2.0.0) - net-ssh (>= 2.6.5, < 6.0.0) - net-ssh (5.2.0) newrelic_rpm (3.13.0.299) + nio4r (2.5.2) nokogiri (1.9.1) mini_portile2 (~> 2.4.0) - oj (2.5.5) os (0.9.6) poltergeist (1.6.0) capybara (~> 2.1) @@ -213,9 +198,9 @@ GEM byebug (~> 2.7) pry (~> 0.10) public_suffix (3.1.1) - puma (2.11.3) - rack (>= 1.1, < 2.0) - quiet_assets (1.0.3) + puma (4.3.3) + nio4r (~> 2.0) + quiet_assets (1.1.0) railties (>= 3.1, < 5.0) rack (1.5.5) rack-test (0.6.3) @@ -237,7 +222,7 @@ GEM activesupport (= 4.1.16) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.5.0) + rake (13.0.1) rb-fsevent (0.10.3) rb-inotify (0.10.1) ffi (~> 1.0) @@ -246,7 +231,7 @@ GEM declarative-option (< 0.2.0) uber (< 0.2.0) retriable (3.1.2) - rmagick (2.13.4) + rmagick (4.0.0) rspec (3.3.0) rspec-core (~> 3.3.0) rspec-expectations (~> 3.3.0) @@ -306,9 +291,6 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - sshkit (1.21.0) - net-scp (>= 1.1.2) - net-ssh (>= 2.8.0) test-unit (3.1.9) power_assert thor (0.20.3) @@ -324,6 +306,8 @@ GEM execjs (>= 0.3.0) json (>= 1.8.0) unicode_utils (1.4.0) + unread (0.10.1) + activerecord (>= 3) web-console (2.3.0) activemodel (>= 4.0) binding_of_caller (>= 0.7.2) @@ -343,16 +327,12 @@ PLATFORMS DEPENDENCIES active_link_to (~> 1.0.2) active_record_union - annotate (~> 2.6.2) + annotate bbcoder (~> 1.0.1) - better_errors (~> 1.1.0) - binding_of_caller (~> 0.7.2) + better_errors + binding_of_caller bluecloth (~> 2.2.0) bourbon (~> 3.1.8) - capistrano (~> 3.1.0) - capistrano-bundler (~> 1.1.2) - capistrano-rails (~> 1.1) - capistrano-rbenv (~> 2.0.2) capybara (~> 2.4.4) carrierwave (~> 0.10.0) codeclimate-test-reporter (~> 0.3.0) @@ -362,7 +342,6 @@ DEPENDENCIES database_cleaner (~> 1.2.0) dotenv-rails dynamic_form (~> 1.1.4) - exceptional (~> 2.0.33) factory_bot_rails faraday (~> 0.9.0) font-awesome-sass (~> 4.1.0.0) @@ -371,20 +350,19 @@ DEPENDENCIES i18n-js i18n_country_select jquery-rails (~> 2.0.2) - mysql2 (~> 0.3.18) + mysql2 (= 0.3.18) neat (~> 1.6.0) newrelic_rpm (~> 3.13.0.299) nokogiri (~> 1.9.0) - oj (~> 2.5.5) poltergeist (~> 1.6.0) protected_attributes (~> 1.1.3) pry-byebug (~> 1.3.2) public_suffix (~> 3.1.1) - puma (~> 2.11.1) - quiet_assets (~> 1.0.2) + puma + quiet_assets rails (~> 4.1.16) rails_autolink (~> 1.1.5) - rmagick (~> 2.13.4) + rmagick rspec rspec-rails (~> 3.3.3) sanitize (~> 2.1.0) @@ -397,11 +375,12 @@ DEPENDENCIES timecop (~> 0.7.1) tinymce-rails (~> 3.5.9) uglifier (~> 2.5.0) + unread (= 0.10.1) web-console will_paginate (~> 3.0.5) RUBY VERSION - ruby 2.2.10p489 + ruby 2.3.8p459 BUNDLED WITH 1.17.3 diff --git a/app/models/group.rb b/app/models/group.rb index 2087a89..8e9c78a 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -63,7 +63,7 @@ class Group < ActiveRecord::Base def self.referees referees = [] - referee_group = where(id: REFEREES).firsto + referee_group = where(id: REFEREES).first return referees unless referee_group (referee_group.groupers).each do |g| diff --git a/app/models/user.rb b/app/models/user.rb index f2269f4..4ecc4aa 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -95,7 +95,9 @@ class User < ActiveRecord::Base joins("LEFT JOIN bans ON bans.user_id = users.id AND expiry > UTC_TIMESTAMP()") .conditions("bans.id IS NOT NULL") } scope :idle, -> { - joins("lastvisit < ?", 30.minutes.ago.utc) } + where("lastvisit < ?", 30.minutes.ago.utc) } + scope :lately, -> { + where("lastvisit > ?", 30.days.ago.utc) } validates_uniqueness_of :username, :email, :steamid validates_length_of :firstname, :in => 1..15, :allow_blank => true diff --git a/config/application.rb b/config/application.rb index 1ce42b6..c3ee281 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,4 +1,5 @@ require File.expand_path('../boot', __FILE__) + require 'rails/all' Bundler.require(*Rails.groups(assets: %w(development test))) diff --git a/config/environments/development.rb b/config/environments/development.rb index 03042d9..493594f 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -35,8 +35,10 @@ Ensl::Application.configure do # config.threadsafe! config.eager_load = false - config.web_console.permissions = '172.18.0.0/16' + config.web_console.whitelisted_ips = '172.18.0.0/16' config.web_console.whiny_requests = true config.eager_load = false + + config.assets.debug = true end diff --git a/config/routes.rb b/config/routes.rb index 8d98791..3285688 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,8 @@ Ensl::Application.routes.draw do - %w(403 404 422 500).each do |code| - get code, to: "errors#show", code: code + if not Rails.env.development? + %w(403 404 422 500).each do |code| + get code, to: "errors#show", code: code + end end namespace :api do diff --git a/lib/plugins/acts_as_readable/README b/lib/plugins/acts_as_readable/README deleted file mode 100644 index 007bcc8..0000000 --- a/lib/plugins/acts_as_readable/README +++ /dev/null @@ -1,47 +0,0 @@ -ActsAsReadable -============== - -ActsAsReadable allows you to create a generic relationship of items which can -be marked as 'read' by users. This is useful for forums or any other kind of -situation where you might need to know whether or not a user has seen a particular -model. - -Installation -============ - -To install the plugin just install from the SVN: - -script/plugin install http://svn.intridea.com/svn/public/acts_as_readable - -You will need the readings table to use this plugin. A generator has been included, -simply type - -script/generate acts_as_readable_migration - -to get the standard migration created for you. - -Example -======= - -class Post < ActiveRecord::Base - acts_as_readable -end - -bob = User.find_by_name("bob") - -bob.readings # => [] - -Post.find_unread_by(bob) # => [,,...] -Post.find_read_by(bob) # => [] - -Post.find(1).read_by?(bob) # => false -Post.find(1).read_by!(bob) # => -Post.find(1).read_by?(bob) # => true -Post.find(1).users_who_read # => [] - -Post.find_unread_by(bob) # => [,...] -Post.find_read_by(bob) # => [] - -bob.readings # => [] - -Copyright (c) 2008 Michael Bleigh and Intridea, Inc. released under the MIT license diff --git a/lib/plugins/acts_as_readable/generators/acts_as_readable_migration/acts_as_readable_migration_generator.rb b/lib/plugins/acts_as_readable/generators/acts_as_readable_migration/acts_as_readable_migration_generator.rb deleted file mode 100644 index 6cdf02c..0000000 --- a/lib/plugins/acts_as_readable/generators/acts_as_readable_migration/acts_as_readable_migration_generator.rb +++ /dev/null @@ -1,11 +0,0 @@ -class ActsAsReadableMigrationGenerator < Rails::Generator::Base - def manifest - record do |m| - m.migration_template 'migration.rb', 'db/migrate' - end - end - - def file_name - "acts_as_readable_migration" - end -end diff --git a/lib/plugins/acts_as_readable/generators/acts_as_readable_migration/templates/migration.rb b/lib/plugins/acts_as_readable/generators/acts_as_readable_migration/templates/migration.rb deleted file mode 100644 index dff5ae6..0000000 --- a/lib/plugins/acts_as_readable/generators/acts_as_readable_migration/templates/migration.rb +++ /dev/null @@ -1,14 +0,0 @@ -class ActsAsReadableMigration < ActiveRecord::Migration - def self.up - create_table :readings do |t| - t.string :readable_type - t.integer :readable_id - t.integer :user_id - t.timestamps - end - end - - def self.down - drop_table :readings - end -end diff --git a/lib/plugins/acts_as_readable/init.rb b/lib/plugins/acts_as_readable/init.rb deleted file mode 100644 index 1381afe..0000000 --- a/lib/plugins/acts_as_readable/init.rb +++ /dev/null @@ -1,3 +0,0 @@ -require 'acts_as_readable' - -ActiveRecord::Base.send :include, ActiveRecord::Acts::Readable diff --git a/lib/plugins/acts_as_readable/lib/acts_as_readable.rb b/lib/plugins/acts_as_readable/lib/acts_as_readable.rb deleted file mode 100644 index 584c1a9..0000000 --- a/lib/plugins/acts_as_readable/lib/acts_as_readable.rb +++ /dev/null @@ -1,43 +0,0 @@ -module ActiveRecord - module Acts - module Readable - def self.included(base) - base.extend ClassMethods - end - - module ClassMethods - def acts_as_readable - has_many :readings, :as => :readable - has_many :users_who_read, :through => :readings, :source => :user - - include ActiveRecord::Acts::Readable::InstanceMethods - extend ActiveRecord::Acts::Readable::SingletonMethods - end - end - - module SingletonMethods - def find_unread_by(user) - find(:all) - find_read_by(user) - end - - def find_read_by(user) - find(:all, :conditions => ["readings.readable_id = #{table_name}.id AND readings.user_id=?", user.id], :include => :readings) - end - end - - module InstanceMethods - def read_by!(user) - readings << Reading.new(:user_id => user.id) - end - - def unread_by!(user) - readings.find(:first, :conditions => ["user_id = ?",user.id]) - end - - def read_by?(user) - !!users_who_read.find(:first, :conditions => ["user_id = ?",user.id]) - end - end - end - end -end diff --git a/lib/plugins/acts_as_readable/lib/reading.rb b/lib/plugins/acts_as_readable/lib/reading.rb deleted file mode 100644 index e589c2c..0000000 --- a/lib/plugins/acts_as_readable/lib/reading.rb +++ /dev/null @@ -1,7 +0,0 @@ -class Reading < ActiveRecord::Base - belongs_to :user - belongs_to :readable, :polymorphic => true - - validates_presence_of :user_id, :readable_id, :readable_type - validates_uniqueness_of :user_id, :scope => [:readable_id, :readable_type] -end \ No newline at end of file diff --git a/lib/plugins/acts_as_readable/lib/user_with_readings.rb b/lib/plugins/acts_as_readable/lib/user_with_readings.rb deleted file mode 100644 index 32dc255..0000000 --- a/lib/plugins/acts_as_readable/lib/user_with_readings.rb +++ /dev/null @@ -1,3 +0,0 @@ -User.class_eval do - has_many :readings -end \ No newline at end of file