mercredi 20 septembre 2017

Why the validates overrides old restrictions

I very new in Rails, but my problem I have is:

When I just the type the following code:

  validates :ipaddress, :format => {
    :with => Resolv::IPv4::Regex,
    :message => 'Deve ser um endereco IP valido'
  }

All my tests works with no problem. But when I add:

  validates :ipaddress, :format => {
    :with => Resolv::IPv4::Regex,
    :message => 'Deve ser um endereco IP valido'
  }

  validates :domain, :format => {
    :with => URI.regexp,
    :message => 'Deve ser um dominio valido'
  }

The tests starts to failure and say:

F

Failure:
UrlTest#test_test_url_with_valid_IP_address 
[/home/olegario/infracrawler/test/models/url_test.rb:7]:
Test a valid IP address.
Expected: true
Actual: false


bin/rails test test/models/url_test.rb:4

..F

Failure:
UrlTest#test_test_url_using_a_valid_domain [/home/olegario/infra-
crawler/test/models/url_test.rb:19]:
Test a valid domain.
Expected: true
Actual: false

Why this is happening?

EDIT

This is the code of my tests:

test 'test an url with a IP address containing characters' do
  url = Url.new()
  url.ipaddress = '192.168.2.AAA'
  assert_equal(false, url.valid?, 'Test a invalid IP address')
end

test 'test url using a valid domain' do
  url = Url.new()
  url.domain = 'http://google.com'
  assert_equal(true, url.valid?, 'Test a valid domain')
end 

Aucun commentaire:

Enregistrer un commentaire