Commit 4226f0e213d0cce4bfe4701a87d51c4c2c32f736

Authored by Daniela Feitosa
1 parent 6cb016a7

ActionItem1086: verifying hhtp on organization_website before save

app/models/enterprise.rb
... ... @@ -12,6 +12,10 @@ class Enterprise < Organization
12 12  
13 13 settings_items :organization_website, :historic_and_current_context, :activities_short_description, :zip_code, :city, :state, :country
14 14  
  15 + before_save do |enterprise|
  16 + enterprise.organization_website = 'http://' + enterprise.organization_website if enterprise.organization_website && enterprise.organization_website !~ /^https?:\/\//
  17 + end
  18 +
15 19 def business_name
16 20 self.nickname
17 21 end
... ...
app/models/person.rb
... ... @@ -83,6 +83,7 @@ class Person < Profile
83 83 before_save do |person|
84 84 person.custom_formation = nil if (! person.formation.nil? && person.formation != 'Others')
85 85 person.custom_area_of_study = nil if (! person.area_of_study.nil? && person.area_of_study != 'Others')
  86 + person.organization_website = 'http://' + person.organization_website if person.organization_website && person.organization_website !~ /^https?:\/\//
86 87 end
87 88  
88 89 def active_fields
... ...
test/unit/enterprise_test.rb
... ... @@ -308,4 +308,18 @@ class EnterpriseTest < Test::Unit::TestCase
308 308 assert enterprise.enable_contact?
309 309 end
310 310  
  311 + should 'save organization_website with http' do
  312 + p = Enterprise.new(:name => 'test_ent', :identifier => 'test_ent')
  313 + p.organization_website = 'website.without.http'
  314 + p.save!
  315 + assert_equal 'http://website.without.http', p.organization_website
  316 + end
  317 +
  318 + should 'save organization_website as typed if has http' do
  319 + p = Enterprise.new(:name => 'test_ent', :identifier => 'test_ent')
  320 + p.organization_website = 'http://website.with.http'
  321 + p.save
  322 + assert_equal 'http://website.with.http', p.organization_website
  323 + end
  324 +
311 325 end
... ...
test/unit/person_test.rb
... ... @@ -540,4 +540,19 @@ class PersonTest < Test::Unit::TestCase
540 540  
541 541 assert !p.ask_to_join?(c)
542 542 end
  543 +
  544 + should 'save organization_website with http' do
  545 + p = create_user('person_test').person
  546 + p.organization_website = 'website.without.http'
  547 + p.save
  548 + assert_equal 'http://website.without.http', p.organization_website
  549 + end
  550 +
  551 + should 'save organization_website as typed if has http' do
  552 + p = create_user('person_test').person
  553 + p.organization_website = 'http://website.with.http'
  554 + p.save
  555 + assert_equal 'http://website.with.http', p.organization_website
  556 + end
  557 +
543 558 end
... ...