pancake 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/pancake +96 -0
- data/lib/pancake.rb +5 -7
- data/lib/pancake/configuration.rb +2 -23
- data/lib/pancake/core_ext/object.rb +1 -1
- data/lib/pancake/defaults/configuration.rb +21 -1
- data/lib/pancake/generators.rb +0 -3
- data/lib/pancake/hooks/inheritable_inner_classes.rb +15 -2
- data/lib/pancake/master.rb +34 -1
- data/lib/pancake/mixins/render.rb +1 -2
- data/lib/pancake/mixins/stack_helper.rb +1 -1
- data/lib/pancake/router.rb +18 -63
- data/lib/pancake/stack/configuration.rb +3 -5
- data/lib/pancake/stack/router.rb +10 -33
- data/lib/pancake/stack/stack.rb +70 -50
- data/{spec/helpers → lib/pancake/test}/helpers.rb +3 -3
- data/lib/pancake/test/matchers.rb +20 -0
- data/lib/pancake/vendor/hashie/.document +5 -0
- data/lib/pancake/vendor/hashie/.gitignore +7 -0
- data/lib/pancake/vendor/hashie/Gemfile +11 -0
- data/lib/pancake/vendor/hashie/Gemfile.lock +25 -0
- data/lib/pancake/{generators/templates/short/%stack_name%/LICENSE.tt → vendor/hashie/LICENSE} +1 -1
- data/lib/pancake/vendor/hashie/README.rdoc +101 -0
- data/lib/pancake/{generators/templates/micro/%stack_name%/Rakefile.tt → vendor/hashie/Rakefile} +3 -13
- data/lib/pancake/vendor/hashie/VERSION +1 -0
- data/lib/pancake/vendor/hashie/hashie.gemspec +33 -0
- data/lib/pancake/vendor/hashie/lib/hashie.rb +5 -0
- data/lib/pancake/vendor/hashie/lib/hashie/clash.rb +86 -0
- data/lib/pancake/vendor/hashie/lib/hashie/dash.rb +108 -0
- data/lib/pancake/vendor/hashie/lib/hashie/hash.rb +22 -0
- data/lib/pancake/vendor/hashie/lib/hashie/hash_extensions.rb +49 -0
- data/lib/pancake/vendor/hashie/lib/hashie/mash.rb +148 -0
- data/lib/pancake/vendor/hashie/spec/hashie/clash_spec.rb +42 -0
- data/lib/pancake/vendor/hashie/spec/hashie/dash_spec.rb +103 -0
- data/lib/pancake/vendor/hashie/spec/hashie/hash_spec.rb +22 -0
- data/lib/pancake/vendor/hashie/spec/hashie/mash_spec.rb +135 -0
- data/lib/pancake/vendor/hashie/spec/spec.opts +2 -0
- data/lib/pancake/{generators/templates/short/%stack_name%/spec/spec_helper.rb.tt → vendor/hashie/spec/spec_helper.rb} +7 -7
- data/spec/pancake/configuration_spec.rb +1 -1
- data/spec/pancake/constants_spec.rb +1 -1
- data/spec/pancake/defaults/configuration_spec.rb +1 -1
- data/spec/pancake/hooks/on_inherit_spec.rb +13 -13
- data/spec/pancake/inheritance_spec.rb +22 -22
- data/spec/pancake/middleware_spec.rb +6 -5
- data/spec/pancake/middlewares/logger_spec.rb +1 -1
- data/spec/pancake/middlewares/static_spec.rb +1 -1
- data/spec/pancake/mime_types_spec.rb +1 -1
- data/spec/pancake/mixins/publish_spec.rb +24 -24
- data/spec/pancake/mixins/render/template_spec.rb +1 -1
- data/spec/pancake/mixins/render/view_context_spec.rb +1 -1
- data/spec/pancake/mixins/render_spec.rb +1 -1
- data/spec/pancake/mixins/request_helper_spec.rb +1 -1
- data/spec/pancake/mixins/stack_helper_spec.rb +3 -3
- data/spec/pancake/pancake_spec.rb +1 -1
- data/spec/pancake/paths_spec.rb +30 -30
- data/spec/pancake/stack/router_spec.rb +24 -62
- data/spec/pancake/stack/stack_configuration_spec.rb +1 -1
- data/spec/pancake/stack/stack_spec.rb +47 -4
- data/spec/spec_helper.rb +3 -3
- metadata +56 -128
- data/bin/pancake-gen +0 -30
- data/lib/pancake/bootloaders.rb +0 -187
- data/lib/pancake/generators/base.rb +0 -12
- data/lib/pancake/generators/micro_generator.rb +0 -17
- data/lib/pancake/generators/short_generator.rb +0 -18
- data/lib/pancake/generators/templates/common/dotgitignore +0 -22
- data/lib/pancake/generators/templates/common/dothtaccess +0 -17
- data/lib/pancake/generators/templates/micro/%stack_name%/%stack_name%.rb.tt +0 -8
- data/lib/pancake/generators/templates/micro/%stack_name%/config.ru.tt +0 -12
- data/lib/pancake/generators/templates/micro/%stack_name%/pancake_init.rb.tt +0 -1
- 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 +0 -1
- data/lib/pancake/generators/templates/short/%stack_name%/README.tt +0 -7
- data/lib/pancake/generators/templates/short/%stack_name%/Rakefile.tt +0 -56
- data/lib/pancake/generators/templates/short/%stack_name%/VERSION.tt +0 -1
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +0 -12
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/%stack_name%.rb.tt +0 -6
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config.ru.tt +0 -10
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/config.rb.tt +0 -23
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/development.rb.tt +0 -15
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/production.rb.tt +0 -16
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config/environments/staging.rb.tt +0 -17
- data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/models/.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%/tasks/%stack_name%.rake.tt +0 -4
- 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 +0 -2
- data/lib/pancake/generators/templates/short/%stack_name%/pancake_init.rb.tt +0 -1
- data/lib/pancake/generators/templates/short/%stack_name%/spec/%stack_name%_spec.rb.tt +0 -11
- data/lib/pancake/stack/app.rb +0 -10
- data/lib/pancake/stack/bootloader.rb +0 -114
- data/lib/pancake/stack/middleware.rb +0 -0
- data/lib/pancake/stacks/short.rb +0 -3
- data/lib/pancake/stacks/short/bootloaders.rb +0 -5
- data/lib/pancake/stacks/short/controller.rb +0 -184
- data/lib/pancake/stacks/short/default/views/base.html.haml +0 -5
- data/lib/pancake/stacks/short/default/views/error.html.haml +0 -12
- data/lib/pancake/stacks/short/stack.rb +0 -207
- data/spec/helpers/matchers.rb +0 -25
- data/spec/pancake/bootloaders_spec.rb +0 -119
- data/spec/pancake/stack/app_spec.rb +0 -28
- data/spec/pancake/stack/bootloader_spec.rb +0 -41
- data/spec/pancake/stack/middleware_spec.rb +0 -0
- data/spec/pancake/stacks/short/controller_spec.rb +0 -442
- data/spec/pancake/stacks/short/middlewares_spec.rb +0 -22
- data/spec/pancake/stacks/short/router_spec.rb +0 -150
- data/spec/pancake/stacks/short/stack_spec.rb +0 -117
data/spec/helpers/matchers.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
module Pancake
|
2
|
-
module Matchers
|
3
|
-
|
4
|
-
class InheritFrom
|
5
|
-
def initialize(expected)
|
6
|
-
@expected = expected
|
7
|
-
end
|
8
|
-
|
9
|
-
def matches?(target)
|
10
|
-
@target = target
|
11
|
-
@target.ancestors.include?(@expected)
|
12
|
-
end
|
13
|
-
|
14
|
-
def failure_message
|
15
|
-
"expected #{@target} to inherit from #{@expected} but did not"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def inherit_from(expected)
|
20
|
-
InheritFrom.new(expected)
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
end # Matchers
|
25
|
-
end # Pancake
|
@@ -1,119 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe "Pancake::Stack::BootLoader" do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
$captures = []
|
7
|
-
|
8
|
-
class ::FooStack < Pancake::Stack
|
9
|
-
roots << File.join(Pancake.get_root(__FILE__), "..", "fixtures", "foo_stack")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
after(:each) do
|
14
|
-
clear_constants(:FooStack)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should not add the bootloader without it having a run! method" do
|
18
|
-
lambda do
|
19
|
-
FooStack::BootLoader.add(:foo){|s,c| :here }
|
20
|
-
end.should raise_error
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should allow me to add an application specific BootLoader" do
|
24
|
-
FooStack::BootLoader.add(:my_initializer){ def run!; :foo; end}
|
25
|
-
FooStack::BootLoader[:my_initializer].call({}).should == :foo
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should provide a bootloader instance" do
|
29
|
-
FooStack::BootLoader.add(:my_initializer){ def run!; :foo; end}
|
30
|
-
FooStack::BootLoader[:my_initializer].should inherit_from(Pancake::BootLoaderMixin::Base)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should allow me to remove a bootloader from another bootloader" do
|
34
|
-
FooStack::BootLoader.add(:foo){ def run!; $captures << :foo; end}
|
35
|
-
FooStack::BootLoader.add(:bar){ def run!; FooStack::BootLoader.delete(:removed); end }
|
36
|
-
FooStack::BootLoader.add(:removed){ def run!; $captures << :removed; end}
|
37
|
-
FooStack.new
|
38
|
-
|
39
|
-
$captures.should == [:foo]
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should allow me to add multiple boot loaders" do
|
43
|
-
FooStack::BootLoader.add(:foo){ def run!; :foo; end}
|
44
|
-
FooStack::BootLoader.add(:bar){ def run!; :bar; end}
|
45
|
-
FooStack::BootLoader[:foo].call({}).should == :foo
|
46
|
-
FooStack::BootLoader[:bar].call({}).should == :bar
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should allow me to add a bootloader before another" do
|
50
|
-
$captures.should be_empty
|
51
|
-
FooStack::BootLoader.add(:foo){ def run!; $captures << :foo; end}
|
52
|
-
FooStack::BootLoader.add(:bar){ def run!; $captures << :bar; end}
|
53
|
-
FooStack::BootLoader.add(:baz, :before => :bar){ def run!; $captures << :baz; end}
|
54
|
-
FooStack.new
|
55
|
-
$captures.should == [:foo, :baz, :bar]
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should allow me to add a bootloader after another" do
|
59
|
-
$captures.should be_empty
|
60
|
-
FooStack::BootLoader.add(:foo){ def run!; $captures << :foo; end}
|
61
|
-
FooStack::BootLoader.add(:bar){ def run!; $captures << :bar; end}
|
62
|
-
FooStack::BootLoader.add(:baz, :after => :foo){ def run!; $captures << :baz; end}
|
63
|
-
FooStack.new
|
64
|
-
$captures.should == [:foo, :baz, :bar]
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should provide an arbitrarily complex setup" do
|
68
|
-
$captures.should be_empty
|
69
|
-
FooStack::BootLoader.add(:foo ){ def run!; $captures << :foo; end}
|
70
|
-
FooStack::BootLoader.add(:bar ){ def run!; $captures << :bar; end}
|
71
|
-
FooStack::BootLoader.add(:baz, :after => :foo ){ def run!; $captures << :baz; end}
|
72
|
-
FooStack::BootLoader.add(:paz, :before => :baz ){ def run!; $captures << :paz; end}
|
73
|
-
FooStack::BootLoader.add(:fred, :before => :bar ){ def run!; $captures << :fred; end}
|
74
|
-
FooStack::BootLoader.add(:barney, :after => :fred ){ def run!; $captures << :barney; end}
|
75
|
-
|
76
|
-
FooStack.new
|
77
|
-
$captures.should == [:foo, :paz, :baz, :fred, :barney, :bar]
|
78
|
-
end
|
79
|
-
|
80
|
-
describe "types" do
|
81
|
-
|
82
|
-
it "should run bootloaders marked as :init" do
|
83
|
-
FooStack::BootLoader.add(:bar, :level => :init ){ def run!; $captures << [:bar, :init ]; end}
|
84
|
-
FooStack::BootLoader.add(:baz, :level => :init ){ def run!; $captures << [:baz, :init ]; end}
|
85
|
-
FooStack::BootLoader.add(:paz, :level => :init, :before => :baz){ def run!; $captures << [:paz, :init]; end}
|
86
|
-
|
87
|
-
FooStack::BootLoader.run!(:only => {:level => :init})
|
88
|
-
$captures.should == [[:bar, :init], [:paz, :init], [:baz, :init]]
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should run init or then default level bootloaders individually" do
|
92
|
-
FooStack::BootLoader.add(:foo ){ def run!; $captures << [:foo, :default]; end}
|
93
|
-
FooStack::BootLoader.add(:grh ){ def run!; $captures << [:grh, :default]; end}
|
94
|
-
FooStack::BootLoader.add(:bar, :level => :init ){ def run!; $captures << [:bar, :init ]; end}
|
95
|
-
FooStack::BootLoader.add(:ptf, :before => :grh ){ def run!; $captures << [:ptf, :default]; end}
|
96
|
-
FooStack::BootLoader.add(:baz, :level => :init ){ def run!; $captures << [:baz, :init ]; end}
|
97
|
-
FooStack::BootLoader.add(:paz, :level => :init, :before => :baz){ def run!; $captures << [:paz, :init]; end}
|
98
|
-
|
99
|
-
FooStack.new
|
100
|
-
$captures.should == [[:bar, :init], [:paz, :init], [:baz, :init], [:foo, :default], [:ptf, :default], [:grh, :default]]
|
101
|
-
end
|
102
|
-
|
103
|
-
# it "should inherit from the default boot loaders" do
|
104
|
-
# ::Pancake::Stack::BootLoader.add(:default_boot_loader_test){def run!; end}
|
105
|
-
# class ::Bario < Pancake::Stack; end
|
106
|
-
# Bario::BootLoader.map{|n,bl| n}.should include(:default_boot_loader_test)
|
107
|
-
# ::Pancake::Stack::BootLoader.
|
108
|
-
# end
|
109
|
-
|
110
|
-
it "should let me pass options to the bootloaders and pass them on" do
|
111
|
-
FooStack::BootLoader.add(:foo){ def run!; config[:result] << :foo; end}
|
112
|
-
FooStack::BootLoader.add(:bar){ def run!; config[:result] << :bar; end}
|
113
|
-
|
114
|
-
opts = { :result => [] }
|
115
|
-
FooStack.new(nil, opts)
|
116
|
-
opts[:result].should == [:foo, :bar]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
@@ -1,28 +0,0 @@
|
|
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
|
@@ -1,41 +0,0 @@
|
|
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
|
@@ -1,442 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)),'..', '..', '..', 'spec_helper')
|
2
|
-
|
3
|
-
describe Pancake::Stacks::Short::Controller do
|
4
|
-
|
5
|
-
before do
|
6
|
-
class ::ShortFoo < Pancake::Stacks::Short
|
7
|
-
add_root(__FILE__)
|
8
|
-
add_root(File.expand_path(File.dirname(__FILE__)), "..", "fixtures", "stacks", "short", "foobar")
|
9
|
-
class Controller
|
10
|
-
|
11
|
-
def do_dispatch!
|
12
|
-
dispatch!
|
13
|
-
end
|
14
|
-
|
15
|
-
publish
|
16
|
-
def show; "show"; end
|
17
|
-
|
18
|
-
publish
|
19
|
-
def index; "index"; end
|
20
|
-
|
21
|
-
publish
|
22
|
-
def a_rack_response
|
23
|
-
r = Rack::Response.new
|
24
|
-
r.redirect("/foo")
|
25
|
-
r
|
26
|
-
end
|
27
|
-
|
28
|
-
publish
|
29
|
-
def an_array_response
|
30
|
-
[200, {"Content-Type" => "text/plain"}, ["Custom Array Response"]]
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
def a_protected_method; "protected"; end
|
35
|
-
|
36
|
-
private
|
37
|
-
def a_private_method; "private"; end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
after do
|
43
|
-
clear_constants "ShortFoo", :ShortBar
|
44
|
-
end
|
45
|
-
|
46
|
-
def app
|
47
|
-
ShortFoo.stackup
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should have a Controller" do
|
51
|
-
Pancake::Stacks::Short.constants.map(&:to_s).should include("Controller")
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should inherit the subclass controller from the parent controller" do
|
55
|
-
ShortFoo::Controller.should inherit_from(Pancake::Stacks::Short::Controller)
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "dispatching an action" do
|
59
|
-
before do
|
60
|
-
@controller = ShortFoo::Controller.new(env_for)
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should call the 'show' action" do
|
64
|
-
@controller.params["action"] = "show"
|
65
|
-
result = @controller.do_dispatch!
|
66
|
-
result[0].should == 200
|
67
|
-
result[2].body.join.should == "show"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should raise a Pancake::Response::NotFound exception when an action is now found" do
|
71
|
-
@controller.params["action"] = :does_not_exist
|
72
|
-
result = @controller.do_dispatch!
|
73
|
-
result[0].should == 404
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should not dispatch to a protected method" do
|
77
|
-
@controller.params["action"] = "a_protected_method"
|
78
|
-
result = @controller.do_dispatch!
|
79
|
-
result[0].should == 404
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should not dispatch to a private method" do
|
83
|
-
@controller.params["action"] = "a_private_method"
|
84
|
-
result = @controller.do_dispatch!
|
85
|
-
result[0].should == 404
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should raise an exception if pancake has told it not to handle errors" do
|
89
|
-
Pancake.should_receive(:handle_errors?).and_return(false)
|
90
|
-
@controller.params["action"] = "a_private_method"
|
91
|
-
lambda do
|
92
|
-
@controller.do_dispatch!
|
93
|
-
end.should raise_error
|
94
|
-
end
|
95
|
-
|
96
|
-
it "should let me return an array as a rack response" do
|
97
|
-
@controller.params["action"] = "an_array_response"
|
98
|
-
result = @controller.do_dispatch!
|
99
|
-
result.should == [200, {"Content-Type" => "text/plain"}, ["Custom Array Response"]]
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should allow me to return a Rack::Response" do
|
103
|
-
@controller.params["action"] = "a_rack_response"
|
104
|
-
result = @controller.do_dispatch!
|
105
|
-
result[0].should == 302
|
106
|
-
result[1]["Location"].should == "/foo"
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "helper in methods" do
|
110
|
-
before do
|
111
|
-
module PancakeTestHelper
|
112
|
-
def some_helper_method
|
113
|
-
"foo"
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class ShortFoo
|
118
|
-
class Controller
|
119
|
-
include PancakeTestHelper
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
after do
|
124
|
-
clear_constants "PancakeTestHelper"
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should not call a helper method" do
|
128
|
-
@controller.params["action"] = "some_helper_method"
|
129
|
-
result = @controller.do_dispatch!
|
130
|
-
result[0].should == 404
|
131
|
-
end
|
132
|
-
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
describe "request helper methods" do
|
137
|
-
before do
|
138
|
-
class ::RequestFoo < Pancake::Stacks::Short
|
139
|
-
add_root(__FILE__, "..", "..", "fixtures", "stacks", "short", "foobar")
|
140
|
-
get "/foobar", :_name => :foobar do
|
141
|
-
url(:foobar)
|
142
|
-
end
|
143
|
-
|
144
|
-
get "/template", :_name => :template do
|
145
|
-
render :template
|
146
|
-
end
|
147
|
-
|
148
|
-
get "/vault" do
|
149
|
-
v[:my_data] = "some data"
|
150
|
-
render :vault
|
151
|
-
end
|
152
|
-
|
153
|
-
get "/redirect" do
|
154
|
-
redirect "/some_other_place"
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
after do
|
160
|
-
clear_constants :RequestFoo
|
161
|
-
end
|
162
|
-
|
163
|
-
def app
|
164
|
-
RequestFoo.stackup
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should include the request helper methods" do
|
168
|
-
(Pancake::Mixins::RequestHelper > ShortFoo::Controller).should be_true
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should provide access to the request methods in the controller" do
|
172
|
-
result = get "/foobar"
|
173
|
-
result.body.should == "/foobar"
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should provide access to the helper methods in the views" do
|
177
|
-
result = get "/template"
|
178
|
-
result.status.should == 200
|
179
|
-
result.body.should include("/foobar")
|
180
|
-
result.body.should include("In Template")
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should allow me to get information between the view and the controller" do
|
184
|
-
result = get "/vault"
|
185
|
-
result.status.should == 200
|
186
|
-
result.body.should include("some data")
|
187
|
-
result.body.should include("In Vault")
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should redirect" do
|
191
|
-
result = get "/redirect"
|
192
|
-
result.status.should == 302
|
193
|
-
result.headers["Location"].should == "/some_other_place"
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe "accept type negotiations" do
|
198
|
-
before do
|
199
|
-
class ::ShortBar < Pancake::Stacks::Short
|
200
|
-
roots << Pancake.get_root(__FILE__)
|
201
|
-
# makes the dispatch method public
|
202
|
-
def do_dispatch!
|
203
|
-
dispatch!
|
204
|
-
end
|
205
|
-
|
206
|
-
provides :json, :xml, :text
|
207
|
-
|
208
|
-
get "/foo/bar(.:format)" do
|
209
|
-
"format #{content_type.inspect}"
|
210
|
-
end
|
211
|
-
end # ShortBar
|
212
|
-
end # before
|
213
|
-
|
214
|
-
def app
|
215
|
-
ShortBar.stackup
|
216
|
-
end
|
217
|
-
|
218
|
-
it "should get json by default" do
|
219
|
-
result = get "/foo/bar", {}, "HTTP_ACCEPT" => "application/json"
|
220
|
-
result.status.should == 200
|
221
|
-
result.headers["Content-Type"].should == "application/json"
|
222
|
-
result.body.to_s.should == "format :json"
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should get xml when specified" do
|
226
|
-
result = get "/foo/bar.xml"
|
227
|
-
result.status.should == 200
|
228
|
-
result.headers["Content-Type"].should == "application/xml"
|
229
|
-
result.body.to_s.should == "format :xml"
|
230
|
-
end
|
231
|
-
|
232
|
-
it "should get json when specified with */*" do
|
233
|
-
result = get "/foo/bar", {}, "HTTP_ACCEPT" => "*/*"
|
234
|
-
result.status.should == 200
|
235
|
-
result.body.to_s.should == "format :json"
|
236
|
-
result.headers["Content-Type"].should == "application/json"
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should get the default when specified with */*" do
|
240
|
-
result = get "/foo/bar", {}, "HTTP_ACCEPT" => "application/xml,*/*"
|
241
|
-
result.status.should == 200
|
242
|
-
result.body.to_s.should == "format :json"
|
243
|
-
result.headers["Content-Type"].should == "application/json"
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should use the format in preference to the content type" do
|
247
|
-
result = get "/foo/bar.xml", {}, "HTTP_ACCEPT" => "*/*"
|
248
|
-
result.status.should == 200
|
249
|
-
result.body.to_s.should == "format :xml"
|
250
|
-
result.headers["Content-Type"].should == "application/xml"
|
251
|
-
end
|
252
|
-
|
253
|
-
it "should get json by default" do
|
254
|
-
result = get "/foo/bar"
|
255
|
-
result.status.should == 200
|
256
|
-
result.body.to_s.should == "format :json"
|
257
|
-
result.headers["Content-Type"].should == "application/json"
|
258
|
-
end
|
259
|
-
|
260
|
-
it "should correctly negotiate different scenarios" do
|
261
|
-
r = get "/foo/bar", {}, {}
|
262
|
-
r.body.should == "format :json"
|
263
|
-
r = get "/foo/bar.xml", {}, {}
|
264
|
-
r.body.should == "format :xml"
|
265
|
-
r = get "/foo/bar", {}, {}
|
266
|
-
r.body.should == "format :json"
|
267
|
-
r = get "/foo/bar", {}, "HTTP_ACCEPT" => "application/xml"
|
268
|
-
r.body.should == "format :xml"
|
269
|
-
r = get "/foo/bar.json"
|
270
|
-
r.body.should == "format :json"
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should negotiate based on extension" do
|
274
|
-
r = get "/foo/bar"
|
275
|
-
r.body.should == "format :json"
|
276
|
-
r = get "/foo/bar.text"
|
277
|
-
r.body.should == "format :text"
|
278
|
-
r = get "/foo/bar.xml"
|
279
|
-
r.body.should == "format :xml"
|
280
|
-
r = get "/foo/bar.txt"
|
281
|
-
r.body.should == "format :text"
|
282
|
-
end
|
283
|
-
|
284
|
-
it "should not provide a response to a format that is not provided" do
|
285
|
-
r = get "/foo/bar.svg"
|
286
|
-
r.status.should == 406
|
287
|
-
end
|
288
|
-
end # Accept type negotiations
|
289
|
-
|
290
|
-
describe "error handling" do
|
291
|
-
before do
|
292
|
-
class ::ShortFoo
|
293
|
-
provides :html, :xml
|
294
|
-
|
295
|
-
get "/foo(.:format)" do
|
296
|
-
"HERE"
|
297
|
-
end
|
298
|
-
|
299
|
-
get "/bad" do
|
300
|
-
raise "This is bad"
|
301
|
-
end
|
302
|
-
|
303
|
-
get "/template/:name" do
|
304
|
-
render params[:name]
|
305
|
-
end
|
306
|
-
|
307
|
-
end
|
308
|
-
end
|
309
|
-
|
310
|
-
describe "default error handling" do
|
311
|
-
def app
|
312
|
-
ShortFoo.stackup
|
313
|
-
end
|
314
|
-
|
315
|
-
it "should handle a NotFound by default" do
|
316
|
-
result = get "/does_not_exist"
|
317
|
-
result.status.should == 404
|
318
|
-
result.body.should include(Pancake::Errors::NotFound.description)
|
319
|
-
end
|
320
|
-
|
321
|
-
it "should return a 500 status for a Random Error by wrapping it in a Pancake::Errors::Server" do
|
322
|
-
result = get "/bad"
|
323
|
-
result.status.should == 500
|
324
|
-
result.body.should include(Pancake::Errors::Server.description)
|
325
|
-
end
|
326
|
-
|
327
|
-
it "should handle a NotAcceptable error" do
|
328
|
-
result = get "/foo.no_format_i_know_of"
|
329
|
-
result.status.should == 406
|
330
|
-
result.body.should include(Pancake::Errors::NotAcceptable.description)
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should return 406 for a format that is in pancake but not in the group" do
|
334
|
-
r = get "/foo.svg"
|
335
|
-
r.status.should == 406
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
describe "custom error handling" do
|
340
|
-
before do
|
341
|
-
ShortFoo.handle_exception do |error|
|
342
|
-
out = ""
|
343
|
-
out << "CUSTOM "
|
344
|
-
out << error.name
|
345
|
-
out << ": "
|
346
|
-
out << error.description
|
347
|
-
end
|
348
|
-
|
349
|
-
ShortFoo.get "/bad" do
|
350
|
-
raise "Really Bad"
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
after do
|
355
|
-
ShortFoo.handle_exception(&Pancake::Stacks::Short::Controller::DEFAULT_EXCEPTION_HANDLER)
|
356
|
-
end
|
357
|
-
|
358
|
-
it "should handle Pancake::Errors::NotFound errors" do
|
359
|
-
r = get "/not_a_thing"
|
360
|
-
r.status.should == 404
|
361
|
-
r.body.should include("CUSTOM")
|
362
|
-
r.body.should include(Pancake::Errors::NotFound.description)
|
363
|
-
end
|
364
|
-
|
365
|
-
it "should handle an unknown server error" do
|
366
|
-
r = get "/bad"
|
367
|
-
r.status.should == 500
|
368
|
-
r.body.should include("CUSTOM")
|
369
|
-
r.body.should include(Pancake::Errors::Server.description)
|
370
|
-
end
|
371
|
-
|
372
|
-
it "should let me do stuff on an instance level inside the handle exception" do
|
373
|
-
ShortFoo.handle_exception do |error|
|
374
|
-
self.status = 123
|
375
|
-
"BOOO!"
|
376
|
-
end
|
377
|
-
|
378
|
-
r = get "/bad"
|
379
|
-
r.status.should == 123
|
380
|
-
r.body.should == "BOOO!"
|
381
|
-
end
|
382
|
-
|
383
|
-
end
|
384
|
-
|
385
|
-
describe "rendering" do
|
386
|
-
|
387
|
-
it "should render a template" do
|
388
|
-
result = get "/template/basic"
|
389
|
-
result.body.should include("basic template")
|
390
|
-
end
|
391
|
-
|
392
|
-
it "should inherit from a base view provided by short stacks" do
|
393
|
-
File.file?(File.join(File.expand_path(File.dirname(__FILE__)), "..", "fixtures", "stacks", "short", "foobar", "views", "base.html.haml")).should be_false
|
394
|
-
result = get "/template/inherited_from_base"
|
395
|
-
result.body.should include("inherited from base")
|
396
|
-
result.body.should include("Pancake")
|
397
|
-
end
|
398
|
-
|
399
|
-
it "should allow me to overwrite the base tempalte in later roots" do
|
400
|
-
ShortFoo.add_root(File.expand_path(File.dirname(__FILE__)), "..", "fixtures", "stacks", "short", "foobar", "other_root")
|
401
|
-
result = get "/template/inherited_from_base"
|
402
|
-
result.body.should include("inherited from base")
|
403
|
-
result.body.should include("Not the default pancake")
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
describe "throwing" do
|
408
|
-
before do
|
409
|
-
ShortFoo.get("/plain_throw"){ throw :halt }
|
410
|
-
ShortFoo.get("/string_throw"){ throw :halt, "output string" }
|
411
|
-
ShortFoo.get("/status_n_throw"){ self.status = 204; throw :halt }
|
412
|
-
ShortFoo.get("/headers_n_throw") do
|
413
|
-
headers["some-header"] = Time.now.to_s
|
414
|
-
throw :halt
|
415
|
-
end
|
416
|
-
end
|
417
|
-
|
418
|
-
it "should handle a plain throw" do
|
419
|
-
result = get "/plain_throw"
|
420
|
-
result.should be_successful
|
421
|
-
result.body.should == ""
|
422
|
-
end
|
423
|
-
|
424
|
-
it "should handle a string throw" do
|
425
|
-
result = get "/string_throw"
|
426
|
-
result.should be_successful
|
427
|
-
result.body.should == "output string"
|
428
|
-
end
|
429
|
-
|
430
|
-
it "should handle a change in the status" do
|
431
|
-
result = get "/status_n_throw"
|
432
|
-
result.status.should == 204
|
433
|
-
result.body.should == ""
|
434
|
-
end
|
435
|
-
|
436
|
-
it "should handle a change in the headers" do
|
437
|
-
result = get "/headers_n_throw"
|
438
|
-
result.headers["some-header"].should_not be_blank
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
442
|
-
end
|