diff --git a/.github/workflows/rails.yml b/.github/workflows/rails.yml index a6703503f..35fe66957 100644 --- a/.github/workflows/rails.yml +++ b/.github/workflows/rails.yml @@ -1,14 +1,22 @@ name: Rails -on: push +on: + - push + - workflow_dispatch jobs: verify: name: Build runs-on: ubuntu-latest + env: + BUNDLE_PATH: vendor/bundle + BUNDLE_WITHOUT: development + SECRET_KEY_BASE: ad4d97aef89588c346638cfe689f667f06bc29d2c40724107558e5d4defe723e42cfb294cdb25d7e3241195cfb7cc952e8a2c1680460bea4904bd79d21784307 + STEAM_API_KEY: abcd1234 + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} services: postgres: - image: postgres:9.5 + image: postgres:16.2 env: POSTGRES_USER: citadel POSTGRES_PASSWORD: citadel @@ -16,40 +24,23 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Install ruby - uses: actions/setup-ruby@v1 - with: - ruby-version: 2.5.x - - name: Setup Cache - uses: actions/cache@v2 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems- - name: Install dependencies run: | - sudo apt-get -yqq install libpq-dev build-essential libcurl4-openssl-dev - gem install bundler - bundle config path vendor/bundle - bundle config set --local without 'development' - bundle install --jobs 4 --retry 3 + sudo apt-get -yqq install libpq-dev libyaml-dev build-essential libcurl4-openssl-dev + - name: Install ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1.6 + bundler-cache: true - name: Setup database env: RAILS_ENV: test PGHOST: localhost run: | cp config/database.yml.github config/database.yml - cp config/secrets.local.yml.example secrets.local.yml - rake "parallel:setup[2]" + bundle exec rake "parallel:setup" - name: Run tests env: RAILS_ENV: test PGHOST: localhost - run: rake test - - name: Upload coverage - env: - RAILS_ENV: test - PGHOST: localhost - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: rake codecov:upload + run: bundle exec rake test diff --git a/.gitignore b/.gitignore index 73d6648dd..dc771e3f4 100644 --- a/.gitignore +++ b/.gitignore @@ -55,10 +55,6 @@ capybara-*.html rerun.txt pickle-email-*.html -# TODO Comment out these rules if you are OK with secrets being uploaded to the repo -config/initializers/secret_token.rb -config/secrets.local.yml - ## Environment normalization: /.bundle /vendor/bundle @@ -77,6 +73,16 @@ bower.json # Ignore pow environment settings .powenv +# Ignore rubocop cache +.cache + +# Ignore node stuff +.npm + # CarrierWave public/uploads spec/carrierwave + +# Ignore credentials +/config/master.key +/config/credentials.yml.enc diff --git a/.rubocop.yml b/.rubocop.yml index b87e75704..cc3c4a45f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,12 @@ require: rubocop-rails Rails: Enabled: true +Rails/ActionOrder: + Enabled: false +Rails/I18nLocaleTexts: + Enabled: false +Rails/UniqueValidationWithoutIndex: + Enabled: false Rails/ApplicationRecord: Exclude: - 'lib/**/*' @@ -45,6 +51,8 @@ Style/FormatStringToken: EnforcedStyle: template Style/StringConcatenation: Enabled: false +Style/NegatedIfElseCondition: + Enabled: false Style/MixinUsage: Exclude: - 'bin/setup' @@ -56,6 +64,8 @@ Naming/MethodParameterName: MinNameLength: 2 AllowedNames: - _ +Naming/VariableNumber: + Enabled: false # 'old' style Style/EmptyMethod: diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..ef538c281 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.1.2 diff --git a/Gemfile b/Gemfile index 939fadc3b..eb6946c8b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,8 @@ source 'https://rubygems.org' -gem 'rails', '~> 5.2.1' +gem 'rails', '~> 7.1.0' gem 'rake', '~> 12.0' +gem 'sprockets-rails' # Use postgres gem 'pg', '~> 1.0' # Fast loading @@ -10,11 +11,11 @@ gem 'pg', '~> 1.0' gem 'active_record_union', '~> 1.3' gem 'ancestry' # SASS for stylesheets -gem 'sass-rails', '~> 5.0' +gem 'sass-rails', '~> 6' # Compress JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views -gem 'coffee-rails', '~> 4.2.0' +gem 'coffee-rails', '~> 5' # Easy styling gem 'bootstrap', '~> 4.5.0' # Easy bootstrap forms @@ -50,10 +51,12 @@ gem 'active_model_serializers', '~> 0.10.0' gem 'counter_culture', '~> 2.0' # Tournament systems gem 'tournament-system', '~> 2.0' +# Backwards compatibility with ruby 2 +gem 'scanf' group :test do # Use rspec for tests - gem 'rspec-rails', '~> 3.8' + gem 'rspec-rails', '~> 6' # Parallelize tests gem 'parallel_tests' @@ -68,7 +71,7 @@ group :test do gem 'database_cleaner' # Easy database manipulation - gem 'factory_bot_rails', '~> 4' + gem 'factory_bot_rails', '~> 6' # Web feature testing gem 'capybara' @@ -76,9 +79,9 @@ group :test do # Keep codebase clean gem 'haml_lint', require: false gem 'rails_best_practices', require: false - gem 'reek', '~> 5', require: false - gem 'rubocop', '~> 0.58', require: false - gem 'rubocop-rails', '~> 2.2.1', require: false + gem 'reek', '~> 6', require: false + gem 'rubocop', '~> 1.64.1', require: false + gem 'rubocop-rails', '~> 2.25.0', require: false gem 'codecov', require: false end diff --git a/Gemfile.lock b/Gemfile.lock index b15b7d7a4..0671f7b76 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,67 +1,101 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.2.7.1) - actionpack (= 5.2.7.1) + actioncable (7.1.3.3) + actionpack (= 7.1.3.3) + activesupport (= 7.1.3.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.7.1) - actionpack (= 5.2.7.1) - actionview (= 5.2.7.1) - activejob (= 5.2.7.1) + zeitwerk (~> 2.6) + actionmailbox (7.1.3.3) + actionpack (= 7.1.3.3) + activejob (= 7.1.3.3) + activerecord (= 7.1.3.3) + activestorage (= 7.1.3.3) + activesupport (= 7.1.3.3) + mail (>= 2.7.1) + net-imap + net-pop + net-smtp + actionmailer (7.1.3.3) + actionpack (= 7.1.3.3) + actionview (= 7.1.3.3) + activejob (= 7.1.3.3) + activesupport (= 7.1.3.3) mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.7.1) - actionview (= 5.2.7.1) - activesupport (= 5.2.7.1) - rack (~> 2.0, >= 2.0.8) + net-imap + net-pop + net-smtp + rails-dom-testing (~> 2.2) + actionpack (7.1.3.3) + actionview (= 7.1.3.3) + activesupport (= 7.1.3.3) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.7.1) - activesupport (= 5.2.7.1) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3.3) + actionpack (= 7.1.3.3) + activerecord (= 7.1.3.3) + activestorage (= 7.1.3.3) + activesupport (= 7.1.3.3) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (7.1.3.3) + activesupport (= 7.1.3.3) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - active_model_serializers (0.10.13) - actionpack (>= 4.1, < 7.1) - activemodel (>= 4.1, < 7.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + active_model_serializers (0.10.14) + actionpack (>= 4.1) + activemodel (>= 4.1) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - active_record_doctor (1.9.0) + active_record_doctor (1.14.0) activerecord (>= 4.2.0) active_record_union (1.3.0) activerecord (>= 4.0) - activejob (5.2.7.1) - activesupport (= 5.2.7.1) + activejob (7.1.3.3) + activesupport (= 7.1.3.3) globalid (>= 0.3.6) - activemodel (5.2.7.1) - activesupport (= 5.2.7.1) - activerecord (5.2.7.1) - activemodel (= 5.2.7.1) - activesupport (= 5.2.7.1) - arel (>= 9.0) - activestorage (5.2.7.1) - actionpack (= 5.2.7.1) - activerecord (= 5.2.7.1) - marcel (~> 1.0.0) - activesupport (5.2.7.1) + activemodel (7.1.3.3) + activesupport (= 7.1.3.3) + activerecord (7.1.3.3) + activemodel (= 7.1.3.3) + activesupport (= 7.1.3.3) + timeout (>= 0.4.0) + activestorage (7.1.3.3) + actionpack (= 7.1.3.3) + activejob (= 7.1.3.3) + activerecord (= 7.1.3.3) + activesupport (= 7.1.3.3) + marcel (~> 1.0) + activesupport (7.1.3.3) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) - airbrussh (1.4.0) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + airbrussh (1.5.2) sshkit (>= 1.6.1, != 1.7.0) - ancestry (4.1.0) + ancestry (4.3.3) activerecord (>= 5.2.6) - arel (9.0.0) ast (2.4.2) - autoprefixer-rails (10.4.2.0) + autoprefixer-rails (10.4.16.0) execjs (~> 2) - bcrypt (3.1.17) + base64 (0.2.0) + bcrypt (3.1.20) + bigdecimal (3.1.8) bootstrap (4.5.3) autoprefixer-rails (>= 9.1.0) popper_js (>= 1.14.3, < 2) @@ -70,144 +104,193 @@ GEM actionpack (>= 5.2) activemodel (>= 5.2) builder (3.2.4) - bullet (7.0.1) + bullet (7.1.6) activesupport (>= 3.0.0) uniform_notifier (~> 1.11) - capistrano (3.17.0) + capistrano (3.18.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) sshkit (>= 1.9.0) - capistrano-bundler (2.0.1) + capistrano-bundler (2.1.0) capistrano (~> 3.1) capistrano-passenger (0.2.1) capistrano (~> 3.0) - capistrano-rails (1.6.2) + capistrano-rails (1.6.3) capistrano (~> 3.1) capistrano-bundler (>= 1.1, < 3) capistrano-rvm (0.1.2) capistrano (~> 3.0) sshkit (~> 1.2) - capybara (3.35.3) + capybara (3.40.0) addressable + matrix mini_mime (>= 0.1.3) - nokogiri (~> 1.8) + nokogiri (~> 1.11) rack (>= 1.6.0) rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - carrierwave (2.2.2) - activemodel (>= 5.0.0) - activesupport (>= 5.0.0) + carrierwave (3.0.7) + activemodel (>= 6.0.0) + activesupport (>= 6.0.0) addressable (~> 2.6) image_processing (~> 1.1) marcel (~> 1.0.0) - mini_mime (>= 0.1.3) ssrf_filter (~> 1.0) case_transform (0.2) activesupport + childprocess (5.0.0) cocoon (1.2.15) code_analyzer (0.5.5) sexp_processor - codeclimate-engine-rb (0.4.2) codecov (0.6.0) simplecov (>= 0.15, < 0.22) - coffee-rails (4.2.2) + coffee-rails (5.0.0) coffee-script (>= 2.2.0) - railties (>= 4.0.0) + railties (>= 5.2.0) coffee-script (2.4.1) coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) counter_culture (2.9.0) activerecord (>= 4.2) activesupport (>= 4.2) crass (1.0.6) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.1) + database_cleaner (2.0.2) + database_cleaner-active_record (>= 2, < 3) + database_cleaner-active_record (2.1.0) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - devise (4.8.1) + date (3.3.4) + 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.5.1) docile (1.4.0) - erubi (1.10.0) + drb (2.2.1) + dry-configurable (1.1.0) + dry-core (~> 1.0, < 2) + zeitwerk (~> 2.6) + dry-core (1.0.1) + concurrent-ruby (~> 1.0) + zeitwerk (~> 2.6) + dry-inflector (1.0.0) + dry-initializer (3.1.1) + dry-logic (1.5.0) + concurrent-ruby (~> 1.0) + dry-core (~> 1.0, < 2) + zeitwerk (~> 2.6) + dry-schema (1.13.4) + concurrent-ruby (~> 1.0) + dry-configurable (~> 1.0, >= 1.0.1) + dry-core (~> 1.0, < 2) + dry-initializer (~> 3.0) + dry-logic (>= 1.4, < 2) + dry-types (>= 1.7, < 2) + zeitwerk (~> 2.6) + dry-types (1.7.2) + bigdecimal (~> 3.0) + concurrent-ruby (~> 1.0) + dry-core (~> 1.0) + dry-inflector (~> 1.0) + dry-logic (~> 1.4) + zeitwerk (~> 2.6) + erubi (1.12.0) erubis (2.7.0) - execjs (2.8.1) - factory_bot (4.11.1) - activesupport (>= 3.0.0) - factory_bot_rails (4.11.1) - factory_bot (~> 4.11.1) - railties (>= 3.0.0) - ffi (1.15.5) + execjs (2.9.1) + factory_bot (6.4.6) + activesupport (>= 5.0.0) + factory_bot_rails (6.4.3) + factory_bot (~> 6.4) + railties (>= 5.0.0) + ffi (1.16.3) font-awesome-rails (4.7.0.8) railties (>= 3.2, < 8.0) - generator (0.0.1) - globalid (1.0.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) graph_matching (0.1.1) rgl (~> 0.5.0) - haml (5.2.2) - temple (>= 0.8.0) + haml (6.1.4) + temple (>= 0.8.2) + thor tilt - haml_lint (0.40.0) - haml (>= 4.0, < 5.3) + haml_lint (0.45.0) + haml (>= 4.0, < 6.2) parallel (~> 1.10) rainbow rubocop (>= 0.50.0) sysexits (~> 1.1) - hamlit (2.16.0) + hamlit (3.0.3) temple (>= 0.8.2) thor tilt hashie (5.0.0) - i18n (1.10.0) + i18n (1.14.5) concurrent-ruby (~> 1.0) image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inline_svg (1.8.0) + inline_svg (1.9.0) activesupport (>= 3.0) nokogiri (>= 1.6) - jquery-rails (4.4.0) + io-console (0.7.2) + irb (1.13.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - json (2.6.1) + json (2.7.2) jsonapi-renderer (0.2.2) - kwalify (0.7.2) - launchy (2.5.0) - addressable (~> 2.7) - lazy_priority_queue (0.1.1) - letter_opener (1.8.1) - launchy (>= 2.2, < 3) - loofah (2.16.0) + language_server-protocol (3.17.0.3) + launchy (3.0.1) + addressable (~> 2.8) + childprocess (~> 5.0) + letter_opener (1.10.0) + launchy (>= 2.2, < 4) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) - marcel (1.0.2) - method_source (1.0.0) - mini_magick (4.11.0) - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minitest (5.15.0) + net-imap + net-pop + net-smtp + marcel (1.0.4) + matrix (0.4.2) + mini_magick (4.12.0) + mini_mime (1.1.5) + mini_portile2 (2.8.6) + minitest (5.23.1) multi_json (1.15.0) - net-scp (3.0.0) - net-ssh (>= 2.6.5, < 7.0.0) - net-ssh (6.1.0) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) + mutex_m (0.2.0) + net-imap (0.4.11) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-scp (4.0.0) + net-ssh (>= 2.6.5, < 8.0.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) + net-smtp (0.5.0) + net-protocol + net-ssh (7.2.3) + nio4r (2.7.3) + nokogiri (1.16.5) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - omniauth (1.9.1) + omniauth (1.9.2) hashie (>= 3.4.6) rack (>= 1.6.2, < 3) omniauth-openid (2.0.1) @@ -222,41 +305,50 @@ GEM orm_adapter (0.5.0) pagedown-bootstrap-rails (2.1.4) railties (> 3.1) - parallel (1.22.1) - parallel_tests (3.8.1) + pairing_heap (3.1.0) + parallel (1.24.0) + parallel_tests (4.7.1) parallel - parser (2.7.2.0) + parser (3.3.3.0) ast (~> 2.4.1) - pg (1.3.5) - popper_js (1.16.0) - psych (3.1.0) - public_suffix (4.0.7) - racc (1.6.0) - rack (2.2.3) + racc + pg (1.5.6) + popper_js (1.16.1) + public_suffix (5.0.5) + racc (1.8.0) + rack (2.2.9) rack-openid (1.4.2) rack (>= 1.1.0) ruby-openid (>= 2.1.8) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.7.1) - actioncable (= 5.2.7.1) - actionmailer (= 5.2.7.1) - actionpack (= 5.2.7.1) - actionview (= 5.2.7.1) - activejob (= 5.2.7.1) - activemodel (= 5.2.7.1) - activerecord (= 5.2.7.1) - activestorage (= 5.2.7.1) - activesupport (= 5.2.7.1) - bundler (>= 1.3.0) - railties (= 5.2.7.1) - sprockets-rails (>= 2.0.0) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rack-session (1.0.2) + rack (< 3) + rack-test (2.1.0) + rack (>= 1.3) + rackup (1.0.0) + rack (< 3) + webrick + rails (7.1.3.3) + actioncable (= 7.1.3.3) + actionmailbox (= 7.1.3.3) + actionmailer (= 7.1.3.3) + actionpack (= 7.1.3.3) + actiontext (= 7.1.3.3) + actionview (= 7.1.3.3) + activejob (= 7.1.3.3) + activemodel (= 7.1.3.3) + activerecord (= 7.1.3.3) + activestorage (= 7.1.3.3) + activesupport (= 7.1.3.3) + bundler (>= 1.15.0) + railties (= 7.1.3.3) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - rails_best_practices (1.23.1) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + rails_best_practices (1.23.2) activesupport code_analyzer (~> 0.5.5) erubis @@ -264,79 +356,77 @@ GEM json require_all (~> 3.0) ruby-progressbar - railties (5.2.7.1) - actionpack (= 5.2.7.1) - activesupport (= 5.2.7.1) - method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) + railties (7.1.3.3) + actionpack (= 7.1.3.3) + activesupport (= 7.1.3.3) + irb + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) rake (12.3.3) - rb-fsevent (0.11.1) - rb-inotify (0.10.1) - ffi (~> 1.0) - redcarpet (3.5.1) - reek (5.6.0) - codeclimate-engine-rb (~> 0.4.0) - kwalify (~> 0.7.0) - parser (>= 2.5.0.0, < 2.8, != 2.5.1.1) - psych (~> 3.1.0) + rdoc (6.3.4.1) + redcarpet (3.6.0) + reek (6.3.0) + dry-schema (~> 1.13.0) + parser (~> 3.3.0) rainbow (>= 2.0, < 4.0) - regexp_parser (2.3.1) + rexml (~> 3.1) + regexp_parser (2.9.2) + reline (0.5.7) + io-console (~> 0.5) require_all (3.0.0) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - rexml (3.2.5) - rgl (0.5.7) - lazy_priority_queue (~> 0.1.0) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) + rexml (3.2.8) + strscan (>= 3.0.9) + rgl (0.5.10) + pairing_heap (>= 0.3.0) + rexml (~> 3.2, >= 3.2.4) stream (~> 0.5.3) - rspec-core (3.9.3) - rspec-support (~> 3.9.3) - rspec-expectations (3.9.4) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-mocks (3.9.1) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.9.0) - rspec-rails (3.9.1) - actionpack (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-core (~> 3.9.0) - rspec-expectations (~> 3.9.0) - rspec-mocks (~> 3.9.0) - rspec-support (~> 3.9.0) - rspec-support (3.9.4) - rubocop (0.93.1) + rspec-support (~> 3.13.0) + rspec-rails (6.1.2) + actionpack (>= 6.1) + activesupport (>= 6.1) + railties (>= 6.1) + rspec-core (~> 3.13) + rspec-expectations (~> 3.13) + rspec-mocks (~> 3.13) + rspec-support (~> 3.13) + rspec-support (3.13.1) + rubocop (1.64.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 2.7.1.5) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8) - rexml - rubocop-ast (>= 0.6.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 2.0) - rubocop-ast (1.4.1) - parser (>= 2.7.1.5) - rubocop-rails (2.2.1) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-rails (2.25.0) + activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.72.0) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-openid (2.9.2) - ruby-progressbar (1.11.0) - ruby-vips (2.1.4) + ruby-progressbar (1.13.0) + ruby-vips (2.2.1) ffi (~> 1.12) - 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.1.0) - railties (>= 5.2.0) - 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) @@ -345,45 +435,50 @@ GEM sprockets (> 3.0) sprockets-rails tilt - sexp_processor (4.16.1) - shoulda-matchers (4.5.1) - activesupport (>= 4.2.0) + scanf (1.0.0) + sexp_processor (4.17.1) + shoulda-matchers (6.2.0) + activesupport (>= 5.2.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) simplecov_json_formatter (0.1.4) - spring (3.1.1) - sprockets (3.7.2) + spring (4.2.1) + sprockets (4.2.1) concurrent-ruby (~> 1.0) - rack (> 1, < 3) + rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sshkit (1.21.2) + sshkit (1.22.2) + base64 + mutex_m net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) - ssrf_filter (1.0.7) - stream (0.5.3) - generator + ssrf_filter (1.1.2) + stream (0.5.5) + strscan (3.1.0) sysexits (1.2.0) - temple (0.8.2) - thor (1.2.1) - thread_safe (0.3.6) - tilt (2.0.10) + temple (0.10.3) + thor (1.3.1) + tilt (2.3.0) + timeout (0.4.1) tournament-system (2.1.0) graph_matching (~> 0.1.1) - tzinfo (1.2.9) - thread_safe (~> 0.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) uglifier (4.2.0) execjs (>= 0.3.0, < 3) - unicode-display_width (1.8.0) + unicode-display_width (2.5.0) uniform_notifier (1.16.0) warden (1.2.9) rack (>= 2.0.9) - websocket-driver (0.7.5) + webrick (1.8.1) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) will_paginate (3.3.1) @@ -391,6 +486,7 @@ GEM will_paginate (~> 3.0, >= 3.0.0) xpath (3.2.0) nokogiri (~> 1.8) + zeitwerk (2.6.15) PLATFORMS ruby @@ -412,11 +508,11 @@ DEPENDENCIES carrierwave cocoon codecov - coffee-rails (~> 4.2.0) + coffee-rails (~> 5) counter_culture (~> 2.0) database_cleaner devise - factory_bot_rails (~> 4) + factory_bot_rails (~> 6) font-awesome-rails haml_lint hamlit @@ -430,22 +526,24 @@ DEPENDENCIES pagedown-bootstrap-rails parallel_tests pg (~> 1.0) - rails (~> 5.2.1) + rails (~> 7.1.0) rails_best_practices rake (~> 12.0) redcarpet - reek (~> 5) - rspec-rails (~> 3.8) - rubocop (~> 0.58) - rubocop-rails (~> 2.2.1) - sass-rails (~> 5.0) + reek (~> 6) + rspec-rails (~> 6) + rubocop (~> 1.64.1) + rubocop-rails (~> 2.25.0) + sass-rails (~> 6) + scanf shoulda-matchers simplecov spring + sprockets-rails tournament-system (~> 2.0) uglifier (>= 1.3.0) will_paginate (~> 3.3.0) will_paginate-bootstrap4 BUNDLED WITH - 2.1.4 + 2.5.13 diff --git a/README.md b/README.md index 2c02d6bad..9f1c8f8e7 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,8 @@ You will also need for testing: * A js runtime supported by [execjs](https://github.com/rails/execjs) -To configure secrets (ie. steam API key) for development, use -`config/secrets.local.yml`. Example at `config/secrets.local.yml.example`. -Or put the secrets in environment variables (`SECRET_KEY_BASE`, `STEAM_API_KEY`) +To configure secrets (ie. steam API key) for development, run `rails +credentials:edit`. ## Installing diff --git a/Rakefile b/Rakefile index eb3b819d0..7880967d5 100644 --- a/Rakefile +++ b/Rakefile @@ -17,7 +17,7 @@ begin RuboCop::RakeTask.new Reek::Rake::Task.new - task :rbp do + task rbp: [:environment] do require 'rails_best_practices' app_root = Rake.application.original_dir @@ -34,7 +34,7 @@ rescue LoadError puts 'Test tasks not available' end -task :log do +task log: [:environment] do ActiveRecord::Base.logger = Logger.new($stdout) end diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js new file mode 100644 index 000000000..581a4806a --- /dev/null +++ b/app/assets/config/manifest.js @@ -0,0 +1,5 @@ +//= link_tree ../images +//= link_directory ../javascripts .js + +//= link application.css +//= link brackets.css diff --git a/app/controllers/concerns/forums/permissions.rb b/app/controllers/concerns/forums/permissions.rb index 7f470fe4f..30ca5511a 100644 --- a/app/controllers/concerns/forums/permissions.rb +++ b/app/controllers/concerns/forums/permissions.rb @@ -11,7 +11,7 @@ def user_can_manage_topic?(topic = nil) return user_can_manage_forums? unless topic - user_signed_in? && (topic.not_isolated? && user_can_manage_forums? || + user_signed_in? && ((topic.not_isolated? && user_can_manage_forums?) || user_can_manage_topics?(topic.ancestors) || current_user.can?(:manage, topic)) end @@ -41,7 +41,7 @@ def user_can_manage_thread?(thread = nil) return user_can_manage_forums? unless thread - user_signed_in? && (thread.not_isolated? && user_can_manage_forums? || + user_signed_in? && ((thread.not_isolated? && user_can_manage_forums?) || user_can_manage_topics?(thread.ancestors) || current_user.can?(:manage, thread)) end diff --git a/app/controllers/concerns/leagues/match_permissions.rb b/app/controllers/concerns/leagues/match_permissions.rb index 8760d9bc1..ad83e2205 100644 --- a/app/controllers/concerns/leagues/match_permissions.rb +++ b/app/controllers/concerns/leagues/match_permissions.rb @@ -18,8 +18,8 @@ def user_can_either_teams? def user_can_confirm_score? status = @match.status - user_can_home_team? && status == 'submitted_by_away_team' || - user_can_away_team? && status == 'submitted_by_home_team' + (user_can_home_team? && status == 'submitted_by_away_team') || + (user_can_away_team? && status == 'submitted_by_home_team') end def user_can_submit_team_score? diff --git a/app/controllers/concerns/leagues/roster_permissions.rb b/app/controllers/concerns/leagues/roster_permissions.rb index 390213677..d6a6f5ee1 100644 --- a/app/controllers/concerns/leagues/roster_permissions.rb +++ b/app/controllers/concerns/leagues/roster_permissions.rb @@ -16,7 +16,7 @@ def user_can_edit_roster?(roster = nil) disbanded = roster&.disbanded? user_can_edit_league?(roster.league) || - user_signed_in? && current_user.can?(:edit, roster.team) && user_not_banned? && !disbanded + (user_signed_in? && current_user.can?(:edit, roster.team) && user_not_banned? && !disbanded) end def user_can_disband_roster?(roster = nil) diff --git a/app/controllers/concerns/team_permissions.rb b/app/controllers/concerns/team_permissions.rb index 891de9f06..61e8626d0 100644 --- a/app/controllers/concerns/team_permissions.rb +++ b/app/controllers/concerns/team_permissions.rb @@ -8,7 +8,7 @@ def user_can_create_team? def user_can_edit_team?(team = nil) team ||= @team - user_signed_in? && current_user.can?(:edit, team) && current_user.can?(:use, :teams) || + (user_signed_in? && current_user.can?(:edit, team) && current_user.can?(:use, :teams)) || user_can_edit_teams? end diff --git a/app/controllers/concerns/users_permissions.rb b/app/controllers/concerns/users_permissions.rb index 7c9d6d2b6..b4ffd59a5 100644 --- a/app/controllers/concerns/users_permissions.rb +++ b/app/controllers/concerns/users_permissions.rb @@ -2,7 +2,7 @@ module UsersPermissions extend ActiveSupport::Concern def user_can_edit_user? - user_signed_in? && current_user == @user && current_user.can?(:use, :users) || + (user_signed_in? && current_user == @user && current_user.can?(:use, :users)) || user_can_edit_users? end diff --git a/app/controllers/leagues/transfers_controller.rb b/app/controllers/leagues/transfers_controller.rb index 5eda87c21..15129e288 100644 --- a/app/controllers/leagues/transfers_controller.rb +++ b/app/controllers/leagues/transfers_controller.rb @@ -28,7 +28,7 @@ def index def update Transfers::ApprovalService.call(@transfer_request, current_user) - flash[:error] = @transfer_request.errors.full_messages.first + flash.now[:error] = @transfer_request.errors.full_messages.first index render :index end @@ -36,7 +36,7 @@ def update def destroy Transfers::DenialService.call(@transfer_request, current_user) - flash[:error] = @transfer_request.errors.full_messages.first + flash.now[:error] = @transfer_request.errors.full_messages.first index render :index end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index 051ca31f0..047bc5e20 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -19,8 +19,8 @@ def read_news_topic_config(config) limit = config['display'] || 3 @topic = Forums::Topic.find(config['id']) - @threads = @topic.threads.ordered.limit(limit) + @threads = @topic.threads.visible.ordered.limit(limit) @news_posts = @threads.map { |thread| [thread, thread.original_post] }.to_h - @more_threads = @topic.threads.limit(limit + 1).size > limit + @more_threads = @topic.threads.visible.limit(limit + 1).size > limit end end diff --git a/app/controllers/permissions_controller.rb b/app/controllers/permissions_controller.rb index 39665df84..55bebd327 100644 --- a/app/controllers/permissions_controller.rb +++ b/app/controllers/permissions_controller.rb @@ -28,7 +28,7 @@ def users excluded_users = users_which_can.select(:id) @users_without_permission = target_users.search(params[:q]) - .where('users.id NOT IN (?)', excluded_users) + .where.not(users: { id: excluded_users }) .paginate(page: params[:page]) end @@ -85,10 +85,10 @@ def user_can_edit_permissions? end def ensure_valid_target - redirect_back if subject? && ![:team, :forums_topic].include?(@subject) + redirect_back if subject? && [:team, :forums_topic].exclude?(@subject) end def redirect_back(options = {}) - super({ fallback_location: permissions_path }.merge(options)) + super(fallback_location: permissions_path, **options) end end diff --git a/app/helpers/forums/topics_helper.rb b/app/helpers/forums/topics_helper.rb index c54dcee54..1fbb1d503 100644 --- a/app/helpers/forums/topics_helper.rb +++ b/app/helpers/forums/topics_helper.rb @@ -2,11 +2,11 @@ module Forums module TopicsHelper include Forums::Permissions - ISOLATE_CONFIRM_MESSAGE = "Are you sure you want to unisolate this Topic?\n"\ + ISOLATE_CONFIRM_MESSAGE = "Are you sure you want to unisolate this Topic?\n" \ 'This means any admin will be able to manage this Topic.'.freeze - UNISOLATE_CONFIRM_MESSAGE = "Are you sure you want to isolate this Topic?\n"\ - 'This means only you and anyone you give access '\ + UNISOLATE_CONFIRM_MESSAGE = "Are you sure you want to isolate this Topic?\n" \ + 'This means only you and anyone you give access ' \ 'to will be able to manage this Topic.'.freeze end end diff --git a/app/models/api_key.rb b/app/models/api_key.rb index 7cbcb0177..9f2e25eb2 100644 --- a/app/models/api_key.rb +++ b/app/models/api_key.rb @@ -2,7 +2,7 @@ class APIKey < ApplicationRecord belongs_to :user, optional: true validates :name, allow_blank: true, length: { maximum: 64 } - validates :user, allow_nil: true, uniqueness: true + # validates :user, allow_nil: true, uniqueness: true validates :key, presence: true before_validation :generate_unique_key, on: :create diff --git a/app/models/concerns/paths.rb b/app/models/concerns/paths.rb index 146f70c1b..dc186c6cf 100644 --- a/app/models/concerns/paths.rb +++ b/app/models/concerns/paths.rb @@ -8,7 +8,7 @@ def paths class_methods do attr_reader :paths_class - # rubocop:disable Metrics/MethodLength, Lint/MissingSuper + # rubocop:disable Metrics/MethodLength def paths(&block) @paths_class = Class.new do include Rails.application.routes.url_helpers @@ -40,6 +40,6 @@ def method_missing(method, *args, &block) @paths_class.class_eval(&block) end - # rubocop:enable Metrics/MethodLength, Lint/MissingSuper + # rubocop:enable Metrics/MethodLength end end diff --git a/app/models/forums/post.rb b/app/models/forums/post.rb index 7d7f24fd5..5c47d4151 100644 --- a/app/models/forums/post.rb +++ b/app/models/forums/post.rb @@ -42,7 +42,7 @@ def self.page_of(post) return 1 unless post post_index = post.thread.posts.where('created_at < ?', post.created_at).count - post_index / Post.per_page + 1 + (post_index / Post.per_page) + 1 end end end diff --git a/app/models/forums/thread.rb b/app/models/forums/thread.rb index ff59dffb6..8c4c6a35d 100644 --- a/app/models/forums/thread.rb +++ b/app/models/forums/thread.rb @@ -27,15 +27,14 @@ class Thread < ApplicationRecord 'forums_threads.hidden' => nil, } + after_initialize :set_defaults, unless: :persisted? before_create :update_depth before_update :update_depth, if: :topic_id_changed? - after_initialize :set_defaults, unless: :persisted? - before_update do if hidden_changed? sign = hidden? ? :- : :+ - ActiveRecord::Base.connection.exec_update(<<-SQL, 'SQL', [[nil, id]]) + ActiveRecord::Base.connection.exec_update(<<-SQL.squish, 'SQL', [id]) UPDATE users SET public_forums_posts_count = public_forums_posts_count #{sign} ( SELECT COUNT(1) FROM forums_posts WHERE thread_id = $1 AND created_by_id = users.id) diff --git a/app/models/league.rb b/app/models/league.rb index 0024a6589..fd7fdc6ba 100644 --- a/app/models/league.rb +++ b/app/models/league.rb @@ -21,7 +21,7 @@ class League < ApplicationRecord has_many :titles, class_name: 'User::Title', dependent: :destroy - enum status: [:hidden, :running, :completed] + enum status: { hidden: 0, running: 1, completed: 2 } validates :name, presence: true, length: { in: 1..64 } validates :description, presence: true @@ -52,7 +52,7 @@ class League < ApplicationRecord validates :points_per_forfeit_loss, presence: true # Scheduling - enum schedule: [:manual, :weeklies] + enum schedule: { manual: 0, weeklies: 1 } has_one :weekly_scheduler, inverse_of: :league, class_name: 'League::Schedulers::Weekly', dependent: :destroy accepts_nested_attributes_for :weekly_scheduler @@ -76,7 +76,7 @@ class League < ApplicationRecord end) def entered?(user) - players.where(user: user).exists? + players.exists?(user: user) end def roster_for(user) diff --git a/app/models/league/match.rb b/app/models/league/match.rb index 59e4c7f88..cd79e8f24 100644 --- a/app/models/league/match.rb +++ b/app/models/league/match.rb @@ -20,13 +20,14 @@ class Match < ApplicationRecord validates :rounds, associated: true # Make *really* sure all rounds are valid - enum status: [:pending, :submitted_by_home_team, :submitted_by_away_team, :confirmed] + enum status: { pending: 0, submitted_by_home_team: 1, submitted_by_away_team: 2, confirmed: 3 } validates :status, presence: true validates :has_winner, inclusion: { in: [true, false] } validates :allow_round_draws, inclusion: { in: [true, false] } - enum forfeit_by: [:no_forfeit, :home_team_forfeit, :away_team_forfeit, :mutual_forfeit, :technical_forfeit] + enum forfeit_by: { no_forfeit: 0, home_team_forfeit: 1, away_team_forfeit: 2, mutual_forfeit: 3, +technical_forfeit: 4 } validates :forfeit_by, presence: true validates :round_name, presence: true, allow_blank: true validates :round_number, presence: true, numericality: { greater_than_or_equal_to: 0 } diff --git a/app/models/league/match/pick_ban.rb b/app/models/league/match/pick_ban.rb index 44cf74336..e89142027 100644 --- a/app/models/league/match/pick_ban.rb +++ b/app/models/league/match/pick_ban.rb @@ -7,8 +7,8 @@ class PickBan < ApplicationRecord belongs_to :picked_by, class_name: 'User', optional: true belongs_to :map, class_name: 'Map', optional: true - enum kind: [:pick, :ban, :deferred] - enum team: [:home_team, :away_team] + enum kind: { pick: 0, ban: 1, deferred: 2 }, _prefix: :kind + enum team: { home_team: 0, away_team: 1 } validates :deferrable, inclusion: { in: [true, false] } @@ -20,7 +20,7 @@ class PickBan < ApplicationRecord delegate :league, to: :match def submit(user, map) - match.rounds.create!(map: map) if pick? + match.rounds.create!(map: map) if kind_pick? update(picked_by: user, map: map) end @@ -80,7 +80,7 @@ def team_pick def map_and_pick_present if map errors.add(:picked_by, 'Must be present') unless picked_by - elsif picked_by && !deferred? + elsif picked_by && !kind_deferred? errors.add(:map, 'Must be present') end end diff --git a/app/models/league/roster.rb b/app/models/league/roster.rb index 07a31e1f5..f7ff4301a 100644 --- a/app/models/league/roster.rb +++ b/app/models/league/roster.rb @@ -54,13 +54,12 @@ class Roster < ApplicationRecord after_destroy { League.decrement_counter(:rosters_count, league.id) } # rubocop:enable Rails/SkipsModelValidations + after_initialize :set_defaults, unless: :persisted? after_create :trigger_score_update!, if: :approved? after_save do trigger_score_update! if [:ranking, :seeding, :approved, :disbanded].any? { |a| saved_change_to_attribute?(a) } end - after_initialize :set_defaults, unless: :persisted? - def self.matches Match.for_roster(all.map(&:id)) end @@ -95,7 +94,7 @@ def remove_player!(user) end def on_roster?(user) - players.where(user: user).exists? + players.exists?(user: user) end def tentative_player_count @@ -149,7 +148,7 @@ def within_roster_size_limits def unique_within_league return if league.blank? - errors.add(:base, 'Can only sign up once') if league.rosters.where(team: team).exists? + errors.add(:base, 'Can only sign up once') if league.rosters.exists?(team: team) end def validate_schedule diff --git a/app/models/league/roster/transfer.rb b/app/models/league/roster/transfer.rb index 8b3c5f22f..50617a2b0 100644 --- a/app/models/league/roster/transfer.rb +++ b/app/models/league/roster/transfer.rb @@ -2,7 +2,7 @@ class League class Roster class Transfer < ApplicationRecord belongs_to :user - belongs_to :roster, class_name: 'Roster', foreign_key: 'roster_id' + belongs_to :roster, class_name: 'Roster' delegate :team, to: :roster, allow_nil: true delegate :division, to: :roster, allow_nil: true delegate :league, to: :division, allow_nil: true diff --git a/app/models/league/tiebreaker.rb b/app/models/league/tiebreaker.rb index dabb450ce..f028ee969 100644 --- a/app/models/league/tiebreaker.rb +++ b/app/models/league/tiebreaker.rb @@ -2,8 +2,8 @@ class League class Tiebreaker < ApplicationRecord belongs_to :league, inverse_of: :tiebreakers - enum kind: [:round_wins, :round_score_sum, :round_wins_against_tied_rosters, :normalized_round_score, - :round_score_difference, :buchholz, :median_buchholz] + enum kind: { round_wins: 0, round_score_sum: 1, round_wins_against_tied_rosters: 2, +normalized_round_score: 3, round_score_difference: 4, buchholz: 5, median_buchholz: 6 } def value_for(roster) send("#{kind}_value_for", roster) diff --git a/app/models/team.rb b/app/models/team.rb index a226e4b8f..a2f04b62d 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -59,13 +59,12 @@ def remove_player!(user) end def on_roster?(user) - players.where(user: user).exists? + players.exists?(user: user) end def entered?(comp) rosters.joins(:division) - .where(league_divisions: { league_id: comp.id }) - .exists? + .exists?(league_divisions: { league_id: comp.id }) end def reset_query_cache! diff --git a/app/models/user.rb b/app/models/user.rb index 9718bc3a7..6f25524b3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,7 +17,7 @@ class User < ApplicationRecord private :team_players, :team_players= has_many :teams, through: :team_players has_many :team_invites, class_name: 'Team::Invite', dependent: :destroy - has_many :team_transfers, -> { order(created_at: :desc) }, class_name: 'Team::Transfer' + has_many :team_transfers, -> { order(created_at: :desc) }, class_name: 'Team::Transfer', dependent: :destroy has_many :roster_players, class_name: 'League::Roster::Player', dependent: :restrict_with_exception private :roster_players, :roster_players= @@ -30,7 +30,7 @@ class User < ApplicationRecord has_many :forums_posts, class_name: 'Forums::Post', inverse_of: :created_by, foreign_key: :created_by, dependent: :destroy has_many :public_forums_posts, -> { publicly_viewable }, class_name: 'Forums::Post', inverse_of: :created_by, - foreign_key: :created_by + foreign_key: :created_by, dependent: :destroy has_many :logs, class_name: 'User::Log', dependent: :destroy diff --git a/app/models/user/log.rb b/app/models/user/log.rb index a1cce0dd3..7b5334871 100644 --- a/app/models/user/log.rb +++ b/app/models/user/log.rb @@ -3,7 +3,7 @@ class Log < ApplicationRecord belongs_to :user def self.log_user!(user, ip) - connection.exec_query(<<-SQL, 'log_user', [[nil, user.id], [nil, ip], [nil, Time.now.utc]]) + connection.exec_query(<<-SQL.squish, 'log_user', [user.id, ip, Time.now.utc]) INSERT INTO user_logs (user_id, ip, first_seen_at, last_seen_at) VALUES ($1, $2::inet, $3, $3) ON CONFLICT (user_id, ip) DO UPDATE SET last_seen_at = $3 diff --git a/app/models/user/name_change.rb b/app/models/user/name_change.rb index de9ff2b92..3beb9125b 100644 --- a/app/models/user/name_change.rb +++ b/app/models/user/name_change.rb @@ -44,8 +44,8 @@ def only_one_request_per_user def name_not_already_used return if name.blank? - if pending? && (User.where(name: name).exists? || - NameChange.pending.where(name: name).exists?) + if pending? && (User.exists?(name: name) || + NameChange.pending.exists?(name: name)) errors.add(:name, 'Must be unique') end end diff --git a/app/presenters/base_presenter.rb b/app/presenters/base_presenter.rb index 991a1a81c..62762da36 100644 --- a/app/presenters/base_presenter.rb +++ b/app/presenters/base_presenter.rb @@ -18,7 +18,6 @@ def initialize(object, view_context) private - # rubocop:disable Lint/MissingSuper def respond_to_missing?(method, _include_private = false) view_context.respond_to?(method) end @@ -30,5 +29,4 @@ def method_missing(method, *args, &block) super end end - # rubocop:enable Lint/MissingSuper end diff --git a/app/presenters/league/match/pick_ban_presenter.rb b/app/presenters/league/match/pick_ban_presenter.rb index a9715f778..6c2c586b8 100644 --- a/app/presenters/league/match/pick_ban_presenter.rb +++ b/app/presenters/league/match/pick_ban_presenter.rb @@ -22,7 +22,7 @@ def map def status if pick_ban.pending? safe_join([team.link, pending_kind, deferrable_message], ' ') - elsif pick_ban.deferred? + elsif pick_ban.kind_deferred? safe_join([team.link, ' (', picked_by.link, ') deferred their ', completed_kind_noun]) else safe_join([team.link, ' (', picked_by.link, ') ', completed_kind_verb, ' ', map.link]) @@ -32,7 +32,7 @@ def status private def completed_kind_verb - if pick_ban.pick? + if pick_ban.kind_pick? 'picked' else 'banned' @@ -40,7 +40,7 @@ def completed_kind_verb end def completed_kind_noun - if pick_ban.pick? + if pick_ban.kind_pick? 'pick' else 'ban' @@ -48,7 +48,7 @@ def completed_kind_noun end def pending_kind - if pick_ban.pick? + if pick_ban.kind_pick? 'picks' else 'bans' diff --git a/app/presenters/league/match_presenter.rb b/app/presenters/league/match_presenter.rb index 0724b69c5..c2a16f972 100644 --- a/app/presenters/league/match_presenter.rb +++ b/app/presenters/league/match_presenter.rb @@ -110,7 +110,7 @@ def match_name def team_score(symbol) if match.no_forfeit? - match.rounds.map(&"#{symbol}_score".to_sym).join(':') + match.rounds.map(&:"#{symbol}_score").join(':') elsif match.send("#{symbol}_forfeit?") || match.mutual_forfeit? 'ff' else diff --git a/app/presenters/league/roster/transfer_request_presenter.rb b/app/presenters/league/roster/transfer_request_presenter.rb index 578ec095f..841bbb159 100644 --- a/app/presenters/league/roster/transfer_request_presenter.rb +++ b/app/presenters/league/roster/transfer_request_presenter.rb @@ -4,13 +4,13 @@ class TransferRequestPresenter < BasePresenter presents :transfer_request # rubocop:disable Rails/OutputSafety - PENDING_MESSAGE = '%{created_by} requested %{user} be transferred %{direction} '\ + PENDING_MESSAGE = '%{created_by} requested %{user} be transferred %{direction} ' \ '%{roster}%{leaving_message}'.html_safe - APPROVED_MESSAGE = '%{approved_by} approved %{user}\'s transfer %{direction} '\ + APPROVED_MESSAGE = '%{approved_by} approved %{user}\'s transfer %{direction} ' \ '%{roster}%{leaving_message} (requested by %{created_by})'.html_safe - DENIED_MESSAGE = '%{denied_by} denied %{user}\'s transfer %{direction} '\ + DENIED_MESSAGE = '%{denied_by} denied %{user}\'s transfer %{direction} ' \ '%{roster}%{leaving_message} (requested by %{created_by})'.html_safe LEAVING_MESSAGE = ', out of %{leaving_roster} in %{division}'.html_safe diff --git a/app/presenters/team/player_presenter.rb b/app/presenters/team/player_presenter.rb index ecc320468..dbc1ccef7 100644 --- a/app/presenters/team/player_presenter.rb +++ b/app/presenters/team/player_presenter.rb @@ -7,14 +7,14 @@ def user end def leave_button - content = safe_join(['Leave', tag(:span, class: 'glyphicon glyphicon-remove')]) + content = safe_join(['Leave', tag.span(class: 'glyphicon glyphicon-remove')]) link_to(content, leave_team_path(player.team), method: :patch, class: 'btn btn-danger', data: { confirm: leave_confirm_message }) end def kick_button - content = safe_join(['Kick', tag(:span, class: 'glyphicon glyphicon-remove')]) + content = safe_join(['Kick', tag.span(class: 'glyphicon glyphicon-remove')]) link_to(content, kick_team_path(player.team, user_id: player.user.id), method: :patch, class: 'btn btn-danger', data: { confirm: kick_confirm_message }) diff --git a/app/presenters/user/ban_presenter.rb b/app/presenters/user/ban_presenter.rb index 774540c82..57cfef40b 100644 --- a/app/presenters/user/ban_presenter.rb +++ b/app/presenters/user/ban_presenter.rb @@ -11,7 +11,7 @@ def from end def title_text - safe_join([expire_s, reason_s], tag(:br)) + safe_join([expire_s, reason_s], tag.br) end def started_at diff --git a/app/services/forums/posts/editing_service.rb b/app/services/forums/posts/editing_service.rb index 3c843e309..7b708a80a 100644 --- a/app/services/forums/posts/editing_service.rb +++ b/app/services/forums/posts/editing_service.rb @@ -6,7 +6,7 @@ module EditingService def call(user, post, params) post.transaction do post.assign_attributes(params) - return post unless post.changed? + next unless post.changed? post.save || rollback! diff --git a/app/services/leagues/matches/comms/creation_service.rb b/app/services/leagues/matches/comms/creation_service.rb index 6db657880..b766993d0 100644 --- a/app/services/leagues/matches/comms/creation_service.rb +++ b/app/services/leagues/matches/comms/creation_service.rb @@ -21,7 +21,7 @@ def call(creator, match, params) private def notify_captains!(user, match) - message = "'#{user.name}' posted a message on the match: "\ + message = "'#{user.name}' posted a message on the match: " \ "'#{match.home_team.name}' vs '#{match.away_team.name}'" link = match_path(match) diff --git a/app/services/leagues/matches/generation_service.rb b/app/services/leagues/matches/generation_service.rb index 192b7abae..3ee93bc6d 100644 --- a/app/services/leagues/matches/generation_service.rb +++ b/app/services/leagues/matches/generation_service.rb @@ -13,7 +13,7 @@ def call(division, match_params, tournament_system, tournament_options) create_notifications_for_matches(matches) rescue League::Division::GenerationError => e - return invalid_match(match_params, e) + invalid_match = invalid_match(match_params, e) end invalid_match diff --git a/app/services/leagues/matches/pick_bans/deferring_service.rb b/app/services/leagues/matches/pick_bans/deferring_service.rb index 00368871c..943679a08 100644 --- a/app/services/leagues/matches/pick_bans/deferring_service.rb +++ b/app/services/leagues/matches/pick_bans/deferring_service.rb @@ -17,13 +17,21 @@ def call(pick_ban, user) private def notify_captains!(pick_ban, kind) - msg = "#{pick_ban.roster.name} deferred their map #{kind}" + msg = "#{pick_ban.roster.name} deferred their map #{kind_noun(kind)}" link = match_path(pick_ban.match) User.which_can(:edit, pick_ban.other_roster.team).each do |captain| Users::NotificationService.call(captain, message: msg, link: link) end end + + def kind_noun(kind) + if kind == :ban + 'ban' + else + 'pick' + end + end end end end diff --git a/app/services/leagues/matches/pick_bans/submission_service.rb b/app/services/leagues/matches/pick_bans/submission_service.rb index 8f31a63d6..d5f82211a 100644 --- a/app/services/leagues/matches/pick_bans/submission_service.rb +++ b/app/services/leagues/matches/pick_bans/submission_service.rb @@ -26,7 +26,7 @@ def notify_captains!(pick_ban) end def completed_kind(pick_ban) - if pick_ban.pick? + if pick_ban.kind_pick? 'picked' else 'banned' diff --git a/app/services/leagues/rosters/creation_service.rb b/app/services/leagues/rosters/creation_service.rb index 9637a831b..3ea1eaac0 100644 --- a/app/services/leagues/rosters/creation_service.rb +++ b/app/services/leagues/rosters/creation_service.rb @@ -19,9 +19,9 @@ def call(league, team, params) private def notify_players(roster, league) - msg = 'You have been entered in '\ - "#{league.name.truncate(48, separator: ' ')} "\ - 'with '\ + msg = 'You have been entered in ' \ + "#{league.name.truncate(48, separator: ' ')} " \ + 'with ' \ "#{roster.name.truncate(48, separator: ' ')}." link = team_path(roster.team) diff --git a/app/services/leagues/rosters/score_updating_service.rb b/app/services/leagues/rosters/score_updating_service.rb index 93925572b..3b9c38dd6 100644 --- a/app/services/leagues/rosters/score_updating_service.rb +++ b/app/services/leagues/rosters/score_updating_service.rb @@ -20,7 +20,7 @@ def call_each_division(league) def call(league, division) rosters = division.rosters.select(*SCORE_ATTRIBUTES).to_a - roster_id_map = rosters.map { |roster| [roster.id, roster] }.to_h + roster_id_map = rosters.index_by(&:id) # Gather stats for later calculations roster_results = Hash.new { |h, k| h[k] = [] } @@ -119,7 +119,7 @@ def update_rosters(league, rosters, roster_results, opponents_map) ) roster.points = calculate_points(league, roster) points_map[roster.points].push roster - roster.normalized_round_score = roster.won_rounds_count * 1.0 + roster.drawn_rounds_count * 0.5 + roster.normalized_round_score = (roster.won_rounds_count * 1.0) + (roster.drawn_rounds_count * 0.5) end # Update scores based on opponents diff --git a/app/services/leagues/rosters/transfers/cancellation_service.rb b/app/services/leagues/rosters/transfers/cancellation_service.rb index d999876bb..505ce81b5 100644 --- a/app/services/leagues/rosters/transfers/cancellation_service.rb +++ b/app/services/leagues/rosters/transfers/cancellation_service.rb @@ -25,7 +25,7 @@ def request_msg(request) end def notify_user(request, user, roster) - msg = "The request for you to transfer #{request_msg(request)} "\ + msg = "The request for you to transfer #{request_msg(request)} " \ "#{roster.name} for #{roster.league.name} has been cancelled" link = team_path(roster.team) diff --git a/app/services/leagues/rosters/transfers/creation_service.rb b/app/services/leagues/rosters/transfers/creation_service.rb index 49a699ad8..fc13e6006 100644 --- a/app/services/leagues/rosters/transfers/creation_service.rb +++ b/app/services/leagues/rosters/transfers/creation_service.rb @@ -49,7 +49,7 @@ def request_msg(request) end def request_notify_user(request, user, roster) - msg = "It has been requested for you to transfer #{request_msg(request)} "\ + msg = "It has been requested for you to transfer #{request_msg(request)} " \ "#{roster.name} for #{roster.league.name}" link = team_path(roster.team) @@ -57,7 +57,7 @@ def request_notify_user(request, user, roster) end def transfer_notify_user(request, user, roster) - msg = "You have been transferred #{request_msg(request)} "\ + msg = "You have been transferred #{request_msg(request)} " \ "#{roster.name} for #{roster.league.name}" link = team_path(roster.team) diff --git a/app/views/forums/threads/_subscribe_btn.html.haml b/app/views/forums/threads/_subscribe_btn.html.haml index 4804c7e7b..535231a88 100644 --- a/app/views/forums/threads/_subscribe_btn.html.haml +++ b/app/views/forums/threads/_subscribe_btn.html.haml @@ -1,4 +1,4 @@ -- subscribed = current_user.forums_subscriptions.where(thread: thread).exists? +- subscribed = current_user.forums_subscriptions.exists?(thread: thread) = button_to toggle_subscription_for_forums_thread_path(thread), method: :patch, class: "btn btn-sm #{subscribed ? 'btn-danger' : 'btn-primary'}" do diff --git a/app/views/forums/topics/_subscribe_btn.html.haml b/app/views/forums/topics/_subscribe_btn.html.haml index 9caa1905d..f5ce03e80 100644 --- a/app/views/forums/topics/_subscribe_btn.html.haml +++ b/app/views/forums/topics/_subscribe_btn.html.haml @@ -1,4 +1,4 @@ -- subscribed = current_user.forums_subscriptions.where(topic: topic).exists? +- subscribed = current_user.forums_subscriptions.exists?(topic: topic) = button_to toggle_subscription_for_forums_topic_path(topic), method: :patch, class: "btn btn-sm #{subscribed ? 'btn-danger' : 'btn-primary'}" do diff --git a/app/views/leagues/matches/generate.html.haml b/app/views/leagues/matches/generate.html.haml index ece22ce37..65144d28a 100644 --- a/app/views/leagues/matches/generate.html.haml +++ b/app/views/leagues/matches/generate.html.haml @@ -26,7 +26,7 @@ - tournament_systems.each do |system| - klass = system == @tournament_system ? 'active' : '' .tab-pane{ id: system, class: klass } - - data_name = "#{system}_tournament".to_sym + - data_name = :"#{system}_tournament" - value = instance_variable_get("@#{data_name}") = render "leagues/matches/tournament_systems/#{system}_form", f: f, data_name => value diff --git a/app/views/leagues/matches/new.html.haml b/app/views/leagues/matches/new.html.haml index 7280fb5be..51e645980 100644 --- a/app/views/leagues/matches/new.html.haml +++ b/app/views/leagues/matches/new.html.haml @@ -13,7 +13,7 @@ - @league.divisions.each do |div| - klass = div == @division ? 'active' : '' - %a.nav-item.nav-link{ data: { toggle: 'tab' }, href: "##{div.to_s.parameterize}", class: klass } + %a.nav-item.nav-link{ data: { toggle: 'tab' }, href: "#div-#{div.id.to_s.parameterize}", class: klass } %h6.m-0 = div.name @@ -22,7 +22,7 @@ - @league.divisions.each do |div| - klass = div == @division ? 'active' : '' - %div{ id: div.to_s.parameterize, class: 'tab-pane ' + klass } + %div{ id: "div-#{div.id.to_s.parameterize}", class: 'tab-pane ' + klass } = bootstrap_form_for @match, as: :match, url: league_matches_path(@league) do |f| = hidden_field_tag :division_id, div.id diff --git a/app/views/leagues/rosters/new.html.haml b/app/views/leagues/rosters/new.html.haml index c73c6aade..29c1f0317 100644 --- a/app/views/leagues/rosters/new.html.haml +++ b/app/views/leagues/rosters/new.html.haml @@ -54,7 +54,7 @@ / Manually display errors. - if player && has_errors - - player.errors.each do |_key_, error| + - player.errors.each_value do |error| %span.help-block= error .d-flex.justify-content-end diff --git a/config.ru b/config.ru index 9797be5ae..81559b870 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. -require ::File.expand_path('config/environment', __dir__) +require File.expand_path('config/environment', __dir__) run Rails.application diff --git a/config/application.rb b/config/application.rb index 232992ec1..235e82773 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,6 +14,9 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.0 + # Use new serialization format + config.active_support.cache_format_version = 7.0 + # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading @@ -22,11 +25,14 @@ class Application < Rails::Application # Make view helpers, view specific config.action_controller.include_all_helpers = false + # New lookup logic + config.add_autoload_paths_to_load_path = false + # Use dynamic error pages config.exceptions_app = self.routes # News config file - config.news = config_for(:news) + config.news = config_for(:news).with_indifferent_access # config.middleware.use 'BadMultipartFormDataSanitizer' config.middleware.insert_before Rack::Runtime, BadMultipartFormDataSanitizer diff --git a/config/deploy.rb b/config/deploy.rb index 816d5c112..9e9fd27f9 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -23,7 +23,7 @@ set :pty, true # Files and folders to keep between deployments -set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'config/news.yml') +set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/credentials.yml.enc', 'master.key', 'config/news.yml') set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp', 'vendor/bundle', 'public/uploads') # Default value for default_env is {} diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index 5b6cd5d04..eeee88dc6 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -240,7 +240,7 @@ # ==> OmniAuth # Add a new OmniAuth provider. Check the wiki for more information on setting # up on your models and hooks. - config.omniauth :steam, Rails.application.secrets.steam_api_key + config.omniauth :steam, Rails.application.credentials.steam_api_key # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/initializers/new_framework_defaults.rb b/config/initializers/new_framework_defaults.rb index ca3ee04bc..ac2cb7e17 100644 --- a/config/initializers/new_framework_defaults.rb +++ b/config/initializers/new_framework_defaults.rb @@ -14,7 +14,7 @@ # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. # Previous versions had false. -ActiveSupport.to_time_preserves_timezone = false +ActiveSupport.to_time_preserves_timezone = true # Require `belongs_to` associations by default. Previous versions had false. ActiveRecord::Base.belongs_to_required_by_default = true diff --git a/config/rails_best_practices.yml b/config/rails_best_practices.yml index 34210861d..e55dab129 100644 --- a/config/rails_best_practices.yml +++ b/config/rails_best_practices.yml @@ -24,7 +24,7 @@ RemoveEmptyHelpersCheck: { } RemoveTabCheck: { } RemoveTrailingWhitespaceCheck: { } RemoveUnusedMethodsInControllersCheck: { except_methods: [] } -RemoveUnusedMethodsInHelpersCheck: { except_methods: [] } +# RemoveUnusedMethodsInHelpersCheck: { except_methods: [] } # RemoveUnusedMethodsInModelsCheck: { except_methods: [] } # False positives for methods used by gems ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 } ReplaceInstanceVariableWithLocalVariableCheck: { } diff --git a/config/secrets.local.yml.example b/config/secrets.local.yml.example deleted file mode 100644 index 3cdd301c1..000000000 --- a/config/secrets.local.yml.example +++ /dev/null @@ -1,10 +0,0 @@ -# This file is automatically included into secrets.yml -# Put api keys and other secrets in here - -development: - secret_key_base: ae7254e01376141d672326a7d9dbba4c551eb0650a351d2ab0ec92105b3bed468005705bb061d72ce1fba0028bc417ffaa7c3d279b68aa0f7e8aa509a7f638d0 - steam_api_key: FOOBARFOOBARFOOBARFOOBARFOOBARFOO - -test: - secret_key_base: eb1797aadd8394ef9a1f8c8032c74832953aeffed0fb12e40a3428b8af4e770819e79f08813d7a12c7fe4545771a530601466f710e4ae9cfca43654050ce0188 - steam_api_key: FOOBARFOOBARFOOBARFOOBARFOOBARFOO diff --git a/config/secrets.yml b/config/secrets.yml deleted file mode 100644 index ec29222a3..000000000 --- a/config/secrets.yml +++ /dev/null @@ -1,29 +0,0 @@ -# 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 `rake secret` to generate a secure secret key. - -# Make sure the secrets in this file are kept private -# if you're sharing your code publicly. - -default: &default - secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> - steam_api_key: <%= ENV["STEAM_API_KEY"] %> - -# Do not keep production secrets in the repository, -# instead read values from the environment or a local secrets config -<% if File.exists?('config/secrets.local.yml') %> -<%= IO.read('config/secrets.local.yml') %> -<% else %> -development: - <<: *default -test: - <<: *default -<% end %> - -production: - <<: *default diff --git a/docs/2._Database.md b/docs/2._Database.md index 54c1a0042..7b796e6d5 100644 --- a/docs/2._Database.md +++ b/docs/2._Database.md @@ -5,7 +5,7 @@ 3. [Customization](3._Customization.md) -## Database setup and management. +## Database setup and management. Citadel is using PostgreSQL as a database, we're going to add a new repository to install a recent version of Postgres easily. @@ -69,12 +69,12 @@ And then load the schema into the database: `rake db:schema:load` -Don't forget to fill in your Steam API key in `/config/secrets.local.yml` (there is an example file, you can simply copy and rename it and then change the API key to yours. +Don't forget to setup your rails credentials using `rails credentials:edit`. You'll need to add `steam_api_key: 12345` to the file. `secret_key_base` is used to generate cookies and other secrets based on this master key base. Changing it after you have users signed up will reset their authorization.) We are now ready to run our application in development: -`rails s` +`rails s` If you are working on a remote server, you may need to bind to the default ip address - run your server with `rails s -b 0.0.0.0` diff --git a/lib/auth/action_state.rb b/lib/auth/action_state.rb index a7b350f71..a62650b9b 100644 --- a/lib/auth/action_state.rb +++ b/lib/auth/action_state.rb @@ -50,7 +50,7 @@ def init_subject(subject, subject_options) end def init_singular_subject(options) - belongs_to @subject, options + belongs_to @subject, **options @subject_cls = reflect_on_all_associations(:belongs_to).second.klass @subject_cls.has_many @association_name, class_name: name, foreign_key: "#{@subject}_id", dependent: :delete_all diff --git a/lib/auth/model.rb b/lib/auth/model.rb index 3ed08842a..f29147bf3 100644 --- a/lib/auth/model.rb +++ b/lib/auth/model.rb @@ -99,7 +99,7 @@ def actor_name end def actor_id - "#{name.underscore}_id".to_sym + :"#{name.underscore}_id" end def permissions(collection = nil) diff --git a/lib/auth/permissions.rb b/lib/auth/permissions.rb index c995abea0..ce7a066cf 100644 --- a/lib/auth/permissions.rb +++ b/lib/auth/permissions.rb @@ -55,7 +55,11 @@ def instance_map end def get_actions_relation(action_model, subject) - action_model.where(actor_name => @instances).for(subject) + if subject.is_a? ActiveRecord::Base + action_model.where(actor_name => @instances, action_model.subject => subject.id) + else + action_model.where(actor_name => @instances) + end end end end diff --git a/lib/steam_id.rb b/lib/steam_id.rb index b2fe0df92..d27f7b47d 100644 --- a/lib/steam_id.rb +++ b/lib/steam_id.rb @@ -46,7 +46,7 @@ def to_id3(value) def from_32_to_64(value) account_lower, account_higher = value.scanf('STEAM_0:%d:%d') - account_lower + account_higher * 2 + UNIVERSE_0_TYPE_PUBLIC + account_lower + (account_higher * 2) + UNIVERSE_0_TYPE_PUBLIC end def from_id3_to_64(value) diff --git a/lib/validators/reduce_errors_validator.rb b/lib/validators/reduce_errors_validator.rb index ba7abaf3d..8103c841c 100644 --- a/lib/validators/reduce_errors_validator.rb +++ b/lib/validators/reduce_errors_validator.rb @@ -5,7 +5,6 @@ def validate_each(record, attribute, _value) errors = record.errors return until errors.messages.key? attribute - error = errors[attribute] - error.slice!(-1) until error.size <= 1 + errors.objects.uniq!(&:attribute) end end diff --git a/spec/controllers/pages_controller_spec.rb b/spec/controllers/pages_controller_spec.rb index 9ffe707a2..40aa47317 100644 --- a/spec/controllers/pages_controller_spec.rb +++ b/spec/controllers/pages_controller_spec.rb @@ -25,6 +25,20 @@ expect(response).to have_http_status(:success) end + + it 'hides hidden threads' do + topic = create(:forums_topic) + thread = create(:forums_thread, topic: topic) + create(:forums_thread, topic: topic, hidden: true) + + Rails.configuration.news['type'] = 'topic' + Rails.configuration.news['id'] = topic.id + + get :home + + expect(response).to have_http_status(:success) + expect(controller.view_assigns['threads']).to eq([thread]) + end end context 'invalid news config' do diff --git a/spec/controllers/users/bans_controller_spec.rb b/spec/controllers/users/bans_controller_spec.rb index 04755cbbd..7f65ea42f 100644 --- a/spec/controllers/users/bans_controller_spec.rb +++ b/spec/controllers/users/bans_controller_spec.rb @@ -31,7 +31,7 @@ describe 'POST #create' do # Need to round off to the nearest second - let(:terminated_at) { Time.zone.at((Time.zone.now + 2.days).to_i) } + let(:terminated_at) { Time.zone.at(2.days.from_now.to_i) } it 'succeeds for authorized user' do admin.grant(:edit, :users) @@ -53,7 +53,7 @@ admin.grant(:edit, :users) sign_in admin - terminated_at = Time.zone.now - 2.days + terminated_at = 2.days.ago post :create, params: { user_id: user.id, ban: { reason: 'foo', terminated_at: terminated_at }, action_: :use, subject: :leagues } diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 4786fbe48..e156402ed 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -329,7 +329,7 @@ user.save! # Jump an hour into the future - allow(Time).to receive(:current).and_return(Time.current + 1.hour) + allow(Time).to receive(:current).and_return(1.hour.from_now) patch :confirm_email, params: { token: token } diff --git a/spec/helpers/admin_helper_spec.rb b/spec/helpers/admin_helper_spec.rb deleted file mode 100644 index 2249ff837..000000000 --- a/spec/helpers/admin_helper_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'rails_helper' - -describe AdminHelper do -end diff --git a/spec/helpers/leagues_helper_spec.rb b/spec/helpers/leagues_helper_spec.rb deleted file mode 100644 index 00086dda2..000000000 --- a/spec/helpers/leagues_helper_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'rails_helper' - -describe LeaguesHelper do -end diff --git a/spec/helpers/meta/formats_helper_spec.rb b/spec/helpers/meta/formats_helper_spec.rb deleted file mode 100644 index 4ecf0f686..000000000 --- a/spec/helpers/meta/formats_helper_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'rails_helper' - -describe Meta::FormatsHelper do -end diff --git a/spec/helpers/meta/games_helper_spec.rb b/spec/helpers/meta/games_helper_spec.rb deleted file mode 100644 index c9f83650c..000000000 --- a/spec/helpers/meta/games_helper_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'rails_helper' - -describe Meta::GamesHelper do -end diff --git a/spec/helpers/teams_helper_spec.rb b/spec/helpers/teams_helper_spec.rb deleted file mode 100644 index 5a6cac749..000000000 --- a/spec/helpers/teams_helper_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'rails_helper' - -describe TeamsHelper do -end diff --git a/spec/helpers/users_helper_spec.rb b/spec/helpers/users_helper_spec.rb deleted file mode 100644 index cd96b9e8c..000000000 --- a/spec/helpers/users_helper_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'rails_helper' - -describe UsersHelper do -end diff --git a/spec/models/league/match/pick_ban_spec.rb b/spec/models/league/match/pick_ban_spec.rb index 39edbc17b..d3578ad73 100644 --- a/spec/models/league/match/pick_ban_spec.rb +++ b/spec/models/league/match/pick_ban_spec.rb @@ -7,7 +7,7 @@ it { should belong_to(:map).class_name('Map').optional } - it { should define_enum_for(:kind).with_values([:pick, :ban, :deferred]) } + it { should define_enum_for(:kind).with_values([:pick, :ban, :deferred]).with_prefix('kind') } it { should define_enum_for(:team).with_values([:home_team, :away_team]) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4cdd7886e..c10e3319a 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -54,7 +54,7 @@ end it 'has avatar' do - image = File.open(Rails.root.join('spec', 'support', 'avatar.png')) + image = Rails.root.join('spec/support/avatar.png').open expect(build(:user, avatar: image)).to be_valid end @@ -160,12 +160,12 @@ user.ban(:use, :users) expect(user.can?(:use, :users)).to be(false) - allow(Time.zone).to receive(:now).and_return(Time.zone.now + 10.years) + allow(Time.zone).to receive(:now).and_return(10.years.from_now) expect(user.can?(:use, :users)).to be(false) end it "can't ban with negative duration" do - time = Time.zone.now - 1.minute + time = 1.minute.ago expect do user.ban(:use, :users, terminated_at: time) diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f0919c909..6610215a8 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -23,7 +23,7 @@ # directory. Alternatively, in the individual `*_spec.rb` files, manually # require only the support files necessary. # -Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f } +Dir[Rails.root.join('spec/support/**/*.rb')].sort.each { |f| require f } # Checks for pending migration and applies them before tests are run. # If you are not using ActiveRecord, you can remove this line. @@ -31,7 +31,7 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = [Rails.root.join('spec/fixtures').to_s] config.before(type: :view) do view.lookup_context.prefixes = %w[application] diff --git a/spec/support/carrierwave.rb b/spec/support/carrierwave.rb index b2f43614f..214480cfb 100644 --- a/spec/support/carrierwave.rb +++ b/spec/support/carrierwave.rb @@ -1,9 +1,9 @@ RSpec.configure do |config| config.before(:suite) do - CarrierWave.root = Rails.root.join('spec', 'carrierwave') + CarrierWave.root = Rails.root.join('spec/carrierwave') end config.after(:suite) do - FileUtils.rm_rf(Rails.root.join('spec', 'carrierwave')) + FileUtils.rm_rf(Rails.root.join('spec/carrierwave')) end end diff --git a/spec/views/leagues/matches/index.html.haml_spec.rb b/spec/views/leagues/matches/index.html.haml_spec.rb index edb00c261..61204ebb1 100644 --- a/spec/views/leagues/matches/index.html.haml_spec.rb +++ b/spec/views/leagues/matches/index.html.haml_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe 'leagues/matches/index' do - let(:div) { build(:league_division) } + let(:div) { build_stubbed(:league_division) } let(:home_team) { build_stubbed(:league_roster) } let(:away_team) { build_stubbed(:league_roster) } diff --git a/spec/views/leagues/matches/show.html.haml_spec.rb b/spec/views/leagues/matches/show.html.haml_spec.rb index 46de7db00..a243f66d7 100644 --- a/spec/views/leagues/matches/show.html.haml_spec.rb +++ b/spec/views/leagues/matches/show.html.haml_spec.rb @@ -116,9 +116,7 @@ after do comms.each do |comm| - if view.user_can_edit_league? - expect(rendered).to include(comm.created_by.name) - elsif comm.exists? + if view.user_can_edit_league? || comm.exists? expect(rendered).to include(comm.created_by.name) else expect(rendered).to_not include(comm.created_by.name) diff --git a/spec/views/users/bans/index.html.haml_spec.rb b/spec/views/users/bans/index.html.haml_spec.rb index 38776397e..3b374da72 100644 --- a/spec/views/users/bans/index.html.haml_spec.rb +++ b/spec/views/users/bans/index.html.haml_spec.rb @@ -7,7 +7,7 @@ [ user.bans_for(:use, :teams).new(id: 1, user: user, created_at: Time.zone.now), user.bans_for(:use, :users).new(id: 2, user: user, created_at: Time.zone.now, duration: 1.hour), - user.bans_for(:use, :leagues).new(id: 3, user: user, created_at: Time.zone.now - 2.hours, duration: 1.hour), + user.bans_for(:use, :leagues).new(id: 3, user: user, created_at: 2.hours.ago, duration: 1.hour), ] end