Skip to content

Commit

Permalink
update scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
kortirso committed Apr 17, 2024
1 parent 06decc2 commit 309a20c
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/controllers/fantasy_teams/transfers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class TransfersController < ApplicationController

before_action :find_fantasy_team
before_action :find_season, only: %i[show]
before_action :validate_season_finishing, only: %i[show]
before_action :find_lineup, only: %i[show]
before_action :check_season_maintenance, only: %i[show]
before_action :set_watchable_players, only: %i[show]
Expand Down Expand Up @@ -38,6 +39,12 @@ def find_season
@season = @fantasy_team.season
end

def validate_season_finishing
return if @season.open_transfers?

page_not_found
end

def find_lineup
@lineup = @fantasy_team.lineups.joins(:week).where(weeks: { status: Week::COMING }).first
end
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/fantasy_teams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class FantasyTeamsController < ApplicationController
include Maintenable

before_action :find_fantasy_team, only: %i[show update]
before_action :validate_season_finishing, only: %i[show]
before_action :find_fantasy_team_relationships, only: %i[show]
before_action :find_season, only: %i[create]
before_action :check_season_maintenance, only: %i[show]
Expand Down Expand Up @@ -47,6 +48,12 @@ def find_fantasy_team
@fantasy_team = Current.user.fantasy_teams.find_by!(uuid: params[:id])
end

def validate_season_finishing
return if @fantasy_team.season.open_transfers?

page_not_found
end

def find_fantasy_team_relationships
@lineup = @fantasy_team.lineups.joins(:week).where(weeks: { status: Week::COMING }).first
@season = @fantasy_team.season
Expand Down
8 changes: 8 additions & 0 deletions app/models/season.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ class Season < ApplicationRecord
def in_progress?
[ACTIVE, FINISHING].include?(status)
end

def open_transfers?
[INACTIVE, ACTIVE].include?(status)
end

def closed_transfers?
[FINISHING, FINISHED].include?(status)
end
end
2 changes: 1 addition & 1 deletion app/views/components/page_wrappers/page_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def global_user_oraculs
end

def season_in_progress?
@fantasy_team.season.in_progress?
@fantasy_team.season.open_transfers?
end

private
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/fantasy_teams/transfers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@

expect(response).to render_template :show
end

context 'for finishing season' do
before { fantasy_team.season.update!(status: Season::FINISHING) }

it 'renders 404 page' do
get :show, params: { fantasy_team_id: fantasy_team.uuid, locale: 'en' }

expect(response).to render_template 'shared/404'
end
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/fantasy_teams_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@
expect(response).to render_template :show
end
end

context 'for finishing season' do
before { fantasy_team.season.update!(status: Season::FINISHING) }

it 'renders 404 page' do
get :show, params: { id: fantasy_team.uuid, locale: 'en' }

expect(response).to render_template 'shared/404'
end
end
end
end

Expand Down

0 comments on commit 309a20c

Please sign in to comment.