Commit ba92876aaa98435257e608c023f330fb129940f2

Authored by AntonioTerceiro
1 parent 911de09a

ActionItem449: adding http:// also when reading


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2022 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 2 changed files with 21 additions and 6 deletions   Show diff stats
app/models/event.rb
... ... @@ -84,12 +84,21 @@ class Event < Article
84 84 end
85 85  
86 86 def link=(value)
87   - self.body[:link] =
88   - if value =~ /https?:\/\//
89   - value
90   - else
91   - 'http://' + value
92   - end
  87 + self.body[:link] = maybe_add_http(value)
  88 + end
  89 +
  90 + def link
  91 + maybe_add_http(self.body[:link])
  92 + end
  93 +
  94 + protected
  95 +
  96 + def maybe_add_http(value)
  97 + if value =~ /https?:\/\//
  98 + value
  99 + else
  100 + 'http://' + value
  101 + end
93 102 end
94 103  
95 104 end
... ...
test/unit/event_test.rb
... ... @@ -143,6 +143,12 @@ class EventTest < ActiveSupport::TestCase
143 143 assert_equal 'http://www.nohttp.net', a.link
144 144 end
145 145  
  146 + should 'add http:// when reading link' do
  147 + a = Event.new
  148 + a.body[:link] = 'www.gnu.org'
  149 + assert_equal 'http://www.gnu.org', a.link
  150 + end
  151 +
146 152 protected
147 153  
148 154 def assert_tag_in_string(text, options)
... ...