Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
SoftwarePublico
noosfero
Commits
d3c41210
Commit
d3c41210
authored
Aug 28, 2015
by
Antonio Terceiro
Browse files
Merge branch 'textarticle_links' of
https://gitlab.com/danielafeitosa/noosfero
parents
6f535a53
764f9947
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
3 deletions
+57
-3
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+1
-1
app/models/profile.rb
app/models/profile.rb
+8
-0
app/models/text_article.rb
app/models/text_article.rb
+2
-2
test/unit/application_helper_test.rb
test/unit/application_helper_test.rb
+21
-0
test/unit/profile_test.rb
test/unit/profile_test.rb
+14
-0
test/unit/text_article_test.rb
test/unit/text_article_test.rb
+11
-0
No files found.
app/helpers/application_helper.rb
View file @
d3c41210
...
...
@@ -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
...
...
app/models/profile.rb
View file @
d3c41210
...
...
@@ -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
...
...
app/models/text_article.rb
View file @
d3c41210
...
...
@@ -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
...
...
test/unit/application_helper_test.rb
View file @
d3c41210
...
...
@@ -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
...
...
test/unit/profile_test.rb
View file @
d3c41210
...
...
@@ -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
)
...
...
test/unit/text_article_test.rb
View file @
d3c41210
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment