From c9f7f5a84af15cc2a675fbba679e8ba4ac2ed2ca Mon Sep 17 00:00:00 2001 From: Gust Date: Tue, 9 Sep 2014 13:29:15 +0000 Subject: [PATCH] Add database validations and tests --- lib/software_database.rb | 3 +++ test/unit/database_validation_test.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/lib/software_database.rb b/lib/software_database.rb index 3ba3481..95e78c7 100644 --- a/lib/software_database.rb +++ b/lib/software_database.rb @@ -4,6 +4,9 @@ class SoftwareDatabase < ActiveRecord::Base belongs_to :software_info belongs_to :database_description + validates_length_of :version, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)") + validates_length_of :operating_system, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)") + validates_presence_of :database_description_id, :version, :operating_system end diff --git a/test/unit/database_validation_test.rb b/test/unit/database_validation_test.rb index b1502e5..73c4fb6 100644 --- a/test/unit/database_validation_test.rb +++ b/test/unit/database_validation_test.rb @@ -33,4 +33,14 @@ class DatabaseValidationTest < ActiveSupport::TestCase @database.version = " " assert_equal true, !@database.save end + + should "Don't save database if version is too long" do + @database.version = "A too long version to be a valid version for database" + assert !@database.save + end + + should "Don't save database if operating system is too long" do + @database.operating_system = "A too long operating system to be a valid operating system for library" + assert !@database.save + end end -- libgit2 0.21.2