pancake 0.2.0 → 0.3.0
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/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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Pancake::Middleware" do
|
|
4
4
|
before(:all) do
|
|
@@ -37,7 +37,7 @@ describe "Pancake::Middleware" do
|
|
|
37
37
|
end # GeneralMiddlware
|
|
38
38
|
|
|
39
39
|
class ::FooApp < Pancake::Stack
|
|
40
|
-
def self.
|
|
40
|
+
def self.new_endpoint_instance; self end
|
|
41
41
|
|
|
42
42
|
def self.call(env)
|
|
43
43
|
$current_env = env
|
|
@@ -48,7 +48,7 @@ describe "Pancake::Middleware" do
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
after(:each) do
|
|
51
|
-
clear_constants(:FooApp, :BarApp, :BazApp, :GeneralMiddleware, :BarMiddle, :FooMiddle, :BazMiddle, :PazMiddle)
|
|
51
|
+
clear_constants(:MasterApp, :FooApp, :BarApp, :BazApp, :GeneralMiddleware, :BarMiddle, :FooMiddle, :BazMiddle, :PazMiddle)
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
describe "pancake middlewares" do
|
|
@@ -80,17 +80,18 @@ describe "Pancake::Middleware" do
|
|
|
80
80
|
class ::BarMiddle < GeneralMiddleware; end
|
|
81
81
|
class ::BarApp < FooApp; end
|
|
82
82
|
class ::BazApp < FooApp; end
|
|
83
|
+
class ::MasterApp < FooApp; end
|
|
83
84
|
|
|
84
85
|
BarApp.use BarMiddle
|
|
85
86
|
BazApp.use FooMiddle
|
|
86
87
|
Pancake.use GeneralMiddleware
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
MasterApp.router do |r|
|
|
89
90
|
r.mount(BarApp, "/bar")
|
|
90
91
|
r.mount(BazApp, "/baz")
|
|
91
92
|
end
|
|
92
93
|
|
|
93
|
-
@app = Pancake.start(:root => @root){
|
|
94
|
+
@app = Pancake.start(:root => @root){ MasterApp.stackup }
|
|
94
95
|
result = get "/baz"
|
|
95
96
|
$current_env["p.s.c"].should == [GeneralMiddleware, FooMiddle]
|
|
96
97
|
reult = get "/bar"
|
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "Pancake::Controller publish declaration" do
|
|
4
4
|
before(:each) do
|
|
5
5
|
class ::PancakeTest
|
|
6
6
|
extend Pancake::Mixins::Publish
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
provides :html
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
publish
|
|
11
11
|
def simple_publish; end
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
publish :id => as(:integer)
|
|
14
14
|
def integer_test; end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
publish :start => as(:date)
|
|
17
17
|
def date_test; end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
publish :page => as(:integer, 12)
|
|
20
20
|
def default_test; end
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
publish :provides => [:xml, :json]
|
|
23
23
|
def provides_test; end
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
publish :only_provides => :xml
|
|
26
26
|
def only_provides_test; end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
publish :name => as(:string, :opt)
|
|
29
29
|
def optional_test; end
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
publish :provides => [:json, :txt],
|
|
32
|
-
:id => as(:integer, :req),
|
|
33
|
-
:name => as(:string, "Campion"),
|
|
32
|
+
:id => as(:integer, :req),
|
|
33
|
+
:name => as(:string, "Campion"),
|
|
34
34
|
:melon => as(:integer, 50),
|
|
35
35
|
:jam => as(:string, :opt),
|
|
36
36
|
:squeeze => as(:string, :req)
|
|
37
37
|
def complex_test; end
|
|
38
38
|
end
|
|
39
39
|
end
|
|
40
|
-
|
|
41
|
-
after do
|
|
40
|
+
|
|
41
|
+
after do
|
|
42
42
|
clear_constants "PancakeTest"
|
|
43
43
|
end
|
|
44
|
-
|
|
44
|
+
|
|
45
45
|
it "should publish an action" do
|
|
46
46
|
PancakeTest.actions['simple_publish'].is_a?(Pancake::Mixins::Publish::ActionOptions).should == true
|
|
47
47
|
end
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
it "should coerce a parameter into an integer" do
|
|
50
50
|
params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'integer_test', 'id' => "30")
|
|
51
51
|
params['id'].should == 30
|
|
52
52
|
end
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
it "should coerce a parameter into a date" do
|
|
55
55
|
date = Date.parse("2009/07/05")
|
|
56
56
|
params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'date_test', 'start' => "2009/07/05")
|
|
57
57
|
params['start'].should == date
|
|
58
58
|
end
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
it "should flag required params that are missing" do
|
|
61
61
|
params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'integer_test', {})
|
|
62
62
|
missing.include?(['id', :integer]).should == true
|
|
63
63
|
end
|
|
64
|
-
|
|
64
|
+
|
|
65
65
|
it "should allow parameters to be optional" do
|
|
66
66
|
params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'optional_test', {})
|
|
67
67
|
missing.empty?.should == true
|
|
68
68
|
end
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
it "should return a default value for a parameter" do
|
|
71
71
|
params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'default_test', {})
|
|
72
72
|
params['page'].should == 12
|
|
73
73
|
end
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
it "should append formats to the list allowed for an action" do
|
|
76
76
|
PancakeTest.actions['provides_test'].formats.should == [:html, :xml, :json]
|
|
77
77
|
end
|
|
78
|
-
|
|
78
|
+
|
|
79
79
|
it "should replace the list of formats allowed for an action" do
|
|
80
80
|
PancakeTest.actions['only_provides_test'].formats.should == [:xml]
|
|
81
81
|
end
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
it "should allow complex declarations" do
|
|
84
84
|
input = {'id' => "30", 'name' => "Purslane"}
|
|
85
85
|
params, missing = PancakeTest.__send__(:validate_and_coerce_params, 'complex_test', input)
|
|
@@ -88,7 +88,7 @@ describe "Pancake::Controller publish declaration" do
|
|
|
88
88
|
params['melon'].should == 50
|
|
89
89
|
params['jame'].should be_nil
|
|
90
90
|
missing.include?(['squeeze', :string]).should == true
|
|
91
|
-
|
|
91
|
+
|
|
92
92
|
PancakeTest.actions['complex_test'].formats.should == [:html, :json, :txt]
|
|
93
93
|
end
|
|
94
94
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Pancake::Mixins::StackHelper do
|
|
4
4
|
before do
|
|
@@ -38,9 +38,9 @@ describe Pancake::Mixins::StackHelper do
|
|
|
38
38
|
class ::FooBar < FooStack::Bar; end
|
|
39
39
|
FooBar.stack_class.should == FooStack
|
|
40
40
|
end
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
it "should provide access to the stack helper from an instance of the Bar class" do
|
|
43
43
|
FooStack::Bar.new.stack_class.should == FooStack
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
end
|
data/spec/pancake/paths_spec.rb
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Pancake::Paths do
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
def fixture_root
|
|
6
6
|
File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "paths"))
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
before(:each) do
|
|
10
10
|
remove_consts!
|
|
11
11
|
class ::Foo
|
|
12
12
|
extend Pancake::Paths
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
after(:all) do
|
|
17
17
|
remove_consts!
|
|
18
18
|
end
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
def remove_consts!
|
|
21
|
-
Object.class_eval do
|
|
21
|
+
Object.class_eval do
|
|
22
22
|
remove_const("Foo") if defined?(Foo)
|
|
23
23
|
remove_const("Bar") if defined?(Bar)
|
|
24
24
|
remove_const("Baz") if defined?(Baz)
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
describe "setting roots" do
|
|
29
29
|
it "should allow me to set roots" do
|
|
30
30
|
Foo.roots.should == []
|
|
@@ -32,31 +32,31 @@ describe Pancake::Paths do
|
|
|
32
32
|
Foo.roots.should == [fixture_root]
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
describe "pushing paths" do
|
|
37
37
|
before do
|
|
38
38
|
Foo.roots << fixture_root
|
|
39
39
|
end
|
|
40
|
-
|
|
40
|
+
|
|
41
41
|
it "should push a single path" do
|
|
42
42
|
Foo.push_paths(:models, "models")
|
|
43
43
|
Foo.dirs_for(:models).should == [File.join(fixture_root,"models")]
|
|
44
44
|
end
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
it "should give me an empty array of paths when there have been no paths added" do
|
|
47
47
|
Foo.dirs_for(:models).should == []
|
|
48
48
|
end
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
it "should raise and error if there are no paths specified" do
|
|
51
51
|
lambda do
|
|
52
52
|
Foo.push_paths(:models)
|
|
53
53
|
end.should raise_error(ArgumentError)
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
lambda do
|
|
56
56
|
Foo.push_paths(:models, [])
|
|
57
57
|
end.should raise_error(Pancake::Paths::NoPathsGiven)
|
|
58
58
|
end
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
it "should allow me to push multiple times to a single path group" do
|
|
61
61
|
Foo.push_paths(:models, "models")
|
|
62
62
|
Foo.push_paths(:models, "stack/models")
|
|
@@ -65,7 +65,7 @@ describe Pancake::Paths do
|
|
|
65
65
|
File.join(fixture_root, "stack", "models")
|
|
66
66
|
]
|
|
67
67
|
end
|
|
68
|
-
|
|
68
|
+
|
|
69
69
|
it "should allow me to push multiple path sets" do
|
|
70
70
|
Foo.push_paths(:models, ["models", "stack/models"])
|
|
71
71
|
Foo.push_paths(:controllers, "controllers")
|
|
@@ -77,7 +77,7 @@ describe Pancake::Paths do
|
|
|
77
77
|
Foo.dirs_for(:controllers ).should == [File.join(fixture_root, "controllers")]
|
|
78
78
|
Foo.dirs_for(:views ).should == [File.join(fixture_root, "stack", "views")]
|
|
79
79
|
end
|
|
80
|
-
|
|
80
|
+
|
|
81
81
|
it "should reverse the dirs_for when specified" do
|
|
82
82
|
Foo.push_paths(:models, ["models", "stack/models"])
|
|
83
83
|
Foo.dirs_for(:models, :invert => true).should == [
|
|
@@ -85,7 +85,7 @@ describe Pancake::Paths do
|
|
|
85
85
|
File.join(fixture_root, "models")
|
|
86
86
|
]
|
|
87
87
|
end
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
describe "globs" do
|
|
90
90
|
it "should allow me to supply a glob to associate with the path" do
|
|
91
91
|
Foo.push_paths(:models, "models", "**/*.rb")
|
|
@@ -95,13 +95,13 @@ describe Pancake::Paths do
|
|
|
95
95
|
[File.join(fixture_root, "stack", "models"), "**/*.rb"]
|
|
96
96
|
]
|
|
97
97
|
end
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
it "should associate an empty glob when not specified" do
|
|
100
100
|
Foo.push_paths(:models, "foo/bar")
|
|
101
101
|
Foo.dirs_for(:models).should == [File.join(fixture_root, "foo/bar")]
|
|
102
102
|
Foo.dirs_and_glob_for(:models).should == [[File.join(fixture_root, "foo/bar"), nil]]
|
|
103
103
|
end
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
it "should revers the dirs_and_globs when requested" do
|
|
106
106
|
Foo.push_paths(:models, "models", "**/*.rb")
|
|
107
107
|
Foo.push_paths(:models, "stack/models", "**/*.rb")
|
|
@@ -113,7 +113,7 @@ describe Pancake::Paths do
|
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
end
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
describe "reading paths" do
|
|
118
118
|
before(:each) do
|
|
119
119
|
@model_root = File.join(fixture_root, "models")
|
|
@@ -121,7 +121,7 @@ describe Pancake::Paths do
|
|
|
121
121
|
Foo.roots << fixture_root
|
|
122
122
|
Foo.push_paths(:model, ["models", "stack/models"], "**/*.rb")
|
|
123
123
|
end
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
it "should have list all the paths for :model" do
|
|
126
126
|
result = Foo.paths_for(:model).should == [
|
|
127
127
|
[@model_root, "/model1.rb"],
|
|
@@ -130,7 +130,7 @@ describe Pancake::Paths do
|
|
|
130
130
|
[@stack_root, "/model3.rb"]
|
|
131
131
|
]
|
|
132
132
|
end
|
|
133
|
-
|
|
133
|
+
|
|
134
134
|
it "should allow me to invert the order of the roots" do
|
|
135
135
|
result = Foo.paths_for(:model, :invert => true).should == [
|
|
136
136
|
[@stack_root, "/model3.rb"],
|
|
@@ -139,7 +139,7 @@ describe Pancake::Paths do
|
|
|
139
139
|
[@model_root, "/model1.rb"]
|
|
140
140
|
]
|
|
141
141
|
end
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
it "should allow me to get the unique_paths" do
|
|
144
144
|
result = Foo.unique_paths_for(:model).should == [
|
|
145
145
|
[@model_root, "/model1.rb"],
|
|
@@ -147,7 +147,7 @@ describe Pancake::Paths do
|
|
|
147
147
|
[@stack_root, "/model3.rb"]
|
|
148
148
|
]
|
|
149
149
|
end
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
it "should allow me to invert the order of the unique_paths" do
|
|
152
152
|
result = Foo.unique_paths_for(:model, :invert => true).should == [
|
|
153
153
|
[@model_root, "/model3.rb"],
|
|
@@ -156,7 +156,7 @@ describe Pancake::Paths do
|
|
|
156
156
|
]
|
|
157
157
|
end
|
|
158
158
|
end
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
describe "inherited paths" do
|
|
161
161
|
before(:each) do
|
|
162
162
|
Foo.push_paths(:model, "models")
|
|
@@ -164,12 +164,12 @@ describe Pancake::Paths do
|
|
|
164
164
|
Foo.roots << fixture_root
|
|
165
165
|
class ::Bar < Foo; end
|
|
166
166
|
end
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
it "should inherit paths from the parent" do
|
|
169
169
|
Bar.dirs_for(:model).should == [File.join(fixture_root, "models")]
|
|
170
170
|
Bar.dirs_for(:controller).should == [File.join(fixture_root, "controllers")]
|
|
171
171
|
end
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
it "should let me add to the collection from the parent" do
|
|
174
174
|
Bar.push_paths(:model, "stack/models")
|
|
175
175
|
Bar.dirs_for(:model).should == [
|
|
@@ -177,12 +177,12 @@ describe Pancake::Paths do
|
|
|
177
177
|
File.join(fixture_root, "stack/models")
|
|
178
178
|
]
|
|
179
179
|
end
|
|
180
|
-
|
|
180
|
+
|
|
181
181
|
it "should not bleed paths back up to the parent" do
|
|
182
182
|
Bar.push_paths(:model, "stack/models")
|
|
183
183
|
Foo.dirs_for(:model).should == [File.join(fixture_root, "models")]
|
|
184
184
|
end
|
|
185
|
-
|
|
185
|
+
|
|
186
186
|
it "should not bleed paths over to a sibling class" do
|
|
187
187
|
class ::Baz < Foo; end
|
|
188
188
|
Bar.push_paths(:model, "stack/models")
|
|
@@ -197,7 +197,7 @@ describe Pancake::Paths do
|
|
|
197
197
|
]
|
|
198
198
|
Foo.dirs_for(:model).should == [File.join(fixture_root, "models")]
|
|
199
199
|
end
|
|
200
|
-
|
|
200
|
+
|
|
201
201
|
it "should inherit multpile times" do
|
|
202
202
|
class ::Baz < Bar; end
|
|
203
203
|
Bar.push_paths(:model, "bar/path")
|
|
@@ -207,4 +207,4 @@ describe Pancake::Paths do
|
|
|
207
207
|
]
|
|
208
208
|
end
|
|
209
209
|
end
|
|
210
|
-
end
|
|
210
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "stack router" do
|
|
4
4
|
before(:all) do
|
|
@@ -14,7 +14,7 @@ describe "stack router" do
|
|
|
14
14
|
JSON.generate({
|
|
15
15
|
"SCRIPT_NAME" => e["SCRIPT_NAME"],
|
|
16
16
|
"PATH_INFO" => e["PATH_INFO"],
|
|
17
|
-
"
|
|
17
|
+
"router.params" => e["router.params"].to_hash
|
|
18
18
|
})
|
|
19
19
|
]
|
|
20
20
|
]
|
|
@@ -34,15 +34,15 @@ describe "stack router" do
|
|
|
34
34
|
describe "mount" do
|
|
35
35
|
it "should let me setup routes for the stack" do
|
|
36
36
|
FooApp.router do |r|
|
|
37
|
-
r.mount(INNER_APP, "/foo", :
|
|
38
|
-
r.mount(INNER_APP, "/bar", :
|
|
37
|
+
r.mount(INNER_APP, "/foo", :default_values => {:action => "foo action"}).name(:foo)
|
|
38
|
+
r.mount(INNER_APP, "/bar", :default_values => {:action => "bar action"}).name(:root)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
@app = FooApp.stackup
|
|
42
42
|
expected = {
|
|
43
43
|
"SCRIPT_NAME" => "/foo",
|
|
44
44
|
"PATH_INFO" => "",
|
|
45
|
-
"
|
|
45
|
+
"router.params" => {"action" => "foo action"}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
get "/foo"
|
|
@@ -50,14 +50,14 @@ describe "stack router" do
|
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
it "should allow me to stop the route from partially matching" do
|
|
53
|
-
FooApp.
|
|
54
|
-
r.mount(INNER_APP, "/foo/bar", :
|
|
53
|
+
FooApp.router do |r|
|
|
54
|
+
r.mount(INNER_APP, "/foo/bar", :default_values => {:action => "foo/bar"}, :_exact => true).name(:foobar)
|
|
55
55
|
end
|
|
56
56
|
@app = FooApp.stackup
|
|
57
57
|
expected = {
|
|
58
58
|
"SCRIPT_NAME" => "/foo/bar",
|
|
59
59
|
"PATH_INFO" => "",
|
|
60
|
-
"
|
|
60
|
+
"router.params" => {"action" => "foo/bar"}
|
|
61
61
|
}
|
|
62
62
|
get "/foo/bar"
|
|
63
63
|
JSON.parse(last_response.body).should == expected
|
|
@@ -66,7 +66,7 @@ describe "stack router" do
|
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
it "should not match a single segment route when only / is defined" do
|
|
69
|
-
FooApp.router.add("/", :
|
|
69
|
+
FooApp.router.add("/", :default_values => {:root => :var}) do |e|
|
|
70
70
|
Rack::Response.new("In the Root").finish
|
|
71
71
|
end
|
|
72
72
|
@app = FooApp.stackup
|
|
@@ -94,28 +94,18 @@ describe "stack router" do
|
|
|
94
94
|
result = get "/stackup"
|
|
95
95
|
result.body.should include("stacked up")
|
|
96
96
|
end
|
|
97
|
-
|
|
98
|
-
it "should provide the rack params as a Hashie" do
|
|
99
|
-
FooApp.router.add("/hashie") do |e|
|
|
100
|
-
r = Rack::Request.new(e)
|
|
101
|
-
r.params.should be_a_kind_of(Hashie::Mash)
|
|
102
|
-
Rack::Response.new("OK").finish
|
|
103
|
-
end
|
|
104
|
-
@app = FooApp.stackup
|
|
105
|
-
get "/hashie"
|
|
106
|
-
end
|
|
107
97
|
end
|
|
108
98
|
end
|
|
109
99
|
|
|
110
100
|
describe "generating routes" do
|
|
111
101
|
before do
|
|
112
102
|
FooApp.router do |r|
|
|
113
|
-
r.add("/simple/route" ).name(:simple)
|
|
114
|
-
r.add("/var/with/:var", :
|
|
115
|
-
r.add("/complex/:var" ).name(:complex)
|
|
116
|
-
r.add("/optional(/:var)" ).name(:optional)
|
|
117
|
-
r.add("/some/:unique_var")
|
|
118
|
-
r.add("/", :
|
|
103
|
+
r.add("/simple/route" ).name(:simple).compile
|
|
104
|
+
r.add("/var/with/:var", :default_values => {:var => "some_var"}).name(:defaults).compile
|
|
105
|
+
r.add("/complex/:var" ).name(:complex).compile
|
|
106
|
+
r.add("/optional(/:var)" ).name(:optional).compile
|
|
107
|
+
r.add("/some/:unique_var").compile
|
|
108
|
+
r.add("/", :default_values => {:var => "root var"}).name(:root).compile
|
|
119
109
|
end
|
|
120
110
|
end
|
|
121
111
|
|
|
@@ -123,11 +113,6 @@ describe "stack router" do
|
|
|
123
113
|
Pancake.url(FooApp, :simple).should == "/simple/route"
|
|
124
114
|
end
|
|
125
115
|
|
|
126
|
-
it "should generate a / when / is optional" do
|
|
127
|
-
FooApp.router.add("(/)").name(:foo)
|
|
128
|
-
Pancake.url(FooApp, :foo).should == "/"
|
|
129
|
-
end
|
|
130
|
-
|
|
131
116
|
it "should allow me to generate a non-named route for a stack" do
|
|
132
117
|
Pancake.url(FooApp, :complex, :var => "a_variable").should == "/complex/a_variable"
|
|
133
118
|
end
|
|
@@ -142,10 +127,6 @@ describe "stack router" do
|
|
|
142
127
|
Pancake.url(FooApp, :defaults, :var => "this_is_a_var").should == "/var/with/this_is_a_var"
|
|
143
128
|
end
|
|
144
129
|
|
|
145
|
-
it "should allow me to generate a route by params" do
|
|
146
|
-
Pancake.url(FooApp, :unique_var => "unique_var").should == "/some/unique_var"
|
|
147
|
-
end
|
|
148
|
-
|
|
149
130
|
it "should generate a base url of '/' for the top level router" do
|
|
150
131
|
FooApp.router.base_url.should == "/"
|
|
151
132
|
end
|
|
@@ -155,8 +136,8 @@ describe "stack router" do
|
|
|
155
136
|
class ::BarApp < Pancake::Stack; end
|
|
156
137
|
BarApp.roots << Pancake.get_root(__FILE__)
|
|
157
138
|
BarApp.router do |r|
|
|
158
|
-
r.add("/simple").name(:simple)
|
|
159
|
-
r.add("/some/:var", :
|
|
139
|
+
r.add("/simple").name(:simple).compile
|
|
140
|
+
r.add("/some/:var", :default_values => {:var => "foo"}).name(:foo).compile
|
|
160
141
|
end
|
|
161
142
|
FooApp.router.mount(BarApp, "/bar")
|
|
162
143
|
FooApp.router.mount_applications!
|
|
@@ -187,9 +168,9 @@ describe "stack router" do
|
|
|
187
168
|
|
|
188
169
|
describe "internal stack routes" do
|
|
189
170
|
it "should pass through to the underlying app when adding a route" do
|
|
190
|
-
FooApp.router.add("/bar", :
|
|
171
|
+
FooApp.router.add("/bar", :default_values => {:action => "bar"}).name(:gary).compile
|
|
191
172
|
class ::FooApp
|
|
192
|
-
def self.
|
|
173
|
+
def self.new_endpoint_instance
|
|
193
174
|
INNER_APP
|
|
194
175
|
end
|
|
195
176
|
end
|
|
@@ -198,39 +179,28 @@ describe "stack router" do
|
|
|
198
179
|
@app = FooApp.stackup
|
|
199
180
|
get "/bar"
|
|
200
181
|
result = JSON.parse(last_response.body)
|
|
201
|
-
result["
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
it "should add the usher.params to the request params" do
|
|
205
|
-
app = mock("app", :call => Rack::Response.new("OK").finish, :null_object => true)
|
|
206
|
-
app.should_receive(:call).with do |e|
|
|
207
|
-
params = Rack::Request.new(e).params
|
|
208
|
-
params[:action].should == "jackson"
|
|
209
|
-
end
|
|
210
|
-
FooApp.router.mount(app, "/foo/app", :_defaults => {:action => "jackson"})
|
|
211
|
-
@app = FooApp.stackup
|
|
212
|
-
get "/foo/app"
|
|
182
|
+
result["router.params"].should == {"action" => "bar"}
|
|
213
183
|
end
|
|
214
184
|
end
|
|
215
185
|
|
|
216
186
|
it "should allow me to inherit routes" do
|
|
217
187
|
FooApp.router do |r|
|
|
218
|
-
r.mount(INNER_APP, "/foo(/:stuff)", :
|
|
188
|
+
r.mount(INNER_APP, "/foo(/:stuff)", :default_values => {"originator" => "FooApp"})
|
|
219
189
|
end
|
|
220
190
|
class ::BarApp < FooApp; end
|
|
221
191
|
BarApp.router do |r|
|
|
222
|
-
r.mount(INNER_APP, "/bar", :
|
|
192
|
+
r.mount(INNER_APP, "/bar", :default_values => {"originator" => "BarApp"})
|
|
223
193
|
end
|
|
224
194
|
|
|
225
195
|
@app = BarApp.stackup
|
|
226
196
|
|
|
227
197
|
get "/bar"
|
|
228
198
|
response = JSON.parse(last_response.body)
|
|
229
|
-
response["
|
|
199
|
+
response["router.params"]["originator"].should == "BarApp"
|
|
230
200
|
|
|
231
201
|
get "/foo/thing"
|
|
232
202
|
response = JSON.parse(last_response.body)
|
|
233
|
-
response["
|
|
203
|
+
response["router.params"]["originator"].should == "FooApp"
|
|
234
204
|
end
|
|
235
205
|
|
|
236
206
|
it "should generate an inherited route" do
|
|
@@ -243,7 +213,6 @@ describe "stack router" do
|
|
|
243
213
|
FooApp.router.mount_applications!
|
|
244
214
|
|
|
245
215
|
Pancake.url(BarApp, :simple).should == "/simple"
|
|
246
|
-
Pancake.url(BarApp, :stuff => "this_stuff").should == "/foo/this_stuff"
|
|
247
216
|
Pancake.url(BarApp, :stuff, :stuff => "that_stuff").should == "/foo/that_stuff"
|
|
248
217
|
end
|
|
249
218
|
|
|
@@ -267,13 +236,6 @@ describe "stack router" do
|
|
|
267
236
|
BarApp.router.class.should == BarApp::Router
|
|
268
237
|
end
|
|
269
238
|
|
|
270
|
-
it "should reset the router to the namespaced router" do
|
|
271
|
-
class ::BarApp < FooApp; end
|
|
272
|
-
BarApp.reset_router!
|
|
273
|
-
BarApp.router.class.should == BarApp::Router
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
|
|
277
239
|
describe "generating urls inside an application" do
|
|
278
240
|
before do
|
|
279
241
|
class ::BarApp < FooApp; end
|