Browse Source

ajout de tests unitaires sur le model team

Lou 2 years ago
parent
commit
544537ead4
2 changed files with 17 additions and 3 deletions
  1. 2
    0
      app/models/team.rb
  2. 15
    3
      test/models/team_test.rb

+ 2
- 0
app/models/team.rb View File

@@ -1,2 +1,4 @@
1 1
 class Team < ApplicationRecord
2
+    validates :name, uniqueness: true, presence: true
3
+
2 4
 end

+ 15
- 3
test/models/team_test.rb View File

@@ -1,7 +1,19 @@
1 1
 require "test_helper"
2 2
 
3 3
 class TeamTest < ActiveSupport::TestCase
4
-  # test "the truth" do
5
-  #   assert true
6
-  # end
4
+  test "team with valid name should be created" do
5
+    team = Team.new(name: "Valid name", description: "Random description")
6
+    assert team.valid?
7
+  end
8
+
9
+  test "team with taken name should not be created" do
10
+    other_team = teams(:one)
11
+    team = Team.new(name: other_team.name, description: "Random description")
12
+    assert_not team.valid?
13
+  end
14
+
15
+  test "team without name should not be created" do
16
+    team = Team.new(description: "Random description")
17
+    assert_not team.valid?
18
+  end
7 19
 end

Loading…
Cancel
Save