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::Resource do
4
+ it "should allow options" do
5
+ r= Orange::Resource.new(:opt_1 => true){ opt_2 true }
6
+ r.options[:opt_1].should == true
7
+ r.options[:opt_2].should == true
8
+ r.options.should have_key(:opt_1)
9
+ r.options.should_not have_key(:opt_3)
10
+ end
11
+
12
+ it "should accept an orange core on set_orange" do
13
+ c= Orange::Core.new
14
+ r= Orange::Resource.new
15
+ r.set_orange(c, :name)
16
+ r.orange.should equal(c)
17
+ r.orange.should be_a_kind_of(Orange::Core)
18
+ end
19
+
20
+ it "should call afterLoad after calling set_orange" do
21
+ c= Orange::Core.new
22
+ r= MockResource.new
23
+ r.options.should_not have_key(:mocked)
24
+ r.set_orange(c, :name)
25
+ r.options.should have_key(:mocked)
26
+ r.options[:mocked].should == true
27
+ end
28
+
29
+ it "should set the orange_name after calling set_orange" do
30
+ c= Orange::Core.new
31
+ r= Orange::Resource.new
32
+ r2= Orange::Resource.new
33
+ r.set_orange(c, :name)
34
+ r2.set_orange(c, 'name')
35
+ r.orange_name.should == :name
36
+ r2.orange_name.should_not == :name
37
+ r2.orange_name.should == 'name'
38
+ end
39
+
40
+ it "should return self after set_orange" do
41
+ c= Orange::Core.new
42
+ r= Orange::Resource.new
43
+ me = r.set_orange(c, :name)
44
+ me.should equal r
45
+ end
46
+
47
+ it "should register for stack_loaded iff stack_init method present" do
48
+ c = Orange::Core.new
49
+ c.should_receive(:register).with(:stack_loaded).once
50
+ mid1 = c.load MockResource.new
51
+ mid2 = c.load MockResourceTwo.new
52
+ end
53
+
54
+ it "should return an error if setting orange on a class" do
55
+ lambda {
56
+ Orange::Resource.set_orange(Orange::Core.new, :mock)
57
+ }.should raise_error(RuntimeError, "instantiate the resource before calling set orange")
58
+ end
59
+
60
+ it "should give access to the core through orange" do
61
+ c= Orange::Core.new
62
+ r= Orange::Resource.new
63
+ r.set_orange(c, :name)
64
+ r.orange.should equal(c)
65
+ r.orange.should be_a_kind_of(Orange::Core)
66
+ end
67
+
68
+ it "should respond to routable" do
69
+ r = Orange::Resource.new
70
+ r.should respond_to(:routable)
71
+ r.routable.should be_false
72
+ end
73
+
74
+ it "should return an empty string on calling view" do
75
+ r = Orange::Resource.new
76
+ r.view.should == ''
77
+ r.view(Orange::Packet.new(Orange::Core.new, {})).should == ''
78
+ end
79
+
80
+ it "should accept an options hash to view" do
81
+ p = Orange::Packet.new(Orange::Core.new, {})
82
+ r = Orange::Resource.new
83
+ lambda{
84
+ r.view(p, :opts => 'foo', :test => 'bar')
85
+ }.should_not raise_error
86
+ end
87
+
88
+ it "should give access to the orange name attribute" do
89
+ c= Orange::Core.new
90
+ r= Orange::Resource.new
91
+ r.set_orange(c, :name)
92
+ r.orange_name.should == :name
93
+ end
94
+
95
+
96
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Orange::Mapper do
4
+ it "should be spec'ed"
5
+ end
@@ -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,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Orange::Parser do
4
+ it "should be spec'ed"
5
+ end
@@ -0,0 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Orange::RoutableResource do
4
+ it "should be spec'ed"
5
+ 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