Commit fb13fffc1ccc132cd7d22a122c05fe63d20ea8ae
Committed by
Fabio Teixeira
1 parent
70a90663
Exists in
master
and in
5 other branches
Add tests of software database.
Signed-off-by: Parley Martins <parley@outlook.com>
Showing
2 changed files
with
39 additions
and
1 deletions
Show diff stats
lib/software_database.rb
| ... | ... | @@ -8,5 +8,4 @@ class SoftwareDatabase < ActiveRecord::Base |
| 8 | 8 | validates_length_of :operating_system, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)") |
| 9 | 9 | |
| 10 | 10 | validates_presence_of :database_description_id, :version, :operating_system |
| 11 | - | |
| 12 | 11 | end | ... | ... |
| ... | ... | @@ -0,0 +1,39 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
| 2 | + | |
| 3 | +class SoftwareDatabaseTest < ActiveSupport::TestCase | |
| 4 | + DatabaseDescription.create!(name: "MySQL") | |
| 5 | + | |
| 6 | + def setup | |
| 7 | + @software_database = SoftwareDatabase.new(:version => "1.0", :operating_system => "Debian") | |
| 8 | + @software_database.database_description_id = 1 | |
| 9 | + end | |
| 10 | + | |
| 11 | + should "save if all informations are filled" do | |
| 12 | + assert @software_database.save, "Database should have been saved" | |
| 13 | + end | |
| 14 | + | |
| 15 | + should "not save if database description id is empty" do | |
| 16 | + @software_database.database_description_id = nil | |
| 17 | + assert !@software_database.save, "Database description must be filled" | |
| 18 | + end | |
| 19 | + | |
| 20 | + should "not save if version is empty" do | |
| 21 | + @software_database.version = nil | |
| 22 | + assert !@software_database.save, "Version must be filled" | |
| 23 | + end | |
| 24 | + | |
| 25 | + should "not save if version has more than 20 characters" do | |
| 26 | + @software_database.version = "a"*21 | |
| 27 | + assert !@software_database.save, "Version must have until 20 characters" | |
| 28 | + end | |
| 29 | + | |
| 30 | + should "not save if operating system is empty" do | |
| 31 | + @software_database.operating_system = nil | |
| 32 | + assert !@software_database.save, "Operating system must be filled" | |
| 33 | + end | |
| 34 | + | |
| 35 | + should "not save if operating system has more than 20 characters" do | |
| 36 | + @software_database.operating_system = "a"*21 | |
| 37 | + assert !@software_database.save, "Operating system must have until 20 characters" | |
| 38 | + end | |
| 39 | +end | ... | ... |