hassox-pancake 0.1.6
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 +18 -0
- data/bin/jeweler +19 -0
- data/bin/pancake-gen +17 -0
- data/bin/rubyforge +19 -0
- data/lib/pancake.rb +48 -0
- data/lib/pancake/bootloaders.rb +180 -0
- data/lib/pancake/configuration.rb +140 -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/errors.rb +61 -0
- data/lib/pancake/generators.rb +8 -0
- data/lib/pancake/generators/base.rb +12 -0
- data/lib/pancake/generators/flat_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/flat/%stack_name%/%stack_name%.rb.tt +8 -0
- data/lib/pancake/generators/templates/flat/%stack_name%/.gitignore +21 -0
- data/lib/pancake/generators/templates/flat/%stack_name%/config.ru.tt +12 -0
- data/lib/pancake/generators/templates/flat/%stack_name%/pancake.init.tt +1 -0
- data/lib/pancake/generators/templates/flat/%stack_name%/public/.empty_directory +0 -0
- data/lib/pancake/generators/templates/flat/%stack_name%/tmp/.empty_directory +0 -0
- data/lib/pancake/generators/templates/short/%stack_name%/.gitignore +21 -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 +48 -0
- data/lib/pancake/generators/templates/short/%stack_name%/VERSION.tt +1 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +5 -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 +12 -0
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/gems/cache/.empty_directory +0 -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%/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%/.gitignore +21 -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 +48 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/VERSION.tt +1 -0
- data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%.rb.tt +3 -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%/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%/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%/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/hooks/inheritable_inner_classes.rb +60 -0
- data/lib/pancake/hooks/on_inherit.rb +34 -0
- data/lib/pancake/master.rb +87 -0
- data/lib/pancake/middleware.rb +354 -0
- data/lib/pancake/mime_types.rb +265 -0
- data/lib/pancake/mixins/publish.rb +125 -0
- data/lib/pancake/mixins/publish/action_options.rb +104 -0
- data/lib/pancake/mixins/render.rb +61 -0
- data/lib/pancake/mixins/request_helper.rb +92 -0
- data/lib/pancake/mixins/stack_helper.rb +44 -0
- data/lib/pancake/mixins/url.rb +10 -0
- data/lib/pancake/more/controller.rb +4 -0
- data/lib/pancake/more/controller/base.rb +34 -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 +18 -0
- data/lib/pancake/stack/stack.rb +57 -0
- data/lib/pancake/stacks/short.rb +2 -0
- data/lib/pancake/stacks/short/controller.rb +105 -0
- data/lib/pancake/stacks/short/stack.rb +194 -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/fixtures/foo_stack/pancake.init +0 -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 +1 -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/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/mime_types_spec.rb +234 -0
- data/spec/pancake/mixins/publish_spec.rb +94 -0
- data/spec/pancake/mixins/render_spec.rb +55 -0
- data/spec/pancake/mixins/stack_helper_spec.rb +46 -0
- data/spec/pancake/pancake_spec.rb +31 -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 +266 -0
- data/spec/pancake/stack/stack_configuration_spec.rb +101 -0
- data/spec/pancake/stack/stack_spec.rb +55 -0
- data/spec/pancake/stacks/short/controller_spec.rb +287 -0
- data/spec/pancake/stacks/short/router_spec.rb +132 -0
- data/spec/pancake/stacks/short/stack_spec.rb +40 -0
- data/spec/spec_helper.rb +21 -0
- metadata +238 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Pancake::Paths do
|
|
4
|
+
|
|
5
|
+
def fixture_root
|
|
6
|
+
File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "paths"))
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
before(:each) do
|
|
10
|
+
remove_consts!
|
|
11
|
+
class ::Foo
|
|
12
|
+
extend Pancake::Paths
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
after(:all) do
|
|
17
|
+
remove_consts!
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def remove_consts!
|
|
21
|
+
Object.class_eval do
|
|
22
|
+
remove_const("Foo") if defined?(Foo)
|
|
23
|
+
remove_const("Bar") if defined?(Bar)
|
|
24
|
+
remove_const("Baz") if defined?(Baz)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe "setting roots" do
|
|
29
|
+
it "should allow me to set roots" do
|
|
30
|
+
Foo.roots.should == []
|
|
31
|
+
Foo.roots << fixture_root
|
|
32
|
+
Foo.roots.should == [fixture_root]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "pushing paths" do
|
|
37
|
+
before do
|
|
38
|
+
Foo.roots << fixture_root
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "should push a single path" do
|
|
42
|
+
Foo.push_paths(:models, "models")
|
|
43
|
+
Foo.dirs_for(:models).should == [File.join(fixture_root,"models")]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "should give me an empty array of paths when there have been no paths added" do
|
|
47
|
+
Foo.dirs_for(:models).should == []
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "should raise and error if there are no paths specified" do
|
|
51
|
+
lambda do
|
|
52
|
+
Foo.push_paths(:models)
|
|
53
|
+
end.should raise_error(ArgumentError)
|
|
54
|
+
|
|
55
|
+
lambda do
|
|
56
|
+
Foo.push_paths(:models, [])
|
|
57
|
+
end.should raise_error(Pancake::Paths::NoPathsGiven)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "should allow me to push multiple times to a single path group" do
|
|
61
|
+
Foo.push_paths(:models, "models")
|
|
62
|
+
Foo.push_paths(:models, "stack/models")
|
|
63
|
+
Foo.dirs_for(:models).should == [
|
|
64
|
+
File.join(fixture_root, "models"),
|
|
65
|
+
File.join(fixture_root, "stack", "models")
|
|
66
|
+
]
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "should allow me to push multiple path sets" do
|
|
70
|
+
Foo.push_paths(:models, ["models", "stack/models"])
|
|
71
|
+
Foo.push_paths(:controllers, "controllers")
|
|
72
|
+
Foo.push_paths(:views, "stack/views")
|
|
73
|
+
Foo.dirs_for(:models).should == [
|
|
74
|
+
File.join(fixture_root, "models"),
|
|
75
|
+
File.join(fixture_root, "stack", "models")
|
|
76
|
+
]
|
|
77
|
+
Foo.dirs_for(:controllers ).should == [File.join(fixture_root, "controllers")]
|
|
78
|
+
Foo.dirs_for(:views ).should == [File.join(fixture_root, "stack", "views")]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should reverse the dirs_for when specified" do
|
|
82
|
+
Foo.push_paths(:models, ["models", "stack/models"])
|
|
83
|
+
Foo.dirs_for(:models, :invert => true).should == [
|
|
84
|
+
File.join(fixture_root, "stack", "models"),
|
|
85
|
+
File.join(fixture_root, "models")
|
|
86
|
+
]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe "globs" do
|
|
90
|
+
it "should allow me to supply a glob to associate with the path" do
|
|
91
|
+
Foo.push_paths(:models, "models", "**/*.rb")
|
|
92
|
+
Foo.push_paths(:models, "stack/models", "**/*.rb")
|
|
93
|
+
Foo.dirs_and_glob_for(:models).should == [
|
|
94
|
+
[File.join(fixture_root, "models"), "**/*.rb"],
|
|
95
|
+
[File.join(fixture_root, "stack", "models"), "**/*.rb"]
|
|
96
|
+
]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should associate an empty glob when not specified" do
|
|
100
|
+
Foo.push_paths(:models, "foo/bar")
|
|
101
|
+
Foo.dirs_for(:models).should == [File.join(fixture_root, "foo/bar")]
|
|
102
|
+
Foo.dirs_and_glob_for(:models).should == [[File.join(fixture_root, "foo/bar"), nil]]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should revers the dirs_and_globs when requested" do
|
|
106
|
+
Foo.push_paths(:models, "models", "**/*.rb")
|
|
107
|
+
Foo.push_paths(:models, "stack/models", "**/*.rb")
|
|
108
|
+
result = Foo.dirs_and_glob_for(:models, :invert => true)
|
|
109
|
+
result.should == [
|
|
110
|
+
[File.join(fixture_root, "stack", "models"), "**/*.rb"],
|
|
111
|
+
[File.join(fixture_root, "models"), "**/*.rb"]
|
|
112
|
+
]
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe "reading paths" do
|
|
118
|
+
before(:each) do
|
|
119
|
+
@model_root = File.join(fixture_root, "models")
|
|
120
|
+
@stack_root = File.join(fixture_root, "stack/models")
|
|
121
|
+
Foo.roots << fixture_root
|
|
122
|
+
Foo.push_paths(:model, ["models", "stack/models"], "**/*.rb")
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it "should have list all the paths for :model" do
|
|
126
|
+
result = Foo.paths_for(:model).should == [
|
|
127
|
+
[@model_root, "/model1.rb"],
|
|
128
|
+
[@model_root, "/model2.rb"],
|
|
129
|
+
[@model_root, "/model3.rb"],
|
|
130
|
+
[@stack_root, "/model3.rb"]
|
|
131
|
+
]
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "should allow me to invert the order of the roots" do
|
|
135
|
+
result = Foo.paths_for(:model, :invert => true).should == [
|
|
136
|
+
[@stack_root, "/model3.rb"],
|
|
137
|
+
[@model_root, "/model3.rb"],
|
|
138
|
+
[@model_root, "/model2.rb"],
|
|
139
|
+
[@model_root, "/model1.rb"]
|
|
140
|
+
]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "should allow me to get the unique_paths" do
|
|
144
|
+
result = Foo.unique_paths_for(:model).should == [
|
|
145
|
+
[@model_root, "/model1.rb"],
|
|
146
|
+
[@model_root, "/model2.rb"],
|
|
147
|
+
[@stack_root, "/model3.rb"]
|
|
148
|
+
]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
it "should allow me to invert the order of the unique_paths" do
|
|
152
|
+
result = Foo.unique_paths_for(:model, :invert => true).should == [
|
|
153
|
+
[@model_root, "/model3.rb"],
|
|
154
|
+
[@model_root, "/model2.rb"],
|
|
155
|
+
[@model_root, "/model1.rb"]
|
|
156
|
+
]
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
describe "inherited paths" do
|
|
161
|
+
before(:each) do
|
|
162
|
+
Foo.push_paths(:model, "models")
|
|
163
|
+
Foo.push_paths(:controller, "controllers")
|
|
164
|
+
Foo.roots << fixture_root
|
|
165
|
+
class ::Bar < Foo; end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it "should inherit paths from the parent" do
|
|
169
|
+
Bar.dirs_for(:model).should == [File.join(fixture_root, "models")]
|
|
170
|
+
Bar.dirs_for(:controller).should == [File.join(fixture_root, "controllers")]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it "should let me add to the collection from the parent" do
|
|
174
|
+
Bar.push_paths(:model, "stack/models")
|
|
175
|
+
Bar.dirs_for(:model).should == [
|
|
176
|
+
File.join(fixture_root, "models"),
|
|
177
|
+
File.join(fixture_root, "stack/models")
|
|
178
|
+
]
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "should not bleed paths back up to the parent" do
|
|
182
|
+
Bar.push_paths(:model, "stack/models")
|
|
183
|
+
Foo.dirs_for(:model).should == [File.join(fixture_root, "models")]
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
it "should not bleed paths over to a sibling class" do
|
|
187
|
+
class ::Baz < Foo; end
|
|
188
|
+
Bar.push_paths(:model, "stack/models")
|
|
189
|
+
Baz.push_paths(:model, "baz/paths")
|
|
190
|
+
Bar.dirs_for(:model).should == [
|
|
191
|
+
File.join(fixture_root, "models"),
|
|
192
|
+
File.join(fixture_root, "stack/models")
|
|
193
|
+
]
|
|
194
|
+
Baz.dirs_for(:model).should == [
|
|
195
|
+
File.join(fixture_root, "models"),
|
|
196
|
+
File.join(fixture_root, "baz/paths")
|
|
197
|
+
]
|
|
198
|
+
Foo.dirs_for(:model).should == [File.join(fixture_root, "models")]
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "should inherit multpile times" do
|
|
202
|
+
class ::Baz < Bar; end
|
|
203
|
+
Bar.push_paths(:model, "bar/path")
|
|
204
|
+
Baz.dirs_for(:model).should == [
|
|
205
|
+
File.join(fixture_root, "models"),
|
|
206
|
+
File.join(fixture_root, "bar/path")
|
|
207
|
+
]
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Pancake::Stack.new_app_instance" do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
class ::FooStack < Pancake::Stack
|
|
7
|
+
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after(:each) do
|
|
12
|
+
clear_constants(:FooStack)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "should provide a new instance of the applciation" do
|
|
16
|
+
FooStack.new_app_instance.should == Pancake::MISSING_APP
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should allow me to overwrite the new_app_instance for this stack" do
|
|
20
|
+
class ::BarStack < Pancake::Stack
|
|
21
|
+
def self.new_app_instance
|
|
22
|
+
::Pancake::OK_APP
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
BarStack.new_app_instance.should == ::Pancake::OK_APP
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Stack BootLoaders" do
|
|
4
|
+
|
|
5
|
+
before(:each) do
|
|
6
|
+
clear_constants(:FooStack, :BarStack)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "should inherit the standard bootloaders from Pancake::Stack" do
|
|
10
|
+
class ::FooStack < Pancake::Stack; end
|
|
11
|
+
FooStack::BootLoader.should inherit_from(Pancake::Stack::BootLoader)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should get all the bootloaders from pancake stack" do
|
|
15
|
+
class ::FooStack < Pancake::Stack; end
|
|
16
|
+
FooStack::BootLoader.map{|n,bl|n}.should == Pancake::Stack::BootLoader.map{|n,bl|n}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "should let FooStack define it's own bootloaders" do
|
|
20
|
+
class ::FooStack < Pancake::Stack; end
|
|
21
|
+
FooStack::BootLoader.add(:foo_stack_bootloader){ def run!; end }
|
|
22
|
+
FooStack::BootLoader.map{|n,b|n}.should include(:foo_stack_bootloader)
|
|
23
|
+
Pancake::Stack::BootLoader.map{|n,b|n}.should_not include(:foo_stack_bootloader)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "should not pollute other bootloaders" do
|
|
27
|
+
class ::FooStack < Pancake::Stack; end
|
|
28
|
+
FooStack::BootLoader.add(:foo_stack_bootloader){ def run!; end }
|
|
29
|
+
class ::BarStack < Pancake::Stack; end
|
|
30
|
+
FooStack::BootLoader.map{|n,b|n}.should_not == BarStack::BootLoader.map{|n,b|n}
|
|
31
|
+
BarStack::BootLoader.map{|n,b|n}.should_not include(:foo_stack_bootloader)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "should inherit custom bootloaders" do
|
|
35
|
+
class ::FooStack < Pancake::Stack; end
|
|
36
|
+
FooStack::BootLoader.add(:foo_stack_bootloader){ def run!; end }
|
|
37
|
+
class ::BarStack < FooStack; end
|
|
38
|
+
BarStack::BootLoader.map{|n,b|n}.should include(:foo_stack_bootloader)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,266 @@
|
|
|
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
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "generating routes" do
|
|
76
|
+
before do
|
|
77
|
+
FooApp.router do |r|
|
|
78
|
+
r.add("/simple/route" ).name(:simple)
|
|
79
|
+
r.add("/var/with/:var", :_defaults => {:var => "some_var"}).name(:defaults)
|
|
80
|
+
r.add("/complex/:var" ).name(:complex)
|
|
81
|
+
r.add("/optional(/:var)" ).name(:optional)
|
|
82
|
+
r.add("/some/:unique_var")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it "should allow me to generate a named route for a stack" do
|
|
87
|
+
Pancake.url(FooApp, :simple).should == "/simple/route"
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should allow me to generate a non-named route for a stack" do
|
|
91
|
+
Pancake.url(FooApp, :complex, :var => "a_variable").should == "/complex/a_variable"
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
it "should allow me to generate a route with values" do
|
|
95
|
+
Pancake.url(FooApp, :optional).should == "/optional"
|
|
96
|
+
Pancake.url(FooApp, :optional, :var => "some_var").should == "/optional/some_var"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it "should allow me to generate routes with defaults" do
|
|
100
|
+
Pancake.url(FooApp, :defaults).should == "/var/with/some_var"
|
|
101
|
+
Pancake.url(FooApp, :defaults, :var => "this_is_a_var").should == "/var/with/this_is_a_var"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it "should allow me to generate a route by params" do
|
|
105
|
+
Pancake.url(FooApp, :unique_var => "unique_var").should == "/some/unique_var"
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe "mounted route generation" do
|
|
109
|
+
before do
|
|
110
|
+
class ::BarApp < Pancake::Stack; end
|
|
111
|
+
BarApp.roots << Pancake.get_root(__FILE__)
|
|
112
|
+
BarApp.router do |r|
|
|
113
|
+
r.add("/simple").name(:simple)
|
|
114
|
+
r.add("/some/:var", :_defaults => {:var => "foo"}).name(:foo)
|
|
115
|
+
end
|
|
116
|
+
FooApp.router.mount(BarApp.stackup, "/bar")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "should allow me to generate a simple nested named route" do
|
|
120
|
+
Pancake.url(BarApp, :simple).should == "/bar/simple"
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "should allow me to generate a simple nested named route for a named app" do
|
|
124
|
+
FooApp.router.mount(BarApp.stackup(:app_name => :bar_app), "/different")
|
|
125
|
+
Pancake.url(:bar_app, :simple).should == "/different/simple"
|
|
126
|
+
Pancake.url(BarApp, :simple).should == "/bar/simple"
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe "internal stack routes" do
|
|
133
|
+
it "should pass through to the underlying app when adding a route" do
|
|
134
|
+
FooApp.router.add("/bar", :_defaults => {:action => "bar"}).name(:gary)
|
|
135
|
+
class ::FooApp
|
|
136
|
+
def self.new_app_instance
|
|
137
|
+
INNER_APP
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
@app = FooApp.stackup
|
|
142
|
+
get "/bar"
|
|
143
|
+
result = JSON.parse(last_response.body)
|
|
144
|
+
result["usher.params"].should == {"action" => "bar"}
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "should add the usher.params to the request params" do
|
|
148
|
+
app = mock("app", :call => Rack::Response.new("OK").finish, :null_object => true)
|
|
149
|
+
app.should_receive(:call).with do |e|
|
|
150
|
+
params = Rack::Request.new(e).params
|
|
151
|
+
params[:action].should == "jackson"
|
|
152
|
+
end
|
|
153
|
+
FooApp.router.mount(app, "/foo/app", :_defaults => {:action => "jackson"})
|
|
154
|
+
@app = FooApp.stackup
|
|
155
|
+
get "/foo/app"
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it "should allow me to inherit routes" do
|
|
160
|
+
FooApp.router do |r|
|
|
161
|
+
r.mount(INNER_APP, "/foo(/:stuff)", :_defaults => {"originator" => "FooApp"})
|
|
162
|
+
end
|
|
163
|
+
class ::BarApp < FooApp; end
|
|
164
|
+
BarApp.router do |r|
|
|
165
|
+
r.mount(INNER_APP, "/bar", :_defaults => {"originator" => "BarApp"})
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
@app = BarApp.stackup
|
|
169
|
+
|
|
170
|
+
get "/bar"
|
|
171
|
+
response = JSON.parse(last_response.body)
|
|
172
|
+
response["usher.params"]["originator"].should == "BarApp"
|
|
173
|
+
|
|
174
|
+
get "/foo/thing"
|
|
175
|
+
response = JSON.parse(last_response.body)
|
|
176
|
+
response["usher.params"]["originator"].should == "FooApp"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it "should generate an inherited route" do
|
|
180
|
+
FooApp.router do |r|
|
|
181
|
+
r.add("/simple").name(:simple)
|
|
182
|
+
r.mount(INNER_APP, "/foo(/:stuff)").name(:stuff)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
class ::BarApp < FooApp; end
|
|
186
|
+
|
|
187
|
+
Pancake.url(BarApp, :simple).should == "/simple"
|
|
188
|
+
Pancake.url(BarApp, :stuff => "this_stuff").should == "/foo/this_stuff"
|
|
189
|
+
Pancake.url(BarApp, :stuff, :stuff => "that_stuff").should == "/foo/that_stuff"
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "should put the configuration into the env" do
|
|
193
|
+
FooApp.router.add("/foo").to do |e|
|
|
194
|
+
e["pancake.request.configuration"].should == Pancake.configuration.configs[FooApp]
|
|
195
|
+
Rack::Response.new("OK").finish
|
|
196
|
+
end
|
|
197
|
+
@app = FooApp.stackup
|
|
198
|
+
get "/foo"
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
describe "generating urls inside an application" do
|
|
202
|
+
before do
|
|
203
|
+
class ::BarApp < FooApp; end
|
|
204
|
+
|
|
205
|
+
class ::InnerApp
|
|
206
|
+
attr_reader :env
|
|
207
|
+
include Pancake::Mixins::RequestHelper
|
|
208
|
+
|
|
209
|
+
def self.app_block(&block)
|
|
210
|
+
if block_given?
|
|
211
|
+
@app_block = block
|
|
212
|
+
end
|
|
213
|
+
@app_block
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
def call(env)
|
|
217
|
+
@env = env
|
|
218
|
+
instance_eval &self.class.app_block
|
|
219
|
+
Rack::Response.new("OK").finish
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
class ::FooApp; def self.new_app_instance; InnerApp.new; end; end
|
|
224
|
+
|
|
225
|
+
BarApp.router do |r|
|
|
226
|
+
r.add("/mounted")
|
|
227
|
+
r.add("/foo").name(:foo)
|
|
228
|
+
r.add("/other").name(:other)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
FooApp.router do |r|
|
|
232
|
+
r.mount(BarApp.stackup, "/bar")
|
|
233
|
+
r.add( "/foo" ).name(:foo)
|
|
234
|
+
r.add( "/simple").name(:simple)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
@app = FooApp.stackup
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
it "should generate the urls correctly" do
|
|
241
|
+
InnerApp.app_block do
|
|
242
|
+
url(:foo).should == "/foo"
|
|
243
|
+
url(:simple).should == "/simple"
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
get "/foo"
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
it "should generate urls correctly when nested" do
|
|
250
|
+
InnerApp.app_block do
|
|
251
|
+
url(:foo).should == "/bar/foo"
|
|
252
|
+
url(:other).should == "/bar/other"
|
|
253
|
+
end
|
|
254
|
+
get "/bar/mounted"
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it "should generate a url for another app" do
|
|
258
|
+
InnerApp.app_block do
|
|
259
|
+
url_for(BarApp, :foo).should == "/bar/foo"
|
|
260
|
+
url_for(FooApp, :foo).should == "/foo"
|
|
261
|
+
end
|
|
262
|
+
get "/foo"
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
end
|
|
266
|
+
end
|