creating facebook url

This commit is contained in:
Maikel Linke
2015-02-02 10:33:13 +11:00
parent 6fddb491db
commit 8d9f8beff3
2 changed files with 27 additions and 0 deletions

View File

@@ -41,4 +41,20 @@ class EnterpriseGroup < ActiveRecord::Base
address.firstname = address.lastname = 'unused' if address.present?
end
def facebook_url
if (facebook.blank?) then
return nil
end
if is_url? facebook then
facebook
else
'https://www.facebook.com/' + facebook
end
end
private
def is_url?(s)
s.andand.include? '://'
end
end

View File

@@ -52,4 +52,15 @@ describe EnterpriseGroup do
EnterpriseGroup.on_front_page.should == [eg1]
end
end
describe "urls" do
it 'provides a Facebook URL' do
g = create(:enterprise_group)
g.facebook_url.should be_nil
g.facebook = 'test'
g.facebook_url.should == 'https://www.facebook.com/test'
g.facebook = 'http://fb.com/test'
g.facebook_url.should == g.facebook
end
end
end