Commit 0b907bbd0b20a87e6eeac82afc7c6f75b5e6e5a9

Authored by Moises Machado
Committed by Antonio Terceiro
1 parent 30b741ff

ActionItem1230: fixed misuse of generate_url

app/helpers/display_helper.rb
@@ -2,7 +2,7 @@ module DisplayHelper @@ -2,7 +2,7 @@ module DisplayHelper
2 2
3 def link_to_product(product, opts={}) 3 def link_to_product(product, opts={})
4 return _('No product') unless product 4 return _('No product') unless product
5 - target = product.enterprise.enabled? ? product.enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => product) : product.enterprise.url 5 + target = product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => product) : product.enterprise.url
6 link_to content_tag( 'span', product.name ), 6 link_to content_tag( 'span', product.name ),
7 target, 7 target,
8 opts 8 opts
app/models/blog_archives_block.rb
@@ -22,7 +22,7 @@ class BlogArchivesBlock < Block @@ -22,7 +22,7 @@ class BlogArchivesBlock < Block
22 results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})")) 22 results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})"))
23 results << "<ul class='#{year}-archive'>" 23 results << "<ul class='#{year}-archive'>"
24 results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month| 24 results_by_year.group_by{|i| [ ('%02d' % i.published_at.month()), gettext(MONTHS[i.published_at.month() - 1])]}.sort.reverse.each do |month, results_by_month|
25 - results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner.generate_url(:controller => 'content_viewer', :action => 'view_page', :page => [owner.blog.path], :year => year, :month => month[0]))) 25 + results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner.blog.url.merge(:year => year, :month => month[0])))
26 end 26 end
27 results << "</ul>" 27 results << "</ul>"
28 end 28 end
app/models/product.rb
@@ -60,7 +60,7 @@ class Product &lt; ActiveRecord::Base @@ -60,7 +60,7 @@ class Product &lt; ActiveRecord::Base
60 end 60 end
61 61
62 def url 62 def url
63 - enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => id) 63 + enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => id)
64 end 64 end
65 65
66 def public? 66 def public?
app/models/products_block.rb
@@ -25,7 +25,7 @@ class ProductsBlock &lt; Block @@ -25,7 +25,7 @@ class ProductsBlock &lt; Block
25 end 25 end
26 26
27 def footer 27 def footer
28 - link_to(_('View all products'), owner.generate_url(:controller => 'catalog', :action => 'index')) 28 + link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index'))
29 end 29 end
30 30
31 settings_items :product_ids, Array 31 settings_items :product_ids, Array
app/models/profile.rb
@@ -362,6 +362,8 @@ class Profile &lt; ActiveRecord::Base @@ -362,6 +362,8 @@ class Profile &lt; ActiveRecord::Base
362 Noosfero.url_options.merge(options) 362 Noosfero.url_options.merge(options)
363 end 363 end
364 364
  365 +private :generate_url, :url_options
  366 +
365 def default_hostname 367 def default_hostname
366 @default_hostname ||= (hostname || environment.default_hostname) 368 @default_hostname ||= (hostname || environment.default_hostname)
367 end 369 end
app/models/tags_block.rb
@@ -24,7 +24,7 @@ class TagsBlock &lt; Block @@ -24,7 +24,7 @@ class TagsBlock &lt; Block
24 block_title(title) + 24 block_title(title) +
25 "\n<div class='tag_cloud'>\n"+ 25 "\n<div class='tag_cloud'>\n"+
26 tag_cloud( tags, :id, 26 tag_cloud( tags, :id,
27 - owner.generate_url(:controller => 'profile', :action => 'tag'), 27 + owner.public_profile_url.merge(:controller => 'profile', :action => 'tag'),
28 :max_size => 16, :min_size => 9 ) + 28 :max_size => 16, :min_size => 9 ) +
29 "\n</div><!-- end class='tag_cloud' -->\n"; 29 "\n</div><!-- end class='tag_cloud' -->\n";
30 end 30 end
test/functional/search_controller_test.rb
@@ -992,6 +992,15 @@ class SearchControllerTest &lt; Test::Unit::TestCase @@ -992,6 +992,15 @@ class SearchControllerTest &lt; Test::Unit::TestCase
992 assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'} 992 assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'}
993 end 993 end
994 994
  995 + should 'find products when enterprises has own hostname' do
  996 + ent = Enterprise.create!(:name => 'teste', :identifier => 'teste')
  997 + ent.domains << Domain.new(:name => 'testent.com'); ent.save!
  998 + prod = ent.products.create!(:name => 'a beautiful product')
  999 + get 'index', :query => 'beautiful', :find_in => ['products']
  1000 + assert_includes assigns(:results)[:products], prod
  1001 + end
  1002 +
  1003 +
995 ################################################################## 1004 ##################################################################
996 ################################################################## 1005 ##################################################################
997 1006
test/unit/product_test.rb
@@ -112,15 +112,12 @@ class ProductTest &lt; Test::Unit::TestCase @@ -112,15 +112,12 @@ class ProductTest &lt; Test::Unit::TestCase
112 should 'provide url' do 112 should 'provide url' do
113 product = Product.new 113 product = Product.new
114 114
115 - result = mock  
116 -  
117 enterprise = Enterprise.new 115 enterprise = Enterprise.new
118 - enterprise.expects(:generate_url).with(:controller => 'catalog', :action => 'show', :id => 999).returns(result) 116 + enterprise.expects(:public_profile_url).returns({})
119 117
120 product.expects(:id).returns(999) 118 product.expects(:id).returns(999)
121 product.expects(:enterprise).returns(enterprise) 119 product.expects(:enterprise).returns(enterprise)
122 -  
123 - assert_same result, product.url 120 + assert_equal({:controller => 'catalog', :action => 'show', :id => 999}, product.url)
124 end 121 end
125 122
126 should 'categorize also with product categorization' do 123 should 'categorize also with product categorization' do
test/unit/products_block_test.rb
@@ -123,4 +123,16 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase @@ -123,4 +123,16 @@ class ProductsBlockTest &lt; ActiveSupport::TestCase
123 end 123 end
124 end 124 end
125 125
  126 + should 'generate footer when enterprise has own hostname' do
  127 + enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise')
  128 + enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save!
  129 + enterprise.products.create!(:name => 'product one')
  130 + enterprise.products.create!(:name => 'product two')
  131 +
  132 + block.stubs(:owner).returns(enterprise)
  133 +
  134 + footer = block.footer
  135 +
  136 + assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'
  137 + end
126 end 138 end
test/unit/profile_test.rb
@@ -262,30 +262,18 @@ class ProfileTest &lt; Test::Unit::TestCase @@ -262,30 +262,18 @@ class ProfileTest &lt; Test::Unit::TestCase
262 assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url) 262 assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url)
263 end 263 end
264 264
265 - should 'generate URL' do  
266 - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)  
267 -  
268 - assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'friends' }, profile.generate_url(:controller => 'profile', :action => 'friends'))  
269 - end  
270 -  
271 - should 'provide URL options' do  
272 - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)  
273 -  
274 - assert_equal({:host => 'mycolivre.net', :profile => 'testprofile'}, profile.url_options)  
275 - end  
276 -  
277 should "use own domain name instead of environment's for home page url" do 265 should "use own domain name instead of environment's for home page url" do
278 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) 266 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
279 profile.domains << Domain.new(:name => 'micojones.net') 267 profile.domains << Domain.new(:name => 'micojones.net')
280 assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) 268 assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url)
281 end 269 end
282 270
283 - should 'help developers by adding a suitable port to url options' do 271 + should 'help developers by adding a suitable port to url' do
284 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) 272 profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
285 273
286 Noosfero.expects(:url_options).returns({ :port => 9999 }) 274 Noosfero.expects(:url_options).returns({ :port => 9999 })
287 275
288 - ok('Profile#url_options must include port option when running in development mode') { profile.url_options[:port] == 9999 } 276 + ok('Profile#url_options must include port option when running in development mode') { profile.url[:port] == 9999 }
289 end 277 end
290 278
291 should 'help developers by adding a suitable port to url options for own domain urls' do 279 should 'help developers by adding a suitable port to url options for own domain urls' do
test/unit/tags_block_test.rb
@@ -3,12 +3,12 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39; @@ -3,12 +3,12 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
3 class TagsBlockTest < Test::Unit::TestCase 3 class TagsBlockTest < Test::Unit::TestCase
4 4
5 def setup 5 def setup
6 - user = create_user('testinguser').person  
7 - user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save!  
8 - user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save!  
9 - user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! 6 + @user = create_user('testinguser').person
  7 + @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save!
  8 + @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save!
  9 + @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save!
10 10
11 - box = Box.create!(:owner => user) 11 + box = Box.create!(:owner => @user)
12 @block = TagsBlock.create!(:box => box) 12 @block = TagsBlock.create!(:box => box)
13 end 13 end
14 attr_reader :block 14 attr_reader :block
@@ -32,4 +32,9 @@ class TagsBlockTest &lt; Test::Unit::TestCase @@ -32,4 +32,9 @@ class TagsBlockTest &lt; Test::Unit::TestCase
32 assert_equal '', block.content 32 assert_equal '', block.content
33 end 33 end
34 34
  35 + should 'generate links when profile has own hostname' do
  36 + @user.domains << Domain.new(:name => 'testuser.net'); @user.save!
  37 + assert_match /profile\/testinguser\/tag\/first-tag/, block.content
  38 + end
  39 +
35 end 40 end