diff --git a/app/models/profile.rb b/app/models/profile.rb index 6767089..2929385 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -254,15 +254,24 @@ class Profile < ActiveRecord::Base end def url - generate_url(url_options.merge(:controller => 'content_viewer', :action => 'view_page', :page => [])) + if self.domains.empty? + generate_url(:controller => 'content_viewer', :action => 'view_page', :page => []) + else + options = { :host => self.domains.first.name, :controller => 'content_viewer', :action => 'view_page', :page => []} + # help developers by generating a suitable URL for development environment + if (ENV['RAILS_ENV'] == 'development') + options.merge!(development_url_options) + end + options + end end def admin_url - generate_url(url_options.merge(:controller => 'profile_editor', :action => 'index')) + generate_url(:controller => 'profile_editor', :action => 'index') end def public_profile_url - generate_url(url_options.merge(:controller => 'profile', :action => 'index')) + generate_url(:controller => 'profile', :action => 'index') end def generate_url(options) diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 48c2c56..e425a3d 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -272,6 +272,12 @@ class ProfileTest < Test::Unit::TestCase 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', :controller => 'content_viewer', :action => 'view_page', :page => []}, profile.url) + end + should 'help developers by adding a suitable port to url options' do profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) @@ -280,6 +286,14 @@ class ProfileTest < Test::Unit::TestCase ok('Profile#url_options must include port option when running in development mode') { profile.url_options[:port] == 9999 } end + should 'help developers by adding a suitable port to url options for own domain urls' do + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('mycolivre.net').id) + profile.domains << Domain.new(:name => 'micojones.net') + ENV.expects(:[]).with('RAILS_ENV').returns('development') + profile.expects(:development_url_options).returns({ :port => 9999 }) + ok('Profile#url must include port options when running in developers mode') { profile.url[:port] == 9999 } + end + should 'list tags for profile' do profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') profile.articles.build(:name => 'first', :tag_list => 'first-tag').save! -- libgit2 0.21.2