diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 27c63f4..6e9954b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -903,7 +903,7 @@ module ApplicationHelper end def base_url - environment.top_url(request.scheme) + profile ? profile.top_url(request.scheme) : environment.top_url(request.scheme) end alias :top_url :base_url diff --git a/app/models/profile.rb b/app/models/profile.rb index 7c5a0e9..def1deb 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -569,6 +569,14 @@ class Profile < ActiveRecord::Base options.merge(Noosfero.url_options) end + def top_url(scheme = 'http') + url = scheme + '://' + url << url_options[:host] + url << ':' << url_options[:port].to_s if url_options.key?(:port) + url << Noosfero.root('') + url + end + private :generate_url, :url_options def default_hostname diff --git a/app/models/text_article.rb b/app/models/text_article.rb index 66dbe9f..0d5ff76 100644 --- a/app/models/text_article.rb +++ b/app/models/text_article.rb @@ -33,11 +33,11 @@ class TextArticle < Article end def change_element_path(el, attribute) - fullpath = /(https?):\/\/(#{environment.default_hostname})(:\d+)?(\/.*)/.match(el[attribute]) + fullpath = /(https?):\/\/(#{profile.default_hostname})(:\d+)?(\/.*)/.match(el[attribute]) if fullpath domain = fullpath[2] path = fullpath[4] - el[attribute] = path if domain == environment.default_hostname + el[attribute] = path if domain == profile.default_hostname end end diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 9380071..a865173 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -1022,6 +1022,27 @@ class ApplicationHelperTest < ActionView::TestCase assert_equal "Clone Article", label_for_clone_article(TinyMceArticle.new) end + should "return top url of environment" do + env = Environment.default + request = mock() + request.expects(:scheme).returns('http') + stubs(:request).returns(request) + stubs(:environment).returns(env) + stubs(:profile).returns(nil) + assert_equal env.top_url('http'), top_url + end + + should "return top url considering profile" do + env = Environment.default + c = fast_create(Community) + request = mock() + request.stubs(:scheme).returns('http') + stubs(:request).returns(request) + stubs(:environment).returns(env) + stubs(:profile).returns(c) + assert_equal c.top_url, top_url + end + protected include NoosferoTestHelper diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 7bf13da..5a87101 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -256,6 +256,20 @@ class ProfileTest < ActiveSupport::TestCase assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) end + should 'provide environment top URL when profile has not a domain' do + env = Environment.default + profile = fast_create(Profile, :environment_id => env.id) + assert_equal env.top_url, profile.top_url + end + + should 'provide top URL to profile with domain' do + env = Environment.default + profile = fast_create(Profile, :environment_id => env.id) + domain = fast_create(Domain, :name => 'example.net') + profile.domains << domain + assert_equal 'http://example.net', profile.top_url + end + should 'help developers by adding a suitable port to url' do profile = build(Profile) diff --git a/test/unit/text_article_test.rb b/test/unit/text_article_test.rb index 500acb8..86fa417 100644 --- a/test/unit/text_article_test.rb +++ b/test/unit/text_article_test.rb @@ -85,6 +85,17 @@ class TextArticleTest < ActiveSupport::TestCase assert_equal "", article.body end + should 'change image path to relative for profile with own domain' do + person = create_user('testuser').person + person.domains << build(Domain) + + article = TextArticle.new(:profile => person, :name => 'test') + env = Environment.default + article.body = "" + article.save! + assert_equal "", article.body + end + should 'not be translatable if there is no language available on environment' do environment = fast_create(Environment) environment.languages = nil -- libgit2 0.21.2