Commit 1e455329edcc3d9e35a9fa82102d38b33251896b
1 parent
2cb08de6
Exists in
master
and in
28 other branches
ActionItem172: generating URL hashes instead of actual URL's, since Profile#url …
…is almost always used in link_to calls git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1472 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
32 additions
and
46 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -69,14 +69,6 @@ class Article < ActiveRecord::Base |
69 | 69 | name |
70 | 70 | end |
71 | 71 | |
72 | - def public_path(with_profile = true) | |
73 | - elements = [path] | |
74 | - if with_profile | |
75 | - elements.unshift(profile.identifier) | |
76 | - end | |
77 | - "/" + elements.join('/') | |
78 | - end | |
79 | - | |
80 | 72 | def self.short_description |
81 | 73 | if self == Article |
82 | 74 | _('Article') |
... | ... | @@ -98,7 +90,7 @@ class Article < ActiveRecord::Base |
98 | 90 | end |
99 | 91 | |
100 | 92 | def url |
101 | - self.profile.url + self.public_path(false) | |
93 | + self.profile.url.merge(:page => path.split('/')) | |
102 | 94 | end |
103 | 95 | |
104 | 96 | def allow_children? | ... | ... |
app/models/change_password.rb
... | ... | @@ -2,8 +2,6 @@ |
2 | 2 | |
3 | 3 | class ChangePassword < Task |
4 | 4 | |
5 | - include Noosfero::URL | |
6 | - | |
7 | 5 | serialize :data, Hash |
8 | 6 | def data |
9 | 7 | self[:data] ||= {} |
... | ... | @@ -69,10 +67,11 @@ class ChangePassword < Task |
69 | 67 | _('Your password was changed successfully.') |
70 | 68 | end |
71 | 69 | |
70 | + include ActionController::UrlWriter | |
72 | 71 | def task_created_message |
73 | 72 | hostname = self.requestor.environment.default_hostname |
74 | 73 | code = self.code |
75 | - url = generate_url(:host => hostname, :controller => 'account', :action => 'new_password', :code => code) | |
74 | + url = url_for(:host => hostname, :controller => 'account', :action => 'new_password', :code => code) | |
76 | 75 | |
77 | 76 | lambda do |
78 | 77 | _("In order to change your password, please visit the following address:\n\n%s") % url | ... | ... |
app/models/profile.rb
... | ... | @@ -183,7 +183,6 @@ class Profile < ActiveRecord::Base |
183 | 183 | false |
184 | 184 | end |
185 | 185 | |
186 | - include ActionController::UrlWriter | |
187 | 186 | def url |
188 | 187 | generate_url(url_options.merge(:controller => 'content_viewer', :action => 'view_page', :page => [])) |
189 | 188 | end |
... | ... | @@ -197,14 +196,11 @@ class Profile < ActiveRecord::Base |
197 | 196 | end |
198 | 197 | |
199 | 198 | def generate_url(options) |
200 | - url_for(url_options.merge(options)) | |
199 | + url_options.merge(options) | |
201 | 200 | end |
202 | 201 | |
203 | 202 | def url_options |
204 | - options = { :host => self.environment.default_hostname, :profile => self.identifier} | |
205 | - options.merge!(:port => 3000) if ENV['RAILS_ENV'] == 'development' | |
206 | - | |
207 | - options | |
203 | + { :host => self.environment.default_hostname, :profile => self.identifier} | |
208 | 204 | end |
209 | 205 | |
210 | 206 | # FIXME this can be SLOW | ... | ... |
app/models/recent_documents_block.rb
app/models/rss_feed.rb
... | ... | @@ -52,6 +52,7 @@ class RssFeed < Article |
52 | 52 | 'text/xml' |
53 | 53 | end |
54 | 54 | |
55 | + include ActionController::UrlWriter | |
55 | 56 | def data |
56 | 57 | articles = |
57 | 58 | if (self.include == 'parent_and_children') && self.parent |
... | ... | @@ -68,7 +69,7 @@ class RssFeed < Article |
68 | 69 | xml.rss(:version=>"2.0") do |
69 | 70 | xml.channel do |
70 | 71 | xml.title(_("%s's RSS feed") % (self.profile.name)) |
71 | - xml.link(self.profile.url) | |
72 | + xml.link(url_for(self.profile.url)) | |
72 | 73 | xml.description(_("%s's content published at %s") % [self.profile.name, self.profile.environment.name]) |
73 | 74 | xml.language("pt_BR") |
74 | 75 | for article in articles |
... | ... | @@ -83,8 +84,8 @@ class RssFeed < Article |
83 | 84 | # rfc822 |
84 | 85 | xml.pubDate(article.created_on.rfc2822) |
85 | 86 | # link to article |
86 | - xml.link(article.url) | |
87 | - xml.guid(article.url) | |
87 | + xml.link(url_for(article.url)) | |
88 | + xml.guid(url_for(article.url)) | |
88 | 89 | end |
89 | 90 | end |
90 | 91 | end | ... | ... |
app/models/tags_block.rb
... | ... | @@ -2,6 +2,7 @@ class TagsBlock < Block |
2 | 2 | |
3 | 3 | include TagsHelper |
4 | 4 | include BlockHelper |
5 | + include ActionController::UrlWriter | |
5 | 6 | |
6 | 7 | def self.description |
7 | 8 | _('Block listing content count by tag') |
... | ... | @@ -16,7 +17,7 @@ class TagsBlock < Block |
16 | 17 | block_title(_('Tags')) + |
17 | 18 | "\n<div class='tag_cloud'>\n"+ |
18 | 19 | tag_cloud( owner.tags, :id, |
19 | - owner.generate_url(:controller => 'profile', :action => 'tag') + '/', | |
20 | + owner.generate_url(:controller => 'profile', :action => 'tag'), | |
20 | 21 | :max_size => 18, :min_size => 9 ) + |
21 | 22 | "\n</div><!-- end class='tag_cloud' -->\n"; |
22 | 23 | end | ... | ... |
app/views/cms/view.rhtml
... | ... | @@ -59,7 +59,7 @@ |
59 | 59 | <%= _('"%{article}", last changed by %{author}') % { :article => @article.name, :author => (@article.last_changed_by ? @article.last_changed_by.name : _('Unknown User')) } %> |
60 | 60 | </li> |
61 | 61 | <li> |
62 | - <%= _('Public address of this article: %s') % link_to(@article.public_path, @article.public_path) %> | |
62 | + <%= _('Public address of this article: %s') % link_to(@article.url, @article.url) %> | |
63 | 63 | </li> |
64 | 64 | <li> |
65 | 65 | <%= _('Tags:') %> <%= @article.tag_list %> | ... | ... |
test/unit/article_test.rb
... | ... | @@ -106,19 +106,6 @@ class ArticleTest < Test::Unit::TestCase |
106 | 106 | assert a4.errors.invalid?(:slug) |
107 | 107 | end |
108 | 108 | |
109 | - should 'calculate public path' do | |
110 | - # top level | |
111 | - a = profile.articles.build(:name => 'aaa') | |
112 | - a.save! | |
113 | - assert_equal "/#{profile.identifier}/aaa", a.public_path | |
114 | - | |
115 | - # child articles | |
116 | - b = profile.articles.build(:name => 'bbb') | |
117 | - b.parent = a | |
118 | - b.save! | |
119 | - assert_equal "/#{profile.identifier}/aaa/bbb", b.public_path | |
120 | - end | |
121 | - | |
122 | 109 | should 'record who did the last change' do |
123 | 110 | a = profile.articles.build(:name => 'test') |
124 | 111 | |
... | ... | @@ -172,7 +159,14 @@ class ArticleTest < Test::Unit::TestCase |
172 | 159 | article = profile.articles.build(:name => 'myarticle') |
173 | 160 | article.save! |
174 | 161 | |
175 | - assert_equal(profile.url + "/myarticle", article.url) | |
162 | + assert_equal(profile.url.merge(:page => ['myarticle']), article.url) | |
163 | + end | |
164 | + | |
165 | + should 'provide a url to itself having a parent topic' do | |
166 | + parent = profile.articles.build(:name => 'parent'); parent.save! | |
167 | + child = profile.articles.build(:name => 'child', :parent => parent); child.save! | |
168 | + | |
169 | + assert_equal(profile.url.merge(:page => [ 'parent', 'child']), child.url) | |
176 | 170 | end |
177 | 171 | |
178 | 172 | should 'associate with categories' do | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -247,23 +247,23 @@ class ProfileTest < Test::Unit::TestCase |
247 | 247 | should 'provide url to itself' do |
248 | 248 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) |
249 | 249 | |
250 | - assert_equal 'http://mycolivre.net/testprofile', profile.url | |
250 | + assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) | |
251 | 251 | end |
252 | 252 | |
253 | 253 | should 'provide URL to admin area' do |
254 | 254 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) |
255 | - assert_equal 'http://mycolivre.net/myprofile/testprofile', profile.admin_url | |
255 | + assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile_editor', :action => 'index'}, profile.admin_url) | |
256 | 256 | end |
257 | 257 | |
258 | 258 | should 'provide URL to public profile' do |
259 | 259 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) |
260 | - assert_equal 'http://mycolivre.net/profile/testprofile', profile.public_profile_url | |
260 | + assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url) | |
261 | 261 | end |
262 | 262 | |
263 | 263 | should 'generate URL' do |
264 | 264 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) |
265 | 265 | |
266 | - assert_equal 'http://mycolivre.net/profile/testprofile/friends', profile.generate_url(:controller => 'profile', :action => 'friends') | |
266 | + assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'friends' }, profile.generate_url(:controller => 'profile', :action => 'friends')) | |
267 | 267 | end |
268 | 268 | |
269 | 269 | should 'provide URL options' do | ... | ... |
test/unit/rss_feed_test.rb
... | ... | @@ -32,7 +32,7 @@ class RssFeedTest < Test::Unit::TestCase |
32 | 32 | feed = RssFeed.new(:name => 'testfeed') |
33 | 33 | feed.profile = profile |
34 | 34 | feed.save! |
35 | - | |
35 | + | |
36 | 36 | rss = feed.data |
37 | 37 | assert_match /<item><title>article 1<\/title>/, rss |
38 | 38 | assert_match /<item><title>article 2<\/title>/, rss |
... | ... | @@ -48,7 +48,7 @@ class RssFeedTest < Test::Unit::TestCase |
48 | 48 | feed = RssFeed.new(:name => 'testfeed') |
49 | 49 | feed.profile = profile |
50 | 50 | feed.save! |
51 | - | |
51 | + | |
52 | 52 | rss = feed.data |
53 | 53 | assert_no_match /<item><title>testfeed<\/title>/, rss |
54 | 54 | end |
... | ... | @@ -112,7 +112,9 @@ class RssFeedTest < Test::Unit::TestCase |
112 | 112 | feed.profile = profile |
113 | 113 | feed.save! |
114 | 114 | |
115 | - assert_match "<link>#{profile.url}</link>", feed.data | |
115 | + profile.environment.expects(:default_hostname).returns('mysite.net').at_least_once | |
116 | + | |
117 | + assert_match "<link>http://mysite.net/testuser</link>", feed.data | |
116 | 118 | end |
117 | 119 | |
118 | 120 | should 'provide link to each article' do |
... | ... | @@ -123,8 +125,8 @@ class RssFeedTest < Test::Unit::TestCase |
123 | 125 | feed.save! |
124 | 126 | |
125 | 127 | data = feed.data |
126 | - assert_match "<link>#{art.url}</link>", data | |
127 | - assert_match "<guid>#{art.url}</guid>", data | |
128 | + assert_match "<link>http://#{art.profile.environment.default_hostname}/testuser/myarticle</link>", data | |
129 | + assert_match "<guid>http://#{art.profile.environment.default_hostname}/testuser/myarticle</guid>", data | |
128 | 130 | end |
129 | 131 | |
130 | 132 | should 'be able to indicate maximum number of items' do | ... | ... |