Commit d3c41210fe0444b7bc8ad0f3257d081f432216f9
Exists in
master
and in
29 other branches
Merge branch 'textarticle_links' of https://gitlab.com/danielafeitosa/noosfero
Showing
6 changed files
with
57 additions
and
3 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -903,7 +903,7 @@ module ApplicationHelper | @@ -903,7 +903,7 @@ module ApplicationHelper | ||
903 | end | 903 | end |
904 | 904 | ||
905 | def base_url | 905 | def base_url |
906 | - environment.top_url(request.scheme) | 906 | + profile ? profile.top_url(request.scheme) : environment.top_url(request.scheme) |
907 | end | 907 | end |
908 | alias :top_url :base_url | 908 | alias :top_url :base_url |
909 | 909 |
app/models/profile.rb
@@ -572,6 +572,14 @@ class Profile < ActiveRecord::Base | @@ -572,6 +572,14 @@ class Profile < ActiveRecord::Base | ||
572 | options.merge(Noosfero.url_options) | 572 | options.merge(Noosfero.url_options) |
573 | end | 573 | end |
574 | 574 | ||
575 | + def top_url(scheme = 'http') | ||
576 | + url = scheme + '://' | ||
577 | + url << url_options[:host] | ||
578 | + url << ':' << url_options[:port].to_s if url_options.key?(:port) | ||
579 | + url << Noosfero.root('') | ||
580 | + url | ||
581 | + end | ||
582 | + | ||
575 | private :generate_url, :url_options | 583 | private :generate_url, :url_options |
576 | 584 | ||
577 | def default_hostname | 585 | def default_hostname |
app/models/text_article.rb
@@ -33,11 +33,11 @@ class TextArticle < Article | @@ -33,11 +33,11 @@ class TextArticle < Article | ||
33 | end | 33 | end |
34 | 34 | ||
35 | def change_element_path(el, attribute) | 35 | def change_element_path(el, attribute) |
36 | - fullpath = /(https?):\/\/(#{environment.default_hostname})(:\d+)?(\/.*)/.match(el[attribute]) | 36 | + fullpath = /(https?):\/\/(#{profile.default_hostname})(:\d+)?(\/.*)/.match(el[attribute]) |
37 | if fullpath | 37 | if fullpath |
38 | domain = fullpath[2] | 38 | domain = fullpath[2] |
39 | path = fullpath[4] | 39 | path = fullpath[4] |
40 | - el[attribute] = path if domain == environment.default_hostname | 40 | + el[attribute] = path if domain == profile.default_hostname |
41 | end | 41 | end |
42 | end | 42 | end |
43 | 43 |
test/unit/application_helper_test.rb
@@ -1022,6 +1022,27 @@ class ApplicationHelperTest < ActionView::TestCase | @@ -1022,6 +1022,27 @@ class ApplicationHelperTest < ActionView::TestCase | ||
1022 | assert_equal "Clone Article", label_for_clone_article(TinyMceArticle.new) | 1022 | assert_equal "Clone Article", label_for_clone_article(TinyMceArticle.new) |
1023 | end | 1023 | end |
1024 | 1024 | ||
1025 | + should "return top url of environment" do | ||
1026 | + env = Environment.default | ||
1027 | + request = mock() | ||
1028 | + request.expects(:scheme).returns('http') | ||
1029 | + stubs(:request).returns(request) | ||
1030 | + stubs(:environment).returns(env) | ||
1031 | + stubs(:profile).returns(nil) | ||
1032 | + assert_equal env.top_url('http'), top_url | ||
1033 | + end | ||
1034 | + | ||
1035 | + should "return top url considering profile" do | ||
1036 | + env = Environment.default | ||
1037 | + c = fast_create(Community) | ||
1038 | + request = mock() | ||
1039 | + request.stubs(:scheme).returns('http') | ||
1040 | + stubs(:request).returns(request) | ||
1041 | + stubs(:environment).returns(env) | ||
1042 | + stubs(:profile).returns(c) | ||
1043 | + assert_equal c.top_url, top_url | ||
1044 | + end | ||
1045 | + | ||
1025 | protected | 1046 | protected |
1026 | include NoosferoTestHelper | 1047 | include NoosferoTestHelper |
1027 | 1048 |
test/unit/profile_test.rb
@@ -256,6 +256,20 @@ class ProfileTest < ActiveSupport::TestCase | @@ -256,6 +256,20 @@ class ProfileTest < ActiveSupport::TestCase | ||
256 | assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) | 256 | assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) |
257 | end | 257 | end |
258 | 258 | ||
259 | + should 'provide environment top URL when profile has not a domain' do | ||
260 | + env = Environment.default | ||
261 | + profile = fast_create(Profile, :environment_id => env.id) | ||
262 | + assert_equal env.top_url, profile.top_url | ||
263 | + end | ||
264 | + | ||
265 | + should 'provide top URL to profile with domain' do | ||
266 | + env = Environment.default | ||
267 | + profile = fast_create(Profile, :environment_id => env.id) | ||
268 | + domain = fast_create(Domain, :name => 'example.net') | ||
269 | + profile.domains << domain | ||
270 | + assert_equal 'http://example.net', profile.top_url | ||
271 | + end | ||
272 | + | ||
259 | should 'help developers by adding a suitable port to url' do | 273 | should 'help developers by adding a suitable port to url' do |
260 | profile = build(Profile) | 274 | profile = build(Profile) |
261 | 275 |
test/unit/text_article_test.rb
@@ -85,6 +85,17 @@ class TextArticleTest < ActiveSupport::TestCase | @@ -85,6 +85,17 @@ class TextArticleTest < ActiveSupport::TestCase | ||
85 | assert_equal "<img src=\"/test.png\">", article.body | 85 | assert_equal "<img src=\"/test.png\">", article.body |
86 | end | 86 | end |
87 | 87 | ||
88 | + should 'change image path to relative for profile with own domain' do | ||
89 | + person = create_user('testuser').person | ||
90 | + person.domains << build(Domain) | ||
91 | + | ||
92 | + article = TextArticle.new(:profile => person, :name => 'test') | ||
93 | + env = Environment.default | ||
94 | + article.body = "<img src=\"http://#{person.default_hostname}:3000/link-profile.png\">" | ||
95 | + article.save! | ||
96 | + assert_equal "<img src=\"/link-profile.png\">", article.body | ||
97 | + end | ||
98 | + | ||
88 | should 'not be translatable if there is no language available on environment' do | 99 | should 'not be translatable if there is no language available on environment' do |
89 | environment = fast_create(Environment) | 100 | environment = fast_create(Environment) |
90 | environment.languages = nil | 101 | environment.languages = nil |