diff --git a/app/helpers/display_helper.rb b/app/helpers/display_helper.rb
index f14e08b..8409c34 100644
--- a/app/helpers/display_helper.rb
+++ b/app/helpers/display_helper.rb
@@ -2,7 +2,7 @@ module DisplayHelper
def link_to_product(product, opts={})
return _('No product') unless product
- target = product.enterprise.enabled? ? product.enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => product) : product.enterprise.url
+ target = product.enterprise.enabled? ? product.enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => product) : product.enterprise.url
link_to content_tag( 'span', product.name ),
target,
opts
diff --git a/app/models/blog_archives_block.rb b/app/models/blog_archives_block.rb
index e9093ab..fe41ff3 100644
--- a/app/models/blog_archives_block.rb
+++ b/app/models/blog_archives_block.rb
@@ -22,7 +22,7 @@ class BlogArchivesBlock < Block
results << content_tag('li', content_tag('strong', "#{year} (#{results_by_year.size})"))
results << "
"
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|
- 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])))
+ results << content_tag('li', link_to("#{month[1]} (#{results_by_month.size})", owner.blog.url.merge(:year => year, :month => month[0])))
end
results << "
"
end
diff --git a/app/models/product.rb b/app/models/product.rb
index 0885e2b..ec41f49 100644
--- a/app/models/product.rb
+++ b/app/models/product.rb
@@ -60,7 +60,7 @@ class Product < ActiveRecord::Base
end
def url
- enterprise.generate_url(:controller => 'catalog', :action => 'show', :id => id)
+ enterprise.public_profile_url.merge(:controller => 'catalog', :action => 'show', :id => id)
end
def public?
diff --git a/app/models/products_block.rb b/app/models/products_block.rb
index a438a64..8c69160 100644
--- a/app/models/products_block.rb
+++ b/app/models/products_block.rb
@@ -25,7 +25,7 @@ class ProductsBlock < Block
end
def footer
- link_to(_('View all products'), owner.generate_url(:controller => 'catalog', :action => 'index'))
+ link_to(_('View all products'), owner.public_profile_url.merge(:controller => 'catalog', :action => 'index'))
end
settings_items :product_ids, Array
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 4788089..ecfdd9f 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -362,6 +362,8 @@ class Profile < ActiveRecord::Base
Noosfero.url_options.merge(options)
end
+private :generate_url, :url_options
+
def default_hostname
@default_hostname ||= (hostname || environment.default_hostname)
end
diff --git a/app/models/tags_block.rb b/app/models/tags_block.rb
index cf9f961..1f7aa08 100644
--- a/app/models/tags_block.rb
+++ b/app/models/tags_block.rb
@@ -24,7 +24,7 @@ class TagsBlock < Block
block_title(title) +
"\n\n"+
tag_cloud( tags, :id,
- owner.generate_url(:controller => 'profile', :action => 'tag'),
+ owner.public_profile_url.merge(:controller => 'profile', :action => 'tag'),
:max_size => 16, :min_size => 9 ) +
"\n
\n";
end
diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb
index 439fe92..1df420d 100644
--- a/test/functional/search_controller_test.rb
+++ b/test/functional/search_controller_test.rb
@@ -992,6 +992,15 @@ class SearchControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'}
end
+ should 'find products when enterprises has own hostname' do
+ ent = Enterprise.create!(:name => 'teste', :identifier => 'teste')
+ ent.domains << Domain.new(:name => 'testent.com'); ent.save!
+ prod = ent.products.create!(:name => 'a beautiful product')
+ get 'index', :query => 'beautiful', :find_in => ['products']
+ assert_includes assigns(:results)[:products], prod
+ end
+
+
##################################################################
##################################################################
diff --git a/test/unit/product_test.rb b/test/unit/product_test.rb
index 7a721f7..f7ce3d9 100644
--- a/test/unit/product_test.rb
+++ b/test/unit/product_test.rb
@@ -112,15 +112,12 @@ class ProductTest < Test::Unit::TestCase
should 'provide url' do
product = Product.new
- result = mock
-
enterprise = Enterprise.new
- enterprise.expects(:generate_url).with(:controller => 'catalog', :action => 'show', :id => 999).returns(result)
+ enterprise.expects(:public_profile_url).returns({})
product.expects(:id).returns(999)
product.expects(:enterprise).returns(enterprise)
-
- assert_same result, product.url
+ assert_equal({:controller => 'catalog', :action => 'show', :id => 999}, product.url)
end
should 'categorize also with product categorization' do
diff --git a/test/unit/products_block_test.rb b/test/unit/products_block_test.rb
index 3f1295d..d140190 100644
--- a/test/unit/products_block_test.rb
+++ b/test/unit/products_block_test.rb
@@ -123,4 +123,16 @@ class ProductsBlockTest < ActiveSupport::TestCase
end
end
+ should 'generate footer when enterprise has own hostname' do
+ enterprise = Enterprise.create!(:name => 'testenterprise', :identifier => 'testenterprise')
+ enterprise.domains << Domain.new(:name => 'sometest.com'); enterprise.save!
+ enterprise.products.create!(:name => 'product one')
+ enterprise.products.create!(:name => 'product two')
+
+ block.stubs(:owner).returns(enterprise)
+
+ footer = block.footer
+
+ assert_tag_in_string footer, :tag => 'a', :attributes => { :href => /\/catalog\/testenterprise$/ }, :content => 'View all products'
+ end
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 5f8890c..1d91359 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -262,30 +262,18 @@ class ProfileTest < Test::Unit::TestCase
assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'index' }, profile.public_profile_url)
end
- should 'generate URL' do
- profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
-
- assert_equal({ :host => 'mycolivre.net', :profile => 'testprofile', :controller => 'profile', :action => 'friends' }, profile.generate_url(:controller => 'profile', :action => 'friends'))
- end
-
- should 'provide URL options' do
- profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
-
- assert_equal({:host => 'mycolivre.net', :profile => 'testprofile'}, profile.url_options)
- end
-
should "use own domain name instead of environment's for home page url" do
profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
profile.domains << Domain.new(:name => 'micojones.net')
assert_equal({:host => 'micojones.net', :profile => nil, :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url)
end
- should 'help developers by adding a suitable port to url options' do
+ should 'help developers by adding a suitable port to url' do
profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id)
Noosfero.expects(:url_options).returns({ :port => 9999 })
- ok('Profile#url_options must include port option when running in development mode') { profile.url_options[:port] == 9999 }
+ ok('Profile#url_options must include port option when running in development mode') { profile.url[:port] == 9999 }
end
should 'help developers by adding a suitable port to url options for own domain urls' do
diff --git a/test/unit/tags_block_test.rb b/test/unit/tags_block_test.rb
index 49b7a82..bc086f2 100644
--- a/test/unit/tags_block_test.rb
+++ b/test/unit/tags_block_test.rb
@@ -3,12 +3,12 @@ require File.dirname(__FILE__) + '/../test_helper'
class TagsBlockTest < Test::Unit::TestCase
def setup
- user = create_user('testinguser').person
- user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save!
- user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save!
- user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save!
+ @user = create_user('testinguser').person
+ @user.articles.build(:name => 'article 1', :tag_list => 'first-tag').save!
+ @user.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save!
+ @user.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save!
- box = Box.create!(:owner => user)
+ box = Box.create!(:owner => @user)
@block = TagsBlock.create!(:box => box)
end
attr_reader :block
@@ -32,4 +32,9 @@ class TagsBlockTest < Test::Unit::TestCase
assert_equal '', block.content
end
+ should 'generate links when profile has own hostname' do
+ @user.domains << Domain.new(:name => 'testuser.net'); @user.save!
+ assert_match /profile\/testinguser\/tag\/first-tag/, block.content
+ end
+
end
--
libgit2 0.21.2