diff --git a/lib/needs_profile.rb b/lib/needs_profile.rb index 5410ce5..4219c48 100644 --- a/lib/needs_profile.rb +++ b/lib/needs_profile.rb @@ -25,7 +25,11 @@ module NeedsProfile if @profile profile_hostname = @profile.hostname if profile_hostname && profile_hostname != request.host - params.delete(:profile) + if params[:controller] == 'content_viewer' + params[:profile] = nil + else + params.delete(:profile) + end redirect_to(Noosfero.url_options.merge(params).merge(:host => profile_hostname)) end else diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb index 6a449e0..e2b6827 100644 --- a/test/functional/content_viewer_controller_test.rb +++ b/test/functional/content_viewer_controller_test.rb @@ -218,6 +218,19 @@ class ContentViewerControllerTest < ActionController::TestCase assert_equal profile, assigns(:profile) end + should 'redirect to custom profile url when access a content using the environment domain' do + environment = Environment.default + environment.domains << Domain.create!(:name => 'environmentdomain.net') + profile = create_user('mytestuser').person + profile.domains << Domain.create!(:name => 'myowndomain.net') + profile.articles.create!(:name => 'myarticle', :body => 'test article') + + ActionController::TestRequest.any_instance.expects(:host).returns('environmentdomain.net').at_least_once + + get :view_page, :page => ['myarticle'], :profile => 'mytestuser' + assert_redirected_to 'http://myowndomain.net/myarticle' + end + should 'give link to edit the article for owner' do login_as('testinguser') xhr :get, :view_page, :profile => 'testinguser', :page => [], :toolbar => true -- libgit2 0.21.2