Commit 1cdb65c9e64ea85c962c1a308bfaa99db0bab85e
1 parent
4054ffc2
Exists in
master
and in
28 other branches
ActionItem1188: better handling of typed URL's
Showing
7 changed files
with
39 additions
and
12 deletions
Show diff stats
app/models/enterprise.rb
... | ... | @@ -13,8 +13,9 @@ class Enterprise < Organization |
13 | 13 | settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country |
14 | 14 | |
15 | 15 | before_save do |enterprise| |
16 | - enterprise.organization_website = 'http://' + enterprise.organization_website if enterprise.organization_website && enterprise.organization_website !~ /^https?:\/\// | |
16 | + enterprise.organization_website = enterprise.maybe_add_http(enterprise.organization_website) | |
17 | 17 | end |
18 | + include MaybeAddHttp | |
18 | 19 | |
19 | 20 | def business_name |
20 | 21 | self.nickname | ... | ... |
app/models/event.rb
... | ... | @@ -100,15 +100,6 @@ class Event < Article |
100 | 100 | maybe_add_http(self.body[:link]) |
101 | 101 | end |
102 | 102 | |
103 | - protected | |
104 | - | |
105 | - def maybe_add_http(value) | |
106 | - return unless value | |
107 | - if value =~ /https?:\/\// | |
108 | - value | |
109 | - else | |
110 | - 'http://' + value | |
111 | - end | |
112 | - end | |
103 | + include MaybeAddHttp | |
113 | 104 | |
114 | 105 | end | ... | ... |
app/models/person.rb
... | ... | @@ -86,8 +86,9 @@ class Person < Profile |
86 | 86 | before_save do |person| |
87 | 87 | person.custom_formation = nil if (! person.formation.nil? && person.formation != 'Others') |
88 | 88 | person.custom_area_of_study = nil if (! person.area_of_study.nil? && person.area_of_study != 'Others') |
89 | - person.organization_website = 'http://' + person.organization_website if person.organization_website && person.organization_website !~ /^https?:\/\// | |
89 | + person.organization_website = person.maybe_add_http(person.organization_website) | |
90 | 90 | end |
91 | + include MaybeAddHttp | |
91 | 92 | |
92 | 93 | def active_fields |
93 | 94 | environment ? environment.active_person_fields : [] | ... | ... |
test/unit/enterprise_test.rb
... | ... | @@ -315,6 +315,13 @@ class EnterpriseTest < Test::Unit::TestCase |
315 | 315 | assert_equal 'http://website.without.http', p.organization_website |
316 | 316 | end |
317 | 317 | |
318 | + should 'save not add http to empty organization_website' do | |
319 | + p = Enterprise.new(:name => 'test_ent', :identifier => 'test_ent') | |
320 | + p.organization_website = '' | |
321 | + p.save! | |
322 | + assert_equal '', p.organization_website | |
323 | + end | |
324 | + | |
318 | 325 | should 'save organization_website as typed if has http' do |
319 | 326 | p = Enterprise.new(:name => 'test_ent', :identifier => 'test_ent') |
320 | 327 | p.organization_website = 'http://website.with.http' | ... | ... |
test/unit/event_test.rb
... | ... | @@ -155,6 +155,14 @@ class EventTest < ActiveSupport::TestCase |
155 | 155 | assert_equal 'http://www.gnu.org', a.link |
156 | 156 | end |
157 | 157 | |
158 | + should 'not add http:// to empty link' do | |
159 | + a = Event.new | |
160 | + a.body[:link] = '' | |
161 | + assert_equal '', a.link | |
162 | + a.body[:link] = nil | |
163 | + assert_equal '', a.link | |
164 | + end | |
165 | + | |
158 | 166 | should 'not escape HTML in description' do |
159 | 167 | a = Event.new(:description => '<p>a paragraph of text</p>', :link => 'www.gnu.org') |
160 | 168 | ... | ... |
test/unit/person_test.rb
... | ... | @@ -536,6 +536,13 @@ class PersonTest < Test::Unit::TestCase |
536 | 536 | assert_equal 'http://website.without.http', p.organization_website |
537 | 537 | end |
538 | 538 | |
539 | + should 'not add protocol for empty organization website' do | |
540 | + p = create_user('person_test').person | |
541 | + p.organization_website = '' | |
542 | + p.save | |
543 | + assert_equal '', p.organization_website | |
544 | + end | |
545 | + | |
539 | 546 | should 'save organization_website as typed if has http' do |
540 | 547 | p = create_user('person_test').person |
541 | 548 | p.organization_website = 'http://website.with.http' | ... | ... |