mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
When deleting a wrestler from weights show page, it now redirects to weights show
This commit is contained in:
@@ -7,11 +7,14 @@ class WeightsController < ApplicationController
|
||||
# GET /weights/1.json
|
||||
def show
|
||||
if params[:wrestler]
|
||||
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
|
||||
redirect_to @weight.tournament
|
||||
respond_to do |format|
|
||||
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
|
||||
format.html { redirect_to @weight, notice: 'Seeds were successfully updated.' }
|
||||
end
|
||||
end
|
||||
@wrestlers = @weight.wrestlers
|
||||
@tournament = @weight.tournament
|
||||
session[:return_path] = "/weights/#{@weight.id}"
|
||||
end
|
||||
|
||||
# GET /weights/new
|
||||
|
||||
@@ -43,8 +43,12 @@ class WrestlersController < ApplicationController
|
||||
@weights = @school.tournament.weights
|
||||
respond_to do |format|
|
||||
if @wrestler.save
|
||||
format.html { redirect_to @school, notice: 'Wrestler was successfully created.' }
|
||||
format.json { render action: 'show', status: :created, location: @wrestler }
|
||||
if session[:return_path]
|
||||
format.html { redirect_to session.delete(:return_path), notice: 'Wrestler was successfully created.' }
|
||||
else
|
||||
format.html { redirect_to @school, notice: 'Wrestler was successfully created.' }
|
||||
format.json { render action: 'show', status: :created, location: @wrestler }
|
||||
end
|
||||
else
|
||||
format.html { render action: 'new' }
|
||||
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
|
||||
@@ -61,8 +65,12 @@ class WrestlersController < ApplicationController
|
||||
@school = @wrestler.school
|
||||
respond_to do |format|
|
||||
if @wrestler.update(wrestler_params)
|
||||
format.html { redirect_to @school, notice: 'Wrestler was successfully updated.' }
|
||||
format.json { head :no_content }
|
||||
if session[:return_path]
|
||||
format.html { redirect_to session.delete(:return_path), notice: 'Wrestler was successfully updated.' }
|
||||
else
|
||||
format.html { redirect_to @school, notice: 'Wrestler was successfully updated.' }
|
||||
format.json { render action: 'show', status: :created, location: @wrestler }
|
||||
end
|
||||
else
|
||||
format.html { render action: 'edit' }
|
||||
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
|
||||
@@ -95,8 +103,12 @@ class WrestlersController < ApplicationController
|
||||
@school = @wrestler.school
|
||||
@wrestler.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to @school }
|
||||
format.json { head :no_content }
|
||||
if session[:return_path]
|
||||
format.html { redirect_to session.delete(:return_path), notice: 'Wrestler was successfully deleted.' }
|
||||
else
|
||||
format.html { redirect_to @school, notice: 'Wrestler was successfully deleted.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ class WeightsControllerTest < ActionController::TestCase
|
||||
@tournament = Tournament.find(1)
|
||||
# @tournament.generateMatchups
|
||||
@weight = @tournament.weights.first
|
||||
@wrestler = @weight.wrestlers.first
|
||||
end
|
||||
|
||||
def create
|
||||
@@ -53,6 +54,20 @@ class WeightsControllerTest < ActionController::TestCase
|
||||
assert_redirected_to '/static_pages/not_allowed'
|
||||
end
|
||||
|
||||
def delete_wrestler_from_weight_show_page
|
||||
get :show, params: { id: @weight.id }
|
||||
old_controller = @controller
|
||||
@controller = WrestlersController.new
|
||||
delete :destroy, params: { id: @wrestler.id }
|
||||
@controller = old_controller
|
||||
end
|
||||
|
||||
test "redirect to weight show when deleting a wrestler from weight show" do
|
||||
sign_in_owner
|
||||
delete_wrestler_from_weight_show_page
|
||||
assert_redirected_to "/weights/#{@weight.id}"
|
||||
end
|
||||
|
||||
test "logged in tournament owner should get edit weight page" do
|
||||
sign_in_owner
|
||||
get_edit
|
||||
|
||||
Reference in New Issue
Block a user