Commit c9f7f5a84af15cc2a675fbba679e8ba4ac2ed2ca

Authored by Gust
Committed by Gabriela Navarro
1 parent 9503be63

Add database validations and tests

Signed-off-by: Luiz Matos <luizff.matos@gmail.com>
Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
lib/software_database.rb
... ... @@ -4,6 +4,9 @@ class SoftwareDatabase &lt; ActiveRecord::Base
4 4 belongs_to :software_info
5 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 10 validates_presence_of :database_description_id, :version, :operating_system
8 11  
9 12 end
... ...
test/unit/database_validation_test.rb
... ... @@ -33,4 +33,14 @@ class DatabaseValidationTest &lt; ActiveSupport::TestCase
33 33 @database.version = " "
34 34 assert_equal true, !@database.save
35 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 46 end
... ...