1
0
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:
2019-01-24 13:44:53 +00:00
parent b15bdf6410
commit c721abe1f6
3 changed files with 38 additions and 8 deletions

View File

@@ -7,11 +7,14 @@ class WeightsController < ApplicationController
# GET /weights/1.json
def show
if params[:wrestler]
respond_to do |format|
Wrestler.update(params[:wrestler].keys, params[:wrestler].values)
redirect_to @weight.tournament
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

View File

@@ -43,8 +43,12 @@ class WrestlersController < ApplicationController
@weights = @school.tournament.weights
respond_to do |format|
if @wrestler.save
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)
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 { head :no_content }
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,10 +103,14 @@ class WrestlersController < ApplicationController
@school = @wrestler.school
@wrestler.destroy
respond_to do |format|
format.html { redirect_to @school }
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
private
# Use callbacks to share common setup or constraints between actions.

View File

@@ -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