Rubocop -A
This commit is contained in:
parent
0baa7901b2
commit
c3af6f9232
|
|
@ -11,9 +11,10 @@ class TournamentsController < ApplicationController
|
||||||
# GET /tournaments
|
# GET /tournaments
|
||||||
def index
|
def index
|
||||||
type = index_params.fetch(:type, 'public')
|
type = index_params.fetch(:type, 'public')
|
||||||
if type == 'public'
|
case type
|
||||||
|
when 'public'
|
||||||
tournaments = Tournament.where(public: true).order(:created_at)
|
tournaments = Tournament.where(public: true).order(:created_at)
|
||||||
elsif type == 'private'
|
when 'private'
|
||||||
tournaments = Tournament.where(owner: current_user, public: false).order(:created_at)
|
tournaments = Tournament.where(owner: current_user, public: false).order(:created_at)
|
||||||
else
|
else
|
||||||
# invalid type specified
|
# invalid type specified
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Match < ApplicationRecord
|
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 :stage, optional: true
|
||||||
belongs_to :group, optional: true
|
belongs_to :group, optional: true
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Stage < ApplicationRecord
|
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
|
belongs_to :tournament
|
||||||
has_many :matches, dependent: :destroy
|
has_many :matches, dependent: :destroy
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class GroupStageService
|
||||||
raise 'Cannot generate group stage without groups' if groups.length.zero?
|
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 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 }
|
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
|
Stage.new level: -1, groups: groups, state: :in_progress
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ module TurniereBackend
|
||||||
config.middleware.insert_before 0, Rack::Cors do
|
config.middleware.insert_before 0, Rack::Cors do
|
||||||
allow do
|
allow do
|
||||||
origins '*'
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ Rails.application.configure do
|
||||||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
|
||||||
|
|
||||||
if ENV['RAILS_LOG_TO_STDOUT'].present?
|
if ENV['RAILS_LOG_TO_STDOUT'].present?
|
||||||
logger = ActiveSupport::Logger.new(STDOUT)
|
logger = ActiveSupport::Logger.new($stdout)
|
||||||
logger.formatter = config.log_formatter
|
logger.formatter = config.log_formatter
|
||||||
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
config.logger = ActiveSupport::TaggedLogging.new(logger)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,16 @@
|
||||||
# the maximum value specified for Puma. Default is set to 5 threads for minimum
|
# 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.
|
# 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
|
threads threads_count, threads_count
|
||||||
|
|
||||||
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
|
# 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.
|
# 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.
|
# Specifies the number of `workers` to boot in clustered mode.
|
||||||
# Workers are forked webserver processes. If using threads and workers together
|
# Workers are forked webserver processes. If using threads and workers together
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ IMAGE_NAME = 'turniere/backend'
|
||||||
|
|
||||||
namespace :docker do
|
namespace :docker do
|
||||||
desc 'Build docker image'
|
desc 'Build docker image'
|
||||||
task :build, [:tag] do |_, args|
|
task build: :environment, [:tag] do |_, args|
|
||||||
args.with_defaults(tag: 'latest')
|
args.with_defaults(tag: 'latest')
|
||||||
sh "docker build -t #{IMAGE_NAME}:#{args.tag} ."
|
sh "docker build -t #{IMAGE_NAME}:#{args.tag} ."
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Tag docker image with Travis build number'
|
desc 'Tag docker image with Travis build number'
|
||||||
task :tag do
|
task tag: :environment do
|
||||||
next if ENV['TRAVIS_PULL_REQUEST'] != 'false'
|
next if ENV['TRAVIS_PULL_REQUEST'] != 'false'
|
||||||
|
|
||||||
tag = "build#{ENV['TRAVIS_BUILD_NUMBER']}"
|
tag = "build#{ENV['TRAVIS_BUILD_NUMBER']}"
|
||||||
|
|
@ -18,7 +18,7 @@ namespace :docker do
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Push docker image'
|
desc 'Push docker image'
|
||||||
task :push do
|
task push: :environment do
|
||||||
sh "docker push #{IMAGE_NAME}"
|
sh "docker push #{IMAGE_NAME}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
apply_authentication_headers_for @another_user
|
apply_authentication_headers_for @another_user
|
||||||
get :index, params: params
|
get :index, params: params
|
||||||
tournaments = deserialize_response response
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ RSpec.describe TournamentsController, type: :controller do
|
||||||
apply_authentication_headers_for @another_user
|
apply_authentication_headers_for @another_user
|
||||||
get :index, params: params
|
get :index, params: params
|
||||||
tournaments = deserialize_response response
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ RSpec.describe AddPlayoffsToTournament, type: :interactor do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'adds playoffs to the tournament' do
|
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)
|
expect(test).to match_array(@stages)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ RSpec.describe MatchService do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises an exception for for 0 teams' do
|
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
|
end
|
||||||
|
|
||||||
it 'generates matches with consecutive positions' do
|
it 'generates matches with consecutive positions' do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue