diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index b4dc488..fa2bc6b 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -1,3 +1,5 @@ #A enterprise is a kind of profile. According to the system concept, only enterprises can offer priducts/services class Enterprise < Profile + + validates_numericality_of :foundation_year, :only_integer => true end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index cc4b7db..ddb80ba 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -1,10 +1,65 @@ require File.dirname(__FILE__) + '/../test_helper' class EnterpriseTest < Test::Unit::TestCase - fixtures :profiles + fixtures :profiles, :virtual_communities, :users - # Replace this with your real tests. - def test_truth - assert true + def test_identifier_validation + p = Enterprise.new + p.valid? + assert p.errors.invalid?(:identifier) + + p.identifier = 'with space' + p.valid? + assert p.errors.invalid?(:identifier) + + p.identifier = 'áéíóú' + p.valid? + assert p.errors.invalid?(:identifier) + + p.identifier = 'rightformat2007' + p.valid? + assert ! p.errors.invalid?(:identifier) + + p.identifier = 'rightformat' + p.valid? + assert ! p.errors.invalid?(:identifier) + + p.identifier = 'right_format' + p.valid? + assert ! p.errors.invalid?(:identifier) + end + + def test_has_domains + p = Enterprise.new + assert_kind_of Array, p.domains + end + + def test_belongs_to_virtual_community_and_has_default + p = Enterprise.new + assert_kind_of VirtualCommunity, p.virtual_community end + + def test_cannot_rename + p1 = profiles(:johndoe) + assert_raise ArgumentError do + p1.identifier = 'bli' + end + end + + def test_numericality_year + count = Enterprise.count + + e = Enterprise.new(:identifier => 'test_numericality_year') + e.foundation_year = 'xxxx' + assert ! e.save + + e.foundation_year = 20.07 + assert ! e.save + + e.foundation_year = 2007 + assert e.save + + assert count + 1, Enterprise.count + end + end -- libgit2 0.21.2