Commit 1d119389a917ec7fe969ed07ecfcec42c39f1b3a
1 parent
cb6c842b
Exists in
master
and in
29 other branches
ActionItem172: generating proper URL's while in development mode
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1474 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
28 additions
and
1 deletions
Show diff stats
app/models/profile.rb
... | ... | @@ -200,7 +200,26 @@ class Profile < ActiveRecord::Base |
200 | 200 | end |
201 | 201 | |
202 | 202 | def url_options |
203 | - { :host => self.environment.default_hostname, :profile => self.identifier} | |
203 | + options = { :host => self.environment.default_hostname, :profile => self.identifier} | |
204 | + | |
205 | + # help developers by generating a suitable URL for development environment | |
206 | + if (ENV['RAILS_ENV'] == 'development') | |
207 | + options.merge!(development_url_options) | |
208 | + end | |
209 | + | |
210 | + options | |
211 | + end | |
212 | + | |
213 | + # FIXME couldn't think of a way to test this. | |
214 | + # | |
215 | + # Works (tested by hand) on Rails 2.0.2, with mongrel. Should work with | |
216 | + # webrick too. | |
217 | + def development_url_options # :nodoc: | |
218 | + if Object.const_defined?('OPTIONS') | |
219 | + { :port => OPTIONS[:port ]} | |
220 | + else | |
221 | + {} | |
222 | + end | |
204 | 223 | end |
205 | 224 | |
206 | 225 | # FIXME this can be SLOW | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -272,6 +272,14 @@ class ProfileTest < Test::Unit::TestCase |
272 | 272 | assert_equal({:host => 'mycolivre.net', :profile => 'testprofile'}, profile.url_options) |
273 | 273 | end |
274 | 274 | |
275 | + 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) | |
277 | + | |
278 | + ENV.expects(:[]).with('RAILS_ENV').returns('development') | |
279 | + profile.expects(:development_url_options).returns({ :port => 9999 }) | |
280 | + ok('Profile#url_options must include port option when running in development mode') { profile.url_options[:port] == 9999 } | |
281 | + end | |
282 | + | |
275 | 283 | should 'list tags for profile' do |
276 | 284 | profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') |
277 | 285 | profile.articles.build(:name => 'first', :tag_list => 'first-tag').save! | ... | ... |