From 836e487565ed454d02cd3b71d769d3173324cfb6 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Thu, 28 Jul 2011 09:27:03 -0300 Subject: [PATCH] Redirecting to own domain if profile has one --- lib/needs_profile.rb | 10 +++++++++- test/functional/profile_controller_test.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/needs_profile.rb b/lib/needs_profile.rb index b3b2c51..def3b07 100644 --- a/lib/needs_profile.rb +++ b/lib/needs_profile.rb @@ -22,7 +22,15 @@ module NeedsProfile def load_profile @profile ||= environment.profiles.find_by_identifier(params[:profile]) - render_not_found unless @profile + if @profile + profile_hostname = @profile.hostname + if profile_hostname && request.host == @environment.default_hostname + params.delete(:profile) + redirect_to(Noosfero.url_options.merge(params).merge(:host => profile_hostname)) + end + else + render_not_found + end end end diff --git a/test/functional/profile_controller_test.rb b/test/functional/profile_controller_test.rb index e462398..4684391 100644 --- a/test/functional/profile_controller_test.rb +++ b/test/functional/profile_controller_test.rb @@ -1183,4 +1183,13 @@ class ProfileControllerTest < Test::Unit::TestCase end end + should 'redirect to profile domain if it has one' do + community = fast_create(Community, :name => 'community with domain') + community.domains << Domain.new(:name => 'community.example.net') + @request.stubs(:host).returns(community.environment.default_hostname) + get :index, :profile => community.identifier + assert_response :redirect + assert_redirected_to :host => 'community.example.net' + end + end -- libgit2 0.21.2