orange-more 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/README.markdown +17 -0
  2. data/lib/orange-more.rb +23 -0
  3. data/lib/orange-more/administration.rb +1 -0
  4. data/lib/orange-more/administration/assets/css/admin.css +286 -0
  5. data/lib/orange-more/administration/assets/css/blueprint-ie.css +35 -0
  6. data/lib/orange-more/administration/assets/css/blueprint-print.css +29 -0
  7. data/lib/orange-more/administration/assets/css/blueprint.css +257 -0
  8. data/lib/orange-more/administration/assets/js/jquery.js +152 -0
  9. data/lib/orange-more/administration/cartons/site.rb +7 -0
  10. data/lib/orange-more/administration/cartons/site_carton.rb +12 -0
  11. data/lib/orange-more/administration/cartons/user.rb +27 -0
  12. data/lib/orange-more/administration/middleware/access_control.rb +156 -0
  13. data/lib/orange-more/administration/middleware/site_load.rb +25 -0
  14. data/lib/orange-more/administration/plugin.rb +23 -0
  15. data/lib/orange-more/administration/resources/admin_resource.rb +27 -0
  16. data/lib/orange-more/administration/resources/site_resource.rb +10 -0
  17. data/lib/orange-more/administration/resources/user_resource.rb +40 -0
  18. data/lib/orange-more/administration/templates/admin.haml +25 -0
  19. data/lib/orange-more/administration/views/openid_login.haml +14 -0
  20. data/lib/orange-more/administration/views/users/create.haml +10 -0
  21. data/lib/orange-more/administration/views/users/edit.haml +15 -0
  22. data/lib/orange-more/adverts.rb +1 -0
  23. data/lib/orange-more/adverts/cartons/adverts_carton.rb +14 -0
  24. data/lib/orange-more/adverts/plugin.rb +13 -0
  25. data/lib/orange-more/adverts/resources/adverts_resource.rb +27 -0
  26. data/lib/orange-more/adverts/views/adverts/adverts.haml +2 -0
  27. data/lib/orange-more/analytics.rb +1 -0
  28. data/lib/orange-more/analytics/middleware/analytics.rb +30 -0
  29. data/lib/orange-more/analytics/plugin.rb +11 -0
  30. data/lib/orange-more/analytics/resources/analytics_resource.rb +42 -0
  31. data/lib/orange-more/assets.rb +1 -0
  32. data/lib/orange-more/assets/cartons/asset_carton.rb +27 -0
  33. data/lib/orange-more/assets/plugin.rb +13 -0
  34. data/lib/orange-more/assets/resources/asset_resource.rb +115 -0
  35. data/lib/orange-more/assets/views/assets/change.haml +1 -0
  36. data/lib/orange-more/assets/views/assets/create.haml +13 -0
  37. data/lib/orange-more/assets/views/assets/insert.haml +1 -0
  38. data/lib/orange-more/blog.rb +1 -0
  39. data/lib/orange-more/blog/cartons/blog.rb +8 -0
  40. data/lib/orange-more/blog/cartons/blog_post.rb +60 -0
  41. data/lib/orange-more/blog/plugin.rb +14 -0
  42. data/lib/orange-more/blog/resources/blog_post_resource.rb +54 -0
  43. data/lib/orange-more/blog/resources/blog_resource.rb +104 -0
  44. data/lib/orange-more/blog/views/blog/blog_archive_view.haml +6 -0
  45. data/lib/orange-more/blog/views/blog/blog_offset_list_view.haml +12 -0
  46. data/lib/orange-more/blog/views/blog/blog_post_view.haml +4 -0
  47. data/lib/orange-more/blog/views/blog/sitemap_row.haml +14 -0
  48. data/lib/orange-more/blog/views/blog_posts/edit.haml +8 -0
  49. data/lib/orange-more/blog/views/blog_posts/show.haml +4 -0
  50. data/lib/orange-more/cloud.rb +1 -0
  51. data/lib/orange-more/cloud/plugin.rb +10 -0
  52. data/lib/orange-more/cloud/resources/cloud_resource.rb +21 -0
  53. data/lib/orange-more/contactforms.rb +1 -0
  54. data/lib/orange-more/contactforms/assets/js/jquery.validate.pack.js +15 -0
  55. data/lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js +6240 -0
  56. data/lib/orange-more/contactforms/assets/js/lib/jquery.form.js +660 -0
  57. data/lib/orange-more/contactforms/assets/js/lib/jquery.js +4376 -0
  58. data/lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js +122 -0
  59. data/lib/orange-more/contactforms/cartons/contactforms_carton.rb +12 -0
  60. data/lib/orange-more/contactforms/plugin.rb +13 -0
  61. data/lib/orange-more/contactforms/resources/contactforms_resource.rb +56 -0
  62. data/lib/orange-more/contactforms/views/contactforms/contactform.haml +20 -0
  63. data/lib/orange-more/debugger.rb +1 -0
  64. data/lib/orange-more/debugger/assets/css/debug_bar.css +46 -0
  65. data/lib/orange-more/debugger/middleware/debugger.rb +50 -0
  66. data/lib/orange-more/debugger/plugin.rb +12 -0
  67. data/lib/orange-more/debugger/views/debug_bar.haml +87 -0
  68. data/lib/orange-more/disqus.rb +1 -0
  69. data/lib/orange-more/disqus/plugin.rb +11 -0
  70. data/lib/orange-more/disqus/resources/disqus_resource.rb +9 -0
  71. data/lib/orange-more/disqus/views/disqus/comment_thread.haml +7 -0
  72. data/lib/orange-more/donations.rb +1 -0
  73. data/lib/orange-more/donations/cartons/donation_carton.rb +9 -0
  74. data/lib/orange-more/donations/plugin.rb +12 -0
  75. data/lib/orange-more/donations/resources/donations_resource.rb +51 -0
  76. data/lib/orange-more/donations/views/donations/donate_form.haml +21 -0
  77. data/lib/orange-more/donations/views/donations/donate_thanks.haml +2 -0
  78. data/lib/orange-more/donations/views/donations/paypal_form.haml +13 -0
  79. data/lib/orange-more/events.rb +1 -0
  80. data/lib/orange-more/events/assets/js/events.js +55 -0
  81. data/lib/orange-more/events/cartons/orange_calendar.rb +8 -0
  82. data/lib/orange-more/events/cartons/orange_event.rb +60 -0
  83. data/lib/orange-more/events/plugin.rb +14 -0
  84. data/lib/orange-more/events/resources/calendar_resource.rb +33 -0
  85. data/lib/orange-more/events/resources/event_resource.rb +147 -0
  86. data/lib/orange-more/events/views/calendar/calendar.haml +8 -0
  87. data/lib/orange-more/events/views/events/create.haml +55 -0
  88. data/lib/orange-more/events/views/events/edit.haml +59 -0
  89. data/lib/orange-more/events/views/events/list.haml +13 -0
  90. data/lib/orange-more/events/views/events/show.haml +4 -0
  91. data/lib/orange-more/events/views/events/table_row.haml +17 -0
  92. data/lib/orange-more/members.rb +1 -0
  93. data/lib/orange-more/members/cartons/member_carton.rb +38 -0
  94. data/lib/orange-more/members/plugin.rb +13 -0
  95. data/lib/orange-more/members/resources/members_resource.rb +327 -0
  96. data/lib/orange-more/members/views/members/create.haml +12 -0
  97. data/lib/orange-more/members/views/members/edit.haml +15 -0
  98. data/lib/orange-more/members/views/members/live.show.haml +1 -0
  99. data/lib/orange-more/members/views/members/login.haml +17 -0
  100. data/lib/orange-more/members/views/members/logout.haml +1 -0
  101. data/lib/orange-more/members/views/members/profile.haml +50 -0
  102. data/lib/orange-more/members/views/members/register.haml +37 -0
  103. data/lib/orange-more/news.rb +1 -0
  104. data/lib/orange-more/news/cartons/news.rb +12 -0
  105. data/lib/orange-more/news/plugin.rb +13 -0
  106. data/lib/orange-more/news/resources/news_resource.rb +83 -0
  107. data/lib/orange-more/news/views/news/archive.haml +14 -0
  108. data/lib/orange-more/news/views/news/edit.haml +7 -0
  109. data/lib/orange-more/news/views/news/latest.haml +8 -0
  110. data/lib/orange-more/news/views/news/sitemap_row.haml +14 -0
  111. data/lib/orange-more/pages.rb +1 -0
  112. data/lib/orange-more/pages/cartons/page_carton.rb +14 -0
  113. data/lib/orange-more/pages/cartons/page_version_carton.rb +12 -0
  114. data/lib/orange-more/pages/plugin.rb +13 -0
  115. data/lib/orange-more/pages/resources/page_resource.rb +179 -0
  116. data/lib/orange-more/pages/views/pages/edit.haml +34 -0
  117. data/lib/orange-more/pages/views/pages/show.haml +6 -0
  118. data/lib/orange-more/sitemap.rb +1 -0
  119. data/lib/orange-more/sitemap/assets/img/sitemap_down.png +0 -0
  120. data/lib/orange-more/sitemap/assets/img/sitemap_down_d.png +0 -0
  121. data/lib/orange-more/sitemap/assets/img/sitemap_indent.png +0 -0
  122. data/lib/orange-more/sitemap/assets/img/sitemap_indent_d.png +0 -0
  123. data/lib/orange-more/sitemap/assets/img/sitemap_outdent.png +0 -0
  124. data/lib/orange-more/sitemap/assets/img/sitemap_outdent_d.png +0 -0
  125. data/lib/orange-more/sitemap/assets/img/sitemap_up.png +0 -0
  126. data/lib/orange-more/sitemap/assets/img/sitemap_up_d.png +0 -0
  127. data/lib/orange-more/sitemap/assets/js/sitemap.js +11 -0
  128. data/lib/orange-more/sitemap/cartons/route.rb +44 -0
  129. data/lib/orange-more/sitemap/middleware/flex_router.rb +25 -0
  130. data/lib/orange-more/sitemap/plugin.rb +17 -0
  131. data/lib/orange-more/sitemap/resources/sitemap_resource.rb +295 -0
  132. data/lib/orange-more/sitemap/views/default_resource/sitemap_row.haml +30 -0
  133. data/lib/orange-more/sitemap/views/sitemap/breadcrumb.haml +12 -0
  134. data/lib/orange-more/sitemap/views/sitemap/list.haml +4 -0
  135. data/lib/orange-more/sitemap/views/sitemap/one_level.haml +7 -0
  136. data/lib/orange-more/sitemap/views/sitemap/route_actions.haml +15 -0
  137. data/lib/orange-more/sitemap/views/sitemap/sitemap_links.haml +14 -0
  138. data/lib/orange-more/sitemap/views/sitemap/table_row.haml +30 -0
  139. data/lib/orange-more/sitemap/views/sitemap/two_level.haml +13 -0
  140. data/lib/orange-more/slices.rb +1 -0
  141. data/lib/orange-more/slices/middleware/radius_parser.rb +24 -0
  142. data/lib/orange-more/slices/plugin.rb +15 -0
  143. data/lib/orange-more/slices/resources/radius.rb +117 -0
  144. data/lib/orange-more/slices/resources/slices.rb +35 -0
  145. data/lib/orange-more/subsites.rb +1 -0
  146. data/lib/orange-more/subsites/cartons/subsite.rb +8 -0
  147. data/lib/orange-more/subsites/middleware/subsite_load.rb +29 -0
  148. data/lib/orange-more/subsites/plugin.rb +17 -0
  149. data/lib/orange-more/subsites/resources/subsite_resource.rb +54 -0
  150. data/lib/orange-more/subsites/views/subsites/index.haml +2 -0
  151. data/lib/orange-more/testimonials.rb +1 -0
  152. data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +15 -0
  153. data/lib/orange-more/testimonials/plugin.rb +13 -0
  154. data/lib/orange-more/testimonials/resources/testimonials_resource.rb +42 -0
  155. data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +4 -0
  156. data/spec/orange-core/application_spec.rb +183 -0
  157. data/spec/orange-core/carton_spec.rb +136 -0
  158. data/spec/orange-core/core_spec.rb +248 -0
  159. data/spec/orange-core/magick_spec.rb +96 -0
  160. data/spec/orange-core/middleware/base_spec.rb +38 -0
  161. data/spec/orange-core/middleware/globals_spec.rb +3 -0
  162. data/spec/orange-core/middleware/rerouter_spec.rb +3 -0
  163. data/spec/orange-core/middleware/restful_router_spec.rb +3 -0
  164. data/spec/orange-core/middleware/route_context_spec.rb +3 -0
  165. data/spec/orange-core/middleware/route_site_spec.rb +3 -0
  166. data/spec/orange-core/middleware/show_exceptions_spec.rb +3 -0
  167. data/spec/orange-core/middleware/static_file_spec.rb +3 -0
  168. data/spec/orange-core/middleware/static_spec.rb +3 -0
  169. data/spec/orange-core/mock/mock_app.rb +16 -0
  170. data/spec/orange-core/mock/mock_carton.rb +43 -0
  171. data/spec/orange-core/mock/mock_core.rb +2 -0
  172. data/spec/orange-core/mock/mock_middleware.rb +25 -0
  173. data/spec/orange-core/mock/mock_mixins.rb +19 -0
  174. data/spec/orange-core/mock/mock_model_resource.rb +47 -0
  175. data/spec/orange-core/mock/mock_pulp.rb +24 -0
  176. data/spec/orange-core/mock/mock_resource.rb +26 -0
  177. data/spec/orange-core/mock/mock_router.rb +10 -0
  178. data/spec/orange-core/orange_spec.rb +19 -0
  179. data/spec/orange-core/packet_spec.rb +203 -0
  180. data/spec/orange-core/resource_spec.rb +96 -0
  181. data/spec/orange-core/resources/mapper_spec.rb +5 -0
  182. data/spec/orange-core/resources/model_resource_spec.rb +246 -0
  183. data/spec/orange-core/resources/parser_spec.rb +5 -0
  184. data/spec/orange-core/resources/routable_resource_spec.rb +5 -0
  185. data/spec/orange-core/spec_helper.rb +53 -0
  186. data/spec/orange-core/stack_spec.rb +232 -0
  187. data/spec/stats.rb +182 -0
  188. metadata +312 -0
@@ -0,0 +1,96 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Orange::DefaultHash do
4
+ it "should be a kind of Hash" do
5
+ Orange::DefaultHash.new.should be_a_kind_of Hash
6
+ end
7
+ it "should handle setting default" do
8
+ x = Orange::DefaultHash.new
9
+ y = Orange::DefaultHash.new
10
+ x.default = true
11
+ y.default = false
12
+ x[:not_there].should be_true
13
+ y[:not_there].should be_false
14
+ end
15
+
16
+ it "should handle default in key access []" do
17
+ x = Orange::DefaultHash.new
18
+ x.default = 'baz'
19
+ x[:not_there].should == 'baz'
20
+ x[:not_there, 'bar'].should == 'bar'
21
+ end
22
+ end
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
+
35
+ describe "Orange::Options" do
36
+ it "should give a hash on hash" do
37
+ Orange::Options.new.hash.should be_an_instance_of(Hash)
38
+ end
39
+
40
+ it "should accept hash key options" do
41
+ hash1 = Orange::Options.new(:one => '1', :two => ['foo']).hash
42
+ hash2 = Orange::Options.new(:one => '1').hash
43
+ hash3 = Orange::Options.new({:one => '1', :two => ['foo']}).hash
44
+ hash4 = Orange::Options.new({:one => '1'}).hash
45
+ hash5 = Orange::Options.new(1,2, {:one => '1', :two => ['foo']}).hash
46
+ hash6 = Orange::Options.new(1,2, {:one => '1'}).hash
47
+ [hash2, hash4, hash6].each{ |hash|
48
+ hash.should have_key(:one)
49
+ hash.should_not have_key(:three)
50
+ hash[:one].should == '1'
51
+ }
52
+ [hash1, hash3, hash5].each{ |hash|
53
+ hash.should have_key(:one)
54
+ hash.should have_key(:two)
55
+ hash.should_not have_key(:three)
56
+ hash[:one].should == '1'
57
+ hash[:two].should == ['foo']
58
+ }
59
+ end
60
+
61
+ it "should accept block options" do
62
+ hash = Orange::Options.new {
63
+ one '1'
64
+ two ['foo']
65
+ }.hash
66
+ hash.should have_key(:one)
67
+ hash.should have_key(:two)
68
+ hash.should_not have_key(:three)
69
+ hash[:one].should == '1'
70
+ hash[:two].should == ['foo']
71
+ end
72
+
73
+ it "should accept both kinds of options" do
74
+ hash = Orange::Options.new(:one => '1'){
75
+ two ['foo']
76
+ }.hash
77
+
78
+ hash.should have_key(:one)
79
+ hash.should have_key(:two)
80
+ hash.should_not have_key(:three)
81
+ hash[:one].should == '1'
82
+ hash[:two].should == ['foo']
83
+ end
84
+
85
+ it "should override hash key options with block options" do
86
+ hash = Orange::Options.new(:one => '1', :two => [:baz]){
87
+ two ['foo']
88
+ }.hash
89
+
90
+ hash.should have_key(:one)
91
+ hash.should have_key(:two)
92
+ hash.should_not have_key(:three)
93
+ hash[:one].should == '1'
94
+ hash[:two].should == ['foo']
95
+ end
96
+ end
@@ -0,0 +1,38 @@
1
+ describe Orange::Middleware::Base do
2
+ it "should call init after initializing" do
3
+ lambda{
4
+ mid = MockOrangeDeathMiddleware.new(nil, Orange::Core.new, :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, Orange::Core.new)
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, Orange::Core.new)
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).and_return([{},200,[]])
25
+ app2.should_receive(:packet_call).with(an_instance_of(Orange::Packet))
26
+ mid = MockOrangeBasedMiddlewareTwo.new(app, Orange::Core.new)
27
+ mid2 = MockOrangeBasedMiddlewareTwo.new(app2, Orange::Core.new)
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
+
38
+ 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::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,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,16 @@
1
+ require 'rubygems'
2
+ require 'rack/abstract_format'
3
+
4
+ class MockApplication < Orange::Application
5
+
6
+ end
7
+
8
+ class MockApplication2 < Orange::Application
9
+
10
+ end
11
+
12
+ class MockExitware
13
+ def call(env)
14
+ raise 'Mock Exitware'
15
+ end
16
+ end
@@ -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
@@ -0,0 +1,2 @@
1
+ class MockCoreSubclass < Orange::Core
2
+ end
@@ -0,0 +1,25 @@
1
+ class MockOrangeBasedMiddleware < Orange::Middleware::Base
2
+ def packet_call(packet)
3
+ raise "It's over 9000 #{@core.class.to_s}s!"
4
+ end
5
+ end
6
+
7
+ class MockMiddleware
8
+ def initialize(app)
9
+ end
10
+ def call(env)
11
+ raise "I'm in ur #{env[:test]}"
12
+ end
13
+ end
14
+
15
+ class MockOrangeBasedMiddlewareTwo < Orange::Middleware::Base; end
16
+ class MockOrangeBasedMiddlewareThree < Orange::Middleware::Base
17
+ def stack_init
18
+ end
19
+ end
20
+ class MockOrangeDeathMiddleware < Orange::Middleware::Base
21
+ def init(*args)
22
+ opts = args.extract_options!
23
+ raise "middleware_init with foo=#{opts[:foo]}"
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module MockMixinOrange1
2
+ def mixin_orange_one
3
+ end
4
+ end
5
+
6
+ module MockMixinOrange2
7
+ def mixin_orange_two
8
+ end
9
+ end
10
+
11
+ module MockMixinCore1
12
+ def mixin_core_one
13
+ end
14
+ end
15
+
16
+ module MockMixinCore2
17
+ def mixin_core_two
18
+ end
19
+ end
@@ -0,0 +1,47 @@
1
+ class MockModelResource < Orange::ModelResource
2
+ use MockCarton
3
+ end
4
+
5
+ class MockModelResourceOne < Orange::ModelResource
6
+ use MockCarton
7
+ def index(packet, *args)
8
+ raise 'I see you\'re using index'
9
+ end
10
+ def show(packet, *args)
11
+ raise 'I see you\'re using show'
12
+ end
13
+ def other(packet, *args)
14
+ raise 'I see you\'re using other'
15
+ end
16
+ def find_one(packet, mode, resource_id =false)
17
+ raise 'calling find_one'
18
+ end
19
+ def find_list(packet, mode)
20
+ raise 'calling find_list'
21
+ end
22
+ end
23
+
24
+ class MockModelResourceTwo < Orange::ModelResource
25
+ use MockCartonTwo
26
+ end
27
+
28
+ class MockModelResourceThree < Orange::ModelResource
29
+ use MockCarton
30
+ def find_extras(packet, mode)
31
+ raise 'calling find_extras'
32
+ end
33
+ end
34
+
35
+ class MockModelResourceFour < Orange::ModelResource
36
+ use MockCarton
37
+ def find_one(packet, mode, resource_id =false)
38
+ 'mock_one'
39
+ end
40
+ def find_list(packet, mode)
41
+ 'mock_list'
42
+ end
43
+ end
44
+
45
+ class MockModelResourceExtreme < Orange::ModelResource
46
+
47
+ end
@@ -0,0 +1,24 @@
1
+ module MockPulpOrange1
2
+ def pulp_orange_one
3
+ end
4
+ end
5
+
6
+ module MockPulpOrange2
7
+ def pulp_orange_two
8
+ end
9
+ end
10
+
11
+ module MockPulpCore1
12
+ def pulp_core_one
13
+ end
14
+ end
15
+
16
+ module MockPulpCore2
17
+ def pulp_core_two
18
+ end
19
+ end
20
+
21
+ module MockPulp
22
+ def my_new_mock_method
23
+ end
24
+ end
@@ -0,0 +1,26 @@
1
+ class MockResource < Orange::Resource
2
+ def mock_method
3
+ 'MockResource#mock_method'
4
+ end
5
+ def afterLoad
6
+ @options[:mocked] = true
7
+ end
8
+ end
9
+
10
+ class MockResourceTwo < Orange::Resource
11
+ def mock_method
12
+ 'MockResource#mock_method'
13
+ end
14
+ def afterLoad
15
+ @options[:mocked] = true
16
+ end
17
+ def stack_init
18
+ true
19
+ end
20
+ end
21
+
22
+ class MockHamlParser < Orange::Resource
23
+ def haml(template, packet, opts)
24
+ [template, packet, opts]
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+
2
+ class TestRouter
3
+ attr_accessor :x
4
+ def initialize
5
+ @x = 0
6
+ end
7
+ def route(packet)
8
+ @x += 1
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ describe Orange do
2
+ it "should allow core mixin via mixin method" do
3
+ c= Orange::Core.new
4
+ c.should_not respond_to(:mixin_orange_one)
5
+ Orange.mixin MockMixinOrange1
6
+ c2= Orange::Core.new
7
+ c.should respond_to(:mixin_orange_one)
8
+ c2.should respond_to(:mixin_orange_one)
9
+ end
10
+ it "should allow pulp mixin via pulp method" do
11
+ c= Orange::Core.new
12
+ p= Orange::Packet.new(c, {})
13
+ p.should_not respond_to(:pulp_orange_one)
14
+ Orange.add_pulp MockPulpOrange1
15
+ p2= Orange::Packet.new(c, {})
16
+ p.should respond_to(:pulp_orange_one)
17
+ p2.should respond_to(:pulp_orange_one)
18
+ end
19
+ end
@@ -0,0 +1,203 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Orange::Packet do
4
+ it "should return a default header content type of html" do
5
+ p= Orange::Packet.new(Orange::Core.new, {})
6
+ p.finish[1].should have_key("Content-Type")
7
+ p.finish[1]["Content-Type"].should eql("text/html")
8
+ end
9
+
10
+ it "should not create a new object for env if one already exists" do
11
+ p= Orange::Packet.new(Orange::Core.new, {})
12
+ env = p.env
13
+ p2= Orange::Packet.new(Orange::Core.new, env)
14
+ p.should equal p2 # Exact equality - same instances
15
+ end
16
+
17
+ it "should save core passed to it on initialization" do
18
+ c= Orange::Core.new
19
+ p= Orange::Packet.new(c, {})
20
+ p.orange.should equal c
21
+ end
22
+
23
+ it "should save the env passed to it on init" do
24
+ p= Orange::Packet.new(Orange::Core.new, {:test => :foo})
25
+ p.env.should have_key(:test)
26
+ p.env[:test].should == :foo
27
+ p.env.should_not be_empty
28
+ end
29
+
30
+ it "should add orange.packet and orange.env to env on init" do
31
+ p= Orange::Packet.new(Orange::Core.new, {})
32
+ p.env.should have_key('orange.packet')
33
+ p.env['orange.packet'].should equal p
34
+ p.env.should have_key('orange.env')
35
+ p.env['orange.env'].should have_key(:request)
36
+ p.env['orange.env'][:request].should be_an_instance_of(Rack::Request)
37
+ p.env['orange.env'].should have_key(:headers)
38
+ p.env['orange.env'][:headers].should be_an_instance_of(Hash)
39
+ end
40
+
41
+ it "should have access to the orange.env through []" do
42
+ p= Orange::Packet.new(Orange::Core.new, {'orange.env' => {'foo' => :true}})
43
+ p['foo'].should == :true
44
+ p['foo'] = 'banana'
45
+ p.env['orange.env']['foo'].should == 'banana'
46
+ p['foo'].should == 'banana'
47
+ end
48
+
49
+ it "should allow defaults through [] calls" do
50
+ p= Orange::Packet.new(Orange::Core.new, {})
51
+ p['nonexistent'].should be_false
52
+ p['nonexistent', true].should be_true
53
+ p['nonexistent', true].should_not be_an_instance_of Hash
54
+ p['nonexistent', {}].should be_an_instance_of Hash
55
+ end
56
+
57
+ it "should give access to the rack.session env" do
58
+ p= Orange::Packet.new(Orange::Core.new, {'rack.session' => {'foo' => 'banana'}})
59
+ p.session.should have_key 'foo'
60
+ p.session.should have_key 'flash'
61
+ end
62
+
63
+ it "should give always have a flash" do
64
+ p= Orange::Packet.new(Orange::Core.new, {'rack.session' => {}})
65
+ p.session.should have_key 'flash'
66
+ p.flash.should == {}
67
+ end
68
+
69
+ it "should destruct a flash value upon reading" do
70
+ p= Orange::Packet.new(Orange::Core.new, {'rack.session' => {}})
71
+ p.session.should have_key 'flash'
72
+ p.session["flash"]["foo"] = "bar"
73
+ p.flash("foo").should == "bar"
74
+ p.flash("foo").should be_nil
75
+ p.session["flash"].should_not have_key("foo")
76
+ p.flash("foo", "bar")
77
+ p.flash("foo").should == "bar"
78
+ p.flash("foo").should be_nil
79
+ p.session["flash"].should_not have_key("foo")
80
+ p.flash["foo"] = "bar"
81
+ p.flash("foo").should == "bar"
82
+ p.flash("foo").should be_nil
83
+ p.flash.should_not have_key("foo")
84
+ end
85
+
86
+ it "should give headers by combining :headers with defaults" do
87
+ p= Orange::Packet.new(Orange::Core.new, {})
88
+ p.headers.should == p[:headers, {}].with_defaults(Orange::Packet::DEFAULT_HEADERS)
89
+ end
90
+
91
+ it "should allow setting headers via header(key, val)" do
92
+ p= Orange::Packet.new(Orange::Core.new, {})
93
+ p.header('Content-Type', 'text/plain')
94
+ p.headers['Content-Type'].should == 'text/plain'
95
+ end
96
+
97
+ it "should allow adding headers with add_header" do
98
+ p1= Orange::Packet.new(Orange::Core.new, {})
99
+ p2= Orange::Packet.new(Orange::Core.new, {})
100
+ p1.add_header('Content-Type', 'text/plain')
101
+ p2.header('Content-Type', 'text/plain')
102
+ p1.headers['Content-Type'].should == p2.headers['Content-Type']
103
+ end
104
+
105
+ it "should give access to the core object via orange" do
106
+ c= Orange::Core.new
107
+ p= Orange::Packet.new(c, {})
108
+ p.orange.should equal c
109
+ p.orange.should be_an_instance_of(Orange::Core)
110
+ end
111
+
112
+ it "should create a triple according to rack standards on #finish" do
113
+ p= Orange::Packet.new(Orange::Core.new, {})
114
+ fin = p.finish
115
+ fin[0].should be_a_kind_of Integer
116
+ fin[1].should be_a_kind_of Hash
117
+ fin[2].should be_a_kind_of Array
118
+ end
119
+
120
+ it "should give self when using packet" do
121
+ p= Orange::Packet.new(Orange::Core.new, {})
122
+ p.packet.should equal p
123
+ end
124
+
125
+ it "should mixin when calling mixin" do
126
+ p= Orange::Packet.new(Orange::Core.new, {})
127
+ p.should_not respond_to(:pulp_orange_two)
128
+ Orange::Packet.mixin MockPulpOrange2
129
+ p.should respond_to(:pulp_orange_two)
130
+ end
131
+
132
+ it "should raise an error if no router set" do
133
+ p= Orange::Packet.new(Orange::Core.new, {})
134
+ lambda{
135
+ p.route
136
+ }.should raise_error(RuntimeError, 'Router not found')
137
+ end
138
+
139
+ it "should pass self to assigned router's route method" do
140
+ class MockDeathRouter
141
+ def route(p); raise "die, die, death, #{p[:lame]}"; end
142
+ end
143
+ p= Orange::Packet.new(Orange::Core.new, {})
144
+ p['route.router'] = MockDeathRouter.new
145
+ p[:lame] = 'death'
146
+ lambda{
147
+ p.route
148
+ }.should_not raise_error(RuntimeError, 'Router not found')
149
+ lambda{
150
+ p.route
151
+ }.should raise_error(RuntimeError, 'die, die, death, death')
152
+ end
153
+
154
+ it "should give a request object" do
155
+ p= Orange::Packet.new(Orange::Core.new, {})
156
+ p.request.should be_an_instance_of Rack::Request
157
+ end
158
+
159
+ it "should store method matchers for extending method_missing handlers" do
160
+ class Orange::Packet
161
+ meta_methods(/pretend_method_we_dont_want/) do |match, args|
162
+ "my mock meta method"
163
+ end
164
+
165
+ meta_methods(/pretend_method_we_dont_want(\w+)/) do |match, args|
166
+ "my mock meta method"
167
+ end
168
+ end
169
+ p= Orange::Packet.new(Orange::Core.new, {})
170
+ p.matchers.size.should >= 2
171
+ end
172
+
173
+ it "should have method_missing capabilities" do
174
+ p= Orange::Packet.new(Orange::Core.new, {})
175
+ p.should respond_to(:method_missing)
176
+ lambda {
177
+ p.my_mock_meta_method
178
+ p.mock_meta_test
179
+ p.mock_meta_test_with_args
180
+ }.should raise_error(NoMethodError)
181
+ class Orange::Packet
182
+ meta_methods(/my_mock_meta_method/) do
183
+ "my mock meta method"
184
+ end
185
+
186
+ meta_methods(/mock_meta_(\w+)/) do |packet, match|
187
+ "my mock #{match[1]} method"
188
+ end
189
+
190
+ meta_methods(/mock_meta_(\w+)_with_args/) do |packet, match, args|
191
+ "my mock #{match[1]} method args0 = #{args[0]}"
192
+ end
193
+ end
194
+ lambda {
195
+ p.my_mock_meta_method
196
+ p.mock_meta_test
197
+ p.mock_meta_test_with_args 'test'
198
+ }.should_not raise_error(NoMethodError)
199
+ p.my_mock_meta_method.should == "my mock meta method"
200
+ p.mock_meta_test.should == "my mock test method"
201
+ p.mock_meta_test_with_args('test').should == "my mock test method args0 = test"
202
+ end
203
+ end