mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Compare commits
2 Commits
f5ddc6652d
...
0aea26967a
| Author | SHA1 | Date | |
|---|---|---|---|
| 0aea26967a | |||
| 5677f4e944 |
@@ -165,7 +165,7 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
|
||||
def create_custom_weights
|
||||
@custom = params[:customValue].to_s
|
||||
@custom = params[:customValue].split(",")
|
||||
@tournament.create_pre_defined_weights(@custom)
|
||||
redirect_to "/tournaments/#{@tournament.id}"
|
||||
end
|
||||
|
||||
@@ -31,15 +31,11 @@ class Tournament < ActiveRecord::Base
|
||||
def tournament_types
|
||||
["Pool to bracket","Modified 16 Man Double Elimination","Double Elimination 1-6"]
|
||||
end
|
||||
|
||||
def create_pre_defined_weights(value)
|
||||
|
||||
def create_pre_defined_weights(weight_classes)
|
||||
weights.destroy_all
|
||||
if value == 'hs'
|
||||
Weight::HS_WEIGHT_CLASSES.each do |w|
|
||||
weights.create(max: w)
|
||||
end
|
||||
else
|
||||
raise "Unspecified behavior"
|
||||
weight_classes.each do |w|
|
||||
weights.create(max: w)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@ class Weight < ActiveRecord::Base
|
||||
|
||||
validates :max, presence: true
|
||||
|
||||
HS_WEIGHT_CLASSES = [106,113,120,126,132,138,145,152,160,170,182,195,220,285]
|
||||
# passed via layouts/_tournament-navbar.html.erb
|
||||
# tournaments controller does a .split(',') on this string and creates an array via commas
|
||||
# tournament model runs the code via method create_pre_defined_weights
|
||||
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,145,152,160,170,182,195,220,285"
|
||||
HS_GIRLS_WEIGHT_CLASSES = "101,106,111,116,121,126,131,137,143,150,160,170,189,235"
|
||||
|
||||
before_destroy do
|
||||
self.tournament.destroy_all_matches
|
||||
|
||||
@@ -42,7 +42,8 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<li><strong>Time Savers</strong></li>
|
||||
<li><%= link_to "Create High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=hs",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Boys High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Girls High School Weights (101-235)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_GIRLS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><strong>Tournament Actions</strong></li>
|
||||
<li><%= link_to "Calculate Team Scores" , "/tournaments/#{@tournament.id}/calculate_team_scores", method: :post %></li>
|
||||
<li><%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { confirm: 'Are you sure? This will delete all current matches.' } %></li>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
Wrestling::Application.configure do
|
||||
# Settings specified here will take precedence over those in config/application.rb.
|
||||
|
||||
# allow all hostnames
|
||||
config.hosts.clear
|
||||
|
||||
# In the development environment your application's code is reloaded on
|
||||
# every request. This slows down response time but is perfect for development
|
||||
# since you don't have to restart the web server when you make code changes.
|
||||
@@ -32,9 +35,5 @@ Wrestling::Application.configure do
|
||||
#Bullet.alert = true
|
||||
#Bullet.console = true
|
||||
#Bullet.bullet_logger = true
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,4 +11,20 @@ class TournamentTest < ActiveSupport::TestCase
|
||||
assert_not tourney.valid?
|
||||
assert_equal [:date, :name, :tournament_type, :address, :director, :director_email], tourney.errors.attribute_names
|
||||
end
|
||||
|
||||
test "Tournament create_pre_defined_weights High School Boys Weights" do
|
||||
tournament = Tournament.find(1)
|
||||
tournament.create_pre_defined_weights(Weight::HS_WEIGHT_CLASSES.split(","))
|
||||
Weight::HS_WEIGHT_CLASSES.split(",").each do |weight|
|
||||
assert tournament.weights.select{|w| w.max == weight.to_i}.count == 1
|
||||
end
|
||||
end
|
||||
|
||||
test "Tournament create_pre_defined_weights High School Girls Weights" do
|
||||
tournament = Tournament.find(1)
|
||||
tournament.create_pre_defined_weights(Weight::HS_GIRLS_WEIGHT_CLASSES.split(","))
|
||||
Weight::HS_GIRLS_WEIGHT_CLASSES.split(",").each do |weight|
|
||||
assert tournament.weights.select{|w| w.max == weight.to_i}.count == 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user