pancake 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.textile +95 -0
- data/Rakefile +56 -0
- data/TODO +17 -0
- data/bin/jeweler +19 -0
- data/bin/pancake-gen +17 -0
- data/bin/rubyforge +19 -0
- data/lib/pancake/bootloaders.rb +180 -0
- data/lib/pancake/configuration.rb +145 -0
- data/lib/pancake/constants.rb +5 -0
- data/lib/pancake/core_ext/class.rb +44 -0
- data/lib/pancake/core_ext/object.rb +22 -0
- data/lib/pancake/core_ext/symbol.rb +15 -0
- data/lib/pancake/defaults/configuration.rb +22 -0
- data/lib/pancake/defaults/middlewares.rb +1 -0
- data/lib/pancake/errors.rb +61 -0
- data/lib/pancake/generators/base.rb +12 -0
- data/lib/pancake/generators/micro_generator.rb +17 -0
- data/lib/pancake/generators/short_generator.rb +17 -0
- data/lib/pancake/generators/stack_generator.rb +17 -0
- data/lib/pancake/generators/templates/common/dotgitignore +22 -0
- data/lib/pancake/generators/templates/common/dothtaccess +17 -0
- data/lib/pancake/generators/templates/micro/%stack_name%/%stack_name%.rb.tt +8 -0
- data/lib/pancake/generators/templates/micro/%stack_name%/config.ru.tt +12 -0
- data/lib/pancake/generators/templates/micro/%stack_name%/pancake.init.tt +1 -0
- data/lib/pancake/generators/templates/micro/%stack_name%/public/.empty_directory +0 -0
- data/lib/pancake/generators/templates/micro/%stack_name%/tmp/.empty_directory +0 -0
- data/lib/pancake/generators/templates/micro/%stack_name%/views/root.html.haml +1 -0
- data/lib/pancake/generators/templates/short/%stack_name%/LICENSE.tt +20 -0
- data/lib/pancake/generators/templates/short/%stack_name%/README.tt +7 -0
- data/lib/pancake/generators/templates/short/%stack_name%/Rakefile.tt +50 -0
- data/lib/pancake/generators/templates/short/%stack_name%/VERSION.tt +1 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/%stack_name%.rb.tt +6 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config.ru.tt +10 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/views/root.html.haml +2 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +5 -0
- data/lib/pancake/generators/templates/short/%stack_name%/pancake.init.tt +1 -0
- data/lib/pancake/generators/templates/short/%stack_name%/spec/%stack_name%_spec.rb.tt +7 -0
- data/lib/pancake/generators/templates/short/%stack_name%/spec/spec_helper.rb.tt +9 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/LICENSE.tt +20 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/README.tt +7 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/Rakefile.tt +50 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/VERSION.tt +1 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/development.rb.tt +18 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/production.rb.tt +18 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/router.rb.tt +6 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config.ru.tt +12 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/gems/cache/.empty_directory +0 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%.rb.tt +3 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/pancake.init.tt +1 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/spec/%stack_name%_spec.rb.tt +7 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/spec/spec_helper.rb.tt +9 -0
- data/lib/pancake/generators.rb +8 -0
- data/lib/pancake/hooks/inheritable_inner_classes.rb +60 -0
- data/lib/pancake/hooks/on_inherit.rb +34 -0
- data/lib/pancake/logger.rb +200 -0
- data/lib/pancake/master.rb +123 -0
- data/lib/pancake/middleware.rb +347 -0
- data/lib/pancake/middlewares/logger.rb +16 -0
- data/lib/pancake/middlewares/static.rb +38 -0
- data/lib/pancake/mime_types.rb +265 -0
- data/lib/pancake/mixins/publish/action_options.rb +104 -0
- data/lib/pancake/mixins/publish.rb +125 -0
- data/lib/pancake/mixins/render/render.rb +168 -0
- data/lib/pancake/mixins/render/template.rb +23 -0
- data/lib/pancake/mixins/render/view_context.rb +21 -0
- data/lib/pancake/mixins/render.rb +109 -0
- data/lib/pancake/mixins/request_helper.rb +100 -0
- data/lib/pancake/mixins/stack_helper.rb +46 -0
- data/lib/pancake/mixins/url.rb +10 -0
- data/lib/pancake/paths.rb +218 -0
- data/lib/pancake/router.rb +99 -0
- data/lib/pancake/stack/app.rb +10 -0
- data/lib/pancake/stack/bootloader.rb +79 -0
- data/lib/pancake/stack/configuration.rb +44 -0
- data/lib/pancake/stack/middleware.rb +0 -0
- data/lib/pancake/stack/router.rb +21 -0
- data/lib/pancake/stack/stack.rb +66 -0
- data/lib/pancake/stacks/short/bootloaders.rb +13 -0
- data/lib/pancake/stacks/short/controller.rb +116 -0
- data/lib/pancake/stacks/short/default/views/base.html.haml +5 -0
- data/lib/pancake/stacks/short/stack.rb +187 -0
- data/lib/pancake/stacks/short.rb +3 -0
- data/lib/pancake.rb +58 -0
- data/spec/helpers/helpers.rb +20 -0
- data/spec/helpers/matchers.rb +25 -0
- data/spec/pancake/bootloaders_spec.rb +109 -0
- data/spec/pancake/configuration_spec.rb +177 -0
- data/spec/pancake/constants_spec.rb +7 -0
- data/spec/pancake/defaults/configuration_spec.rb +58 -0
- data/spec/pancake/fixtures/foo_stack/pancake.init +0 -0
- data/spec/pancake/fixtures/middlewares/other_public/two.html +1 -0
- data/spec/pancake/fixtures/middlewares/public/foo#bar.html +1 -0
- data/spec/pancake/fixtures/middlewares/public/one.html +1 -0
- data/spec/pancake/fixtures/paths/controllers/controller1.rb +0 -0
- data/spec/pancake/fixtures/paths/controllers/controller2.rb +0 -0
- data/spec/pancake/fixtures/paths/controllers/controller3.rb +0 -0
- data/spec/pancake/fixtures/paths/models/model1.rb +0 -0
- data/spec/pancake/fixtures/paths/models/model2.rb +0 -0
- data/spec/pancake/fixtures/paths/models/model3.rb +0 -0
- data/spec/pancake/fixtures/paths/stack/controllers/controller1.rb +0 -0
- data/spec/pancake/fixtures/paths/stack/models/model3.rb +0 -0
- data/spec/pancake/fixtures/paths/stack/views/view1.erb +0 -0
- data/spec/pancake/fixtures/paths/stack/views/view1.rb +0 -0
- data/spec/pancake/fixtures/paths/stack/views/view2.erb +0 -0
- data/spec/pancake/fixtures/paths/stack/views/view2.haml +0 -0
- data/spec/pancake/fixtures/render_templates/context_template.html.erb +2 -0
- data/spec/pancake/fixtures/render_templates/erb_template.html.erb +1 -0
- data/spec/pancake/fixtures/render_templates/erb_template.json.erb +1 -0
- data/spec/pancake/fixtures/render_templates/haml_template.html.haml +1 -0
- data/spec/pancake/fixtures/render_templates/haml_template.xml.haml +1 -0
- data/spec/pancake/fixtures/render_templates/templates/context.erb +2 -0
- data/spec/pancake/fixtures/render_templates/view_context/capture_erb.erb +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/capture_haml.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/concat_erb.erb +2 -0
- data/spec/pancake/fixtures/render_templates/view_context/concat_haml.haml +2 -0
- data/spec/pancake/fixtures/render_templates/view_context/context.erb +3 -0
- data/spec/pancake/fixtures/render_templates/view_context/context2.erb +3 -0
- data/spec/pancake/fixtures/render_templates/view_context/helper_methods.erb +3 -0
- data/spec/pancake/fixtures/render_templates/view_context/inherited_erb_from_haml.erb +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/inherited_erb_level_0.erb +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/inherited_erb_level_1.erb +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/inherited_haml_from_erb.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_0.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/inherited_haml_level_1.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/nested_content_level_0.haml +6 -0
- data/spec/pancake/fixtures/render_templates/view_context/nested_content_level_1.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/nested_inner.erb +1 -0
- data/spec/pancake/fixtures/render_templates/view_context/nested_outer.erb +3 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_erb_0.erb +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_erb_1.erb +6 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_haml_0.erb +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_erb_from_haml_1.erb +6 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_erb_0.haml +4 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_erb_1.haml +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_haml_0.haml +5 -0
- data/spec/pancake/fixtures/render_templates/view_context/super_haml_from_haml_1.haml +5 -0
- data/spec/pancake/fixtures/stacks/short/foobar/other_root/views/base.html.haml +4 -0
- data/spec/pancake/fixtures/stacks/short/foobar/views/basic.html.haml +1 -0
- data/spec/pancake/fixtures/stacks/short/foobar/views/inherited_from_base.html.haml +5 -0
- data/spec/pancake/hooks/on_inherit_spec.rb +65 -0
- data/spec/pancake/inheritance_spec.rb +100 -0
- data/spec/pancake/middleware_spec.rb +401 -0
- data/spec/pancake/middlewares/logger_spec.rb +29 -0
- data/spec/pancake/middlewares/static_spec.rb +83 -0
- data/spec/pancake/mime_types_spec.rb +234 -0
- data/spec/pancake/mixins/publish_spec.rb +94 -0
- data/spec/pancake/mixins/render/template_spec.rb +69 -0
- data/spec/pancake/mixins/render/view_context_spec.rb +248 -0
- data/spec/pancake/mixins/render_spec.rb +56 -0
- data/spec/pancake/mixins/request_helper_spec.rb +27 -0
- data/spec/pancake/mixins/stack_helper_spec.rb +46 -0
- data/spec/pancake/pancake_spec.rb +90 -0
- data/spec/pancake/paths_spec.rb +210 -0
- data/spec/pancake/stack/app_spec.rb +28 -0
- data/spec/pancake/stack/bootloader_spec.rb +41 -0
- data/spec/pancake/stack/middleware_spec.rb +0 -0
- data/spec/pancake/stack/router_spec.rb +282 -0
- data/spec/pancake/stack/stack_configuration_spec.rb +101 -0
- data/spec/pancake/stack/stack_spec.rb +60 -0
- data/spec/pancake/stacks/short/controller_spec.rb +322 -0
- data/spec/pancake/stacks/short/middlewares_spec.rb +22 -0
- data/spec/pancake/stacks/short/router_spec.rb +136 -0
- data/spec/pancake/stacks/short/stack_spec.rb +64 -0
- data/spec/spec_helper.rb +23 -0
- metadata +294 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "stack router" do
|
|
4
|
+
before(:all) do
|
|
5
|
+
clear_constants "FooApp" ,"INNER_APP", "BarApp", "InnerApp", "InnerFoo", "InnerBar"
|
|
6
|
+
end
|
|
7
|
+
before(:each) do
|
|
8
|
+
|
|
9
|
+
::INNER_APP = Proc.new{ |e|
|
|
10
|
+
[
|
|
11
|
+
200,
|
|
12
|
+
{"Content-Type" => "text/plain"},
|
|
13
|
+
[
|
|
14
|
+
JSON.generate({
|
|
15
|
+
"SCRIPT_NAME" => e["SCRIPT_NAME"],
|
|
16
|
+
"PATH_INFO" => e["PATH_INFO"],
|
|
17
|
+
"usher.params" => e["usher.params"]
|
|
18
|
+
})
|
|
19
|
+
]
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
class ::FooApp < Pancake::Stack; end
|
|
23
|
+
FooApp.roots << Pancake.get_root(__FILE__)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
after(:each) do
|
|
27
|
+
clear_constants "FooApp" ,"INNER_APP", "BarApp"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def app
|
|
31
|
+
@app
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe "mount" do
|
|
35
|
+
it "should let me setup routes for the stack" do
|
|
36
|
+
FooApp.router do |r|
|
|
37
|
+
r.mount(INNER_APP, "/foo", :_defaults => {:action => "foo action"}).name(:foo)
|
|
38
|
+
r.mount(INNER_APP, "/bar", :_defaults => {:action => "bar action"}).name(:root)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
@app = FooApp.stackup
|
|
42
|
+
expected = {
|
|
43
|
+
"SCRIPT_NAME" => "/foo",
|
|
44
|
+
"PATH_INFO" => "",
|
|
45
|
+
"usher.params" => {"action" => "foo action"}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get "/foo"
|
|
49
|
+
JSON.parse(last_response.body).should == expected
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "should allow me to stop the route from partially matching" do
|
|
53
|
+
FooApp.with_router do |r|
|
|
54
|
+
r.mount(INNER_APP, "/foo/bar", :_defaults => {:action => "foo/bar"}, :_exact => true).name(:foobar)
|
|
55
|
+
end
|
|
56
|
+
@app = FooApp.stackup
|
|
57
|
+
expected = {
|
|
58
|
+
"SCRIPT_NAME" => "/foo/bar",
|
|
59
|
+
"PATH_INFO" => "",
|
|
60
|
+
"usher.params" => {"action" => "foo/bar"}
|
|
61
|
+
}
|
|
62
|
+
get "/foo/bar"
|
|
63
|
+
JSON.parse(last_response.body).should == expected
|
|
64
|
+
get "/foo"
|
|
65
|
+
last_response.status.should == 404
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should make sure that the application is a rack application" do
|
|
69
|
+
lambda do
|
|
70
|
+
FooApp.router.mount(:not_an_app, "/foo")
|
|
71
|
+
end.should raise_error(Pancake::Router::RackApplicationExpected)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
it "should not match a single segment route when only / is defined" do
|
|
76
|
+
FooApp.router.add("/", :_defaults => {:root => :var}) do |e|
|
|
77
|
+
Rack::Response.new("In the Root").finish
|
|
78
|
+
end
|
|
79
|
+
@app = FooApp.stackup
|
|
80
|
+
result = get "/not_a_route"
|
|
81
|
+
result.status.should == 404
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
describe "generating routes" do
|
|
86
|
+
before do
|
|
87
|
+
FooApp.router do |r|
|
|
88
|
+
r.add("/simple/route" ).name(:simple)
|
|
89
|
+
r.add("/var/with/:var", :_defaults => {:var => "some_var"}).name(:defaults)
|
|
90
|
+
r.add("/complex/:var" ).name(:complex)
|
|
91
|
+
r.add("/optional(/:var)" ).name(:optional)
|
|
92
|
+
r.add("/some/:unique_var")
|
|
93
|
+
r.add("/", :_defaults => {:var => "root var"}).name(:root)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should allow me to generate a named route for a stack" do
|
|
98
|
+
Pancake.url(FooApp, :simple).should == "/simple/route"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should allow me to generate a non-named route for a stack" do
|
|
102
|
+
Pancake.url(FooApp, :complex, :var => "a_variable").should == "/complex/a_variable"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should allow me to generate a route with values" do
|
|
106
|
+
Pancake.url(FooApp, :optional).should == "/optional"
|
|
107
|
+
Pancake.url(FooApp, :optional, :var => "some_var").should == "/optional/some_var"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should allow me to generate routes with defaults" do
|
|
111
|
+
Pancake.url(FooApp, :defaults).should == "/var/with/some_var"
|
|
112
|
+
Pancake.url(FooApp, :defaults, :var => "this_is_a_var").should == "/var/with/this_is_a_var"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "should allow me to generate a route by params" do
|
|
116
|
+
Pancake.url(FooApp, :unique_var => "unique_var").should == "/some/unique_var"
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
describe "mounted route generation" do
|
|
121
|
+
before do
|
|
122
|
+
class ::BarApp < Pancake::Stack; end
|
|
123
|
+
BarApp.roots << Pancake.get_root(__FILE__)
|
|
124
|
+
BarApp.router do |r|
|
|
125
|
+
r.add("/simple").name(:simple)
|
|
126
|
+
r.add("/some/:var", :_defaults => {:var => "foo"}).name(:foo)
|
|
127
|
+
end
|
|
128
|
+
FooApp.router.mount(BarApp.stackup, "/bar")
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it "should allow me to generate a simple nested named route" do
|
|
132
|
+
Pancake.url(BarApp, :simple).should == "/bar/simple"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "should allow me to generate a simple nested named route for a named app" do
|
|
136
|
+
FooApp.router.mount(BarApp.stackup(:app_name => :bar_app), "/different")
|
|
137
|
+
Pancake.url(:bar_app, :simple).should == "/different/simple"
|
|
138
|
+
Pancake.url(BarApp, :simple).should == "/bar/simple"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
describe "internal stack routes" do
|
|
145
|
+
it "should pass through to the underlying app when adding a route" do
|
|
146
|
+
FooApp.router.add("/bar", :_defaults => {:action => "bar"}).name(:gary)
|
|
147
|
+
class ::FooApp
|
|
148
|
+
def self.new_app_instance
|
|
149
|
+
INNER_APP
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
@app = FooApp.stackup
|
|
154
|
+
get "/bar"
|
|
155
|
+
result = JSON.parse(last_response.body)
|
|
156
|
+
result["usher.params"].should == {"action" => "bar"}
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it "should add the usher.params to the request params" do
|
|
160
|
+
app = mock("app", :call => Rack::Response.new("OK").finish, :null_object => true)
|
|
161
|
+
app.should_receive(:call).with do |e|
|
|
162
|
+
params = Rack::Request.new(e).params
|
|
163
|
+
params[:action].should == "jackson"
|
|
164
|
+
end
|
|
165
|
+
FooApp.router.mount(app, "/foo/app", :_defaults => {:action => "jackson"})
|
|
166
|
+
@app = FooApp.stackup
|
|
167
|
+
get "/foo/app"
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it "should allow me to inherit routes" do
|
|
172
|
+
FooApp.router do |r|
|
|
173
|
+
r.mount(INNER_APP, "/foo(/:stuff)", :_defaults => {"originator" => "FooApp"})
|
|
174
|
+
end
|
|
175
|
+
class ::BarApp < FooApp; end
|
|
176
|
+
BarApp.router do |r|
|
|
177
|
+
r.mount(INNER_APP, "/bar", :_defaults => {"originator" => "BarApp"})
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
@app = BarApp.stackup
|
|
181
|
+
|
|
182
|
+
get "/bar"
|
|
183
|
+
response = JSON.parse(last_response.body)
|
|
184
|
+
response["usher.params"]["originator"].should == "BarApp"
|
|
185
|
+
|
|
186
|
+
get "/foo/thing"
|
|
187
|
+
response = JSON.parse(last_response.body)
|
|
188
|
+
response["usher.params"]["originator"].should == "FooApp"
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "should generate an inherited route" do
|
|
192
|
+
FooApp.router do |r|
|
|
193
|
+
r.add("/simple").name(:simple)
|
|
194
|
+
r.mount(INNER_APP, "/foo(/:stuff)").name(:stuff)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
class ::BarApp < FooApp; end
|
|
198
|
+
|
|
199
|
+
Pancake.url(BarApp, :simple).should == "/simple"
|
|
200
|
+
Pancake.url(BarApp, :stuff => "this_stuff").should == "/foo/this_stuff"
|
|
201
|
+
Pancake.url(BarApp, :stuff, :stuff => "that_stuff").should == "/foo/that_stuff"
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
it "should put the configuration into the env" do
|
|
205
|
+
FooApp.router.add("/foo").to do |e|
|
|
206
|
+
e["pancake.request.configuration"].should == Pancake.configuration.configs[FooApp]
|
|
207
|
+
Rack::Response.new("OK").finish
|
|
208
|
+
end
|
|
209
|
+
@app = FooApp.stackup
|
|
210
|
+
get "/foo"
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "should inherit the router as an inherited inner class" do
|
|
214
|
+
class ::BarApp < FooApp; end
|
|
215
|
+
BarApp::Router.should inherit_from(FooApp::Router)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
describe "generating urls inside an application" do
|
|
219
|
+
before do
|
|
220
|
+
class ::BarApp < FooApp; end
|
|
221
|
+
|
|
222
|
+
class ::InnerApp
|
|
223
|
+
attr_reader :env
|
|
224
|
+
include Pancake::Mixins::RequestHelper
|
|
225
|
+
|
|
226
|
+
def self.app_block(&block)
|
|
227
|
+
if block_given?
|
|
228
|
+
@app_block = block
|
|
229
|
+
end
|
|
230
|
+
@app_block
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def call(env)
|
|
234
|
+
@env = env
|
|
235
|
+
instance_eval &self.class.app_block
|
|
236
|
+
Rack::Response.new("OK").finish
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
class ::FooApp; def self.new_app_instance; InnerApp.new; end; end
|
|
241
|
+
|
|
242
|
+
BarApp.router do |r|
|
|
243
|
+
r.add("/mounted")
|
|
244
|
+
r.add("/foo").name(:foo)
|
|
245
|
+
r.add("/other").name(:other)
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
FooApp.router do |r|
|
|
249
|
+
r.mount(BarApp.stackup, "/bar")
|
|
250
|
+
r.add( "/foo" ).name(:foo)
|
|
251
|
+
r.add( "/simple").name(:simple)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
@app = FooApp.stackup
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it "should generate the urls correctly" do
|
|
258
|
+
InnerApp.app_block do
|
|
259
|
+
url(:foo).should == "/foo"
|
|
260
|
+
url(:simple).should == "/simple"
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
get "/foo"
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
it "should generate urls correctly when nested" do
|
|
267
|
+
InnerApp.app_block do
|
|
268
|
+
url(:foo).should == "/bar/foo"
|
|
269
|
+
url(:other).should == "/bar/other"
|
|
270
|
+
end
|
|
271
|
+
get "/bar/mounted"
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
it "should generate a url for another app" do
|
|
275
|
+
InnerApp.app_block do
|
|
276
|
+
url_for(BarApp, :foo).should == "/bar/foo"
|
|
277
|
+
url_for(FooApp, :foo).should == "/foo"
|
|
278
|
+
end
|
|
279
|
+
get "/foo"
|
|
280
|
+
end
|
|
281
|
+
end
|
|
282
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "pancake stack configuration" do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
Pancake.configuration.stacks.clear
|
|
7
|
+
Pancake.configuration.configs.clear
|
|
8
|
+
class ::FooStack < Pancake::Stack
|
|
9
|
+
end
|
|
10
|
+
FooStack.roots << Pancake.get_root(__FILE__)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
after(:each) do
|
|
14
|
+
clear_constants(:FooStack)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "should provide access to the stack configuration" do
|
|
18
|
+
FooStack.configuration.class.should inherit_from(Pancake::Configuration::Base)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should allow me to set defaults on a stack" do
|
|
22
|
+
FooStack.configuration do
|
|
23
|
+
default :foo, :bar
|
|
24
|
+
default :bar, "Foo Bar Man"
|
|
25
|
+
end
|
|
26
|
+
FooStack.configuration.foo.should == :bar
|
|
27
|
+
FooStack.configuration.bar.should == "Foo Bar Man"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "should allow me to extend the configuration" do
|
|
31
|
+
class Pancake::Stack::Configuration
|
|
32
|
+
default :foo, :bar, "I am a foo default"
|
|
33
|
+
default :bar do
|
|
34
|
+
foobar
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def foobar
|
|
38
|
+
:foobar
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
class FooBarStack < Pancake::Stack; end
|
|
42
|
+
|
|
43
|
+
FooBarStack.configuration.foo.should == :bar
|
|
44
|
+
FooBarStack.configuration.bar.should == :foobar
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe "configurations" do
|
|
48
|
+
|
|
49
|
+
it "should provide a configuration object for the stack" do
|
|
50
|
+
app = FooStack.stackup
|
|
51
|
+
app.configuration.should be_an_instance_of(FooStack::Configuration)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "should put a copy of the application at the stack identified by the class" do
|
|
55
|
+
router = FooStack.stackup
|
|
56
|
+
Pancake.configuration.stacks[FooStack].should be_an_instance_of(FooStack)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "should allow me to set a configuration object manually" do
|
|
60
|
+
config = FooStack::Configuration.new
|
|
61
|
+
app = FooStack.stackup(:config => config)
|
|
62
|
+
app.configuration.should equal(config)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "should allow me to have access to the configuration object when creating the stack through a block" do
|
|
66
|
+
app = FooStack.stackup do |config|
|
|
67
|
+
config.foo = :foo
|
|
68
|
+
config.bar = :bar
|
|
69
|
+
end
|
|
70
|
+
app.configuration.foo.should == :foo
|
|
71
|
+
app.configuration.bar.should == :bar
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "should setup access to the configuration object through Pancakes configuration" do
|
|
75
|
+
router = FooStack.stackup
|
|
76
|
+
Pancake.configuration.stacks(FooStack).should be_an_instance_of(FooStack)
|
|
77
|
+
Pancake.configuration.configs(FooStack).should equal(router.configuration)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should allow me to create a configuration with a label" do
|
|
81
|
+
FooStack.configuration(:my_config).should be_an_instance_of(FooStack::Configuration)
|
|
82
|
+
FooStack.configuration(:my_config).should_not equal(FooStack.configuration)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should create a stack with an app_name" do
|
|
86
|
+
FooStack.stackup(:app_name => "my.app.name")
|
|
87
|
+
Pancake.configuration.stacks(FooStack).should be_nil
|
|
88
|
+
Pancake.configuration.stacks("my.app.name").should be_an_instance_of(FooStack)
|
|
89
|
+
Pancake.configuration.configs("my.app.name").should be_an_instance_of(FooStack::Configuration)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "should provide access to the configuration in a block" do
|
|
93
|
+
Pancake.configuration.configs(FooStack) do |config|
|
|
94
|
+
config.foo = :foo
|
|
95
|
+
end
|
|
96
|
+
@app = FooStack.stackup
|
|
97
|
+
@app.configuration.foo.should == :foo
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Pancake::Stack" do
|
|
4
|
+
before(:each) do
|
|
5
|
+
class ::StackSpecStack < Pancake::Stack
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
after(:each) do
|
|
10
|
+
clear_constants(:StackSpecStack)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe "roots" do
|
|
14
|
+
|
|
15
|
+
it "should provide access to setting the roots" do
|
|
16
|
+
StackSpecStack.roots.should be_empty
|
|
17
|
+
StackSpecStack.roots << File.expand_path(File.dirname(__FILE__))
|
|
18
|
+
StackSpecStack.roots.should include(File.expand_path(File.dirname(__FILE__)))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "should provide access to adding a root" do
|
|
22
|
+
StackSpecStack.roots.should be_empty
|
|
23
|
+
StackSpecStack.roots << Pancake.get_root(__FILE__)
|
|
24
|
+
StackSpecStack.roots.should include(File.expand_path(File.dirname(__FILE__)))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should allow me to get multiple roots in the order they're added" do
|
|
28
|
+
StackSpecStack.roots.should be_empty
|
|
29
|
+
StackSpecStack.roots << Pancake.get_root(__FILE__)
|
|
30
|
+
StackSpecStack.roots << "/tmp"
|
|
31
|
+
StackSpecStack.roots.should == [Pancake.get_root(__FILE__), "/tmp"]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should iterate over the roots in the direction they're added" do
|
|
35
|
+
StackSpecStack.roots.should be_empty
|
|
36
|
+
StackSpecStack.roots << Pancake.get_root(__FILE__)
|
|
37
|
+
StackSpecStack.roots << "/foo"
|
|
38
|
+
StackSpecStack.roots.map{|f| f}.should == [Pancake.get_root(__FILE__), "/foo"]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should allow me to set a root with a file" do
|
|
42
|
+
StackSpecStack.add_root(__FILE__)
|
|
43
|
+
StackSpecStack.roots.should include(Pancake.get_root(__FILE__))
|
|
44
|
+
end
|
|
45
|
+
end # roots
|
|
46
|
+
|
|
47
|
+
# describe "initialize stack" do
|
|
48
|
+
|
|
49
|
+
it "should mark a stack as initialized once it has called the initialize_stack method" do
|
|
50
|
+
StackSpecStack::BootLoader
|
|
51
|
+
StackSpecStack.roots << ::Pancake.get_root(__FILE__)
|
|
52
|
+
StackSpecStack.initialize_stack
|
|
53
|
+
StackSpecStack.should be_initialized
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "should not be initialized when it has not called initialize_stack" do
|
|
57
|
+
StackSpecStack.should_not be_initialized
|
|
58
|
+
end
|
|
59
|
+
# end
|
|
60
|
+
end
|