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
|
# GET /weights/1.json
|
||||||
def show
|
def show
|
||||||
if params[:wrestler]
|
if params[:wrestler]
|
||||||
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
|
respond_to do |format|
|
||||||
redirect_to @weight.tournament
|
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
|
||||||
|
format.html { redirect_to @weight, notice: 'Seeds were successfully updated.' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@wrestlers = @weight.wrestlers
|
@wrestlers = @weight.wrestlers
|
||||||
@tournament = @weight.tournament
|
@tournament = @weight.tournament
|
||||||
|
session[:return_path] = "/weights/#{@weight.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /weights/new
|
# GET /weights/new
|
||||||
|
|||||||
@@ -43,8 +43,12 @@ class WrestlersController < ApplicationController
|
|||||||
@weights = @school.tournament.weights
|
@weights = @school.tournament.weights
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @wrestler.save
|
if @wrestler.save
|
||||||
format.html { redirect_to @school, notice: 'Wrestler was successfully created.' }
|
if session[:return_path]
|
||||||
format.json { render action: 'show', status: :created, location: @wrestler }
|
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
|
else
|
||||||
format.html { render action: 'new' }
|
format.html { render action: 'new' }
|
||||||
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
|
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
|
||||||
@@ -61,8 +65,12 @@ class WrestlersController < ApplicationController
|
|||||||
@school = @wrestler.school
|
@school = @wrestler.school
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @wrestler.update(wrestler_params)
|
if @wrestler.update(wrestler_params)
|
||||||
format.html { redirect_to @school, notice: 'Wrestler was successfully updated.' }
|
if session[:return_path]
|
||||||
format.json { head :no_content }
|
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
|
else
|
||||||
format.html { render action: 'edit' }
|
format.html { render action: 'edit' }
|
||||||
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
|
format.json { render json: @wrestler.errors, status: :unprocessable_entity }
|
||||||
@@ -95,8 +103,12 @@ class WrestlersController < ApplicationController
|
|||||||
@school = @wrestler.school
|
@school = @wrestler.school
|
||||||
@wrestler.destroy
|
@wrestler.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to @school }
|
if session[:return_path]
|
||||||
format.json { head :no_content }
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
@tournament = Tournament.find(1)
|
@tournament = Tournament.find(1)
|
||||||
# @tournament.generateMatchups
|
# @tournament.generateMatchups
|
||||||
@weight = @tournament.weights.first
|
@weight = @tournament.weights.first
|
||||||
|
@wrestler = @weight.wrestlers.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@@ -53,6 +54,20 @@ class WeightsControllerTest < ActionController::TestCase
|
|||||||
assert_redirected_to '/static_pages/not_allowed'
|
assert_redirected_to '/static_pages/not_allowed'
|
||||||
end
|
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
|
test "logged in tournament owner should get edit weight page" do
|
||||||
sign_in_owner
|
sign_in_owner
|
||||||
get_edit
|
get_edit
|
||||||
|
|||||||
Reference in New Issue
Block a user