From 7812879965f7b77b5afc8c4cfb909425037192f9 Mon Sep 17 00:00:00 2001 From: Toru Takahashi Date: Thu, 9 Aug 2018 20:27:46 +0900 Subject: [PATCH] [phase-17]Make unit test for GlossaryTerm, add test for GlossaryCategory --- test/fixtures/glossary_terms.yml | 31 +++++++++++++++++++++++++++++ test/unit/glossary_category_test.rb | 2 +- test/unit/glossary_term_test.rb | 18 ++++++++++++++--- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/glossary_terms.yml diff --git a/test/fixtures/glossary_terms.yml b/test/fixtures/glossary_terms.yml new file mode 100644 index 0000000..0e8cef5 --- /dev/null +++ b/test/fixtures/glossary_terms.yml @@ -0,0 +1,31 @@ +red: + id: 1 + project_id: 1 + category_id: 1 + name: red + +green: + id: 2 + project_id: 1 + category_id: 1 + name: green + created_at: 2018-08-08 18:18:18 + updated_at: 2018-08-08 18:18:18 + +blue: + id: 3 + project_id: 2 + category_id: 1 + name: blue + created_at: 2018-08-08 18:18:18 + updated_at: 2018-08-08 18:18:18 + +clear: + id: 4 + project_id: 1 + name: clear + created_at: 2018-08-08 18:18:18 + updated_at: 2018-08-08 18:18:18 + + + diff --git a/test/unit/glossary_category_test.rb b/test/unit/glossary_category_test.rb index dc07cf2..eea9d2d 100644 --- a/test/unit/glossary_category_test.rb +++ b/test/unit/glossary_category_test.rb @@ -10,6 +10,6 @@ class GlossaryCategoryTest < ActiveSupport::TestCase end def test_valid - assert !@category.valid? + assert @category.valid? end end diff --git a/test/unit/glossary_term_test.rb b/test/unit/glossary_term_test.rb index b142feb..bce67a5 100644 --- a/test/unit/glossary_term_test.rb +++ b/test/unit/glossary_term_test.rb @@ -1,9 +1,21 @@ require File.expand_path('../../test_helper', __FILE__) class GlossaryTermTest < ActiveSupport::TestCase + fixtures :glossary_terms + plugin_fixtures :glossary_terms - # Replace this with your real tests. - def test_truth - assert true + def setup + @term = glossary_terms('red') + end + + def test_valid + assert @term.valid? + end + + def test_invalid_without_name + @term.name = nil + assert_raises ActiveRecord::NotNullViolation do + @term.save + end end end