Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make the injector take into account custom injectables

  • Loading branch information...
commit 9091cbb4ad6a1c42dfa5b2555488bb35b8e5df65 1 parent 33ffbca
@dpick authored
Showing with 49 additions and 2 deletions.
  1. +2 −1  lib/raptor/router.rb
  2. +47 −1 spec/router_spec.rb
View
3  lib/raptor/router.rb
@@ -15,7 +15,8 @@ def call(env)
Raptor.log "App: routing #{request.request_method} #{request.path_info}"
injector = Injector.for_app(@app).
add_request(request)
- injector = Injector.new.add_request(request)
+ injector = injector.add_request(request)
+
begin
route = route_for_request(injector, request)
rescue NoRouteMatches
View
48 spec/router_spec.rb
@@ -11,5 +11,51 @@
response.status.should == 404
end
end
-end
+ describe 'with custom injectables' do
+ it 'sets the params with the custom injectable' do
+ module Foo
+ module Presenters
+ class Post
+ def initialize(subject); @subject = subject; end
+ end
+ end
+
+ module Records
+ class Post
+ def self.all(watermelon); watermelon.should == 'tasty'; nil; end
+ end
+ end
+
+ module Presenters
+ class PostList
+ def all
+ RouterTestApp::Records::Post.all
+ end
+ end
+ end
+
+ module Injectables
+ class Fruit
+ def sources(injector)
+ {:watermelon => lambda { "tasty" } }
+ end
+ end
+ end
+ end
+
+ params = {:present => :post_list,
+ :to => "Records::Post.all",
+ :action => :index,
+ :http_method => "GET",
+ :path => "/post/"}
+
+ routes = [Raptor::Route.for_app_module(Foo, '', params)]
+
+ router = Raptor::Router.new(Foo, routes)
+ Raptor::Template.stub(:from_path => stub(:render => ""))
+
+ router.call(env('GET', '/post'))
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.