From 1d119389a917ec7fe969ed07ecfcec42c39f1b3a Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 22 Feb 2008 17:13:59 +0000 Subject: [PATCH] ActionItem172: generating proper URL's while in development mode --- app/models/profile.rb | 21 ++++++++++++++++++++- test/unit/profile_test.rb | 8 ++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index faf7bf9..96656d8 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -200,7 +200,26 @@ class Profile < ActiveRecord::Base end def url_options - { :host => self.environment.default_hostname, :profile => self.identifier} + options = { :host => self.environment.default_hostname, :profile => self.identifier} + + # help developers by generating a suitable URL for development environment + if (ENV['RAILS_ENV'] == 'development') + options.merge!(development_url_options) + end + + options + end + + # FIXME couldn't think of a way to test this. + # + # Works (tested by hand) on Rails 2.0.2, with mongrel. Should work with + # webrick too. + def development_url_options # :nodoc: + if Object.const_defined?('OPTIONS') + { :port => OPTIONS[:port ]} + else + {} + end end # FIXME this can be SLOW diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 448aaa8..bf8ea7f 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -272,6 +272,14 @@ class ProfileTest < Test::Unit::TestCase assert_equal({:host => 'mycolivre.net', :profile => 'testprofile'}, profile.url_options) 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) + + ENV.expects(:[]).with('RAILS_ENV').returns('development') + profile.expects(:development_url_options).returns({ :port => 9999 }) + ok('Profile#url_options must include port option when running in development mode') { profile.url_options[: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