added #convert_url to add http:// when user forgot to put
Esse commit está contido em:
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 |
Referência em uma Nova Issue
Bloquear um usuário