added #convert_url to add http:// when user forgot to put

Esse commit está contido em:
Antônio Roberto Silva
2014-05-07 11:34:04 -03:00
commit 15b59d44b2
4 arquivos alterados com 34 adições e 0 exclusões
+8
Ver Arquivo
@@ -6,4 +6,12 @@ class ChannelPartner < ActiveRecord::Base
validates_presence_of :channel_id, :url, :image
scope :ordered, -> { order('id desc') }
before_save :convert_url
def convert_url
unless self.url.starts_with?('http://', 'https://')
self.url = ['http://', self.url] * ''
end
end
end
+6
Ver Arquivo
@@ -15,6 +15,12 @@ FactoryGirl.define do
"foo_page_#{n}"
end
factory :channel_partner do |f|
f.url "http://google.com"
f.image File.open("#{Rails.root}/spec/support/testimg.png")
f.association :channel
end
factory :user do |f|
f.name "Foo bar"
f.password "123456"
+20
Ver Arquivo
@@ -10,4 +10,24 @@ describe ChannelPartner do
it{ should validate_presence_of field }
end
end
describe '#convert_url' do
context "with invalid url" do
let(:partner) { create(:channel_partner, url: 'www.google.com.br') }
before do
partner.convert_url
end
it { expect(partner.url).to eq('http://www.google.com.br') }
end
context "with https url" do
let(:partner) { create(:channel_partner, url: 'https://www.google.com.br') }
before do
partner.convert_url
end
it { expect(partner.url).to eq('https://www.google.com.br') }
end
end
end
Arquivo binário não exibido.

Depois

Largura:  |  Altura:  |  Tamanho: 1.8 KiB