From c3af6f923230605199b7c6af934b2c6eeba6cfd2 Mon Sep 17 00:00:00 2001 From: Malaber Date: Sun, 15 Aug 2021 14:31:50 +0200 Subject: [PATCH] Rubocop -A --- app/controllers/tournaments_controller.rb | 5 +++-- app/models/match.rb | 3 ++- app/models/stage.rb | 2 +- app/services/group_stage_service.rb | 2 +- config/application.rb | 2 +- config/environments/production.rb | 2 +- config/puma.rb | 6 +++--- lib/tasks/docker.rake | 6 +++--- spec/controllers/tournaments_controller_spec.rb | 4 ++-- .../add_playoffs_to_tournament_interactor_spec.rb | 2 +- spec/services/match_service_spec.rb | 2 +- 11 files changed, 19 insertions(+), 17 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index dbfaabf..a40c6bf 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -11,9 +11,10 @@ class TournamentsController < ApplicationController # GET /tournaments def index type = index_params.fetch(:type, 'public') - if type == 'public' + case type + when 'public' tournaments = Tournament.where(public: true).order(:created_at) - elsif type == 'private' + when 'private' tournaments = Tournament.where(owner: current_user, public: false).order(:created_at) else # invalid type specified diff --git a/app/models/match.rb b/app/models/match.rb index 6e15b10..6f0a089 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true class Match < ApplicationRecord - enum state: %i[single_team not_ready not_started in_progress finished undecided] + enum state: { single_team: 0, not_ready: 1, not_started: 2, in_progress: 3, finished: 4, + undecided: 5 } belongs_to :stage, optional: true belongs_to :group, optional: true diff --git a/app/models/stage.rb b/app/models/stage.rb index 8e4267f..97eb036 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class Stage < ApplicationRecord - enum state: %i[playoff_stage intermediate_stage in_progress finished] + enum state: { playoff_stage: 0, intermediate_stage: 1, in_progress: 2, finished: 3 } belongs_to :tournament has_many :matches, dependent: :destroy diff --git a/app/services/group_stage_service.rb b/app/services/group_stage_service.rb index 71011f0..8f091b0 100644 --- a/app/services/group_stage_service.rb +++ b/app/services/group_stage_service.rb @@ -6,7 +6,7 @@ class GroupStageService raise 'Cannot generate group stage without groups' if groups.length.zero? # raise an error if the average group size is not a whole number - raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 1).zero? + raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length % 1).zero? groups = groups.map(&method(:get_group_object_from)).each_with_index { |group, i| group.number = i + 1 } Stage.new level: -1, groups: groups, state: :in_progress diff --git a/config/application.rb b/config/application.rb index 879cffc..fad1661 100644 --- a/config/application.rb +++ b/config/application.rb @@ -37,7 +37,7 @@ module TurniereBackend config.middleware.insert_before 0, Rack::Cors do allow do origins '*' - resource '*', headers: :any, methods: :any, expose: ['access-token', 'client', 'expiry', 'uid'] + resource '*', headers: :any, methods: :any, expose: %w[access-token client expiry uid] end end diff --git a/config/environments/production.rb b/config/environments/production.rb index e77ac60..9940700 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -69,7 +69,7 @@ Rails.application.configure do # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV['RAILS_LOG_TO_STDOUT'].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end diff --git a/config/puma.rb b/config/puma.rb index 940c8ba..d9a94f3 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -6,16 +6,16 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS', 5) threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch('PORT') { 3000 } +port ENV.fetch('PORT', 3000) # Specifies the `environment` that Puma will run in. # -environment ENV.fetch('RAILS_ENV') { 'development' } +environment ENV.fetch('RAILS_ENV', 'development') # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/lib/tasks/docker.rake b/lib/tasks/docker.rake index a4c97e7..7f2a908 100644 --- a/lib/tasks/docker.rake +++ b/lib/tasks/docker.rake @@ -4,13 +4,13 @@ IMAGE_NAME = 'turniere/backend' namespace :docker do desc 'Build docker image' - task :build, [:tag] do |_, args| + task build: :environment, [:tag] do |_, args| args.with_defaults(tag: 'latest') sh "docker build -t #{IMAGE_NAME}:#{args.tag} ." end desc 'Tag docker image with Travis build number' - task :tag do + task tag: :environment do next if ENV['TRAVIS_PULL_REQUEST'] != 'false' tag = "build#{ENV['TRAVIS_BUILD_NUMBER']}" @@ -18,7 +18,7 @@ namespace :docker do end desc 'Push docker image' - task :push do + task push: :environment do sh "docker push #{IMAGE_NAME}" end diff --git a/spec/controllers/tournaments_controller_spec.rb b/spec/controllers/tournaments_controller_spec.rb index 2e9307c..ae8f469 100644 --- a/spec/controllers/tournaments_controller_spec.rb +++ b/spec/controllers/tournaments_controller_spec.rb @@ -60,7 +60,7 @@ RSpec.describe TournamentsController, type: :controller do apply_authentication_headers_for @another_user get :index, params: params tournaments = deserialize_response response - expect(tournaments.filter { |t| t[:public] }.size).to eq(0) + expect(tournaments.count { |t| t[:public] }).to eq(0) end end @@ -80,7 +80,7 @@ RSpec.describe TournamentsController, type: :controller do apply_authentication_headers_for @another_user get :index, params: params tournaments = deserialize_response response - expect(tournaments.filter { |t| !t[:public] }.size).to eq(0) + expect(tournaments.count { |t| !t[:public] }).to eq(0) end end diff --git a/spec/interactors/add_playoffs_to_tournament_interactor_spec.rb b/spec/interactors/add_playoffs_to_tournament_interactor_spec.rb index e1cebfc..5749372 100644 --- a/spec/interactors/add_playoffs_to_tournament_interactor_spec.rb +++ b/spec/interactors/add_playoffs_to_tournament_interactor_spec.rb @@ -44,7 +44,7 @@ RSpec.describe AddPlayoffsToTournament, type: :interactor do end it 'adds playoffs to the tournament' do - test = group_stage_tournament_context.tournament.stages[1..-1] + test = group_stage_tournament_context.tournament.stages[1..] expect(test).to match_array(@stages) end end diff --git a/spec/services/match_service_spec.rb b/spec/services/match_service_spec.rb index 726fc55..20dc4b2 100644 --- a/spec/services/match_service_spec.rb +++ b/spec/services/match_service_spec.rb @@ -115,7 +115,7 @@ RSpec.describe MatchService do end it 'raises an exception for for 0 teams' do - expect { MatchService.generate_matches([]) }. to raise_error 'Cannot generate Matches without teams' + expect { MatchService.generate_matches([]) }.to raise_error 'Cannot generate Matches without teams' end it 'generates matches with consecutive positions' do