Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

users define MySite::App instead of MySite::Routes

  • Loading branch information...
commit 108d839b1349fbbeb13503fc095011bfa3ba4269 1 parent c862ae8
@garybernhardt authored
Showing with 30 additions and 26 deletions.
  1. +5 −6 lib/raptor.rb
  2. +25 −20 spec/app_spec.rb
View
11 lib/raptor.rb
@@ -10,17 +10,16 @@
require_relative 'raptor/validation'
module Raptor
- def self.routes(app_module, &block)
- Router.build(app_module, &block)
- end
-
class App
- def initialize(app_module)
+ attr_reader :routes
+
+ def initialize(app_module, &block)
@app_module = app_module
+ @routes = Router.build(app_module, &block)
end
def call(env)
- return Rack::MethodOverride.new(@app_module::Routes).call(env)
+ return Rack::MethodOverride.new(@routes).call(env)
end
def presenters
View
45 spec/app_spec.rb
@@ -4,8 +4,8 @@
describe Raptor::App, "integrated" do
before do
- module App
- Routes = Raptor.routes(self) do
+ module AwesomeSite
+ App = Raptor::App.new(self) do
path 'post' do
index :to => "Object.new"
end
@@ -18,9 +18,9 @@ class PostList
end
end
- after { Object.send(:remove_const, :App) }
+ after { Object.send(:remove_const, :AwesomeSite) }
- let(:app) { Raptor::App.new(App) }
+ let(:app) { AwesomeSite::App }
describe 'method override' do
def request_method(method)
@@ -28,15 +28,15 @@ def request_method(method)
end
it "tunnels PUT over POST" do
- App::Routes.should_receive(:call).with(request_method('PUT'))
- Raptor::App.new(App).call(env('POST', '/irrelevant',
- StringIO.new('_method=PUT')))
+ AwesomeSite::App.routes.should_receive(:call).
+ with(request_method('PUT'))
+ app.call(env('POST', '/irrelevant', StringIO.new('_method=PUT')))
end
it "tunnels DELETE over POST" do
- App::Routes.should_receive(:call).with(request_method('DELETE'))
- Raptor::App.new(App).call(env('POST', '/irrelevant',
- StringIO.new('_method=DELETE')))
+ AwesomeSite::App.routes.should_receive(:call).
+ with(request_method('DELETE'))
+ app.call(env('POST', '/irrelevant', StringIO.new('_method=DELETE')))
end
end
@@ -50,7 +50,7 @@ def request_method(method)
describe Raptor::App, "app wrapping" do
before do
- module App
+ module AwesomeSite
module Presenters
class Post
end
@@ -60,37 +60,42 @@ module Injectables
module Fruit
end
end
+
+ App = Raptor::App.new(self) do
+ end
end
- module EmptyApp
+ module EmptySite
+ App = Raptor::App.new(self) do
+ end
end
end
after do
- Object.send(:remove_const, :App)
- Object.send(:remove_const, :EmptyApp)
+ Object.send(:remove_const, :AwesomeSite)
+ Object.send(:remove_const, :EmptySite)
end
describe "#presenters" do
it "lists presenters" do
- app = Raptor::App.new(App)
- app.presenters.should == {:Post => App::Presenters::Post}
+ app = AwesomeSite::App
+ app.presenters.should == {:Post => AwesomeSite::Presenters::Post}
end
it "lists nothing when the app has no presenter module" do
- app = Raptor::App.new(EmptyApp)
+ app = EmptySite::App
app.presenters.should == {}
end
end
describe "#injectables" do
it "lists injectables" do
- app = Raptor::App.new(App)
- app.injectables.should == [App::Injectables::Fruit]
+ app = AwesomeSite::App
+ app.injectables.should == [AwesomeSite::Injectables::Fruit]
end
it "lists nothing when the app has no injectables module" do
- app = Raptor::App.new(EmptyApp)
+ app = EmptySite::App
app.injectables.should == []
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.