From 13851777146a3abf2d53d6f20d0d730be4c619d2 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Wed, 23 Jan 2008 22:52:18 +0000 Subject: [PATCH] ActionItem154: refactoring and adding new methods for dealing with urls --- app/models/profile.rb | 13 +++++++++++-- test/unit/profile_test.rb | 17 +++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index cdfa6a8..5c0b7f2 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -173,9 +173,18 @@ class Profile < ActiveRecord::Base include ActionController::UrlWriter def url - options = { :host => self.environment.default_hostname, :profile => self.identifier, :controller => 'content_viewer', :action => 'view_page', :page => [] } + generate_url(url_options.merge(:controller => 'content_viewer', :action => 'view_page', :page => [])) + end + + def generate_url(options) + url_for(url_options.merge(options)) + end + + def url_options + options = { :host => self.environment.default_hostname, :profile => self.identifier} options.merge!(:port => 3000) if ENV['RAILS_ENV'] == 'development' - url_for(options) + + options end end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index a72c82f..a7889be 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -231,14 +231,23 @@ class ProfileTest < Test::Unit::TestCase end should 'provide url to itself' do - env = Environment.default - assert_equal 'colivre.net', env.default_hostname - - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => env.id) + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('colivre.net').id) assert_equal 'http://colivre.net/testprofile', profile.url end + should 'generate URL' do + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('colivre.net').id) + + assert_equal 'http://colivre.net/profile/testprofile/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('colivre.net').id) + + assert_equal({:host => 'colivre.net', :profile => 'testprofile'}, profile.url_options) + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2