lego-core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/README.rdoc +95 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/examples/config.ru +137 -0
- data/lego-core.gemspec +70 -0
- data/lib/lego.rb +38 -0
- data/lib/lego/controller.rb +162 -0
- data/lib/lego/controller/action_context.rb +56 -0
- data/lib/lego/controller/config.rb +25 -0
- data/lib/lego/controller/route_handler.rb +86 -0
- data/lib/lego/plugin.rb +5 -0
- data/lib/lego/plugin/controller/not_found.rb +11 -0
- data/spec/integration/test_full_stack_spec.rb +82 -0
- data/spec/lego/controller/action_context_spec.rb +73 -0
- data/spec/lego/controller/config_spec.rb +102 -0
- data/spec/lego/controller/route_handler_spec.rb +188 -0
- data/spec/lego/controller_spec.rb +297 -0
- data/spec/lego/plugin/controller/not_found_spec.rb +22 -0
- data/spec/lego/plugin_spec.rb +0 -0
- data/spec/lego_spec.rb +90 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +42 -0
- metadata +86 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.join('spec', '/spec_helper')
|
2
|
+
|
3
|
+
describe Lego::Plugin::Controller::NotFound do
|
4
|
+
|
5
|
+
it 'should register itself' do
|
6
|
+
lego = mock('Lego')
|
7
|
+
lego.should_receive('add_plugin').with(:controller, Lego::Plugin::Controller::NotFound)
|
8
|
+
Lego::Plugin::Controller::NotFound.register(lego)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should add a :not_found route to lego controller' do
|
12
|
+
class TestPlugin
|
13
|
+
extend Lego::Plugin::Controller::NotFound
|
14
|
+
end
|
15
|
+
block = lambda { "test" }
|
16
|
+
TestPlugin.should_receive(:add_route).with(:not_found, { :set_response_code => 404, :action_block => block})
|
17
|
+
TestPlugin.not_found(&block)
|
18
|
+
rm_const 'TestPlugin'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
File without changes
|
data/spec/lego_spec.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.join('spec', '/spec_helper')
|
2
|
+
|
3
|
+
describe Lego do
|
4
|
+
|
5
|
+
context 'module' do
|
6
|
+
it 'should contain a Controller Class' do
|
7
|
+
Lego::Controller.should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should have a plugin method to load plugins globally' do
|
11
|
+
Lego.should respond_to(:plugin)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have a version' do
|
15
|
+
Lego.version.should == Lego::VERSION.join('.')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should provide a global set" do
|
19
|
+
Lego.set(:foo => "bar")
|
20
|
+
Lego::Controller.current_config.config.should eql({"foo"=>"bar"})
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should provide a global config" do
|
24
|
+
Lego.config do
|
25
|
+
set :foo => "bar"
|
26
|
+
set :baz => "quux"
|
27
|
+
end
|
28
|
+
|
29
|
+
Lego::Controller.current_config.config.should eql({"foo"=>"bar","baz"=>"quux"})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context '.plugin <plugin_module>' do
|
34
|
+
it 'should call add_plugin on controller' do
|
35
|
+
mymod = mock("MyModule")
|
36
|
+
mymod.should_receive(:register).with(Lego::Controller)
|
37
|
+
Lego.plugin mymod
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when plugin context is :controller' do
|
41
|
+
before do
|
42
|
+
reset_lego_base
|
43
|
+
end
|
44
|
+
it 'should be injected to Lego::Controller base' do
|
45
|
+
module MyPlug
|
46
|
+
def self.register(lego)
|
47
|
+
lego.add_plugin :controller, self
|
48
|
+
end
|
49
|
+
def get_something; end
|
50
|
+
end
|
51
|
+
Lego::Controller.should_not respond_to(:get_something)
|
52
|
+
Lego.plugin MyPlug
|
53
|
+
create_new_app("MyApp1", Lego::Controller)
|
54
|
+
create_new_app("MyApp2", Lego::Controller)
|
55
|
+
MyApp1.should respond_to(:get_something)
|
56
|
+
end
|
57
|
+
|
58
|
+
after do
|
59
|
+
rm_const "MyPlug", "MyApp1", "MyApp2"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'when plugin context is :router' do
|
64
|
+
before do
|
65
|
+
reset_lego_base
|
66
|
+
end
|
67
|
+
it 'should be injected to Lego::Controller::RouteHandler base' do
|
68
|
+
module GlobalPlugX
|
69
|
+
def self.register(lego)
|
70
|
+
lego.add_plugin :router, self
|
71
|
+
end
|
72
|
+
|
73
|
+
def another_routehandler
|
74
|
+
add_route(:get, {})
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.match_route(route, env); end
|
78
|
+
end
|
79
|
+
|
80
|
+
Lego.plugin GlobalPlugX
|
81
|
+
Lego::Controller::RouteHandler.matchers.should eql([GlobalPlugX])
|
82
|
+
end
|
83
|
+
|
84
|
+
after do
|
85
|
+
rm_const "GlobalPlug"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
3
|
+
|
4
|
+
require 'lib/lego'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
def create_new_app(class_name, baseclass = Class)
|
8
|
+
Object.class_eval do
|
9
|
+
remove_const class_name.to_sym if const_defined? class_name
|
10
|
+
end
|
11
|
+
Object.const_set(class_name.to_sym, Class.new(baseclass))
|
12
|
+
end
|
13
|
+
|
14
|
+
def rm_const(*const_name)
|
15
|
+
const_name = [const_name] if const_name.kind_of?(String)
|
16
|
+
Object.class_eval do
|
17
|
+
const_name.each do |constant|
|
18
|
+
remove_const constant.to_sym if const_defined? constant
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def reset_lego_base
|
24
|
+
return if not Object.const_defined? :Lego
|
25
|
+
Lego.class_eval do
|
26
|
+
Lego::Controller.class_eval do
|
27
|
+
remove_const :RouteHandler if const_defined? :RouteHandler
|
28
|
+
remove_const :ActionContext if const_defined? :ActionContext
|
29
|
+
end
|
30
|
+
remove_const :Controller if const_defined? :Controller
|
31
|
+
end
|
32
|
+
Object.class_eval do
|
33
|
+
remove_const :Lego
|
34
|
+
end
|
35
|
+
load 'lib/lego.rb'
|
36
|
+
load 'lib/lego/plugin.rb'
|
37
|
+
load 'lib/lego/plugin/controller/not_found.rb'
|
38
|
+
load 'lib/lego/controller.rb'
|
39
|
+
load 'lib/lego/controller/route_handler.rb'
|
40
|
+
load 'lib/lego/controller/action_context.rb'
|
41
|
+
load 'lib/lego/controller/config.rb'
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lego-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Mathias Stjernstr\xC3\xB6m"
|
8
|
+
- Patrik Hedman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-01-12 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: It's all about the bits and peices
|
18
|
+
email: mathias@globalinn.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION
|
30
|
+
- examples/config.ru
|
31
|
+
- lego-core.gemspec
|
32
|
+
- lib/lego.rb
|
33
|
+
- lib/lego/controller.rb
|
34
|
+
- lib/lego/controller/action_context.rb
|
35
|
+
- lib/lego/controller/config.rb
|
36
|
+
- lib/lego/controller/route_handler.rb
|
37
|
+
- lib/lego/plugin.rb
|
38
|
+
- lib/lego/plugin/controller/not_found.rb
|
39
|
+
- spec/integration/test_full_stack_spec.rb
|
40
|
+
- spec/lego/controller/action_context_spec.rb
|
41
|
+
- spec/lego/controller/config_spec.rb
|
42
|
+
- spec/lego/controller/route_handler_spec.rb
|
43
|
+
- spec/lego/controller_spec.rb
|
44
|
+
- spec/lego/plugin/controller/not_found_spec.rb
|
45
|
+
- spec/lego/plugin_spec.rb
|
46
|
+
- spec/lego_spec.rb
|
47
|
+
- spec/spec.opts
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/stjernstrom/lego-core
|
51
|
+
licenses: []
|
52
|
+
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options:
|
55
|
+
- --charset=UTF-8
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.3.5
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: It's all about the bits and peices
|
77
|
+
test_files:
|
78
|
+
- spec/integration/test_full_stack_spec.rb
|
79
|
+
- spec/lego/controller/action_context_spec.rb
|
80
|
+
- spec/lego/controller/config_spec.rb
|
81
|
+
- spec/lego/controller/route_handler_spec.rb
|
82
|
+
- spec/lego/controller_spec.rb
|
83
|
+
- spec/lego/plugin/controller/not_found_spec.rb
|
84
|
+
- spec/lego/plugin_spec.rb
|
85
|
+
- spec/lego_spec.rb
|
86
|
+
- spec/spec_helper.rb
|