Commit cf4d226c9862ecf943dc1dce8e4b61ed98bf7222
Committed by
Daniela Feitosa
1 parent
db309ec7
Exists in
master
and in
29 other branches
Domains are allowed to have hyphen
(ActionItem1978)
Showing
2 changed files
with
35 additions
and
18 deletions
Show diff stats
app/models/domain.rb
@@ -10,7 +10,7 @@ class Domain < ActiveRecord::Base | @@ -10,7 +10,7 @@ class Domain < ActiveRecord::Base | ||
10 | 10 | ||
11 | # <tt>name</tt> must be a sequence of word characters (a to z, plus 0 to 9, | 11 | # <tt>name</tt> must be a sequence of word characters (a to z, plus 0 to 9, |
12 | # plus '_'). Letters must be lowercase | 12 | # plus '_'). Letters must be lowercase |
13 | - validates_format_of :name, :with => /^([a-z0-9_]+\.)+[a-z0-9_]+$/, :message => N_('%{fn} must be composed only of lowercase latters (a to z), numbers (0 to 9) and "_"') | 13 | + validates_format_of :name, :with => /^([a-z0-9_-]+\.)+[a-z0-9_-]+$/, :message => N_('%{fn} must be composed only of lowercase latters (a to z), numbers (0 to 9), "_" and "-"') |
14 | 14 | ||
15 | # checks validations that could not be expressed using Rails' predefined | 15 | # checks validations that could not be expressed using Rails' predefined |
16 | # validations. In particular: | 16 | # validations. In particular: |
test/unit/domain_test.rb
@@ -7,23 +7,40 @@ class DomainTest < Test::Unit::TestCase | @@ -7,23 +7,40 @@ class DomainTest < Test::Unit::TestCase | ||
7 | Domain.clear_cache | 7 | Domain.clear_cache |
8 | end | 8 | end |
9 | 9 | ||
10 | - # Replace this with your real tests. | ||
11 | - def test_domain_name_format | ||
12 | - c = Domain.new | ||
13 | - assert !c.valid? | ||
14 | - assert c.errors.invalid?(:name) | ||
15 | - | ||
16 | - c.name = 'bliblibli' | ||
17 | - assert !c.valid? | ||
18 | - assert c.errors.invalid?(:name) | ||
19 | - | ||
20 | - c.name = 'EXAMPLE.NET' | ||
21 | - assert !c.valid? | ||
22 | - assert c.errors.invalid?(:name) | ||
23 | - | ||
24 | - c.name = 'test.net' | ||
25 | - c.valid? | ||
26 | - assert !c.errors.invalid?(:name) | 10 | + should 'not allow domains without name' do |
11 | + domain = Domain.new | ||
12 | + domain.valid? | ||
13 | + assert domain.errors.invalid?(:name) | ||
14 | + end | ||
15 | + | ||
16 | + should 'not allow domain without dot' do | ||
17 | + domain = Domain.new(:name => 'test') | ||
18 | + domain.valid? | ||
19 | + assert domain.errors.invalid?(:name) | ||
20 | + end | ||
21 | + | ||
22 | + should 'allow domains with dot' do | ||
23 | + domain = Domain.new(:name => 'test.org') | ||
24 | + domain.valid? | ||
25 | + assert !domain.errors.invalid?(:name) | ||
26 | + end | ||
27 | + | ||
28 | + should 'not allow domains with upper cased letters' do | ||
29 | + domain = Domain.new(:name => 'tEst.org') | ||
30 | + domain.valid? | ||
31 | + assert domain.errors.invalid?(:name) | ||
32 | + end | ||
33 | + | ||
34 | + should 'allow domains with hyphen' do | ||
35 | + domain = Domain.new(:name => 'test-domain.org') | ||
36 | + domain.valid? | ||
37 | + assert !domain.errors.invalid?(:name) | ||
38 | + end | ||
39 | + | ||
40 | + should 'allow domains with underscore' do | ||
41 | + domain = Domain.new(:name => 'test_domain.org') | ||
42 | + domain.valid? | ||
43 | + assert !domain.errors.invalid?(:name) | ||
27 | end | 44 | end |
28 | 45 | ||
29 | def test_owner | 46 | def test_owner |