diff --git a/app/models/mat.rb b/app/models/mat.rb index 4d36353..d798a22 100644 --- a/app/models/mat.rb +++ b/app/models/mat.rb @@ -2,6 +2,8 @@ class Mat < ActiveRecord::Base belongs_to :tournament has_many :matches + validates :name, presence: true + before_destroy do if tournament.matches.size > 0 tournament.resetMats diff --git a/app/models/school.rb b/app/models/school.rb index a7e25ae..56c183d 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -3,6 +3,7 @@ class School < ActiveRecord::Base has_many :wrestlers, dependent: :destroy has_many :deductedPoints, through: :wrestlers + validates :name, presence: true #calculate score here def pageScore diff --git a/app/models/tournament.rb b/app/models/tournament.rb index c11eee3..35477a5 100644 --- a/app/models/tournament.rb +++ b/app/models/tournament.rb @@ -9,7 +9,7 @@ class Tournament < ActiveRecord::Base has_many :wrestlers, through: :weights has_many :matches, dependent: :destroy - validates :date, presence: true + validates :date, :name, :tournament_type, :address, :director, :director_email , presence: true def daysUntil time = (Date.today - self.date).to_i diff --git a/app/models/weight.rb b/app/models/weight.rb index 02e412f..f3093f2 100644 --- a/app/models/weight.rb +++ b/app/models/weight.rb @@ -4,6 +4,8 @@ class Weight < ActiveRecord::Base has_many :matches, dependent: :destroy attr_accessor :pools + + validates :max, presence: true HS_WEIGHT_CLASSES = [106,113,120,132,138,145,152,160,170,182,195,220,285] diff --git a/app/models/wrestler.rb b/app/models/wrestler.rb index a891a38..162c7a0 100644 --- a/app/models/wrestler.rb +++ b/app/models/wrestler.rb @@ -5,6 +5,8 @@ class Wrestler < ActiveRecord::Base has_many :matches, through: :weight has_many :deductedPoints, class_name: "Teampointadjust" attr_accessor :poolNumber, :poolAdvancePoints + + validates :name, :weight_id, :school_id, presence: true before_create do self.tournament.destroyAllMatches diff --git a/test/models/mat_test.rb b/test/models/mat_test.rb index f13d33b..84ca133 100644 --- a/test/models/mat_test.rb +++ b/test/models/mat_test.rb @@ -4,4 +4,10 @@ class MatTest < ActiveSupport::TestCase test "the truth" do assert true end + + test "Mat validations" do + mat = Mat.new + assert_not mat.valid? + assert_equal [:name], mat.errors.keys + end end diff --git a/test/models/school_test.rb b/test/models/school_test.rb index 4e521f2..652b1a0 100644 --- a/test/models/school_test.rb +++ b/test/models/school_test.rb @@ -4,4 +4,10 @@ class SchoolTest < ActiveSupport::TestCase test "the truth" do assert true end + + test "School validations" do + school = School.new + assert_not school.valid? + assert_equal [:name], school.errors.keys + end end diff --git a/test/models/tournament_test.rb b/test/models/tournament_test.rb index 21ed0cc..2eb7ae9 100644 --- a/test/models/tournament_test.rb +++ b/test/models/tournament_test.rb @@ -5,9 +5,9 @@ class TournamentTest < ActiveSupport::TestCase assert true end - test "Tournament needs a date" do + test "Tournament validations" do tourney = Tournament.new assert_not tourney.valid? - assert_equal [:date], tourney.errors.keys + assert_equal [:date, :name, :tournament_type, :address, :director, :director_email], tourney.errors.keys end end diff --git a/test/models/weight_test.rb b/test/models/weight_test.rb index 96d1276..cc9f002 100644 --- a/test/models/weight_test.rb +++ b/test/models/weight_test.rb @@ -4,4 +4,10 @@ class WeightTest < ActiveSupport::TestCase test "the truth" do assert true end + + test "Weight validations" do + weight = Weight.new + assert_not weight.valid? + assert_equal [:max], weight.errors.keys + end end diff --git a/test/models/wrestler_test.rb b/test/models/wrestler_test.rb index 4b1d189..a585910 100644 --- a/test/models/wrestler_test.rb +++ b/test/models/wrestler_test.rb @@ -4,4 +4,10 @@ class WrestlerTest < ActiveSupport::TestCase test "the truth" do assert true end + + test "Wrestler validations" do + wrestler = Wrestler.new + assert_not wrestler.valid? + assert_equal [:name, :weight_id, :school_id], wrestler.errors.keys + end end