Commit 165e70fbe7de4a7d7489a9d38622a017cddeb8e5
Committed by
Gabriela Navarro
1 parent
c9f7f5a8
Exists in
master
and in
5 other branches
Add operating system 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
7 additions
and
0 deletions
Show diff stats
lib/operating_system.rb
@@ -4,5 +4,7 @@ class OperatingSystem < ActiveRecord::Base | @@ -4,5 +4,7 @@ class OperatingSystem < ActiveRecord::Base | ||
4 | belongs_to :software_info | 4 | belongs_to :software_info |
5 | belongs_to :operating_system_name | 5 | belongs_to :operating_system_name |
6 | 6 | ||
7 | + validates_length_of :version, maximum: 20, too_long: _("Operating system is too long (maximum is 20 characters)") | ||
8 | + | ||
7 | validates :version, :operating_system_name, :presence=>true | 9 | validates :version, :operating_system_name, :presence=>true |
8 | end | 10 | end |
9 | \ No newline at end of file | 11 | \ No newline at end of file |
test/unit/operating_system_validation_test.rb
@@ -23,4 +23,9 @@ class OperatingSystemValidationTest < ActiveSupport::TestCase | @@ -23,4 +23,9 @@ class OperatingSystemValidationTest < ActiveSupport::TestCase | ||
23 | assert !@operating_system.save | 23 | assert !@operating_system.save |
24 | end | 24 | end |
25 | 25 | ||
26 | + should "not save if OperatingSystem have a version too long" do | ||
27 | + @operating_system.version = "A too long version to be a valid operating system version" | ||
28 | + assert !@operating_system.save | ||
29 | + end | ||
30 | + | ||
26 | end | 31 | end |