prenultima revisión

This commit is contained in:
Jordi Pujol i Larena
2015-01-20 23:12:51 +01:00
parent f0d7a5b32c
commit fa1cfe4e6e
2 changed files with 40 additions and 41 deletions
+10 -13
View File
@@ -41,22 +41,19 @@ class Organization < ActiveRecord::Base
end
def web_url
begin
URI.parse(web)
rescue
false
end
URI.parse(web)
rescue
false
end
def ensure_url
begin
URI.parse(web)
rescue
self.web = ""
end
return if web.blank?
if !URI.parse(web).is_a? URI::HTTP
self.web = "http://" + web
if web_url
return if web.blank?
if !URI.parse(web).is_a? URI::HTTP
self.web = "http://" + web
end
else
errors.add(:web, "formato de url incorrecto")
end
end
end
+30 -28
View File
@@ -9,32 +9,34 @@ describe Organization do
end
it "2: with http" do
org = Organization.new
org.web = "http://www.casa.com"
org.ensure_url
expect(org.web).to eq "http://www.casa.com"
end
it "3: with https" do
org = Organization.new
org.web = "https://www.casa.com"
org.ensure_url
expect(org.web).to eq "https://www.casa.com"
end
it "4: blank" do
org = Organization.new
org.web = ""
org.ensure_url
expect(org.web).to eq ""
end
it "5: nil" do
org = Organization.new
org.web = ""
org.ensure_url
expect(org.web).to eq ""
end
it "6: no url" do
org = Organization.new
org.web = "la casa"
org.ensure_url
expect(org.web).to eq ""
end
org.web = "http://www.casa.com"
org.ensure_url
expect(org.web).to eq "http://www.casa.com"
end
it "3: with https" do
org = Organization.new
org.web = "https://www.casa.com"
org.ensure_url
expect(org.web).to eq "https://www.casa.com"
end
it "4: blank" do
org = Organization.new
org.web = ""
org.ensure_url
expect(org.web).to eq ""
end
it "5: nil" do
org = Organization.new
org.web = ""
org.ensure_url
expect(org.web).to eq ""
end
it "6: no url" do
org = Organization.new
org.web = "la casa"
org.ensure_url
expect(org.web).to eq "la casa"
expect(org.errors.size).to eq 1
end
end