Commit 764f9947 authored by Daniela Feitosa's avatar Daniela Feitosa
Browse files

Fixed change of imgs/links url on profiles with domain

Links and images are saved with relative path but it wasn't considering
the profile domain. Because of this, the links were broken on article
visualization.
This commit also fix the url on edition of tinymce articles.
parent e520c0fb
......@@ -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
......
......@@ -572,6 +572,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
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -85,6 +85,17 @@ class TextArticleTest < ActiveSupport::TestCase
assert_equal "<img src=\"/test.png\">", 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 = "<img src=\"http://#{person.default_hostname}:3000/link-profile.png\">"
article.save!
assert_equal "<img src=\"/link-profile.png\">", article.body
end
should 'not be translatable if there is no language available on environment' do
environment = fast_create(Environment)
environment.languages = nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment