orange 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/lib/orange/application.rb +1 -1
  2. data/lib/orange/carton.rb +55 -27
  3. data/lib/orange/cartons/site_carton.rb +4 -1
  4. data/lib/orange/core.rb +10 -2
  5. data/lib/orange/magick.rb +11 -0
  6. data/lib/orange/middleware/access_control.rb +16 -7
  7. data/lib/orange/middleware/base.rb +40 -1
  8. data/lib/orange/middleware/flex_router.rb +59 -0
  9. data/lib/orange/middleware/route_context.rb +2 -2
  10. data/lib/orange/middleware/route_site.rb +1 -1
  11. data/lib/orange/middleware/show_exceptions.rb +3 -1
  12. data/lib/orange/middleware/site_load.rb +14 -1
  13. data/lib/orange/middleware/static.rb +0 -2
  14. data/lib/orange/middleware/template.rb +3 -1
  15. data/lib/orange/resources/admin_resource.rb +25 -0
  16. data/lib/orange/resources/mapper.rb +3 -0
  17. data/lib/orange/resources/model_resource.rb +15 -9
  18. data/lib/orange/resources/page_parts.rb +0 -7
  19. data/lib/orange/resources/parser.rb +5 -4
  20. data/lib/orange/resources/singleton_model_resource.rb +7 -0
  21. data/lib/orange/resources/sitemap_resource.rb +96 -0
  22. data/lib/orange/stack.rb +5 -5
  23. data/spec/{application_spec.rb → orange/application_spec.rb} +0 -0
  24. data/spec/orange/carton_spec.rb +136 -0
  25. data/spec/{core_spec.rb → orange/core_spec.rb} +10 -0
  26. data/spec/{magick_spec.rb → orange/magick_spec.rb} +11 -0
  27. data/spec/orange/middleware/access_control_spec.rb +3 -0
  28. data/spec/orange/middleware/base_spec.rb +37 -0
  29. data/spec/orange/middleware/database_spec.rb +3 -0
  30. data/spec/orange/middleware/globals_spec.rb +3 -0
  31. data/spec/orange/middleware/recapture_spec.rb +3 -0
  32. data/spec/orange/middleware/rerouter_spec.rb +3 -0
  33. data/spec/orange/middleware/restful_router_spec.rb +3 -0
  34. data/spec/orange/middleware/route_context_spec.rb +3 -0
  35. data/spec/orange/middleware/route_site_spec.rb +3 -0
  36. data/spec/orange/middleware/show_exceptions_spec.rb +3 -0
  37. data/spec/orange/middleware/site_load_spec.rb +26 -0
  38. data/spec/orange/middleware/static_file_spec.rb +3 -0
  39. data/spec/orange/middleware/static_spec.rb +3 -0
  40. data/spec/orange/middleware/template_spec.rb +3 -0
  41. data/spec/{mock → orange/mock}/mock_app.rb +0 -0
  42. data/spec/orange/mock/mock_carton.rb +43 -0
  43. data/spec/{mock → orange/mock}/mock_core.rb +0 -0
  44. data/spec/{mock → orange/mock}/mock_middleware.rb +8 -0
  45. data/spec/{mock → orange/mock}/mock_mixins.rb +0 -0
  46. data/spec/{mock → orange/mock}/mock_model_resource.rb +4 -0
  47. data/spec/{mock → orange/mock}/mock_pulp.rb +0 -0
  48. data/spec/{mock → orange/mock}/mock_resource.rb +0 -0
  49. data/spec/{mock → orange/mock}/mock_router.rb +0 -0
  50. data/spec/{orange_spec.rb → orange/orange_spec.rb} +0 -0
  51. data/spec/{packet_spec.rb → orange/packet_spec.rb} +0 -0
  52. data/spec/{resource_spec.rb → orange/resource_spec.rb} +0 -0
  53. data/spec/orange/resources/admin_resource_spec.rb +16 -0
  54. data/spec/{resources → orange/resources}/mapper_spec.rb +0 -0
  55. data/spec/{resources → orange/resources}/model_resource_spec.rb +104 -0
  56. data/spec/{resources → orange/resources}/parser_spec.rb +0 -0
  57. data/spec/{resources → orange/resources}/routable_resource_spec.rb +0 -0
  58. data/spec/orange/resources/singleton_model_resource_spec.rb +4 -0
  59. data/spec/{resources/flex_router_spec.rb → orange/resources/sitemap_resource_spec.rb} +1 -1
  60. data/spec/orange/spec_helper.rb +51 -0
  61. data/spec/{stack_spec.rb → orange/stack_spec.rb} +0 -0
  62. metadata +45 -40
  63. data/lib/orange/resources/flex_router.rb +0 -13
  64. data/spec/carton_spec.rb +0 -5
  65. data/spec/middleware/access_control_spec.rb +0 -0
  66. data/spec/middleware/base_spec.rb +0 -0
  67. data/spec/middleware/database_spec.rb +0 -0
  68. data/spec/middleware/globals_spec.rb +0 -0
  69. data/spec/middleware/recapture_spec.rb +0 -0
  70. data/spec/middleware/rerouter_spec.rb +0 -0
  71. data/spec/middleware/restful_router_spec.rb +0 -0
  72. data/spec/middleware/route_context_spec.rb +0 -0
  73. data/spec/middleware/route_site_spec.rb +0 -0
  74. data/spec/middleware/show_exceptions_spec.rb +0 -0
  75. data/spec/middleware/site_load_spec.rb +0 -0
  76. data/spec/middleware/static_file_spec.rb +0 -0
  77. data/spec/middleware/static_spec.rb +0 -0
  78. data/spec/middleware/template_spec.rb +0 -0
  79. data/spec/mock/mock_carton.rb +0 -15
  80. data/spec/spec_helper.rb +0 -20
@@ -228,4 +228,14 @@ describe Orange::Core do
228
228
  c[:mock].should be_an_kind_of(Orange::Resource)
229
229
  c[:mock].mock_method.should eql 'MockResource#mock_method'
230
230
  end
231
+
232
+ it "should have option to silently ignore resource calls" do
233
+ c= Orange::Core.new
234
+ lambda {
235
+ c[:mock].test
236
+ }.should raise_error
237
+ lambda {
238
+ c[:mock, true].test
239
+ }.should_not raise_error
240
+ end
231
241
  end
@@ -21,6 +21,17 @@ describe Orange::DefaultHash do
21
21
  end
22
22
  end
23
23
 
24
+ describe Orange::Ignore do
25
+ it "should silently accept method" do
26
+ o = Orange::Ignore.new
27
+ lambda {
28
+ o.banana
29
+ o.args
30
+ o.foo.bar('banana').baz
31
+ }.should_not raise_error
32
+ end
33
+ end
34
+
24
35
  describe "Orange::Options" do
25
36
  it "should give a hash on hash" do
26
37
  Orange::Options.new.hash.should be_an_instance_of(Hash)
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::AccessControl do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,37 @@
1
+ describe Orange::Middleware::Base do
2
+ it "should call init after initializing" do
3
+ lambda{
4
+ mid = MockOrangeDeathMiddleware.new(nil, nil, :foo => 'bar')
5
+ }.should raise_error(RuntimeError, "middleware_init with foo=bar")
6
+ end
7
+
8
+ it "should create a packet and call packet call" do
9
+ mid = MockOrangeBasedMiddlewareTwo.new(nil, nil)
10
+ mid.should_receive(:packet_call).with(an_instance_of(Orange::Packet))
11
+ mid.call({})
12
+ end
13
+
14
+ it "should pass the packet on by default for packet_call" do
15
+ mid = MockOrangeBasedMiddlewareTwo.new(nil, nil)
16
+ mid.should_receive(:pass).with(an_instance_of(Orange::Packet))
17
+ mid.packet_call(empty_packet)
18
+ end
19
+
20
+ it "should call the downstream app on pass" do
21
+ app = mock("downstream")
22
+ app2 = mock("downstream_orange")
23
+ my_hash = {:foo => :bar}
24
+ app.should_receive(:call).with(my_hash)
25
+ app2.should_receive(:packet_call).with(an_instance_of(Orange::Packet))
26
+ mid = MockOrangeBasedMiddlewareTwo.new(app, nil)
27
+ mid2 = MockOrangeBasedMiddlewareTwo.new(app2, nil)
28
+ mid.call(my_hash)
29
+ mid2.call(my_hash)
30
+ end
31
+
32
+ it "should give access to the orange core on calling orange" do
33
+ c = Orange::Core.new
34
+ mid = MockOrangeBasedMiddlewareTwo.new(nil, c)
35
+ mid.orange.should equal c
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::Database do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::Globals do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::Recapture do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::Rerouter do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::RestfulRouter do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::RouteContext do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::RouteSite do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::ShowExceptions do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,26 @@
1
+ describe Orange::Middleware::SiteLoad do
2
+ it "should load Orange::SiteResource when used in stack" do
3
+ c = Orange::Core.new
4
+ c.should_receive(:load).with(an_instance_of(Orange::SiteResource), an_instance_of(Symbol))
5
+ app = Orange::Middleware::SiteLoad.new(nil, c)
6
+
7
+ end
8
+
9
+ it "should load the site object into the packet, if available" do
10
+ Orange::Site.should_receive(:first).with(an_instance_of(Hash)).and_return('foo')
11
+ app = Orange::Middleware::SiteLoad.new(return_env_app, Orange::Core.new)
12
+ ret = app.call({})
13
+ ret['orange.env'].should have_key('site')
14
+ ret['orange.env']['site'].should == 'foo'
15
+ end
16
+
17
+ it "should create a new site object, if one doesn't exist" do
18
+ Orange::Site.should_receive(:first).with(an_instance_of(Hash)).and_return(false)
19
+ m = mock("site")
20
+ Orange::Site.should_receive(:new).with(an_instance_of(Hash)).and_return(m)
21
+ m.should_receive(:save).and_return(true)
22
+ app = Orange::Middleware::SiteLoad.new(return_env_app, Orange::Core.new)
23
+ ret = app.call({})
24
+ ret['orange.env'].should have_key('site')
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::StaticFile do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::Static do
2
+ it "should be spec'ed"
3
+ end
@@ -0,0 +1,3 @@
1
+ describe Orange::Middleware::Template do
2
+ it "should be spec'ed"
3
+ end
File without changes
@@ -0,0 +1,43 @@
1
+ class MockCarton < Orange::Carton
2
+ def self.scaffold_properties
3
+ @scaffold_properties
4
+ end
5
+ id
6
+ admin do
7
+ text :admin
8
+ end
9
+ orange do
10
+ text :orange
11
+ end
12
+ front do
13
+ text :front
14
+ end
15
+ end
16
+
17
+ class MockCartonTwo < Orange::Carton
18
+ id
19
+ def self.get(id)
20
+ 'mock_get'
21
+ end
22
+ def self.all
23
+ 'mock_all'
24
+ end
25
+ def save
26
+ raise 'mock_save'
27
+ end
28
+ def destroy!
29
+ raise 'mock_destroy'
30
+ end
31
+ def update(*args)
32
+ raise 'mock_update'
33
+ end
34
+ end
35
+
36
+ class MockCartonBlank < Orange::Carton
37
+ def self.levels
38
+ @levels
39
+ end
40
+ end
41
+
42
+ class MockCartonBlankTwo < Orange::Carton
43
+ end
File without changes
@@ -10,4 +10,12 @@ class MockMiddleware
10
10
  def call(env)
11
11
  raise "I'm in ur #{env[:test]}"
12
12
  end
13
+ end
14
+
15
+ class MockOrangeBasedMiddlewareTwo < Orange::Middleware::Base; end
16
+ class MockOrangeDeathMiddleware < Orange::Middleware::Base
17
+ def init(*args)
18
+ opts = args.extract_options!
19
+ raise "middleware_init with foo=#{opts[:foo]}"
20
+ end
13
21
  end
@@ -40,4 +40,8 @@ class MockModelResourceFour < Orange::ModelResource
40
40
  def find_list(packet, mode)
41
41
  'mock_list'
42
42
  end
43
+ end
44
+
45
+ class MockModelResourceExtreme < Orange::ModelResource
46
+
43
47
  end
File without changes
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Orange::AdminResource do
4
+ before(:all) do
5
+ end
6
+ it "should have a function for returning list of links" do
7
+ a = Orange::AdminResource.new
8
+ a.set_orange(Orange::Core.new, :admin)
9
+ a.links(empty_packet)
10
+ end
11
+ it "should be have an add_link function" do
12
+ a = Orange::AdminResource.new
13
+ a.set_orange(Orange::Core.new, :admin)
14
+ a.add_link('Content', {})
15
+ end
16
+ end
@@ -138,5 +138,109 @@ describe Orange::ModelResource do
138
138
  a.find_extras(Orange::Packet.new(Orange::Core.new, {}), :show).should == {}
139
139
  end
140
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
+
141
245
 
142
246
  end
@@ -0,0 +1,4 @@
1
+ describe Orange::SingletonModelResource do
2
+
3
+ it "should be spec'ed"
4
+ end
@@ -1,5 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe Orange::FlexRouter do
3
+ describe Orange::SitemapResource do
4
4
  it "should be spec'ed"
5
5
  end
@@ -0,0 +1,51 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'orange'
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
28
+ end
29
+
30
+ def mock_delete
31
+ p= mock("request", :null_object => true)
32
+ p.stub!(:delete?).and_return(true)
33
+ p.stub!(:params).and_return({})
34
+ p
35
+ end
36
+
37
+ def empty_packet(c = Orange::Core.new)
38
+ Orange::Packet.new(c, {})
39
+ end
40
+
41
+ def packet_finish_app
42
+ lambda { |env|
43
+ Orange::Packet.new(env).finish
44
+ }
45
+ end
46
+
47
+ def return_env_app
48
+ lambda { |env|
49
+ env
50
+ }
51
+ end