Skip to content
This repository
Browse code

absolutize redirect urls

  • Loading branch information...
commit cca68b5ea04419119a68a59babf3dbb61be462d2 1 parent b7aa5fd
ethn authored December 18, 2012
1  app/controllers/application_controller.rb
@@ -71,6 +71,7 @@ def read_ok
71 71
   # ----------( rendering methods ) -------------
72 72
 
73 73
   def wagn_redirect url
  74
+    url = wagn_url url #make sure we have absolute url
74 75
     if ajax?
75 76
       render :text => url, :status => 303
76 77
     else
2  app/controllers/card_controller.rb
@@ -228,7 +228,7 @@ def success default_target='_self'
228 228
       end
229 229
 
230 230
     case
231  
-    when  redirect        ; wagn_redirect ( Card===target ? url_for_page(target.cardname, new_params) : target )
  231
+    when  redirect        ; wagn_redirect ( Card===target ? path_for_page( target.cardname, new_params ) : target )
232 232
     when  String===target ; render :text => target
233 233
     else
234 234
       @card = target
14  app/helpers/location_helper.rb
@@ -23,8 +23,8 @@ def location_history
23 23
   def save_location
24 24
     return if ajax? || !html? || !@card.known?
25 25
 
26  
-    discard_locations_for(@card)
27  
-    @previous_location = wagn_path(@card)
  26
+    discard_locations_for @card
  27
+    @previous_location = wagn_path @card
28 28
     location_history.push @previous_location
29 29
   end
30 30
 
@@ -50,7 +50,7 @@ def url_key_for_location(location)
50 50
 
51 51
 
52 52
   # FIXME: missing test
53  
-  def url_for_page( title, opts={} )
  53
+  def path_for_page( title, opts={} )
54 54
     format = (opts[:format] ? ".#{opts.delete(:format)}"  : "")
55 55
     vars = ''
56 56
     if !opts.empty?
@@ -61,13 +61,13 @@ def url_for_page( title, opts={} )
61 61
     wagn_path "/#{title.to_name.url_key}#{format}#{vars}"
62 62
   end
63 63
 
64  
-  def wagn_path( rel ) #should be in cardname?
  64
+  def wagn_path( rel ) #should be in smartname?
65 65
     rel_path = Card===rel ? rel.cardname.url_key : rel
66 66
     Wagn::Conf[:root_path].to_s + ( rel_path =~ /^\// ? '' : '/' ) + rel_path
67 67
   end
68 68
 
69  
-  def wagn_url( rel ) #should be in cardname?
70  
-    "#{Wagn::Conf[:base_url]}#{wagn_path(rel)}"
  69
+  def wagn_url rel #should be in smartname?
  70
+    rel =~ /^http\:/ ? rel : "#{Wagn::Conf[:base_url]}#{wagn_path(rel)}"
71 71
   end
72 72
 
73 73
 
@@ -76,7 +76,7 @@ def wagn_url( rel ) #should be in cardname?
76 76
   def link_to_page( text, title=nil, options={})
77 77
     title ||= text
78 78
     url_options = (options[:type]) ? {:type=>options[:type]} : {}
79  
-    url = url_for_page(title, url_options)
  79
+    url = path_for_page(title, url_options)
80 80
     link_to text, url, options
81 81
   end
82 82
 
2  lib/wagn/set/self/head_and_foot.rb
@@ -24,7 +24,7 @@ module Set::Self::HeadAndFoot
24 24
         if root.card.type_id == Card::SearchTypeID
25 25
           opts = { :format => :rss }
26 26
           root.search_params[:vars].each { |key, val| opts["_#{key}"] = val }
27  
-          rss_href = url_for_page root.card.name, opts
  27
+          rss_href = path_for_page root.card.name, opts
28 28
           bits << %{<link rel="alternate" type="application/rss+xml" title="RSS" href=#{rss_href} />}
29 29
        end
30 30
       end
2  test/functional/account_request_test.rb
@@ -26,7 +26,7 @@ def test_should_redirect_to_account_request_landing_card
26 26
       :content=>"Let me in!"
27 27
     }
28 28
     assert_response 302
29  
-    #assert_redirected_to @controller.url_for_page(::Setting.find_by_codename('account_request_landing').card.name)
  29
+    #assert_redirected_to @controller.path_for_page(::Setting.find_by_codename('account_request_landing').card.name)
30 30
   end
31 31
 
32 32
   def test_should_create_account_request
6  test/integration/card_action_test.rb
@@ -97,11 +97,11 @@ def test_removal_and_return_to_previous_undeleted_card_after_deletion
97 97
       t2 = Card.create! :name => "Testable1+bandana", :content => "world"
98 98
     end
99 99
 
100  
-    get url_for_page( t1.name )
101  
-    get url_for_page( t2.name )
  100
+    get path_for_page( t1.name )
  101
+    get path_for_page( t2.name )
102 102
 
103 103
     post 'card/delete/~' + t2.id.to_s
104  
-    assert_redirected_to url_for_page( t1.name )
  104
+    assert_redirected_to path_for_page( t1.name )
105 105
     assert_nil Card[ t2.name ]
106 106
 
107 107
     post 'card/delete/~' + t1.id.to_s

0 notes on commit cca68b5

Please sign in to comment.
Something went wrong with that request. Please try again.