orange-core 0.5.3
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/README.markdown +145 -0
- data/lib/orange-core.rb +8 -0
- data/lib/orange-core/application.rb +132 -0
- data/lib/orange-core/assets/css/exceptions.css +50 -0
- data/lib/orange-core/assets/js/exceptions.js +44 -0
- data/lib/orange-core/carton.rb +178 -0
- data/lib/orange-core/core.rb +266 -0
- data/lib/orange-core/magick.rb +270 -0
- data/lib/orange-core/middleware/base.rb +96 -0
- data/lib/orange-core/middleware/database.rb +45 -0
- data/lib/orange-core/middleware/four_oh_four.rb +45 -0
- data/lib/orange-core/middleware/globals.rb +17 -0
- data/lib/orange-core/middleware/loader.rb +13 -0
- data/lib/orange-core/middleware/rerouter.rb +53 -0
- data/lib/orange-core/middleware/restful_router.rb +99 -0
- data/lib/orange-core/middleware/route_context.rb +39 -0
- data/lib/orange-core/middleware/route_site.rb +51 -0
- data/lib/orange-core/middleware/show_exceptions.rb +80 -0
- data/lib/orange-core/middleware/static.rb +67 -0
- data/lib/orange-core/middleware/static_file.rb +32 -0
- data/lib/orange-core/middleware/template.rb +60 -0
- data/lib/orange-core/packet.rb +232 -0
- data/lib/orange-core/plugin.rb +172 -0
- data/lib/orange-core/resource.rb +96 -0
- data/lib/orange-core/resources/mapper.rb +36 -0
- data/lib/orange-core/resources/model_resource.rb +228 -0
- data/lib/orange-core/resources/not_found.rb +10 -0
- data/lib/orange-core/resources/page_parts.rb +68 -0
- data/lib/orange-core/resources/parser.rb +113 -0
- data/lib/orange-core/resources/routable_resource.rb +16 -0
- data/lib/orange-core/resources/scaffold.rb +106 -0
- data/lib/orange-core/stack.rb +226 -0
- data/lib/orange-core/templates/exceptions.haml +111 -0
- data/lib/orange-core/views/default_resource/create.haml +4 -0
- data/lib/orange-core/views/default_resource/edit.haml +9 -0
- data/lib/orange-core/views/default_resource/list.haml +10 -0
- data/lib/orange-core/views/default_resource/show.haml +4 -0
- data/lib/orange-core/views/default_resource/table_row.haml +7 -0
- data/lib/orange-core/views/not_found/404.haml +2 -0
- data/spec/orange-core/application_spec.rb +183 -0
- data/spec/orange-core/carton_spec.rb +136 -0
- data/spec/orange-core/core_spec.rb +248 -0
- data/spec/orange-core/magick_spec.rb +96 -0
- data/spec/orange-core/middleware/base_spec.rb +38 -0
- data/spec/orange-core/middleware/globals_spec.rb +3 -0
- data/spec/orange-core/middleware/rerouter_spec.rb +3 -0
- data/spec/orange-core/middleware/restful_router_spec.rb +3 -0
- data/spec/orange-core/middleware/route_context_spec.rb +3 -0
- data/spec/orange-core/middleware/route_site_spec.rb +3 -0
- data/spec/orange-core/middleware/show_exceptions_spec.rb +3 -0
- data/spec/orange-core/middleware/static_file_spec.rb +3 -0
- data/spec/orange-core/middleware/static_spec.rb +3 -0
- data/spec/orange-core/mock/mock_app.rb +16 -0
- data/spec/orange-core/mock/mock_carton.rb +43 -0
- data/spec/orange-core/mock/mock_core.rb +2 -0
- data/spec/orange-core/mock/mock_middleware.rb +25 -0
- data/spec/orange-core/mock/mock_mixins.rb +19 -0
- data/spec/orange-core/mock/mock_model_resource.rb +47 -0
- data/spec/orange-core/mock/mock_pulp.rb +24 -0
- data/spec/orange-core/mock/mock_resource.rb +26 -0
- data/spec/orange-core/mock/mock_router.rb +10 -0
- data/spec/orange-core/orange_spec.rb +19 -0
- data/spec/orange-core/packet_spec.rb +203 -0
- data/spec/orange-core/resource_spec.rb +96 -0
- data/spec/orange-core/resources/mapper_spec.rb +5 -0
- data/spec/orange-core/resources/model_resource_spec.rb +246 -0
- data/spec/orange-core/resources/parser_spec.rb +5 -0
- data/spec/orange-core/resources/routable_resource_spec.rb +5 -0
- data/spec/orange-core/spec_helper.rb +53 -0
- data/spec/orange-core/stack_spec.rb +232 -0
- data/spec/stats.rb +182 -0
- metadata +227 -0
@@ -0,0 +1,246 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Orange::ModelResource do
|
4
|
+
|
5
|
+
it "should extend class inheritable attributes" do
|
6
|
+
Orange::ModelResource.should be_a_kind_of(ClassInheritableAttributes)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should have a model class when calling use" do
|
10
|
+
a = MockModelResourceOne.new
|
11
|
+
b = MockModelResourceTwo.new
|
12
|
+
MockModelResourceOne.model_class.should equal MockCarton
|
13
|
+
a.model_class.should equal MockCarton
|
14
|
+
MockModelResourceTwo.model_class.should equal MockCartonTwo
|
15
|
+
b.model_class.should equal MockCartonTwo
|
16
|
+
end
|
17
|
+
|
18
|
+
it "have a usable view method" do
|
19
|
+
a = MockModelResource.new
|
20
|
+
a.should respond_to(:view)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should call index or show by default for an orange packet" do
|
24
|
+
c = Orange::Core.new
|
25
|
+
c.load(MockModelResourceOne.new, :mocked)
|
26
|
+
p = Orange::Packet.new(c, {})
|
27
|
+
p2 = Orange::Packet.new(c, {})
|
28
|
+
p2['route.resource_id'] = 1
|
29
|
+
lambda {
|
30
|
+
c[:mocked].view(p)
|
31
|
+
}.should raise_error(RuntimeError, "I see you're using index")
|
32
|
+
lambda {
|
33
|
+
c[:mocked].view(p2)
|
34
|
+
}.should raise_error(RuntimeError, "I see you're using show")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should send the mode to the appropriate method" do
|
38
|
+
c = Orange::Core.new
|
39
|
+
c.load(MockModelResourceOne.new, :mocked)
|
40
|
+
p = Orange::Packet.new(c, {})
|
41
|
+
lambda {
|
42
|
+
c[:mocked].view(p, :mode => :other)
|
43
|
+
}.should raise_error(RuntimeError, "I see you're using other")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "shouldn't give a shit" do
|
47
|
+
lambda{
|
48
|
+
MockModelResource.shit
|
49
|
+
}.should raise_error(NoMethodError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should call find_one if calling view_opts with is_list false" do
|
53
|
+
a= MockModelResourceOne.new
|
54
|
+
lambda{
|
55
|
+
a.view_opts(Orange::Packet.new(Orange::Core.new, {}), :list, false)
|
56
|
+
}.should raise_error(RuntimeError, "calling find_one")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should call find_list if calling view_opts with is_list true" do
|
60
|
+
a= MockModelResourceOne.new
|
61
|
+
lambda{
|
62
|
+
a.view_opts(Orange::Packet.new(Orange::Core.new, {}), :list, true)
|
63
|
+
}.should raise_error(RuntimeError, "calling find_list")
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return a hash of options on calling view_opts" do
|
67
|
+
a= MockModelResourceFour.new
|
68
|
+
c= Orange::Core.new
|
69
|
+
p= Orange::Packet.new(c, {})
|
70
|
+
lambda{
|
71
|
+
a.view_opts(p, :list, true)
|
72
|
+
}.should_not raise_error(RuntimeError)
|
73
|
+
opts = a.view_opts(p, :list, true, :extra => 'foo')
|
74
|
+
opts3 = a.view_opts(p, :list, false, :extra => 'foo')
|
75
|
+
opts2 = a.view_opts(p, :list, true, :list => 'banana')
|
76
|
+
opts[:props].should == MockCarton.form_props(p['route.context'])
|
77
|
+
opts.should have_key(:list)
|
78
|
+
opts3.should_not have_key(:list)
|
79
|
+
opts.should have_key(:resource)
|
80
|
+
opts.should have_key(:model_name)
|
81
|
+
opts.should_not have_key(:model)
|
82
|
+
opts3.should have_key(:model)
|
83
|
+
opts.should have_key(:extra)
|
84
|
+
opts3.should have_key(:extra)
|
85
|
+
opts[:extra].should == 'foo'
|
86
|
+
opts3[:extra].should == 'foo'
|
87
|
+
opts[:list].should_not == opts2[:list]
|
88
|
+
opts2[:list].should == 'banana'
|
89
|
+
opts[:list].should == 'mock_list'
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should call view_extras after during view_opts" do
|
93
|
+
a= MockModelResourceThree.new
|
94
|
+
lambda{
|
95
|
+
a.view_opts(Orange::Packet.new(Orange::Core.new, {}), :list, true)
|
96
|
+
}.should raise_error(RuntimeError, "calling find_extras")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should call haml parser with opts on do_view" do
|
100
|
+
c= Orange::Core.new
|
101
|
+
p= Orange::Packet.new(c, {})
|
102
|
+
c.load(MockHamlParser.new, :parser)
|
103
|
+
c.load(MockModelResourceFour.new, :mocked)
|
104
|
+
parsed = c[:mocked].do_view(p, :test, :extra => 'foo')
|
105
|
+
parsed.first.should == 'test.haml'
|
106
|
+
parsed.last.should == c[:mocked].view_opts(p, :test, false, :extra => 'foo')
|
107
|
+
parsed.last.should_not == c[:mocked].view_opts(p, :test, true, :extra => 'foo')
|
108
|
+
parsed.last.should have_key(:extra)
|
109
|
+
parsed[1].should equal(p)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should call haml parser with opts on do_list_view" do
|
113
|
+
c= Orange::Core.new
|
114
|
+
p= Orange::Packet.new(c, {})
|
115
|
+
c.load(MockHamlParser.new, :parser)
|
116
|
+
c.load(MockModelResourceFour.new, :mocked)
|
117
|
+
parsed = c[:mocked].do_list_view(p, :test, :extra => 'foo')
|
118
|
+
parsed.first.should == 'test.haml'
|
119
|
+
parsed.last.should == c[:mocked].view_opts(p, :test, true, :extra => 'foo')
|
120
|
+
parsed.last.should_not == c[:mocked].view_opts(p, :test, false, :extra => 'foo')
|
121
|
+
parsed.last.should have_key(:extra)
|
122
|
+
parsed[1].should equal(p)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should call carton's get on find_one(packet, mode, id)" do
|
126
|
+
a= MockModelResourceTwo.new
|
127
|
+
a.find_one(Orange::Packet.new(Orange::Core.new, {}), :show).should == false
|
128
|
+
a.find_one(Orange::Packet.new(Orange::Core.new, {}), :show, 1).should == 'mock_get'
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should call carton's all on find_list(packet, mode)" do
|
132
|
+
a= MockModelResourceTwo.new
|
133
|
+
a.find_list(Orange::Packet.new(Orange::Core.new, {}), :show).should == 'mock_all'
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should return an empty hash by default for find_extras" do
|
137
|
+
a= MockModelResourceTwo.new
|
138
|
+
a.find_extras(Orange::Packet.new(Orange::Core.new, {}), :show).should == {}
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should have the view_list method in packet" do
|
142
|
+
c = Orange::Core.new
|
143
|
+
c.load(MockModelResourceOne.new, :mocked)
|
144
|
+
p = Orange::Packet.new(c, {})
|
145
|
+
lambda {
|
146
|
+
p.view_index(:mocked)
|
147
|
+
}.should raise_error(RuntimeError, "I see you're using index")
|
148
|
+
lambda {
|
149
|
+
p.view_show(:mocked)
|
150
|
+
}.should raise_error(RuntimeError, "I see you're using show")
|
151
|
+
lambda {
|
152
|
+
p.view_other(:mocked)
|
153
|
+
}.should raise_error(RuntimeError, "I see you're using other")
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should call carton's save on POST new and reroute" do
|
157
|
+
a= MockModelResourceTwo.new
|
158
|
+
m= mock("carton", :null_object => true)
|
159
|
+
m.should_receive(:save)
|
160
|
+
a.stub!(:model_class).and_return(m)
|
161
|
+
p2 = mock("packet", :null_object => true)
|
162
|
+
p2.should_receive(:reroute)
|
163
|
+
p2.stub!(:request).and_return(mock_post)
|
164
|
+
lambda{
|
165
|
+
a.new(Orange::Packet.new(Orange::Core.new, {}))
|
166
|
+
}.should raise_error(Orange::Reroute, 'Unhandled reroute')
|
167
|
+
a.new(p2)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should call carton's destroy! on DELETE delete and reroute" do
|
171
|
+
a= MockModelResourceTwo.new
|
172
|
+
m= mock("carton", :null_object => true)
|
173
|
+
m.should_receive(:destroy)
|
174
|
+
a.stub!(:model_class).and_return(m)
|
175
|
+
p2 = mock("packet", :null_object => true)
|
176
|
+
p2.should_receive(:reroute)
|
177
|
+
p2.stub!(:request).and_return(mock_delete)
|
178
|
+
lambda{
|
179
|
+
a.delete(Orange::Packet.new(Orange::Core.new, {}))
|
180
|
+
}.should raise_error(Orange::Reroute, 'Unhandled reroute')
|
181
|
+
a.delete(p2)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should call carton's update on POST save and reroute" do
|
185
|
+
a= MockModelResourceTwo.new
|
186
|
+
m= mock("carton", :null_object => true)
|
187
|
+
m.should_receive(:update)
|
188
|
+
a.stub!(:model_class).and_return(m)
|
189
|
+
p2 = mock("packet", :null_object => true)
|
190
|
+
p2.should_receive(:reroute)
|
191
|
+
p2.stub!(:request).and_return(mock_post)
|
192
|
+
lambda{
|
193
|
+
a.delete(Orange::Packet.new(Orange::Core.new, {}))
|
194
|
+
}.should raise_error(Orange::Reroute, 'Unhandled reroute')
|
195
|
+
a.save(p2)
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should call do_view with mode = :show for show" do
|
199
|
+
a= MockModelResource.new
|
200
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :show)
|
201
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :show, {})
|
202
|
+
a.show(empty_packet)
|
203
|
+
a.show(empty_packet, {})
|
204
|
+
end
|
205
|
+
it "should call do_view with mode = :edit for edit" do
|
206
|
+
a= MockModelResource.new
|
207
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :edit)
|
208
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :edit, {})
|
209
|
+
a.edit(empty_packet)
|
210
|
+
a.edit(empty_packet, {})
|
211
|
+
end
|
212
|
+
it "should call do_view with mode = :create for create" do
|
213
|
+
a= MockModelResource.new
|
214
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :create)
|
215
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :create, {})
|
216
|
+
a.create(empty_packet)
|
217
|
+
a.create(empty_packet, {})
|
218
|
+
end
|
219
|
+
|
220
|
+
it "should call do_view with mode = :table_row for table_row" do
|
221
|
+
a= MockModelResource.new
|
222
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :table_row)
|
223
|
+
a.should_receive(:do_view).with(an_instance_of(Orange::Packet), :table_row, {})
|
224
|
+
a.table_row(empty_packet)
|
225
|
+
a.table_row(empty_packet, {})
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should call do_list_view with mode = :list for list" do
|
229
|
+
a= MockModelResource.new
|
230
|
+
a.should_receive(:do_list_view).with(an_instance_of(Orange::Packet), :list)
|
231
|
+
a.should_receive(:do_list_view).with(an_instance_of(Orange::Packet), :list, {})
|
232
|
+
a.list(empty_packet)
|
233
|
+
a.list(empty_packet, {})
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
it "should call do_list_view with mode = :list for index" do
|
238
|
+
a= MockModelResource.new
|
239
|
+
a.should_receive(:do_list_view).with(an_instance_of(Orange::Packet), :list)
|
240
|
+
a.should_receive(:do_list_view).with(an_instance_of(Orange::Packet), :list, {})
|
241
|
+
a.index(empty_packet)
|
242
|
+
a.index(empty_packet, {})
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'orange-core'
|
5
|
+
require 'rubygems'
|
6
|
+
|
7
|
+
require 'mock/mock_app'
|
8
|
+
require 'mock/mock_pulp'
|
9
|
+
require 'mock/mock_core'
|
10
|
+
require 'mock/mock_carton'
|
11
|
+
require 'mock/mock_model_resource'
|
12
|
+
require 'mock/mock_mixins'
|
13
|
+
require 'mock/mock_router'
|
14
|
+
require 'mock/mock_resource'
|
15
|
+
require 'mock/mock_middleware'
|
16
|
+
require 'rack/test'
|
17
|
+
|
18
|
+
|
19
|
+
Spec::Runner.configure do |config|
|
20
|
+
config.include(Rack::Test::Methods)
|
21
|
+
end
|
22
|
+
|
23
|
+
def mock_post
|
24
|
+
p= mock("request", :null_object => true)
|
25
|
+
p.stub!(:post?).and_return(true)
|
26
|
+
p.stub!(:params).and_return({})
|
27
|
+
p.stub!(:xhr?).and_return(false)
|
28
|
+
p
|
29
|
+
end
|
30
|
+
|
31
|
+
def mock_delete
|
32
|
+
p= mock("request", :null_object => true)
|
33
|
+
p.stub!(:delete?).and_return(true)
|
34
|
+
p.stub!(:params).and_return({})
|
35
|
+
p.stub!(:xhr?).and_return(false)
|
36
|
+
p
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty_packet(c = Orange::Core.new)
|
40
|
+
Orange::Packet.new(c, {})
|
41
|
+
end
|
42
|
+
|
43
|
+
def packet_finish_app
|
44
|
+
lambda { |env|
|
45
|
+
Orange::Packet.new(env).finish
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def return_env_app
|
50
|
+
lambda { |env|
|
51
|
+
[env, 200, ["ok"]]
|
52
|
+
}
|
53
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Orange::Stack do
|
4
|
+
before(:all) do
|
5
|
+
# allow deep introspection into rack builder
|
6
|
+
class Rack::Builder
|
7
|
+
attr_accessor :ins
|
8
|
+
# introspection into the Builder object's list of items
|
9
|
+
# builder uses Proc magic to chain the middleware together,
|
10
|
+
# so we undo it.
|
11
|
+
def ins_no_procs
|
12
|
+
@ins.map{|x| x.instance_of?(Proc)? x.call(nil) : x }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
class Orange::Stack
|
16
|
+
attr_accessor :build
|
17
|
+
def middlewarez
|
18
|
+
build.ins_no_procs
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def app
|
24
|
+
MockApplication.app
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should create a default stack when called by Application" do
|
28
|
+
MockApplication2.app.should be_an_instance_of(Orange::Stack)
|
29
|
+
MockApplication2.app.main_app.should be_a_kind_of(Orange::Application)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have access to core" do
|
33
|
+
MockApplication.app.orange.should be_an_instance_of(Orange::Core)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have access to the main application instance" do
|
37
|
+
MockApplication2.app.main_app.should be_an_instance_of(MockApplication2)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have the run function" do
|
41
|
+
x= Orange::Stack.new do
|
42
|
+
run MockExitware.new
|
43
|
+
end
|
44
|
+
lambda {
|
45
|
+
x.call({:test => 'middlewarez'})
|
46
|
+
}.should raise_error(RuntimeError, "Mock Exitware")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should accept a core object in initialization" do
|
50
|
+
c = Orange::Core.new
|
51
|
+
c2 = Orange::Core.new
|
52
|
+
|
53
|
+
x = Orange::Stack.new(nil, c) do
|
54
|
+
run MockExitware.new
|
55
|
+
end
|
56
|
+
x.orange.should equal(c)
|
57
|
+
x.orange.should_not equal(c2)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have the use function" do
|
61
|
+
x= Orange::Stack.new do
|
62
|
+
use MockMiddleware
|
63
|
+
run MockExitware.new
|
64
|
+
end
|
65
|
+
lambda {
|
66
|
+
x.call({:test => 'middlewarez'})
|
67
|
+
}.should raise_error(RuntimeError, "I'm in ur middlewarez")
|
68
|
+
lambda {
|
69
|
+
x.call({:test => 'middlewarez'})
|
70
|
+
}.should_not raise_error(RuntimeError, "It's over 9000")
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should have the stack function" do
|
74
|
+
x= Orange::Stack.new do
|
75
|
+
stack MockOrangeBasedMiddleware
|
76
|
+
run MockExitware.new
|
77
|
+
end
|
78
|
+
lambda {
|
79
|
+
x.call({:test => 'middlewarez'})
|
80
|
+
}.should raise_error(RuntimeError, "It's over 9000 Orange::Cores!")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should respect order of stack/use cases" do
|
84
|
+
x= Orange::Stack.new do
|
85
|
+
use MockMiddleware
|
86
|
+
stack MockOrangeBasedMiddleware
|
87
|
+
run MockExitware.new
|
88
|
+
end
|
89
|
+
y= Orange::Stack.new do
|
90
|
+
stack MockOrangeBasedMiddleware
|
91
|
+
use MockMiddleware
|
92
|
+
run MockExitware.new
|
93
|
+
end
|
94
|
+
lambda {
|
95
|
+
x.call({:test => 'middlewarez'})
|
96
|
+
}.should raise_error(RuntimeError, "I'm in ur middlewarez")
|
97
|
+
lambda {
|
98
|
+
y.call({:test => 'middlewarez'})
|
99
|
+
}.should raise_error(RuntimeError, "It's over 9000 Orange::Cores!")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should load a resource when using load" do
|
103
|
+
x= Orange::Stack.new
|
104
|
+
x.load(MockResource.new, :test)
|
105
|
+
x.orange[:test].mock_method.should == 'MockResource#mock_method'
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should not rebuild stack if auto_reload not set" do
|
109
|
+
x= Orange::Stack.new do
|
110
|
+
run MockExitware.new
|
111
|
+
end
|
112
|
+
x.app.should eql(x.app)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should fire the stack events" do
|
116
|
+
c = Orange::Core.new
|
117
|
+
c2 = Orange::Core.new
|
118
|
+
x= Orange::Stack.new(nil, c) do
|
119
|
+
run MockExitware.new
|
120
|
+
end
|
121
|
+
x2= Orange::Stack.new(nil, c2) do
|
122
|
+
auto_reload!
|
123
|
+
run MockExitware.new
|
124
|
+
end
|
125
|
+
c.should_receive(:fire).with(:stack_loaded, anything()).once
|
126
|
+
c.should_receive(:fire).with(:stack_reloading, anything()).exactly(0).times
|
127
|
+
x.app
|
128
|
+
x.app
|
129
|
+
c2.should_receive(:fire).with(:stack_loaded, anything()).exactly(3).times
|
130
|
+
c2.should_receive(:fire).with(:stack_reloading, anything()).twice
|
131
|
+
x2.app
|
132
|
+
x2.app
|
133
|
+
x2.app
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should rebuild stack if auto_reload! set" do
|
137
|
+
x= Orange::Stack.new do
|
138
|
+
auto_reload!
|
139
|
+
use MockMiddleware
|
140
|
+
run MockExitware.new
|
141
|
+
end
|
142
|
+
x.app.should_not eql(x.app)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should include ShowExceptions in stack if use_exceptions called" do
|
146
|
+
x= Orange::Stack.new do
|
147
|
+
use_exceptions
|
148
|
+
run MockExitware.new
|
149
|
+
end
|
150
|
+
mapped = x.middlewarez
|
151
|
+
mapped.should_not eql([])
|
152
|
+
mapped.select{|x| x.instance_of?(Orange::Middleware::ShowExceptions)}.should_not be_empty
|
153
|
+
mapped.select{|x| x.instance_of?(Orange::Middleware::ShowExceptions)}.should have(1).items
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should add middleware when calling prerouting" do
|
157
|
+
x= Orange::Stack.new do
|
158
|
+
no_recapture
|
159
|
+
run MockExitware.new
|
160
|
+
end
|
161
|
+
x.middlewarez.should have(1).middlewares
|
162
|
+
x.prerouting
|
163
|
+
x.middlewarez.should have(9).middlewares
|
164
|
+
x.middlewarez.select{|y| y.instance_of?(Rack::AbstractFormat)}.should_not be_empty
|
165
|
+
x.middlewarez.select{|y| y.instance_of?(Orange::Middleware::RouteSite)}.should_not be_empty
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should have routing, postrouting and responder middleware hooks" do
|
169
|
+
x = Orange::Stack.new do
|
170
|
+
run MockExitware.new
|
171
|
+
end
|
172
|
+
x.should respond_to(:routing)
|
173
|
+
x.should respond_to(:postrouting)
|
174
|
+
x.should respond_to(:responders)
|
175
|
+
q = mock(:plugins)
|
176
|
+
plugin = mock(:plugin)
|
177
|
+
Orange.should_receive(:plugins).exactly(3).times.and_return(q)
|
178
|
+
q.should_receive(:each).exactly(3).times.and_return([plugin])
|
179
|
+
x.routing
|
180
|
+
x.postrouting
|
181
|
+
x.responders
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should add one less middleware when calling prerouting with opt :no_abstract_format" do
|
185
|
+
x= Orange::Stack.new do
|
186
|
+
no_recapture
|
187
|
+
run MockExitware.new
|
188
|
+
end
|
189
|
+
x.middlewarez.should have(1).middlewares
|
190
|
+
x.prerouting(:no_abstract_format => true)
|
191
|
+
x.middlewarez.should have(8).middlewares
|
192
|
+
x.middlewarez.select{|y| y.instance_of?(Rack::AbstractFormat)}.should be_empty
|
193
|
+
x.middlewarez.select{|y| y.instance_of?(Orange::Middleware::RouteSite)}.should_not be_empty
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
it "should have not have extra middleware for a default stack" do
|
198
|
+
x= Orange::Stack.new MockApplication
|
199
|
+
x.middlewarez.should have(1).middlewares
|
200
|
+
end
|
201
|
+
|
202
|
+
# it "should not include Rack::OpenID unless openid_access_control enabled" do
|
203
|
+
# defined?(Rack::OpenID).should be_nil
|
204
|
+
# x= Orange::Stack.new do
|
205
|
+
# openid_access_control
|
206
|
+
# run MockExitware.new
|
207
|
+
# end
|
208
|
+
# defined?(Rack::OpenID).should == "constant"
|
209
|
+
# end
|
210
|
+
|
211
|
+
# it "should add middleware when calling openid_access_control" do
|
212
|
+
# x= Orange::Stack.new do
|
213
|
+
# no_recapture
|
214
|
+
# run MockExitware.new
|
215
|
+
# end
|
216
|
+
# x.middlewarez.should have(1).middlewares
|
217
|
+
# x.openid_access_control
|
218
|
+
# x.middlewarez.should have(3).middlewares
|
219
|
+
# x.middlewarez.select{|y| y.instance_of?(Rack::OpenID)}.should_not be_empty
|
220
|
+
# x.middlewarez.select{|y| y.instance_of?(Orange::Middleware::AccessControl)}.should_not be_empty
|
221
|
+
# end
|
222
|
+
|
223
|
+
it "should include a module into Orange::Packet on add_pulp" do
|
224
|
+
x= Orange::Stack.new
|
225
|
+
p= Orange::Packet.new(Orange::Core.new, {})
|
226
|
+
p.should_not respond_to(:my_new_mock_method)
|
227
|
+
x.add_pulp(MockPulp)
|
228
|
+
p.should respond_to(:my_new_mock_method)
|
229
|
+
p.should be_a_kind_of(MockPulp)
|
230
|
+
end
|
231
|
+
|
232
|
+
end
|