Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Clean up redirection a little

  • Loading branch information...
commit 6c28f185bd93abc56abf5cd3683cf4fbd8f12dda 1 parent 0644056
authored October 01, 2010
2  Gemfile.lock
@@ -42,6 +42,7 @@ GEM
42 42
     erubis (2.6.6)
43 43
       abstract (>= 1.0.0)
44 44
     i18n (0.4.1)
  45
+    json (1.4.6)
45 46
     json (1.4.6-x86-mingw32)
46 47
     mail (2.2.6.1)
47 48
       activesupport (>= 2.3.6)
@@ -88,6 +89,7 @@ GEM
88 89
       ruby_parser (>= 2.0.4)
89 90
 
90 91
 PLATFORMS
  92
+  ruby
91 93
   x86-mingw32
92 94
 
93 95
 DEPENDENCIES
11  lib/vanna.rb
@@ -29,10 +29,15 @@ def html_render(dictionary)
29 29
       self.response_body = "Over there!"
30 30
     end
31 31
   end
  32
+
  33
+  def new_resource(url)
  34
+    Redirection.new(url)
  35
+  end
  36
+
32 37
   class Redirection
33  
-    attr_accessor :dictionary, :target
34  
-    def initialize(dictionary, target); @dictionary = dictionary; @target = target; end
35  
-    def to_json; @dictionary.to_json; end
  38
+    attr_accessor :target
  39
+    def initialize(target); @target = target; end
  40
+    def to_json; {:url => @target}.to_json; end
36 41
     def json_status; "201"; end
37 42
   end
38 43
   class Base < ActionController::Metal
3  test/app/controllers/welcome_controller.rb
@@ -5,6 +5,7 @@ def index
5 5
     {:text => "hello"}
6 6
   end
7 7
   def create
8  
-    Redirection.new({}, "/redirection_target")
  8
+    candy = {:show_url => "/link_to_candy"} #Model created from post data
  9
+    new_resource(candy[:show_url])
9 10
   end
10 11
 end
4  test/basic_test.rb
@@ -21,13 +21,13 @@ def test_html_renders_template
21 21
   def test_html_redirects_on_post
22 22
     post "/welcome/create", "candy"
23 23
     assert { last_response.status == 302 }
24  
-    assert { last_response.location == "/redirection_target"}
  24
+    assert { last_response.location == "/link_to_candy"}
25 25
   end
26 26
   def test_json_renders_on_post
27 27
     header "Accept", 'application/json'
28 28
     post "/welcome/create", "candy"
29 29
     assert { last_response.status == 201 }
30  
-    assert { JSON(last_response.body) == {}}
  30
+    assert { JSON(last_response.body) == {"url" => "/link_to_candy"}}
31 31
   end
32 32
 end
33 33
 

0 notes on commit 6c28f18

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