Commit 6e4a7b0458095a87b8300984a102cd9ed21bf934
1 parent
c82d3272
Exists in
master
and in
27 other branches
rails3: fix domain test
Showing
2 changed files
with
15 additions
and
13 deletions
Show diff stats
app/models/domain.rb
| @@ -19,7 +19,9 @@ class Domain < ActiveRecord::Base | @@ -19,7 +19,9 @@ class Domain < ActiveRecord::Base | ||
| 19 | # checks validations that could not be expressed using Rails' predefined | 19 | # checks validations that could not be expressed using Rails' predefined |
| 20 | # validations. In particular: | 20 | # validations. In particular: |
| 21 | # * <tt>name</tt> must not start with 'www.' | 21 | # * <tt>name</tt> must not start with 'www.' |
| 22 | - def validate | 22 | + validate :no_www |
| 23 | + | ||
| 24 | + def no_www | ||
| 23 | if self.name =~ /^www\./ | 25 | if self.name =~ /^www\./ |
| 24 | self.errors.add(:name, _('%{fn} must not start with www.').fix_i18n) | 26 | self.errors.add(:name, _('%{fn} must not start with www.').fix_i18n) |
| 25 | end | 27 | end |
test/unit/domain_test.rb
| @@ -14,38 +14,38 @@ class DomainTest < ActiveSupport::TestCase | @@ -14,38 +14,38 @@ class DomainTest < ActiveSupport::TestCase | ||
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | should 'not allow domain without dot' do | 16 | should 'not allow domain without dot' do |
| 17 | - domain = Domain.new(:name => 'test') | 17 | + domain = build(Domain, :name => 'test') |
| 18 | domain.valid? | 18 | domain.valid? |
| 19 | assert domain.errors[:name.to_s].present? | 19 | assert domain.errors[:name.to_s].present? |
| 20 | end | 20 | end |
| 21 | 21 | ||
| 22 | should 'allow domains with dot' do | 22 | should 'allow domains with dot' do |
| 23 | - domain = Domain.new(:name => 'test.org') | 23 | + domain = build(Domain, :name => 'test.org') |
| 24 | domain.valid? | 24 | domain.valid? |
| 25 | assert !domain.errors[:name.to_s].present? | 25 | assert !domain.errors[:name.to_s].present? |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | should 'not allow domains with upper cased letters' do | 28 | should 'not allow domains with upper cased letters' do |
| 29 | - domain = Domain.new(:name => 'tEst.org') | 29 | + domain = build(Domain, :name => 'tEst.org') |
| 30 | domain.valid? | 30 | domain.valid? |
| 31 | assert domain.errors[:name.to_s].present? | 31 | assert domain.errors[:name.to_s].present? |
| 32 | end | 32 | end |
| 33 | 33 | ||
| 34 | should 'allow domains with hyphen' do | 34 | should 'allow domains with hyphen' do |
| 35 | - domain = Domain.new(:name => 'test-domain.org') | 35 | + domain = build(Domain, :name => 'test-domain.org') |
| 36 | domain.valid? | 36 | domain.valid? |
| 37 | assert !domain.errors[:name.to_s].present? | 37 | assert !domain.errors[:name.to_s].present? |
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | should 'allow domains with underscore' do | 40 | should 'allow domains with underscore' do |
| 41 | - domain = Domain.new(:name => 'test_domain.org') | 41 | + domain = build(Domain, :name => 'test_domain.org') |
| 42 | domain.valid? | 42 | domain.valid? |
| 43 | assert !domain.errors[:name.to_s].present? | 43 | assert !domain.errors[:name.to_s].present? |
| 44 | end | 44 | end |
| 45 | 45 | ||
| 46 | def test_owner | 46 | def test_owner |
| 47 | - d = Domain.new(:name => 'example.com') | ||
| 48 | - d.owner = Environment.new(:name => 'Example') | 47 | + d = build(Domain, :name => 'example.com') |
| 48 | + d.owner = build(Environment, :name => 'Example') | ||
| 49 | assert d.save | 49 | assert d.save |
| 50 | assert_kind_of Environment, d.owner | 50 | assert_kind_of Environment, d.owner |
| 51 | end | 51 | end |
| @@ -59,7 +59,7 @@ class DomainTest < ActiveSupport::TestCase | @@ -59,7 +59,7 @@ class DomainTest < ActiveSupport::TestCase | ||
| 59 | d = Domain.new | 59 | d = Domain.new |
| 60 | d.name = 'www.example.net' | 60 | d.name = 'www.example.net' |
| 61 | d.valid? | 61 | d.valid? |
| 62 | - assert d.errors[:name.to_s].present? | 62 | + assert d.errors[:name.to_s].present?, "Name should not accept www." |
| 63 | 63 | ||
| 64 | d.name = 'example.net' | 64 | d.name = 'example.net' |
| 65 | d.valid? | 65 | d.valid? |
| @@ -78,9 +78,9 @@ class DomainTest < ActiveSupport::TestCase | @@ -78,9 +78,9 @@ class DomainTest < ActiveSupport::TestCase | ||
| 78 | 78 | ||
| 79 | def test_unique_name | 79 | def test_unique_name |
| 80 | Domain.delete_all | 80 | Domain.delete_all |
| 81 | - assert Domain.create(:name => 'example.net') | 81 | + assert create(Domain, :name => 'example.net') |
| 82 | 82 | ||
| 83 | - d = Domain.new(:name => 'example.net') | 83 | + d = build(Domain, :name => 'example.net') |
| 84 | assert !d.valid? | 84 | assert !d.valid? |
| 85 | assert d.errors[:name.to_s].present? | 85 | assert d.errors[:name.to_s].present? |
| 86 | end | 86 | end |
| @@ -108,12 +108,12 @@ class DomainTest < ActiveSupport::TestCase | @@ -108,12 +108,12 @@ class DomainTest < ActiveSupport::TestCase | ||
| 108 | assert_equal false, Domain.hosting_profile_at('example.com') | 108 | assert_equal false, Domain.hosting_profile_at('example.com') |
| 109 | 109 | ||
| 110 | profile = create_user('hosted_user').person | 110 | profile = create_user('hosted_user').person |
| 111 | - Domain.create!(:name => 'example.com', :owner => profile) | 111 | + create(Domain, :name => 'example.com', :owner => profile) |
| 112 | assert_equal true, Domain.hosting_profile_at('example.com') | 112 | assert_equal true, Domain.hosting_profile_at('example.com') |
| 113 | end | 113 | end |
| 114 | 114 | ||
| 115 | def test_not_report_profile_hosted_for_environment_domains | 115 | def test_not_report_profile_hosted_for_environment_domains |
| 116 | - Domain.create!(:name => 'example.com', :owner => Environment.default) | 116 | + create(Domain, :name => 'example.com', :owner => Environment.default) |
| 117 | assert_equal false, Domain.hosting_profile_at('example.com') | 117 | assert_equal false, Domain.hosting_profile_at('example.com') |
| 118 | end | 118 | end |
| 119 | 119 |