Permalink
Browse files

Clean up redirection a little

  • Loading branch information...
1 parent 0644056 commit 6c28f185bd93abc56abf5cd3683cf4fbd8f12dda Steve Conover committed Oct 1, 2010
Showing with 14 additions and 6 deletions.
  1. +2 −0 Gemfile.lock
  2. +8 −3 lib/vanna.rb
  3. +2 −1 test/app/controllers/welcome_controller.rb
  4. +2 −2 test/basic_test.rb
View
@@ -42,6 +42,7 @@ GEM
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.4.1)
+ json (1.4.6)
json (1.4.6-x86-mingw32)
mail (2.2.6.1)
activesupport (>= 2.3.6)
@@ -88,6 +89,7 @@ GEM
ruby_parser (>= 2.0.4)
PLATFORMS
+ ruby
x86-mingw32
DEPENDENCIES
View
@@ -29,10 +29,15 @@ def html_render(dictionary)
self.response_body = "Over there!"
end
end
+
+ def new_resource(url)
+ Redirection.new(url)
+ end
+
class Redirection
- attr_accessor :dictionary, :target
- def initialize(dictionary, target); @dictionary = dictionary; @target = target; end
- def to_json; @dictionary.to_json; end
+ attr_accessor :target
+ def initialize(target); @target = target; end
+ def to_json; {:url => @target}.to_json; end
def json_status; "201"; end
end
class Base < ActionController::Metal
@@ -5,6 +5,7 @@ def index
{:text => "hello"}
end
def create
- Redirection.new({}, "/redirection_target")
+ candy = {:show_url => "/link_to_candy"} #Model created from post data
+ new_resource(candy[:show_url])
end
end
View
@@ -21,13 +21,13 @@ def test_html_renders_template
def test_html_redirects_on_post
post "/welcome/create", "candy"
assert { last_response.status == 302 }
- assert { last_response.location == "/redirection_target"}
+ assert { last_response.location == "/link_to_candy"}
end
def test_json_renders_on_post
header "Accept", 'application/json'
post "/welcome/create", "candy"
assert { last_response.status == 201 }
- assert { JSON(last_response.body) == {}}
+ assert { JSON(last_response.body) == {"url" => "/link_to_candy"}}
end
end

0 comments on commit 6c28f18

Please sign in to comment.