diff --git a/app/models/combat.rb b/app/models/combat.rb index 7f8ee35..7529f1a 100644 --- a/app/models/combat.rb +++ b/app/models/combat.rb @@ -5,6 +5,11 @@ class Combat < ApplicationRecord belongs_to :right_fighter, class_name: 'Creature' belongs_to :winner, class_name: 'Creature', optional: true + def to_label + return "Invalid combat" unless valid? + "Combat '#{name}' entre #{left_fighter.name} et #{right_fighter.name}" + end + def baston! return if left_fighter.nil? || right_fighter.nil? diff --git a/db/seeds.rb b/db/seeds.rb index 4bfcb14..14c4a89 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -14,4 +14,13 @@ nb_creatures.times do c = Creature.create(name: rng.compose(nb_syllables), health_points: rand(6..50)) puts "Création de #{c.to_label}" +end + +3.times do |i| + combat = Combat.new(left_fighter: Creature.alive.first, right_fighter: Creature.alive.last, name: "Auto-généré #{i + 1}") + combat.baston! + combat.left_fighter.save! + combat.right_fighter.save! + combat.save! + puts combat.to_label end \ No newline at end of file