Commit c9f7f5a84af15cc2a675fbba679e8ba4ac2ed2ca
Committed by
Gabriela Navarro
1 parent
9503be63
Exists in
master
and in
5 other branches
Add database validations and tests
Signed-off-by: Luiz Matos <luizff.matos@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
2 changed files
with
13 additions
and
0 deletions
Show diff stats
lib/software_database.rb
@@ -4,6 +4,9 @@ class SoftwareDatabase < ActiveRecord::Base | @@ -4,6 +4,9 @@ class SoftwareDatabase < ActiveRecord::Base | ||
4 | belongs_to :software_info | 4 | belongs_to :software_info |
5 | belongs_to :database_description | 5 | belongs_to :database_description |
6 | 6 | ||
7 | + validates_length_of :version, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)") | ||
8 | + validates_length_of :operating_system, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)") | ||
9 | + | ||
7 | validates_presence_of :database_description_id, :version, :operating_system | 10 | validates_presence_of :database_description_id, :version, :operating_system |
8 | 11 | ||
9 | end | 12 | end |
test/unit/database_validation_test.rb
@@ -33,4 +33,14 @@ class DatabaseValidationTest < ActiveSupport::TestCase | @@ -33,4 +33,14 @@ class DatabaseValidationTest < ActiveSupport::TestCase | ||
33 | @database.version = " " | 33 | @database.version = " " |
34 | assert_equal true, !@database.save | 34 | assert_equal true, !@database.save |
35 | end | 35 | end |
36 | + | ||
37 | + should "Don't save database if version is too long" do | ||
38 | + @database.version = "A too long version to be a valid version for database" | ||
39 | + assert !@database.save | ||
40 | + end | ||
41 | + | ||
42 | + should "Don't save database if operating system is too long" do | ||
43 | + @database.operating_system = "A too long operating system to be a valid operating system for library" | ||
44 | + assert !@database.save | ||
45 | + end | ||
36 | end | 46 | end |