Start on Interactor vodoo magic
This commit is contained in:
parent
2b94e7f627
commit
2fc6d8e75b
4
Gemfile
4
Gemfile
|
|
@ -32,8 +32,12 @@ gem 'bootsnap', '>= 1.1.0', require: false
|
||||||
gem 'devise'
|
gem 'devise'
|
||||||
gem 'devise_token_auth'
|
gem 'devise_token_auth'
|
||||||
|
|
||||||
|
|
||||||
gem 'rack-cors'
|
gem 'rack-cors'
|
||||||
|
|
||||||
|
# Interactors
|
||||||
|
gem 'interactor', '~> 3.1.1'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug', platforms: %i[mri mingw x64_mingw]
|
gem 'byebug', platforms: %i[mri mingw x64_mingw]
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ GEM
|
||||||
domain_name (~> 0.5)
|
domain_name (~> 0.5)
|
||||||
i18n (1.1.1)
|
i18n (1.1.1)
|
||||||
concurrent-ruby (~> 1.0)
|
concurrent-ruby (~> 1.0)
|
||||||
|
interactor (3.1.1)
|
||||||
jaro_winkler (1.5.1)
|
jaro_winkler (1.5.1)
|
||||||
json (2.1.0)
|
json (2.1.0)
|
||||||
kramdown (1.17.0)
|
kramdown (1.17.0)
|
||||||
|
|
@ -253,6 +254,7 @@ DEPENDENCIES
|
||||||
devise_token_auth
|
devise_token_auth
|
||||||
factory_bot_rails
|
factory_bot_rails
|
||||||
faker
|
faker
|
||||||
|
interactor (~> 3.1.1)
|
||||||
listen (>= 3.0.5, < 3.2)
|
listen (>= 3.0.5, < 3.2)
|
||||||
puma (~> 3.11)
|
puma (~> 3.11)
|
||||||
rack-cors
|
rack-cors
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MatchesController < ApplicationController
|
class MatchesController < ApplicationController
|
||||||
before_action :set_match, only: [:show, :update, :destroy]
|
before_action :set_match, only: %i[show update destroy]
|
||||||
|
|
||||||
# GET /matches
|
# GET /matches
|
||||||
def index
|
def index
|
||||||
|
|
@ -39,6 +41,7 @@ class MatchesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_match
|
def set_match
|
||||||
@match = Match.find(params[:id])
|
@match = Match.find(params[:id])
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class TeamsController < ApplicationController
|
class TeamsController < ApplicationController
|
||||||
before_action :set_team, only: [:show, :update, :destroy]
|
before_action :set_team, only: %i[show update destroy]
|
||||||
|
|
||||||
# GET /teams
|
# GET /teams
|
||||||
def index
|
def index
|
||||||
|
|
@ -39,6 +41,7 @@ class TeamsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_team
|
def set_team
|
||||||
@team = Team.find(params[:id])
|
@team = Team.find(params[:id])
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class TournamentsController < ApplicationController
|
class TournamentsController < ApplicationController
|
||||||
before_action :set_tournament, only: [:show, :update, :destroy]
|
before_action :set_tournament, only: %i[show update destroy]
|
||||||
|
|
||||||
# GET /tournaments
|
# GET /tournaments
|
||||||
def index
|
def index
|
||||||
|
|
@ -39,6 +41,7 @@ class TournamentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_tournament
|
def set_tournament
|
||||||
@tournament = Tournament.find(params[:id])
|
@tournament = Tournament.find(params[:id])
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ChangeMatchScore
|
||||||
|
include Interactor
|
||||||
|
|
||||||
|
def call
|
||||||
|
context.match.score_team1 = context.score_team1
|
||||||
|
context.match.score_team2 = context.score_team2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'match'
|
||||||
|
|
||||||
|
class UpdateMatchStatus
|
||||||
|
include Interactor
|
||||||
|
|
||||||
|
def call
|
||||||
|
context.match.status = evaluate_new_match_state(context.match)
|
||||||
|
end
|
||||||
|
|
||||||
|
def evaluate_new_match_state(match)
|
||||||
|
score_team1 = match.score_team1
|
||||||
|
score_team2 = match.score_team2
|
||||||
|
if score_team1 < score_team2
|
||||||
|
return Match.team2_won
|
||||||
|
elsif score_team2 < score_team1
|
||||||
|
return Match.team1_won
|
||||||
|
else
|
||||||
|
if match.is_group_match
|
||||||
|
return Match.undecided
|
||||||
|
else
|
||||||
|
return Match.in_progress
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Match < ApplicationRecord
|
class Match < ApplicationRecord
|
||||||
|
enum status: %i[team1_won team2_won undecided in_progress not_started]
|
||||||
|
|
||||||
belongs_to :stage
|
belongs_to :stage
|
||||||
belongs_to :group
|
belongs_to :group
|
||||||
has_many :scores, dependent: :destroy
|
has_many :scores, dependent: :destroy
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class UpdateMatchScore
|
||||||
|
include Interactor::Organizer
|
||||||
|
|
||||||
|
organize ChangeMatchScore, UpdateMatchScore
|
||||||
|
end
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class MatchesControllerTest < ActionDispatch::IntegrationTest
|
class MatchesControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
|
@ -5,30 +7,30 @@ class MatchesControllerTest < ActionDispatch::IntegrationTest
|
||||||
@match = matches(:one)
|
@match = matches(:one)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test 'should get index' do
|
||||||
get matches_url, as: :json
|
get matches_url, as: :json
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should create match" do
|
test 'should create match' do
|
||||||
assert_difference('Match.count') do
|
assert_difference('Match.count') do
|
||||||
post matches_url, params: { match: { } }, as: :json
|
post matches_url, params: { match: {} }, as: :json
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_response 201
|
assert_response 201
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show match" do
|
test 'should show match' do
|
||||||
get match_url(@match), as: :json
|
get match_url(@match), as: :json
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update match" do
|
test 'should update match' do
|
||||||
patch match_url(@match), params: { match: { } }, as: :json
|
patch match_url(@match), params: { match: {} }, as: :json
|
||||||
assert_response 200
|
assert_response 200
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should destroy match" do
|
test 'should destroy match' do
|
||||||
assert_difference('Match.count', -1) do
|
assert_difference('Match.count', -1) do
|
||||||
delete match_url(@match), as: :json
|
delete match_url(@match), as: :json
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class TeamsControllerTest < ActionDispatch::IntegrationTest
|
class TeamsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
|
@ -5,30 +7,30 @@ class TeamsControllerTest < ActionDispatch::IntegrationTest
|
||||||
@team = teams(:one)
|
@team = teams(:one)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test 'should get index' do
|
||||||
get teams_url, as: :json
|
get teams_url, as: :json
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should create team" do
|
test 'should create team' do
|
||||||
assert_difference('Team.count') do
|
assert_difference('Team.count') do
|
||||||
post teams_url, params: { team: { } }, as: :json
|
post teams_url, params: { team: {} }, as: :json
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_response 201
|
assert_response 201
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show team" do
|
test 'should show team' do
|
||||||
get team_url(@team), as: :json
|
get team_url(@team), as: :json
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update team" do
|
test 'should update team' do
|
||||||
patch team_url(@team), params: { team: { } }, as: :json
|
patch team_url(@team), params: { team: {} }, as: :json
|
||||||
assert_response 200
|
assert_response 200
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should destroy team" do
|
test 'should destroy team' do
|
||||||
assert_difference('Team.count', -1) do
|
assert_difference('Team.count', -1) do
|
||||||
delete team_url(@team), as: :json
|
delete team_url(@team), as: :json
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class TournamentsControllerTest < ActionDispatch::IntegrationTest
|
class TournamentsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
|
@ -5,30 +7,30 @@ class TournamentsControllerTest < ActionDispatch::IntegrationTest
|
||||||
@tournament = tournaments(:one)
|
@tournament = tournaments(:one)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test 'should get index' do
|
||||||
get tournaments_url, as: :json
|
get tournaments_url, as: :json
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should create tournament" do
|
test 'should create tournament' do
|
||||||
assert_difference('Tournament.count') do
|
assert_difference('Tournament.count') do
|
||||||
post tournaments_url, params: { tournament: { } }, as: :json
|
post tournaments_url, params: { tournament: {} }, as: :json
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_response 201
|
assert_response 201
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should show tournament" do
|
test 'should show tournament' do
|
||||||
get tournament_url(@tournament), as: :json
|
get tournament_url(@tournament), as: :json
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should update tournament" do
|
test 'should update tournament' do
|
||||||
patch tournament_url(@tournament), params: { tournament: { } }, as: :json
|
patch tournament_url(@tournament), params: { tournament: {} }, as: :json
|
||||||
assert_response 200
|
assert_response 200
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should destroy tournament" do
|
test 'should destroy tournament' do
|
||||||
assert_difference('Tournament.count', -1) do
|
assert_difference('Tournament.count', -1) do
|
||||||
delete tournament_url(@tournament), as: :json
|
delete tournament_url(@tournament), as: :json
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue