Commit 97f389ba1297ef930f59f97b7ab16980e7eaeb82

Authored by Rodrigo Souto
1 parent acd66894

needs_profile: not redirect if request.host is equal to profile hostname

(ActionItem2887)
lib/needs_profile.rb
... ... @@ -24,7 +24,7 @@ module NeedsProfile
24 24 @profile ||= environment.profiles.find_by_identifier(params[:profile])
25 25 if @profile
26 26 profile_hostname = @profile.hostname
27   - if profile_hostname && request.host == @environment.default_hostname
  27 + if profile_hostname && profile_hostname != request.host
28 28 params.delete(:profile)
29 29 redirect_to(Noosfero.url_options.merge(params).merge(:host => profile_hostname))
30 30 end
... ...
test/functional/profile_editor_controller_test.rb
... ... @@ -624,6 +624,7 @@ class ProfileEditorControllerTest < ActionController::TestCase
624 624  
625 625 profile.domains << Domain.new(:name => 'myowndomain.net')
626 626 profile.environment.domains << Domain.new(:name => 'myenv.net')
  627 + ActionController::TestRequest.any_instance.stubs(:host).returns(profile.hostname)
627 628  
628 629 get :edit, :profile => profile.identifier
629 630 assert_tag :tag => 'select', :attributes => { :name => 'profile_data[preferred_domain_id]' }, :descendant => { :tag => "option", :content => 'myowndomain.net' }
... ... @@ -639,6 +640,7 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
639 640  
640 641 profile.domains << Domain.new(:name => 'myowndomain.net')
641 642 profile.environment.domains << Domain.new(:name => 'myenv.net')
  643 + ActionController::TestRequest.any_instance.stubs(:host).returns(profile.hostname)
642 644  
643 645 get :edit, :profile => profile.identifier
644 646 assert_tag :tag => "select", :attributes => { :name => 'profile_data[preferred_domain_id]'}, :descendant => { :tag => 'option', :content => '&lt;Select domain&gt;', :attributes => { :value => '' } }
... ... @@ -978,4 +980,13 @@ class ProfileEditorControllerTest &lt; ActionController::TestCase
978 980 assert_equal({}, person.reload.fields_privacy)
979 981 end
980 982  
  983 + should 'not redirect if the profile_hostname is the same as environment hostname' do
  984 + Person.any_instance.stubs(:hostname).returns('hostname.org')
  985 + Environment.any_instance.stubs(:default_hostname).returns('hostname.org')
  986 + ActionController::TestRequest.any_instance.stubs(:host).returns('hostname.org')
  987 + get :index, :profile => profile.identifier
  988 + assert_response :success
  989 + end
  990 +
  991 +
981 992 end
... ...