Commit 13851777146a3abf2d53d6f20d0d730be4c619d2

Authored by AntonioTerceiro
1 parent 358c5f33

ActionItem154: refactoring and adding new methods for dealing with urls


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1258 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/models/profile.rb
... ... @@ -173,9 +173,18 @@ class Profile < ActiveRecord::Base
173 173  
174 174 include ActionController::UrlWriter
175 175 def url
176   - options = { :host => self.environment.default_hostname, :profile => self.identifier, :controller => 'content_viewer', :action => 'view_page', :page => [] }
  176 + generate_url(url_options.merge(:controller => 'content_viewer', :action => 'view_page', :page => []))
  177 + end
  178 +
  179 + def generate_url(options)
  180 + url_for(url_options.merge(options))
  181 + end
  182 +
  183 + def url_options
  184 + options = { :host => self.environment.default_hostname, :profile => self.identifier}
177 185 options.merge!(:port => 3000) if ENV['RAILS_ENV'] == 'development'
178   - url_for(options)
  186 +
  187 + options
179 188 end
180 189  
181 190 end
... ...
test/unit/profile_test.rb
... ... @@ -231,14 +231,23 @@ class ProfileTest < Test::Unit::TestCase
231 231 end
232 232  
233 233 should 'provide url to itself' do
234   - env = Environment.default
235   - assert_equal 'colivre.net', env.default_hostname
236   -
237   - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => env.id)
  234 + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('colivre.net').id)
238 235  
239 236 assert_equal 'http://colivre.net/testprofile', profile.url
240 237 end
241 238  
  239 + should 'generate URL' do
  240 + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('colivre.net').id)
  241 +
  242 + assert_equal 'http://colivre.net/profile/testprofile/friends', profile.generate_url(:controller => 'profile', :action => 'friends')
  243 + end
  244 +
  245 + should 'provide URL options' do
  246 + profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile', :environment_id => create_environment('colivre.net').id)
  247 +
  248 + assert_equal({:host => 'colivre.net', :profile => 'testprofile'}, profile.url_options)
  249 + end
  250 +
242 251 private
243 252  
244 253 def assert_invalid_identifier(id)
... ...