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 | 19 | # checks validations that could not be expressed using Rails' predefined |
| 20 | 20 | # validations. In particular: |
| 21 | 21 | # * <tt>name</tt> must not start with 'www.' |
| 22 | - def validate | |
| 22 | + validate :no_www | |
| 23 | + | |
| 24 | + def no_www | |
| 23 | 25 | if self.name =~ /^www\./ |
| 24 | 26 | self.errors.add(:name, _('%{fn} must not start with www.').fix_i18n) |
| 25 | 27 | end | ... | ... |
test/unit/domain_test.rb
| ... | ... | @@ -14,38 +14,38 @@ class DomainTest < ActiveSupport::TestCase |
| 14 | 14 | end |
| 15 | 15 | |
| 16 | 16 | should 'not allow domain without dot' do |
| 17 | - domain = Domain.new(:name => 'test') | |
| 17 | + domain = build(Domain, :name => 'test') | |
| 18 | 18 | domain.valid? |
| 19 | 19 | assert domain.errors[:name.to_s].present? |
| 20 | 20 | end |
| 21 | 21 | |
| 22 | 22 | should 'allow domains with dot' do |
| 23 | - domain = Domain.new(:name => 'test.org') | |
| 23 | + domain = build(Domain, :name => 'test.org') | |
| 24 | 24 | domain.valid? |
| 25 | 25 | assert !domain.errors[:name.to_s].present? |
| 26 | 26 | end |
| 27 | 27 | |
| 28 | 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 | 30 | domain.valid? |
| 31 | 31 | assert domain.errors[:name.to_s].present? |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | 34 | should 'allow domains with hyphen' do |
| 35 | - domain = Domain.new(:name => 'test-domain.org') | |
| 35 | + domain = build(Domain, :name => 'test-domain.org') | |
| 36 | 36 | domain.valid? |
| 37 | 37 | assert !domain.errors[:name.to_s].present? |
| 38 | 38 | end |
| 39 | 39 | |
| 40 | 40 | should 'allow domains with underscore' do |
| 41 | - domain = Domain.new(:name => 'test_domain.org') | |
| 41 | + domain = build(Domain, :name => 'test_domain.org') | |
| 42 | 42 | domain.valid? |
| 43 | 43 | assert !domain.errors[:name.to_s].present? |
| 44 | 44 | end |
| 45 | 45 | |
| 46 | 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 | 49 | assert d.save |
| 50 | 50 | assert_kind_of Environment, d.owner |
| 51 | 51 | end |
| ... | ... | @@ -59,7 +59,7 @@ class DomainTest < ActiveSupport::TestCase |
| 59 | 59 | d = Domain.new |
| 60 | 60 | d.name = 'www.example.net' |
| 61 | 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 | 64 | d.name = 'example.net' |
| 65 | 65 | d.valid? |
| ... | ... | @@ -78,9 +78,9 @@ class DomainTest < ActiveSupport::TestCase |
| 78 | 78 | |
| 79 | 79 | def test_unique_name |
| 80 | 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 | 84 | assert !d.valid? |
| 85 | 85 | assert d.errors[:name.to_s].present? |
| 86 | 86 | end |
| ... | ... | @@ -108,12 +108,12 @@ class DomainTest < ActiveSupport::TestCase |
| 108 | 108 | assert_equal false, Domain.hosting_profile_at('example.com') |
| 109 | 109 | |
| 110 | 110 | profile = create_user('hosted_user').person |
| 111 | - Domain.create!(:name => 'example.com', :owner => profile) | |
| 111 | + create(Domain, :name => 'example.com', :owner => profile) | |
| 112 | 112 | assert_equal true, Domain.hosting_profile_at('example.com') |
| 113 | 113 | end |
| 114 | 114 | |
| 115 | 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 | 117 | assert_equal false, Domain.hosting_profile_at('example.com') |
| 118 | 118 | end |
| 119 | 119 | ... | ... |