prenultima revisión
This commit is contained in:
+10
-13
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user