orange 0.5.5 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/orange.rb +2 -5
- data/spec/orange_spec.rb +5 -0
- data/spec/{orange-core/spec_helper.rb → spec_helper.rb} +0 -0
- metadata +28 -235
- data/lib/orange-core.rb +0 -8
- data/lib/orange-core/application.rb +0 -132
- data/lib/orange-core/assets/css/exceptions.css +0 -50
- data/lib/orange-core/assets/js/exceptions.js +0 -44
- data/lib/orange-core/carton.rb +0 -178
- data/lib/orange-core/core.rb +0 -266
- data/lib/orange-core/magick.rb +0 -270
- data/lib/orange-core/middleware/base.rb +0 -96
- data/lib/orange-core/middleware/database.rb +0 -45
- data/lib/orange-core/middleware/four_oh_four.rb +0 -45
- data/lib/orange-core/middleware/globals.rb +0 -17
- data/lib/orange-core/middleware/loader.rb +0 -13
- data/lib/orange-core/middleware/rerouter.rb +0 -53
- data/lib/orange-core/middleware/restful_router.rb +0 -99
- data/lib/orange-core/middleware/route_context.rb +0 -39
- data/lib/orange-core/middleware/route_site.rb +0 -51
- data/lib/orange-core/middleware/show_exceptions.rb +0 -80
- data/lib/orange-core/middleware/static.rb +0 -67
- data/lib/orange-core/middleware/static_file.rb +0 -32
- data/lib/orange-core/middleware/template.rb +0 -60
- data/lib/orange-core/packet.rb +0 -232
- data/lib/orange-core/plugin.rb +0 -172
- data/lib/orange-core/resource.rb +0 -96
- data/lib/orange-core/resources/mapper.rb +0 -36
- data/lib/orange-core/resources/model_resource.rb +0 -228
- data/lib/orange-core/resources/not_found.rb +0 -10
- data/lib/orange-core/resources/page_parts.rb +0 -68
- data/lib/orange-core/resources/parser.rb +0 -113
- data/lib/orange-core/resources/routable_resource.rb +0 -16
- data/lib/orange-core/resources/scaffold.rb +0 -106
- data/lib/orange-core/stack.rb +0 -226
- data/lib/orange-core/templates/exceptions.haml +0 -111
- data/lib/orange-core/views/default_resource/create.haml +0 -4
- data/lib/orange-core/views/default_resource/edit.haml +0 -9
- data/lib/orange-core/views/default_resource/list.haml +0 -10
- data/lib/orange-core/views/default_resource/show.haml +0 -4
- data/lib/orange-core/views/default_resource/table_row.haml +0 -7
- data/lib/orange-core/views/not_found/404.haml +0 -2
- data/lib/orange-more.rb +0 -23
- data/lib/orange-more/administration.rb +0 -1
- data/lib/orange-more/administration/assets/css/admin.css +0 -286
- data/lib/orange-more/administration/assets/css/blueprint-ie.css +0 -35
- data/lib/orange-more/administration/assets/css/blueprint-print.css +0 -29
- data/lib/orange-more/administration/assets/css/blueprint.css +0 -257
- data/lib/orange-more/administration/assets/js/jquery.js +0 -152
- data/lib/orange-more/administration/cartons/site.rb +0 -7
- data/lib/orange-more/administration/cartons/site_carton.rb +0 -12
- data/lib/orange-more/administration/cartons/user.rb +0 -27
- data/lib/orange-more/administration/middleware/access_control.rb +0 -156
- data/lib/orange-more/administration/middleware/site_load.rb +0 -25
- data/lib/orange-more/administration/plugin.rb +0 -23
- data/lib/orange-more/administration/resources/admin_resource.rb +0 -27
- data/lib/orange-more/administration/resources/site_resource.rb +0 -10
- data/lib/orange-more/administration/resources/user_resource.rb +0 -40
- data/lib/orange-more/administration/templates/admin.haml +0 -25
- data/lib/orange-more/administration/views/openid_login.haml +0 -14
- data/lib/orange-more/administration/views/users/create.haml +0 -10
- data/lib/orange-more/administration/views/users/edit.haml +0 -15
- data/lib/orange-more/adverts.rb +0 -1
- data/lib/orange-more/adverts/cartons/adverts_carton.rb +0 -14
- data/lib/orange-more/adverts/plugin.rb +0 -13
- data/lib/orange-more/adverts/resources/adverts_resource.rb +0 -27
- data/lib/orange-more/adverts/views/adverts/adverts.haml +0 -2
- data/lib/orange-more/analytics.rb +0 -1
- data/lib/orange-more/analytics/middleware/analytics.rb +0 -30
- data/lib/orange-more/analytics/plugin.rb +0 -11
- data/lib/orange-more/analytics/resources/analytics_resource.rb +0 -42
- data/lib/orange-more/assets.rb +0 -1
- data/lib/orange-more/assets/cartons/asset_carton.rb +0 -27
- data/lib/orange-more/assets/plugin.rb +0 -13
- data/lib/orange-more/assets/resources/asset_resource.rb +0 -115
- data/lib/orange-more/assets/views/assets/change.haml +0 -1
- data/lib/orange-more/assets/views/assets/create.haml +0 -13
- data/lib/orange-more/assets/views/assets/insert.haml +0 -1
- data/lib/orange-more/blog.rb +0 -1
- data/lib/orange-more/blog/cartons/blog.rb +0 -8
- data/lib/orange-more/blog/cartons/blog_post.rb +0 -60
- data/lib/orange-more/blog/plugin.rb +0 -14
- data/lib/orange-more/blog/resources/blog_post_resource.rb +0 -53
- data/lib/orange-more/blog/resources/blog_resource.rb +0 -104
- data/lib/orange-more/blog/views/blog/blog_archive_view.haml +0 -6
- data/lib/orange-more/blog/views/blog/blog_offset_list_view.haml +0 -12
- data/lib/orange-more/blog/views/blog/blog_post_view.haml +0 -4
- data/lib/orange-more/blog/views/blog/sitemap_row.haml +0 -14
- data/lib/orange-more/blog/views/blog_posts/edit.haml +0 -8
- data/lib/orange-more/blog/views/blog_posts/show.haml +0 -4
- data/lib/orange-more/cloud.rb +0 -1
- data/lib/orange-more/cloud/plugin.rb +0 -10
- data/lib/orange-more/cloud/resources/cloud_resource.rb +0 -21
- data/lib/orange-more/contactforms.rb +0 -1
- data/lib/orange-more/contactforms/assets/js/jquery.validate.pack.js +0 -15
- data/lib/orange-more/contactforms/assets/js/lib/jquery-1.4.2.js +0 -6240
- data/lib/orange-more/contactforms/assets/js/lib/jquery.form.js +0 -660
- data/lib/orange-more/contactforms/assets/js/lib/jquery.js +0 -4376
- data/lib/orange-more/contactforms/assets/js/lib/jquery.metadata.js +0 -122
- data/lib/orange-more/contactforms/cartons/contactforms_carton.rb +0 -12
- data/lib/orange-more/contactforms/plugin.rb +0 -13
- data/lib/orange-more/contactforms/resources/contactforms_resource.rb +0 -56
- data/lib/orange-more/contactforms/views/contactforms/contactform.haml +0 -20
- data/lib/orange-more/debugger.rb +0 -1
- data/lib/orange-more/debugger/assets/css/debug_bar.css +0 -46
- data/lib/orange-more/debugger/middleware/debugger.rb +0 -50
- data/lib/orange-more/debugger/plugin.rb +0 -12
- data/lib/orange-more/debugger/views/debug_bar.haml +0 -87
- data/lib/orange-more/disqus.rb +0 -1
- data/lib/orange-more/disqus/plugin.rb +0 -11
- data/lib/orange-more/disqus/resources/disqus_resource.rb +0 -9
- data/lib/orange-more/disqus/views/disqus/comment_thread.haml +0 -7
- data/lib/orange-more/donations.rb +0 -1
- data/lib/orange-more/donations/cartons/donation_carton.rb +0 -9
- data/lib/orange-more/donations/plugin.rb +0 -12
- data/lib/orange-more/donations/resources/donations_resource.rb +0 -51
- data/lib/orange-more/donations/views/donations/donate_form.haml +0 -21
- data/lib/orange-more/donations/views/donations/donate_thanks.haml +0 -2
- data/lib/orange-more/donations/views/donations/paypal_form.haml +0 -13
- data/lib/orange-more/events.rb +0 -1
- data/lib/orange-more/events/assets/js/events.js +0 -55
- data/lib/orange-more/events/cartons/orange_calendar.rb +0 -8
- data/lib/orange-more/events/cartons/orange_event.rb +0 -60
- data/lib/orange-more/events/plugin.rb +0 -14
- data/lib/orange-more/events/resources/calendar_resource.rb +0 -33
- data/lib/orange-more/events/resources/event_resource.rb +0 -147
- data/lib/orange-more/events/views/calendar/calendar.haml +0 -8
- data/lib/orange-more/events/views/events/create.haml +0 -55
- data/lib/orange-more/events/views/events/edit.haml +0 -59
- data/lib/orange-more/events/views/events/list.haml +0 -13
- data/lib/orange-more/events/views/events/show.haml +0 -4
- data/lib/orange-more/events/views/events/table_row.haml +0 -17
- data/lib/orange-more/members.rb +0 -1
- data/lib/orange-more/members/cartons/member_carton.rb +0 -38
- data/lib/orange-more/members/plugin.rb +0 -13
- data/lib/orange-more/members/resources/members_resource.rb +0 -327
- data/lib/orange-more/members/views/members/create.haml +0 -12
- data/lib/orange-more/members/views/members/edit.haml +0 -15
- data/lib/orange-more/members/views/members/live.show.haml +0 -1
- data/lib/orange-more/members/views/members/login.haml +0 -17
- data/lib/orange-more/members/views/members/logout.haml +0 -1
- data/lib/orange-more/members/views/members/profile.haml +0 -50
- data/lib/orange-more/members/views/members/register.haml +0 -37
- data/lib/orange-more/news.rb +0 -1
- data/lib/orange-more/news/cartons/news.rb +0 -12
- data/lib/orange-more/news/plugin.rb +0 -13
- data/lib/orange-more/news/resources/news_resource.rb +0 -82
- data/lib/orange-more/news/views/news/archive.haml +0 -14
- data/lib/orange-more/news/views/news/edit.haml +0 -7
- data/lib/orange-more/news/views/news/latest.haml +0 -8
- data/lib/orange-more/news/views/news/sitemap_row.haml +0 -14
- data/lib/orange-more/pages.rb +0 -1
- data/lib/orange-more/pages/cartons/page_carton.rb +0 -14
- data/lib/orange-more/pages/cartons/page_version_carton.rb +0 -12
- data/lib/orange-more/pages/plugin.rb +0 -13
- data/lib/orange-more/pages/resources/page_resource.rb +0 -179
- data/lib/orange-more/pages/views/pages/edit.haml +0 -34
- data/lib/orange-more/pages/views/pages/show.haml +0 -6
- data/lib/orange-more/sitemap.rb +0 -1
- data/lib/orange-more/sitemap/assets/img/sitemap_down.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_down_d.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_indent.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_indent_d.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_outdent.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_outdent_d.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_up.png +0 -0
- data/lib/orange-more/sitemap/assets/img/sitemap_up_d.png +0 -0
- data/lib/orange-more/sitemap/assets/js/sitemap.js +0 -11
- data/lib/orange-more/sitemap/cartons/route.rb +0 -43
- data/lib/orange-more/sitemap/middleware/flex_router.rb +0 -25
- data/lib/orange-more/sitemap/plugin.rb +0 -17
- data/lib/orange-more/sitemap/resources/sitemap_resource.rb +0 -295
- data/lib/orange-more/sitemap/views/default_resource/sitemap_row.haml +0 -30
- data/lib/orange-more/sitemap/views/sitemap/breadcrumb.haml +0 -12
- data/lib/orange-more/sitemap/views/sitemap/list.haml +0 -4
- data/lib/orange-more/sitemap/views/sitemap/one_level.haml +0 -7
- data/lib/orange-more/sitemap/views/sitemap/route_actions.haml +0 -15
- data/lib/orange-more/sitemap/views/sitemap/sitemap_links.haml +0 -14
- data/lib/orange-more/sitemap/views/sitemap/table_row.haml +0 -30
- data/lib/orange-more/sitemap/views/sitemap/two_level.haml +0 -13
- data/lib/orange-more/slices.rb +0 -1
- data/lib/orange-more/slices/middleware/radius_parser.rb +0 -24
- data/lib/orange-more/slices/plugin.rb +0 -15
- data/lib/orange-more/slices/resources/radius.rb +0 -117
- data/lib/orange-more/slices/resources/slices.rb +0 -35
- data/lib/orange-more/subsites.rb +0 -1
- data/lib/orange-more/subsites/cartons/subsite.rb +0 -8
- data/lib/orange-more/subsites/middleware/subsite_load.rb +0 -29
- data/lib/orange-more/subsites/plugin.rb +0 -17
- data/lib/orange-more/subsites/resources/subsite_resource.rb +0 -54
- data/lib/orange-more/subsites/views/subsites/index.haml +0 -2
- data/lib/orange-more/testimonials.rb +0 -1
- data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +0 -15
- data/lib/orange-more/testimonials/plugin.rb +0 -13
- data/lib/orange-more/testimonials/resources/testimonials_resource.rb +0 -42
- data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +0 -4
- data/spec/orange-core/application_spec.rb +0 -183
- data/spec/orange-core/carton_spec.rb +0 -136
- data/spec/orange-core/core_spec.rb +0 -248
- data/spec/orange-core/magick_spec.rb +0 -96
- data/spec/orange-core/middleware/base_spec.rb +0 -38
- data/spec/orange-core/middleware/globals_spec.rb +0 -3
- data/spec/orange-core/middleware/rerouter_spec.rb +0 -3
- data/spec/orange-core/middleware/restful_router_spec.rb +0 -3
- data/spec/orange-core/middleware/route_context_spec.rb +0 -3
- data/spec/orange-core/middleware/route_site_spec.rb +0 -3
- data/spec/orange-core/middleware/show_exceptions_spec.rb +0 -3
- data/spec/orange-core/middleware/static_file_spec.rb +0 -3
- data/spec/orange-core/middleware/static_spec.rb +0 -3
- data/spec/orange-core/mock/mock_app.rb +0 -16
- data/spec/orange-core/mock/mock_carton.rb +0 -43
- data/spec/orange-core/mock/mock_core.rb +0 -2
- data/spec/orange-core/mock/mock_middleware.rb +0 -25
- data/spec/orange-core/mock/mock_mixins.rb +0 -19
- data/spec/orange-core/mock/mock_model_resource.rb +0 -47
- data/spec/orange-core/mock/mock_pulp.rb +0 -24
- data/spec/orange-core/mock/mock_resource.rb +0 -26
- data/spec/orange-core/mock/mock_router.rb +0 -10
- data/spec/orange-core/orange_spec.rb +0 -19
- data/spec/orange-core/packet_spec.rb +0 -203
- data/spec/orange-core/resource_spec.rb +0 -96
- data/spec/orange-core/resources/mapper_spec.rb +0 -5
- data/spec/orange-core/resources/model_resource_spec.rb +0 -246
- data/spec/orange-core/resources/parser_spec.rb +0 -5
- data/spec/orange-core/resources/routable_resource_spec.rb +0 -5
- data/spec/orange-core/stack_spec.rb +0 -232
@@ -1 +0,0 @@
|
|
1
|
-
require File.join('orange-more', 'testimonials', 'plugin')
|
@@ -1,13 +0,0 @@
|
|
1
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
|
2
|
-
Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
|
3
|
-
|
4
|
-
module Orange::Plugins
|
5
|
-
class Testimonials < Base
|
6
|
-
views_dir File.join(File.dirname(__FILE__), 'views')
|
7
|
-
|
8
|
-
resource Orange::TestimonialsResource.new
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
Orange.plugin(Orange::Plugins::Testimonials.new)
|
13
|
-
|
@@ -1,42 +0,0 @@
|
|
1
|
-
module Orange
|
2
|
-
class TestimonialsResource < Orange::ModelResource
|
3
|
-
use OrangeTestimonial
|
4
|
-
call_me :testimonials
|
5
|
-
def stack_init
|
6
|
-
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Testimonials')
|
7
|
-
orange[:radius].define_tag "testimonials" do |tag|
|
8
|
-
packet = tag.locals.packet
|
9
|
-
if tag.attr["tag"] && for_site(packet).with_tag(tag.attr["tag"]).count >0
|
10
|
-
m = for_site(packet).with_tag(tag.attr["tag"]).first(:offset => rand(for_site(packet).with_tag(tag.attr["tag"]).count)) #selects testimonial based on tag
|
11
|
-
elsif for_site(packet).count > 0 && !tag.attr.include?("tag")
|
12
|
-
m = for_site(packet).first(:offset => rand(for_site(packet).count)) #selects a random testimonial
|
13
|
-
end
|
14
|
-
unless m.nil?
|
15
|
-
template = tag.attr["template"] || "testimonials"
|
16
|
-
orange[:testimonials].testimonial(packet, {:model => m, :template => template})
|
17
|
-
else
|
18
|
-
""
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def afterNew(packet, obj, params = {})
|
24
|
-
obj.orange_site = packet['subsite'].blank? ? packet['site'] : packet['subsite']
|
25
|
-
end
|
26
|
-
|
27
|
-
def for_site(packet, opts = {})
|
28
|
-
site_filtered = model_class.all(:orange_site => packet['subsite'].blank? ? packet['site'] : packet['subsite'])
|
29
|
-
if site_filtered.count > 0
|
30
|
-
site_filtered
|
31
|
-
else
|
32
|
-
# Return unfiltered if no site-specific ones
|
33
|
-
model_class.all
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def testimonial(packet, opts = {})
|
38
|
-
template = opts[:template].to_sym || :testimonials
|
39
|
-
do_view(packet, template, opts)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,183 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Orange::Application do
|
4
|
-
before(:all) do
|
5
|
-
class MockApplication
|
6
|
-
set :banana, 'foo'
|
7
|
-
attr_accessor :quux, :wibble
|
8
|
-
def init
|
9
|
-
opts[:init] = true
|
10
|
-
@quux = true
|
11
|
-
end
|
12
|
-
def stack_init
|
13
|
-
opts[:stack_init] = true
|
14
|
-
@wibble = true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
# allow deep introspection into rack builder
|
18
|
-
class Rack::Builder
|
19
|
-
attr_accessor :ins
|
20
|
-
# introspection into the Builder object's list of items
|
21
|
-
# builder uses Proc magic to chain the middleware together,
|
22
|
-
# so we undo it.
|
23
|
-
def ins_no_procs
|
24
|
-
@ins.map{|x| x.instance_of?(Proc)? x.call(nil) : x }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
class Orange::Stack
|
28
|
-
attr_accessor :build
|
29
|
-
def middlewarez
|
30
|
-
build.ins_no_procs
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def app
|
36
|
-
MockApplication.app
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should be a subclass of Orange::Application" do
|
40
|
-
MockApplication.new(Orange::Core.new).should be_a_kind_of(Orange::Application)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should have a stack method" do
|
44
|
-
MockApplication.should respond_to(:stack)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should have a different app stack after using stack method" do
|
48
|
-
lambda {
|
49
|
-
MockApplication.stack do
|
50
|
-
end
|
51
|
-
}.should change(MockApplication, :app)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should respond to the app method" do
|
55
|
-
MockApplication.should respond_to(:app)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should return an Orange::Stack with the app method" do
|
59
|
-
MockApplication.stack do
|
60
|
-
end
|
61
|
-
MockApplication.app.should be_an_instance_of(Orange::Stack)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should be able to set options" do
|
65
|
-
MockApplication.set(:test4, Time.now.to_f-5)
|
66
|
-
opts_test4 = MockApplication.opts[:test4]
|
67
|
-
MockApplication.set(:test4, Time.now.to_f)
|
68
|
-
MockApplication.opts[:test4].should_not == opts_test4
|
69
|
-
MockApplication.opts[:banana].should == 'foo'
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should be able to accept instance option setting" do
|
73
|
-
x= MockApplication.new(Orange::Core.new, {:test => 'go'}){
|
74
|
-
baz 'bar'
|
75
|
-
}
|
76
|
-
x.opts.should have_key(:baz)
|
77
|
-
x.opts.should have_key(:banana)
|
78
|
-
x.opts[:baz].should == 'bar'
|
79
|
-
x.opts[:test].should == 'go'
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should override class variables with instance ones" do
|
83
|
-
x= MockApplication.new(Orange::Core.new)
|
84
|
-
y= MockApplication.new(Orange::Core.new){
|
85
|
-
banana 'bar'
|
86
|
-
}
|
87
|
-
x.opts.should have_key(:banana)
|
88
|
-
y.opts.should have_key(:banana)
|
89
|
-
x.opts[:banana].should == 'foo'
|
90
|
-
y.opts[:banana].should == 'bar'
|
91
|
-
x.opts[:banana].should_not == y.opts[:banana]
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should be able to access options via #opts" do
|
95
|
-
x= MockApplication.new(Orange::Core.new){
|
96
|
-
baz 'bar'
|
97
|
-
}
|
98
|
-
x.opts.should be_an_instance_of(Hash)
|
99
|
-
x.opts.should respond_to(:[])
|
100
|
-
x.opts.should have_key(:baz)
|
101
|
-
x.opts[:baz].should == 'bar'
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should call init after being initialized" do
|
105
|
-
x=MockApplication.new(Orange::Core.new){
|
106
|
-
init false
|
107
|
-
}
|
108
|
-
x.opts[:init].should be_true
|
109
|
-
x.quux.should be_true
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should call stack_init after stack loaded" do
|
113
|
-
c = Orange::Core.new
|
114
|
-
app = MockApplication.new(c){
|
115
|
-
stack_init false
|
116
|
-
}
|
117
|
-
c.fire(:stack_loaded, false) # Falsify the stack_load call
|
118
|
-
app.opts[:stack_init].should be_true
|
119
|
-
app.wibble.should be_true
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should raise a default error if route isn't redefined" do
|
123
|
-
x= MockApplication.new(Orange::Core.new)
|
124
|
-
lambda{
|
125
|
-
x.route(Orange::Packet.new(x.orange, {}))
|
126
|
-
}.should raise_error(Exception, 'default response from Orange::Application.route')
|
127
|
-
end
|
128
|
-
|
129
|
-
it "should return the orange core on #orange" do
|
130
|
-
c = Orange::Core.new
|
131
|
-
x= MockApplication.new(c)
|
132
|
-
x.orange.should eql(c)
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should change the core on #set_core(orange_core)" do
|
136
|
-
c1 = Orange::Core.new
|
137
|
-
c2 = Orange::Core.new
|
138
|
-
x= MockApplication.new(c1)
|
139
|
-
c1.should_not eql(c2)
|
140
|
-
lambda {
|
141
|
-
x.set_core(c2)
|
142
|
-
}.should change(x, :orange)
|
143
|
-
end
|
144
|
-
|
145
|
-
it "should allow setting the core via #app" do
|
146
|
-
c = Orange::Core.new
|
147
|
-
x= MockApplication.app(c)
|
148
|
-
x.orange.should equal(c)
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should allow setting the core via #stack" do
|
152
|
-
c = Orange::Core.new
|
153
|
-
MockApplication.stack(c) do
|
154
|
-
run MockApplication.new(orange)
|
155
|
-
end
|
156
|
-
x= MockApplication.app
|
157
|
-
x.orange.should equal(c)
|
158
|
-
x.middlewarez.first.orange.should equal(c)
|
159
|
-
p = Orange::Packet.new(c, {'orange.core' => c})
|
160
|
-
Orange::Packet.should_receive(:new).with(c, {'orange.core' => c}).and_return(p)
|
161
|
-
lambda{
|
162
|
-
x.call({}) # We don't care about the error, we care about the should_receive
|
163
|
-
}.should raise_error
|
164
|
-
end
|
165
|
-
|
166
|
-
it "should respond correctly to call" do
|
167
|
-
x= MockApplication.new(Orange::Core.new)
|
168
|
-
lambda{
|
169
|
-
x.call({})
|
170
|
-
}.should raise_error(Exception, 'default response from Orange::Application.route')
|
171
|
-
r = TestRouter.new
|
172
|
-
lambda{
|
173
|
-
x.call({'orange.env' => {'route.router' => r}})
|
174
|
-
}.should change(r, :x)
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should auto initialize the self.opts" do
|
178
|
-
lambda{
|
179
|
-
MockApplication2.opts
|
180
|
-
}.should_not raise_error
|
181
|
-
end
|
182
|
-
|
183
|
-
end
|
@@ -1,136 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Orange::Carton do
|
4
|
-
it "should call property with :id, Serial on #self.id" do
|
5
|
-
MockCartonBlank.should_receive(:property).with(:id, DataMapper::Types::Serial)
|
6
|
-
MockCartonBlank.id
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should call self.init after calling id" do
|
10
|
-
MockCartonBlankTwo.should_receive(:init)
|
11
|
-
MockCartonBlankTwo.id
|
12
|
-
end
|
13
|
-
|
14
|
-
it "should give form properties" do
|
15
|
-
MockCarton.form_props(:live).length.should >= 1
|
16
|
-
MockCarton.form_props(:admin).length.should >= 2
|
17
|
-
MockCarton.form_props(:orange).length.should >= 3
|
18
|
-
MockCarton.form_props(:banana).should have(0).items
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should call instance eval on admin block" do
|
22
|
-
MockCartonBlank.should_receive(:instance_eval)
|
23
|
-
MockCartonBlank.admin {}
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should call instance eval on orange block" do
|
27
|
-
MockCartonBlank.should_receive(:instance_eval)
|
28
|
-
MockCartonBlank.orange {}
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should call instance eval on front block" do
|
32
|
-
MockCartonBlank.should_receive(:instance_eval)
|
33
|
-
MockCartonBlank.front {}
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should change props when calling front_property" do
|
37
|
-
lambda {
|
38
|
-
MockCarton.front_property :foo, String
|
39
|
-
}.should change(MockCarton, :form_props)
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should change admin props when calling admin_property (but not front props)" do
|
44
|
-
old_props = MockCarton.form_props(:admin)
|
45
|
-
lambda {
|
46
|
-
MockCarton.admin_property :foo, String
|
47
|
-
}.should_not change(MockCarton, :form_props)
|
48
|
-
old_props.should_not == MockCarton.form_props(:admin)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should change orange props when calling orange_property (but not front/admin props)" do
|
52
|
-
admin_props = MockCarton.form_props(:admin)
|
53
|
-
old_props = MockCarton.form_props(:orange)
|
54
|
-
lambda {
|
55
|
-
MockCarton.orange_property :foo, String
|
56
|
-
}.should_not change(MockCarton, :form_props)
|
57
|
-
admin_props.should == MockCarton.form_props(:admin)
|
58
|
-
old_props.should_not == MockCarton.form_props(:orange)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should change the levels var when using front block" do
|
62
|
-
MockCartonBlank.should_receive(:test_levels){|me| me.levels.should include(:live)}
|
63
|
-
MockCartonBlank.front{ test_levels(self) }
|
64
|
-
MockCartonBlank.levels.should == false
|
65
|
-
end
|
66
|
-
|
67
|
-
it "should change the levels var when using admin block" do
|
68
|
-
MockCartonBlank.should_receive(:test_levels){|me|
|
69
|
-
me.levels.should_not include(:front)
|
70
|
-
me.levels.should include(:admin)
|
71
|
-
}
|
72
|
-
MockCartonBlank.admin{ test_levels(self) }
|
73
|
-
MockCartonBlank.levels.should == false
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should change the levels var when using orange block" do
|
77
|
-
MockCartonBlank.should_receive(:test_levels){|me|
|
78
|
-
me.levels.should_not include(:front)
|
79
|
-
me.levels.should_not include(:admin)
|
80
|
-
me.levels.should include(:orange)
|
81
|
-
}
|
82
|
-
MockCartonBlank.orange{ test_levels(self) }
|
83
|
-
MockCartonBlank.levels.should == false
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should have a front property after calling #front" do
|
87
|
-
front = MockCarton.scaffold_properties.select{|i| i[:name] == :front}
|
88
|
-
front.should have_at_least(1).items
|
89
|
-
front.first[:levels].should include(:live)
|
90
|
-
end
|
91
|
-
|
92
|
-
it "should have an admin property after calling #admin" do
|
93
|
-
front = MockCarton.scaffold_properties.select{|i| i[:name] == :admin}
|
94
|
-
front.should have_at_least(1).items
|
95
|
-
front.first[:levels].should_not include(:live)
|
96
|
-
front.first[:levels].should include(:admin)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should have an orange property after calling #orange" do
|
100
|
-
front = MockCarton.scaffold_properties.select{|i| i[:name] == :orange}
|
101
|
-
front.should have_at_least(1).items
|
102
|
-
front.first[:levels].should_not include(:live)
|
103
|
-
front.first[:levels].should_not include(:admin)
|
104
|
-
front.first[:levels].should include(:orange)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should call property on title" do
|
108
|
-
MockCarton.should_receive(:property).with(an_instance_of(Symbol), String, anything())
|
109
|
-
MockCarton.title(:wibble)
|
110
|
-
end
|
111
|
-
|
112
|
-
it "should call property on text" do
|
113
|
-
MockCarton.should_receive(:property).with(an_instance_of(Symbol), String, anything())
|
114
|
-
MockCarton.text(:wobble)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should call property on string" do
|
118
|
-
MockCarton.should_receive(:property).with(an_instance_of(Symbol), String, anything())
|
119
|
-
MockCarton.string(:wubble)
|
120
|
-
end
|
121
|
-
|
122
|
-
it "should call property on fulltext" do
|
123
|
-
MockCarton.should_receive(:property).with(an_instance_of(Symbol), DataMapper::Types::Text, anything())
|
124
|
-
MockCarton.fulltext(:cudge)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should define a constant (resource class)" do
|
128
|
-
lambda{
|
129
|
-
MockCartonBlankTwo_Resource.nil?
|
130
|
-
}.should raise_error(NameError)
|
131
|
-
MockCartonBlankTwo.as_resource
|
132
|
-
lambda{
|
133
|
-
MockCartonBlankTwo_Resource.nil?
|
134
|
-
}.should_not raise_error
|
135
|
-
end
|
136
|
-
end
|
@@ -1,248 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe Orange::Core do
|
4
|
-
before(:all) do
|
5
|
-
class Orange::Core; attr_reader :resources, :events, :file; end;
|
6
|
-
end
|
7
|
-
|
8
|
-
it "should allow core mixin via class mixin method" do
|
9
|
-
c= Orange::Core.new
|
10
|
-
c.should_not respond_to(:mixin_core_one)
|
11
|
-
Orange::Core.mixin MockMixinCore1
|
12
|
-
c2= Orange::Core.new
|
13
|
-
c.should respond_to(:mixin_core_one)
|
14
|
-
c2.should respond_to(:mixin_core_one)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should allow pulp mixin via class pulp method" do
|
18
|
-
c= Orange::Core.new
|
19
|
-
p= Orange::Packet.new(c, {})
|
20
|
-
p.should_not respond_to(:pulp_core_one)
|
21
|
-
Orange::Core.add_pulp MockPulpCore1
|
22
|
-
p2= Orange::Packet.new(c, {})
|
23
|
-
p.should respond_to(:pulp_core_one)
|
24
|
-
p2.should respond_to(:pulp_core_one)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should allow core mixin via instance mixin method" do
|
28
|
-
c= Orange::Core.new
|
29
|
-
c.should_not respond_to(:mixin_core_two)
|
30
|
-
c.mixin MockMixinCore2
|
31
|
-
c2= Orange::Core.new
|
32
|
-
c.should respond_to(:mixin_core_two)
|
33
|
-
c2.should respond_to(:mixin_core_two)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "should allow pulp mixin via instance pulp method" do
|
37
|
-
c= Orange::Core.new
|
38
|
-
p= Orange::Packet.new(c, {})
|
39
|
-
p.should_not respond_to(:pulp_core_two)
|
40
|
-
c.add_pulp MockPulpCore2
|
41
|
-
p2= Orange::Packet.new(c, {})
|
42
|
-
p.should respond_to(:pulp_core_two)
|
43
|
-
p2.should respond_to(:pulp_core_two)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should have three contexts by default" do
|
47
|
-
Orange::Core::DEFAULT_CORE_OPTIONS.should have_key(:contexts)
|
48
|
-
Orange::Core::DEFAULT_CORE_OPTIONS[:contexts].should have(3).items
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should default to live context" do
|
52
|
-
Orange::Core::DEFAULT_CORE_OPTIONS.should have_key(:default_context)
|
53
|
-
Orange::Core::DEFAULT_CORE_OPTIONS[:default_context].should == :live
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should load at least two resources by default" do
|
57
|
-
c= Orange::Core.new
|
58
|
-
c.resources.size.should >= 2
|
59
|
-
c.loaded?(:mapper).should be_true
|
60
|
-
c.loaded?(:parser).should be_true
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should have two events by default" do
|
64
|
-
c= Orange::Core.new
|
65
|
-
c.events.should have(2).events
|
66
|
-
c.events.should have_key(:stack_reloading)
|
67
|
-
c.events.should have_key(:stack_loaded)
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return a directory that contains core.rb when calling core_dir" do
|
71
|
-
c= Orange::Core.new
|
72
|
-
c.core_dir.should match(/orange-core$/)
|
73
|
-
File.should exist(File.join(c.core_dir, 'core.rb'))
|
74
|
-
File.should exist(File.join(c.core_dir, 'stack.rb'))
|
75
|
-
File.should exist(File.join(c.core_dir, 'application.rb'))
|
76
|
-
File.should exist(File.join(c.core_dir, 'carton.rb'))
|
77
|
-
File.should exist(File.join(c.core_dir, 'views'))
|
78
|
-
File.should exist(File.join(c.core_dir, 'templates'))
|
79
|
-
File.should exist(File.join(c.core_dir, 'assets'))
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should return the directory of the super class when calling core_dir on subclass" do
|
83
|
-
c= MockCoreSubclass.new
|
84
|
-
c.core_dir.should match(/orange-core$/)
|
85
|
-
File.should exist(File.join(c.core_dir, 'core.rb'))
|
86
|
-
File.should exist(File.join(c.core_dir, 'stack.rb'))
|
87
|
-
File.should exist(File.join(c.core_dir, 'application.rb'))
|
88
|
-
File.should exist(File.join(c.core_dir, 'carton.rb'))
|
89
|
-
File.should exist(File.join(c.core_dir, 'views'))
|
90
|
-
File.should exist(File.join(c.core_dir, 'templates'))
|
91
|
-
File.should exist(File.join(c.core_dir, 'assets'))
|
92
|
-
end
|
93
|
-
|
94
|
-
it "should call afterLoad after init" do
|
95
|
-
c1= MockCoreSubclass.new
|
96
|
-
class MockCoreSubclass
|
97
|
-
def afterLoad
|
98
|
-
options[:called_afterload_for_subclass] = true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
c2= MockCoreSubclass.new
|
102
|
-
c1.options[:called_afterload_for_subclass].should_not == c2.options[:called_afterload_for_subclass]
|
103
|
-
c1.options.should_not have_key(:called_afterload_for_subclass)
|
104
|
-
c2.options.should have_key(:called_afterload_for_subclass)
|
105
|
-
c2.options[:called_afterload_for_subclass].should be_true
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should allow changing of default core_dir" do
|
109
|
-
c= Orange::Core.new
|
110
|
-
c.options[:core_dir] = "/non/existent/dir"
|
111
|
-
c.core_dir.should_not == File.dirname(c.file)
|
112
|
-
c.core_dir.should == "/non/existent/dir"
|
113
|
-
File.should exist(File.join(File.dirname(c.file), 'core.rb'))
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should return Dir.pwd for app_dir by default" do
|
117
|
-
Orange::Core.new.app_dir.should == Dir.pwd
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should return assigned app_dir if option set" do
|
121
|
-
c= Orange::Core.new
|
122
|
-
c.options[:app_dir] = "/non/existent/dir"
|
123
|
-
c.app_dir.should_not == Dir.pwd
|
124
|
-
c.app_dir.should == "/non/existent/dir"
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should return assigned app_dir with extra path if args passed" do
|
128
|
-
c= Orange::Core.new
|
129
|
-
c.options[:app_dir] = "/non/existent/dir"
|
130
|
-
c.app_dir('foo', 'bar').should_not == c.app_dir
|
131
|
-
c.app_dir('foo', 'bar').should == "/non/existent/dir/foo/bar"
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should allow options" do
|
135
|
-
c= Orange::Core.new(:opt_1 => true){ opt_2 true }
|
136
|
-
c.options[:opt_1].should == true
|
137
|
-
c.options[:opt_2].should == true
|
138
|
-
c.options.should have_key(:opt_1)
|
139
|
-
c.options.should_not have_key(:opt_3)
|
140
|
-
end
|
141
|
-
|
142
|
-
it "should load a resource when passed resource instance" do
|
143
|
-
c= Orange::Core.new
|
144
|
-
c.load(MockResource.new, :mock_one)
|
145
|
-
c.resources.should have_key(:mock_one)
|
146
|
-
c.resources[:mock_one].should be_an_instance_of(MockResource)
|
147
|
-
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should default to lowercase resource name to symbol as resource short name" do
|
151
|
-
c= Orange::Core.new
|
152
|
-
c.load(MockResource.new)
|
153
|
-
sym = MockResource.to_s.gsub(/::/, '_').downcase.to_sym
|
154
|
-
c.resources.should have_key(sym)
|
155
|
-
c.should be_loaded(sym)
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should say a resource is loaded after calling load for resource" do
|
159
|
-
c= Orange::Core.new
|
160
|
-
c.load(MockResource.new, :mock_one)
|
161
|
-
c.should be_loaded(:mock_one)
|
162
|
-
c.resources.should have_key(:mock_one)
|
163
|
-
end
|
164
|
-
|
165
|
-
it "should return self on orange" do
|
166
|
-
c= Orange::Core.new
|
167
|
-
c.orange.should eql(c)
|
168
|
-
end
|
169
|
-
|
170
|
-
it "should add event to events list when register called" do
|
171
|
-
c= Orange::Core.new
|
172
|
-
c.register(:mock_event) {|x| x }
|
173
|
-
c.events.should_not be_empty
|
174
|
-
c.events.should have_key(:mock_event)
|
175
|
-
c.events[:mock_event].should be_an_instance_of(Array)
|
176
|
-
c.events[:mock_event].should have(1).callback
|
177
|
-
c.register(:mock_event) {|x| x }
|
178
|
-
c.events[:mock_event].should have(2).callbacks
|
179
|
-
end
|
180
|
-
|
181
|
-
it "should add events in specified order when registered with position" do
|
182
|
-
c= Orange::Core.new
|
183
|
-
c.register(:mock_event, 5) {|x| '5' }
|
184
|
-
c.events.should_not be_empty
|
185
|
-
c.events.should have_key(:mock_event)
|
186
|
-
c.events[:mock_event].compact.should have(1).callback
|
187
|
-
5.times{ |i| c.events[:mock_event][i].should be_nil }
|
188
|
-
c.register(:mock_event, 2) {|x| '2' }
|
189
|
-
c.events[:mock_event].compact.should have(2).callbacks
|
190
|
-
c.events[:mock_event][2].call(nil).should eql '2'
|
191
|
-
c.events[:mock_event][6].call(nil).should eql '5'
|
192
|
-
c.events[:mock_event].compact.first.call(nil).should eql '2'
|
193
|
-
c.events[:mock_event].compact.last.call(nil).should eql '5'
|
194
|
-
c.register(:mock_event, 5) {|x| '5.2' }
|
195
|
-
c.events[:mock_event].compact.should have(3).callbacks
|
196
|
-
c.events[:mock_event][2].call(nil).should eql '2'
|
197
|
-
c.events[:mock_event][5].call(nil).should eql '5.2'
|
198
|
-
c.events[:mock_event][7].call(nil).should eql '5'
|
199
|
-
c.events[:mock_event].compact.first.call(nil).should eql '2'
|
200
|
-
c.events[:mock_event].compact.last.call(nil).should eql '5'
|
201
|
-
end
|
202
|
-
|
203
|
-
it "should fire registered events when fire called" do
|
204
|
-
class OtherMockCore < Orange::Core
|
205
|
-
attr_accessor :mock_counter
|
206
|
-
def afterLoad
|
207
|
-
@mock_counter = 0
|
208
|
-
end
|
209
|
-
end
|
210
|
-
c= OtherMockCore.new
|
211
|
-
c.mock_counter.should == 0
|
212
|
-
c.register(:mock_event) {|i| c.mock_counter += i }
|
213
|
-
c.register(:mock_event_two) {|i| c.mock_counter -= i }
|
214
|
-
c.mock_counter.should == 0
|
215
|
-
c.fire(:mock_event, 3)
|
216
|
-
c.mock_counter.should_not == 0
|
217
|
-
c.mock_counter.should == 3
|
218
|
-
c.fire(:mock_event_two, 2)
|
219
|
-
c.mock_counter.should_not == 0
|
220
|
-
c.mock_counter.should == 1
|
221
|
-
c.register(:mock_event) {|i| c.mock_counter += i }
|
222
|
-
c.fire(:mock_event, 3)
|
223
|
-
c.mock_counter.should_not == 1
|
224
|
-
c.mock_counter.should == 7
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should have an options hash" do
|
228
|
-
Orange::Core.new.options.should be_an_instance_of(Hash)
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should allow access to the resources via []" do
|
232
|
-
c= Orange::Core.new
|
233
|
-
c.load(MockResource.new, :mock)
|
234
|
-
c[:mock].should be_an_instance_of(MockResource)
|
235
|
-
c[:mock].should be_an_kind_of(Orange::Resource)
|
236
|
-
c[:mock].mock_method.should eql 'MockResource#mock_method'
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should have option to silently ignore resource calls" do
|
240
|
-
c= Orange::Core.new
|
241
|
-
lambda {
|
242
|
-
c[:mock].test
|
243
|
-
}.should raise_error
|
244
|
-
lambda {
|
245
|
-
c[:mock, true].test
|
246
|
-
}.should_not raise_error
|
247
|
-
end
|
248
|
-
end
|