Commit 99d7ddca7430e0a892c9eb251ca583192d6dfc83
1 parent
2b966b41
Exists in
master
and in
29 other branches
ActionItem519: only generate url's with own domain for content
(articles) URL's git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2320 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
26 additions
and
3 deletions
Show diff stats
app/models/profile.rb
@@ -254,15 +254,24 @@ class Profile < ActiveRecord::Base | @@ -254,15 +254,24 @@ class Profile < ActiveRecord::Base | ||
254 | end | 254 | end |
255 | 255 | ||
256 | def url | 256 | def url |
257 | - generate_url(url_options.merge(:controller => 'content_viewer', :action => 'view_page', :page => [])) | 257 | + if self.domains.empty? |
258 | + generate_url(:controller => 'content_viewer', :action => 'view_page', :page => []) | ||
259 | + else | ||
260 | + options = { :host => self.domains.first.name, :controller => 'content_viewer', :action => 'view_page', :page => []} | ||
261 | + # help developers by generating a suitable URL for development environment | ||
262 | + if (ENV['RAILS_ENV'] == 'development') | ||
263 | + options.merge!(development_url_options) | ||
264 | + end | ||
265 | + options | ||
266 | + end | ||
258 | end | 267 | end |
259 | 268 | ||
260 | def admin_url | 269 | def admin_url |
261 | - generate_url(url_options.merge(:controller => 'profile_editor', :action => 'index')) | 270 | + generate_url(:controller => 'profile_editor', :action => 'index') |
262 | end | 271 | end |
263 | 272 | ||
264 | def public_profile_url | 273 | def public_profile_url |
265 | - generate_url(url_options.merge(:controller => 'profile', :action => 'index')) | 274 | + generate_url(:controller => 'profile', :action => 'index') |
266 | end | 275 | end |
267 | 276 | ||
268 | def generate_url(options) | 277 | def generate_url(options) |
test/unit/profile_test.rb
@@ -272,6 +272,12 @@ class ProfileTest < Test::Unit::TestCase | @@ -272,6 +272,12 @@ class ProfileTest < Test::Unit::TestCase | ||
272 | assert_equal({:host => 'mycolivre.net', :profile => 'testprofile'}, profile.url_options) | 272 | assert_equal({:host => 'mycolivre.net', :profile => 'testprofile'}, profile.url_options) |
273 | end | 273 | end |
274 | 274 | ||
275 | + should "use own domain name instead of environment's for home page url" do | ||
276 | + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | ||
277 | + profile.domains << Domain.new(:name => 'micojones.net') | ||
278 | + assert_equal({:host => 'micojones.net', :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) | ||
279 | + end | ||
280 | + | ||
275 | should 'help developers by adding a suitable port to url options' do | 281 | should 'help developers by adding a suitable port to url options' do |
276 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | 282 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) |
277 | 283 | ||
@@ -280,6 +286,14 @@ class ProfileTest < Test::Unit::TestCase | @@ -280,6 +286,14 @@ class ProfileTest < Test::Unit::TestCase | ||
280 | ok('Profile#url_options must include port option when running in development mode') { profile.url_options[:port] == 9999 } | 286 | ok('Profile#url_options must include port option when running in development mode') { profile.url_options[:port] == 9999 } |
281 | end | 287 | end |
282 | 288 | ||
289 | + should 'help developers by adding a suitable port to url options for own domain urls' do | ||
290 | + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) | ||
291 | + profile.domains << Domain.new(:name => 'micojones.net') | ||
292 | + ENV.expects(:[]).with('RAILS_ENV').returns('development') | ||
293 | + profile.expects(:development_url_options).returns({ :port => 9999 }) | ||
294 | + ok('Profile#url must include port options when running in developers mode') { profile.url[:port] == 9999 } | ||
295 | + end | ||
296 | + | ||
283 | should 'list tags for profile' do | 297 | should 'list tags for profile' do |
284 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') | 298 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') |
285 | profile.articles.build(:name => 'first', :tag_list => 'first-tag').save! | 299 | profile.articles.build(:name => 'first', :tag_list => 'first-tag').save! |