nitro 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{ChangeLog → CHANGELOG} +137 -0
- data/INSTALL +1 -2
- data/README +1 -1
- data/Rakefile +10 -61
- data/benchmark/{nitro/bench.rb → bench.rb} +1 -1
- data/benchmark/{nitro/simple-webrick-n-200.txt → simple-webrick-n-200.txt} +0 -0
- data/benchmark/{nitro/static-webrick-n-200.txt → static-webrick-n-200.txt} +0 -0
- data/benchmark/{nitro/tiny-lhttpd-n-200-c-5.txt → tiny-lhttpd-n-200-c-5.txt} +0 -0
- data/benchmark/{nitro/tiny-webrick-n-200-c-5.txt → tiny-webrick-n-200-c-5.txt} +0 -0
- data/benchmark/{nitro/tiny-webrick-n-200.txt → tiny-webrick-n-200.txt} +0 -0
- data/benchmark/{nitro/tiny2-webrick-n-200.txt → tiny2-webrick-n-200.txt} +0 -0
- data/doc/{ChangeLog.1 → CHANGELOG.1} +0 -0
- data/{RELEASES → doc/RELEASES} +46 -0
- data/doc/faq.txt +7 -0
- data/examples/README.windows +1 -1
- data/examples/ajax/controller.rb +21 -0
- data/examples/ajax/public/index.xhtml +70 -0
- data/examples/ajax/public/js/ajax.js +64 -0
- data/examples/ajax/run.rb +16 -0
- data/examples/blog/README +6 -3
- data/examples/blog/conf/apache.conf +2 -2
- data/examples/blog/conf/lhttpd.conf +2 -2
- data/examples/blog/log/apache.error_log +777 -0
- data/examples/blog/{root → public}/base.xsl +0 -0
- data/examples/blog/{root → public}/fcgi.rb +0 -0
- data/examples/blog/{root → public}/m/bubbles.gif +0 -0
- data/examples/blog/{root → public}/m/comments_curve.gif +0 -0
- data/examples/blog/{root → public}/m/down.gif +0 -0
- data/examples/blog/{root → public}/m/footer_bg.gif +0 -0
- data/examples/blog/{root → public}/m/garrow.gif +0 -0
- data/examples/blog/{root → public}/m/gbull.gif +0 -0
- data/examples/blog/{root → public}/m/grbull.gif +0 -0
- data/examples/blog/{root → public}/m/h1_bg.gif +0 -0
- data/examples/blog/{root → public}/m/header_bg.gif +0 -0
- data/examples/blog/{root → public}/m/nitro.gif +0 -0
- data/examples/blog/{root → public}/m/obull.gif +0 -0
- data/examples/blog/{root → public}/m/page_bg.gif +0 -0
- data/examples/blog/{root → public}/m/rss.gif +0 -0
- data/examples/blog/{root → public}/m/side_title_bg.gif +0 -0
- data/examples/blog/{root → public}/m/sidebar_bg.gif +0 -0
- data/examples/{no_xsl_blog/root → blog/public}/style.css +6 -0
- data/examples/blog/run.rb +10 -12
- data/examples/blog/{lib → src}/blog.rb +3 -3
- data/examples/blog/{lib/blog → src}/controller.rb +13 -2
- data/examples/blog/src/mailer.rb +23 -0
- data/examples/blog/{lib/blog/model.rb → src/models/blog.rb} +4 -7
- data/examples/blog/src/models/content.rb +52 -0
- data/examples/blog/src/views/blog_entry_email.xhtml +16 -0
- data/examples/blog/{root → src/views}/comments.xhtml +0 -0
- data/examples/blog/{root → src/views}/entry_form.xhtml +0 -0
- data/examples/blog/{root → src/views}/error.xhtml +0 -0
- data/examples/blog/{root → src/views}/index.xhtml +0 -0
- data/examples/blog/{root → src/views}/login.xhtml +0 -0
- data/examples/blog/{root → src/views}/recent_posts.xhtml +0 -0
- data/examples/blog/{root → src/views}/view_entry.xhtml +8 -0
- data/examples/blog/{root → src/views}/view_entry.xml +0 -0
- data/examples/blog/src/xsl/base.xsl +153 -0
- data/examples/blog/{root → src/xsl}/style.xsl +2 -2
- data/examples/no_xsl_blog/README +5 -1
- data/examples/no_xsl_blog/conf/apache.conf +2 -2
- data/examples/no_xsl_blog/conf/lhttpd.conf +2 -2
- data/examples/no_xsl_blog/lib/blog/model.rb +1 -1
- data/{lib/parts → examples/no_xsl_blog/lib}/content.rb +1 -11
- data/examples/no_xsl_blog/log/apache.error_log +405 -0
- data/examples/no_xsl_blog/{root → public}/comments.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/entry_form.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/fcgi.rb +0 -0
- data/examples/no_xsl_blog/{root → public}/index.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/login.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/m/bubbles.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/comments_curve.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/down.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/footer_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/garrow.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/gbull.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/grbull.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/h1_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/header_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/nitro.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/obull.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/page_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/rss.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/side_title_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/m/sidebar_bg.gif +0 -0
- data/examples/no_xsl_blog/{root → public}/recent_posts.xhtml +0 -0
- data/examples/{blog/root → no_xsl_blog/public}/style.css +0 -0
- data/examples/no_xsl_blog/{root → public}/view_entry.xhtml +0 -0
- data/examples/no_xsl_blog/{root → public}/view_entry.xml +0 -0
- data/examples/tiny/conf/apache.conf +2 -2
- data/examples/tiny/log/apache.error_log +100 -0
- data/examples/tiny/{root → public}/fcgi.rb +0 -0
- data/examples/tiny/{root → public}/include.xhtml +0 -0
- data/examples/tiny/{root → public}/index.xhtml +0 -0
- data/{bin/proto/root/m → examples/tiny/public}/nitro.png +0 -0
- data/examples/tiny/{root → public}/upload.xhtml +0 -0
- data/examples/tiny/run.rb +1 -2
- data/examples/why_wiki/wiki.yml +1 -0
- data/install.rb +5 -2
- data/lib/nitro.rb +2 -6
- data/lib/nitro/adapters/fastcgi.rb +2 -2
- data/lib/nitro/adapters/webrick.rb +4 -4
- data/lib/nitro/conf.rb +5 -2
- data/lib/nitro/controller.rb +2 -2
- data/lib/nitro/dispatcher.rb +19 -8
- data/lib/nitro/mail.rb +252 -8
- data/lib/nitro/render.rb +24 -21
- data/lib/nitro/runner.rb +1 -1
- data/lib/nitro/scaffold.rb +2 -5
- data/lib/nitro/simple.rb +2 -1
- data/lib/nitro/template.rb +42 -2
- data/test/nitro/tc_controller.rb +9 -4
- data/test/nitro/tc_dispatcher.rb +4 -6
- data/test/nitro/tc_mail.rb +95 -0
- data/test/{root → public}/blog/list.xhtml +0 -0
- data/test/public/dummy_mailer/registration.xhtml +5 -0
- data/vendor/README +0 -1
- metadata +136 -181
- data/benchmark/og/bench.rb +0 -75
- data/benchmark/og/sqlite-no-prepare.1.txt +0 -13
- data/benchmark/og/sqlite-no-prepare.2.txt +0 -13
- data/benchmark/og/sqlite-prepare.1.txt +0 -13
- data/benchmark/og/sqlite-prepare.2.txt +0 -13
- data/bin/proto/README +0 -34
- data/bin/proto/conf/apache.conf +0 -1
- data/bin/proto/conf/app.conf.rb +0 -14
- data/bin/proto/conf/lhttpd.conf +0 -236
- data/bin/proto/ctl +0 -4
- data/bin/proto/lib/README +0 -5
- data/bin/proto/log/README +0 -3
- data/bin/proto/root/fcgi.rb +0 -6
- data/bin/proto/root/index.xhtml +0 -69
- data/bin/proto/root/style.css +0 -152
- data/bin/proto/root/style.xsl +0 -99
- data/doc/og_config.txt +0 -35
- data/doc/og_tutorial.txt +0 -595
- data/examples/og/README +0 -11
- data/examples/og/mock_example.rb +0 -50
- data/examples/og/mysql_to_psql.rb +0 -96
- data/examples/og/run.rb +0 -286
- data/examples/tiny/root/nitro.png +0 -0
- data/lib/glue.rb +0 -55
- data/lib/glue/array.rb +0 -61
- data/lib/glue/attribute.rb +0 -83
- data/lib/glue/cache.rb +0 -138
- data/lib/glue/flexob.rb +0 -12
- data/lib/glue/hash.rb +0 -122
- data/lib/glue/inflector.rb +0 -91
- data/lib/glue/logger.rb +0 -147
- data/lib/glue/misc.rb +0 -14
- data/lib/glue/mixins.rb +0 -36
- data/lib/glue/number.rb +0 -24
- data/lib/glue/object.rb +0 -32
- data/lib/glue/pool.rb +0 -60
- data/lib/glue/property.rb +0 -408
- data/lib/glue/string.rb +0 -162
- data/lib/glue/time.rb +0 -85
- data/lib/glue/validation.rb +0 -394
- data/lib/og.rb +0 -185
- data/lib/og/adapter.rb +0 -513
- data/lib/og/adapters/filesys.rb +0 -121
- data/lib/og/adapters/mysql.rb +0 -347
- data/lib/og/adapters/oracle.rb +0 -375
- data/lib/og/adapters/psql.rb +0 -273
- data/lib/og/adapters/sqlite.rb +0 -262
- data/lib/og/backend.rb +0 -297
- data/lib/og/connection.rb +0 -304
- data/lib/og/database.rb +0 -282
- data/lib/og/enchant.rb +0 -125
- data/lib/og/meta.rb +0 -373
- data/lib/og/mock.rb +0 -165
- data/lib/og/observer.rb +0 -53
- data/lib/og/typemacros.rb +0 -23
- data/lib/parts/README +0 -9
- data/test/glue/tc_attribute.rb +0 -22
- data/test/glue/tc_cache.rb +0 -45
- data/test/glue/tc_hash.rb +0 -38
- data/test/glue/tc_logger.rb +0 -39
- data/test/glue/tc_numbers.rb +0 -20
- data/test/glue/tc_property.rb +0 -89
- data/test/glue/tc_property_mixins.rb +0 -93
- data/test/glue/tc_property_type_checking.rb +0 -35
- data/test/glue/tc_strings.rb +0 -103
- data/test/glue/tc_validation.rb +0 -188
- data/test/og/tc_filesys.rb +0 -83
- data/test/og/tc_lifecycle.rb +0 -104
- data/test/og/tc_many_to_many.rb +0 -62
- data/test/og/tc_meta.rb +0 -55
- data/test/og/tc_observer.rb +0 -85
- data/test/og/tc_sqlite.rb +0 -87
- data/test/tc_og.rb +0 -355
- data/vendor/composite_sexp_processor.rb +0 -43
- data/vendor/parse_tree.rb +0 -745
- data/vendor/sexp_processor.rb +0 -453
data/test/og/tc_lifecycle.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
# vim:sw=2:ai
|
3
|
-
|
4
|
-
# * Thomas Quas <tquas@yahoo.com>
|
5
|
-
# * George Moschovitis <gm@navel.gr>
|
6
|
-
# $Id$
|
7
|
-
|
8
|
-
$LOAD_PATH.unshift 'lib'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'glue/logger'
|
12
|
-
require 'og/mock'
|
13
|
-
|
14
|
-
$DBG = false
|
15
|
-
|
16
|
-
class Dummy
|
17
|
-
prop_accessor :date, Time
|
18
|
-
attr_reader :call_stack
|
19
|
-
|
20
|
-
def og_pre_insert( oid )
|
21
|
-
@call_stack << 'pre_insert'
|
22
|
-
end
|
23
|
-
|
24
|
-
def og_post_insert( oid )
|
25
|
-
@call_stack << 'post_insert'
|
26
|
-
end
|
27
|
-
|
28
|
-
def og_pre_update( oid )
|
29
|
-
@call_stack << 'pre_update'
|
30
|
-
end
|
31
|
-
|
32
|
-
def og_post_update( oid )
|
33
|
-
@call_stack << 'post_update'
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.og_pre_delete( conn, oid )
|
37
|
-
raise 'undeletable'
|
38
|
-
end
|
39
|
-
|
40
|
-
def initialize
|
41
|
-
@call_stack = []
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Tests the Og managed objects lifecycle.
|
46
|
-
class TC_CallbackTest < ::Test::Unit::TestCase
|
47
|
-
def test_insert
|
48
|
-
obj = Dummy.new
|
49
|
-
obj.save!
|
50
|
-
|
51
|
-
assert( obj.call_stack.shift == 'pre_insert' )
|
52
|
-
assert( obj.call_stack.shift == 'post_insert' )
|
53
|
-
assert( obj.call_stack.empty? )
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_update
|
57
|
-
obj = Dummy.new
|
58
|
-
obj.save!
|
59
|
-
obj.call_stack.shift
|
60
|
-
obj.call_stack.shift
|
61
|
-
|
62
|
-
obj.date = Time.now
|
63
|
-
obj.save
|
64
|
-
assert( obj.call_stack.shift == "pre_update" )
|
65
|
-
assert( obj.call_stack.shift == "post_update" )
|
66
|
-
assert( obj.call_stack.empty? )
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_delete
|
70
|
-
obj = Dummy.new
|
71
|
-
obj.save!
|
72
|
-
obj.call_stack.shift
|
73
|
-
obj.call_stack.shift
|
74
|
-
|
75
|
-
assert_raise( RuntimeError, 'undeletable' ) { obj.delete! }
|
76
|
-
end
|
77
|
-
|
78
|
-
def setup
|
79
|
-
psql = true
|
80
|
-
|
81
|
-
if psql
|
82
|
-
config = {
|
83
|
-
:adapter => 'psql',
|
84
|
-
# :address => 'localhost',
|
85
|
-
:database => 'test',
|
86
|
-
:user => 'postgres',
|
87
|
-
:password => 'navelrulez',
|
88
|
-
:connection_count => 1
|
89
|
-
}
|
90
|
-
else
|
91
|
-
config = {
|
92
|
-
:adapter => 'mysql',
|
93
|
-
# :address => 'localhost',
|
94
|
-
:database => 'test',
|
95
|
-
:user => 'root',
|
96
|
-
:password => 'navelrulez',
|
97
|
-
:connection_count => 1
|
98
|
-
}
|
99
|
-
end
|
100
|
-
Og::Database.drop_db!(config)
|
101
|
-
$og = Og::Database.new(config)
|
102
|
-
$og.get_connection()
|
103
|
-
end
|
104
|
-
end
|
data/test/og/tc_many_to_many.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
require 'og'
|
7
|
-
|
8
|
-
class TC_OgManyToMany < Test::Unit::TestCase # :nodoc: all
|
9
|
-
include N
|
10
|
-
|
11
|
-
class Attribute
|
12
|
-
property :name, String
|
13
|
-
|
14
|
-
def initialize(name = nil)
|
15
|
-
@name = name
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Klass
|
20
|
-
property :name, String
|
21
|
-
many_to_many :observed_attributes, Attribute, :linkback => :klass_observers
|
22
|
-
many_to_many :controlled_attributes, Attribute, :linkback => :klass_controllers
|
23
|
-
|
24
|
-
def initialize(name = nil)
|
25
|
-
@name = name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_all
|
30
|
-
config = {
|
31
|
-
:adapter => 'psql',
|
32
|
-
:database => 'test',
|
33
|
-
:user => 'postgres',
|
34
|
-
:password => 'navelrulez',
|
35
|
-
:connection_count => 2
|
36
|
-
}
|
37
|
-
|
38
|
-
Og::Database.drop_db!(config)
|
39
|
-
og = Og::Database.new(config)
|
40
|
-
|
41
|
-
og.get_connection
|
42
|
-
|
43
|
-
k = Klass.create('klass1')
|
44
|
-
a1 = Attribute.create('attr1')
|
45
|
-
a2 = Attribute.create('attr2')
|
46
|
-
|
47
|
-
k.add_observed_attribute(a1)
|
48
|
-
k.add_observed_attribute(a2)
|
49
|
-
|
50
|
-
assert_equal 2, k.observed_attributes.size
|
51
|
-
assert_equal 1, a1.klass_observers.size
|
52
|
-
|
53
|
-
k.add_controlled_attribute(a1)
|
54
|
-
|
55
|
-
assert_equal 1, k.controlled_attributes.size
|
56
|
-
assert_equal 1, a1.klass_controllers.size
|
57
|
-
|
58
|
-
og.put_connection
|
59
|
-
og.shutdown
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
data/test/og/tc_meta.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
require 'og'
|
7
|
-
|
8
|
-
class TC_OgMeta < Test::Unit::TestCase # :nodoc: all
|
9
|
-
include N
|
10
|
-
|
11
|
-
# Forward declaration.
|
12
|
-
|
13
|
-
class Comment; end
|
14
|
-
|
15
|
-
class Article
|
16
|
-
property :name, String
|
17
|
-
property :age, Fixnum
|
18
|
-
has_many :comments, Comment
|
19
|
-
|
20
|
-
def initialize (name = nil, age = nil)
|
21
|
-
@name, @age = name, age
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Comment
|
26
|
-
prop_accessor :text, String
|
27
|
-
belongs_to :article, Article
|
28
|
-
|
29
|
-
def initialize(text = nil)
|
30
|
-
@text = text
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def setup
|
35
|
-
end
|
36
|
-
|
37
|
-
def teardown
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_all
|
41
|
-
par = Article.__meta[:props_and_relations]
|
42
|
-
assert_equal 3, par.size
|
43
|
-
assert_equal N::Property, par[1].class
|
44
|
-
assert_equal Og::HasMany, par[2].class
|
45
|
-
|
46
|
-
par = Comment.__meta[:props_and_relations]
|
47
|
-
assert_equal 3, par.size
|
48
|
-
assert_equal N::Property, par[0].class
|
49
|
-
assert_equal Og::BelongsTo, par[1].class
|
50
|
-
assert_equal 'article_oid', par[1].meta[:property].to_s
|
51
|
-
assert_equal String, par[0].klass
|
52
|
-
assert_equal Article, par[1].foreign_class
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
data/test/og/tc_observer.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
require 'og'
|
7
|
-
|
8
|
-
class TC_OgObserver < Test::Unit::TestCase # :nodoc: all
|
9
|
-
include N
|
10
|
-
|
11
|
-
class User
|
12
|
-
property :name
|
13
|
-
end
|
14
|
-
|
15
|
-
class Article
|
16
|
-
property :name, String
|
17
|
-
property :age, Fixnum
|
18
|
-
|
19
|
-
def initialize (name = nil, age = nil)
|
20
|
-
@name, @age = name, age
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Example of a simple class that acts as an observer.
|
25
|
-
|
26
|
-
class ArticleObserver
|
27
|
-
attr :count
|
28
|
-
|
29
|
-
def initialize
|
30
|
-
@count = 0
|
31
|
-
end
|
32
|
-
|
33
|
-
def og_pre_insert(conn, obj)
|
34
|
-
@count += 1
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Rails style observer, baaah...
|
39
|
-
|
40
|
-
class MultiObserver < Og::Observer
|
41
|
-
observe Article, User
|
42
|
-
|
43
|
-
attr :count
|
44
|
-
|
45
|
-
def initialize
|
46
|
-
@count = 0
|
47
|
-
end
|
48
|
-
|
49
|
-
def og_pre_insert(conn, obj)
|
50
|
-
@count += 1
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def setup
|
55
|
-
end
|
56
|
-
|
57
|
-
def teardown
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_all
|
61
|
-
config = {
|
62
|
-
:adapter => 'psql',
|
63
|
-
:database => 'test',
|
64
|
-
:user => 'postgres',
|
65
|
-
:password => 'navelrulez',
|
66
|
-
:connection_count => 2
|
67
|
-
}
|
68
|
-
|
69
|
-
Og::Database.drop_db!(config)
|
70
|
-
og = Og::Database.new(config)
|
71
|
-
|
72
|
-
og.get_connection
|
73
|
-
|
74
|
-
ao = ArticleObserver.new
|
75
|
-
Article.add_observer(ao)
|
76
|
-
Article.create('Hello', 5)
|
77
|
-
|
78
|
-
assert_equal 1, ao.count
|
79
|
-
assert_equal 1, MultiObserver.instance.count
|
80
|
-
|
81
|
-
og.put_connection
|
82
|
-
og.shutdown
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
data/test/og/tc_sqlite.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
=begin
|
4
|
-
|
5
|
-
require 'test/unit'
|
6
|
-
require 'ostruct'
|
7
|
-
|
8
|
-
require 'og'
|
9
|
-
require 'og/adapters/sqlite'
|
10
|
-
|
11
|
-
class TC_OgSqlite3 < Test::Unit::TestCase # :nodoc: all
|
12
|
-
include N
|
13
|
-
|
14
|
-
# Forward declaration.
|
15
|
-
|
16
|
-
class Comment; end
|
17
|
-
|
18
|
-
class Article
|
19
|
-
prop_accessor :name, String
|
20
|
-
prop_accessor :age, Fixnum
|
21
|
-
has_many :comments, Comment
|
22
|
-
|
23
|
-
def initialize (name = nil, age = nil)
|
24
|
-
@name, @age = name, age
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
class Comment
|
29
|
-
prop_accessor :text, String
|
30
|
-
belongs_to :article, Article
|
31
|
-
|
32
|
-
def initialize(text = nil)
|
33
|
-
@text = text
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def setup
|
38
|
-
config = {
|
39
|
-
:adapter => 'sqlite',
|
40
|
-
:database => 'test',
|
41
|
-
:connection_count => 2
|
42
|
-
}
|
43
|
-
|
44
|
-
$DBG = true
|
45
|
-
|
46
|
-
Og::Database.drop_db!(config)
|
47
|
-
@og = Og::Database.new(config)
|
48
|
-
end
|
49
|
-
|
50
|
-
def teardown
|
51
|
-
@og.shutdown
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_all
|
55
|
-
a = Article.new('gmosx', 30)
|
56
|
-
a.save!
|
57
|
-
|
58
|
-
a1 = Article[1]
|
59
|
-
|
60
|
-
assert_equal 'gmosx', a1.name
|
61
|
-
assert_equal 30, a1.age
|
62
|
-
assert_equal 1, a1.oid
|
63
|
-
|
64
|
-
Article.create('drak', 12)
|
65
|
-
Article.create('ekarak', 34)
|
66
|
-
Article.create('mario', 53)
|
67
|
-
Article.create('elathan', 34)
|
68
|
-
|
69
|
-
articles = Article.all
|
70
|
-
|
71
|
-
assert_equal 5, articles.size
|
72
|
-
|
73
|
-
a3 = Article[3]
|
74
|
-
|
75
|
-
assert_equal 'ekarak', a3.name
|
76
|
-
|
77
|
-
c1 = Comment.new('a comment')
|
78
|
-
c1.save!
|
79
|
-
a3.add_comment(c1)
|
80
|
-
|
81
|
-
a5 = Article[3]
|
82
|
-
assert_equal 1, a5.comments.size
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
=end
|
data/test/tc_og.rb
DELETED
@@ -1,355 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
-
|
3
|
-
$DBG = true
|
4
|
-
|
5
|
-
require 'test/unit'
|
6
|
-
|
7
|
-
require 'og'
|
8
|
-
|
9
|
-
module Test # :nodoc: all
|
10
|
-
|
11
|
-
# bug: creates a table that fucks-up postgres if not
|
12
|
-
# correctly escaped.
|
13
|
-
class User
|
14
|
-
prop_accessor :name, String, :unique => true
|
15
|
-
prop_accessor :banned, TrueClass
|
16
|
-
|
17
|
-
def initialize(name = nil)
|
18
|
-
@name = name
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Role
|
23
|
-
prop_accessor :title, String
|
24
|
-
property :chk_not_null, Fixnum, :default => 2
|
25
|
-
end
|
26
|
-
|
27
|
-
class Comment; end
|
28
|
-
class Article; end
|
29
|
-
|
30
|
-
class Category
|
31
|
-
prop_accessor :title, String
|
32
|
-
many_to_many :articles, Article
|
33
|
-
end
|
34
|
-
|
35
|
-
class Article
|
36
|
-
prop_accessor :title, String
|
37
|
-
prop_accessor :body, String
|
38
|
-
prop_accessor :owner_oid, Fixnum, :sql_index => true
|
39
|
-
prop_accessor :another_oid, Fixnum
|
40
|
-
property :create_time, Time
|
41
|
-
property :rate, Float
|
42
|
-
sql_index 'owner_oid, another_oid'
|
43
|
-
prop_accessor :options, Hash
|
44
|
-
has_many :comments, Test::Comment
|
45
|
-
|
46
|
-
def initialize(title = nil, body = nil)
|
47
|
-
@title = title
|
48
|
-
@body = body
|
49
|
-
@options = {"hello" => "world"}
|
50
|
-
end
|
51
|
-
|
52
|
-
def og_pre_insert(conn)
|
53
|
-
puts "-- PRE INSERT CALLED FOR ARTICLE"
|
54
|
-
end
|
55
|
-
|
56
|
-
def og_post_insert_update(conn)
|
57
|
-
puts "-- POST INSERT UPDATE CALLED FOR ARTICLE"
|
58
|
-
end
|
59
|
-
|
60
|
-
def og_post_update(conn)
|
61
|
-
puts "-- POST UPDATE CALLED FOR ARTICLE"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class Comment
|
66
|
-
prop_accessor :body, String
|
67
|
-
prop_accessor :create_time, Time
|
68
|
-
belongs_to :article, Test::Article, :extra_sql => 'NOT NULL'
|
69
|
-
belongs_to :author, Test::User
|
70
|
-
|
71
|
-
def initialize(body = nil)
|
72
|
-
@create_time = Time.now
|
73
|
-
@body = body
|
74
|
-
end
|
75
|
-
|
76
|
-
def og_pre_insert(conn)
|
77
|
-
puts "-- PRE INSERT CALLED FOR COMMENT"
|
78
|
-
end
|
79
|
-
|
80
|
-
def og_post_insert(conn)
|
81
|
-
puts "-- POST INSERT CALLED FOR COMMENT"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
module MyMixin
|
86
|
-
prop_accessor :title, String
|
87
|
-
end
|
88
|
-
|
89
|
-
class MyClass
|
90
|
-
include Test::MyMixin
|
91
|
-
end
|
92
|
-
|
93
|
-
class OrderItem
|
94
|
-
prop_accessor :onumber, Fixnum
|
95
|
-
refers_to :article, Article
|
96
|
-
end
|
97
|
-
|
98
|
-
class TC_N_OG < Test::Unit::TestCase
|
99
|
-
|
100
|
-
@@adapter = :psql
|
101
|
-
|
102
|
-
case @@adapter
|
103
|
-
|
104
|
-
when :psql
|
105
|
-
def test_psql
|
106
|
-
config = {
|
107
|
-
:adapter => 'psql',
|
108
|
-
# :address => 'localhost',
|
109
|
-
:database => 'test',
|
110
|
-
:user => 'postgres',
|
111
|
-
:password => 'navelrulez',
|
112
|
-
:connection_count => 2
|
113
|
-
}
|
114
|
-
|
115
|
-
run_all_tests(config)
|
116
|
-
end
|
117
|
-
|
118
|
-
when :mysql
|
119
|
-
def test_mysql
|
120
|
-
config = {
|
121
|
-
:adapter => 'mysql',
|
122
|
-
# :address => 'localhost',
|
123
|
-
:database => 'test',
|
124
|
-
:user => 'root',
|
125
|
-
:password => 'navelrulez',
|
126
|
-
:connection_count => 2
|
127
|
-
}
|
128
|
-
|
129
|
-
run_all_tests(config)
|
130
|
-
end
|
131
|
-
|
132
|
-
when :oracle
|
133
|
-
def test_oracle
|
134
|
-
config = {
|
135
|
-
:adapter => 'oracle',
|
136
|
-
# :address => 'localhost',
|
137
|
-
:database => 'test',
|
138
|
-
:user => 'root',
|
139
|
-
:password => 'navelrulez',
|
140
|
-
:connection_count => 2
|
141
|
-
}
|
142
|
-
|
143
|
-
run_all_tests(config)
|
144
|
-
end
|
145
|
-
|
146
|
-
when :sqlite
|
147
|
-
def test_sqlite
|
148
|
-
config = {
|
149
|
-
:adapter => 'sqlite',
|
150
|
-
:database => 'test',
|
151
|
-
:connection_count => 2
|
152
|
-
}
|
153
|
-
|
154
|
-
run_all_tests(config)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
# gmosx: hmm, implemented in one method to enforce order.
|
159
|
-
|
160
|
-
def run_all_tests(config)
|
161
|
-
Og::Database.drop_db!(config)
|
162
|
-
og = Og::Database.new(config)
|
163
|
-
|
164
|
-
og.get_connection
|
165
|
-
|
166
|
-
article = Article.new("Title", "Here comes the body")
|
167
|
-
article.create_time = now = Time.now
|
168
|
-
article.rate = rate = 12.33
|
169
|
-
og << article
|
170
|
-
|
171
|
-
article.title = "Changed"
|
172
|
-
article.save!
|
173
|
-
|
174
|
-
og.pupdate("body='Hello'", article)
|
175
|
-
|
176
|
-
article.update_properties "body='Hello'"
|
177
|
-
|
178
|
-
another = Article[1]
|
179
|
-
assert_equal(1, another.oid)
|
180
|
-
assert_equal now.to_i, another.create_time.to_i
|
181
|
-
assert_equal rate, another.rate
|
182
|
-
|
183
|
-
# bug: yaml load problem.
|
184
|
-
assert_equal("world", another.options["hello"])
|
185
|
-
|
186
|
-
# bug: YAMLing nil property
|
187
|
-
another.options = nil
|
188
|
-
another.save!
|
189
|
-
|
190
|
-
assert_equal(nil, og.load(30000, Article))
|
191
|
-
|
192
|
-
articles = og.load_all(Article)
|
193
|
-
|
194
|
-
# p articles
|
195
|
-
# p Article[23]
|
196
|
-
|
197
|
-
user = User.new("gmosx")
|
198
|
-
user.save!
|
199
|
-
|
200
|
-
user = User["gmosx"]
|
201
|
-
|
202
|
-
assert_equal("gmosx", user.name)
|
203
|
-
|
204
|
-
users1 = og.select("name='gmosx' ORDER BY oid", User)
|
205
|
-
|
206
|
-
users = og.select("SELECT * FROM #{User::DBTABLE} WHERE name='gmosx' ORDER BY oid", User)
|
207
|
-
|
208
|
-
users2 = User.select "name='gmosx' ORDER BY oid"
|
209
|
-
|
210
|
-
assert_equal(users1.size, users2.size)
|
211
|
-
|
212
|
-
article = Article.new("Title", "Body")
|
213
|
-
article.save!
|
214
|
-
|
215
|
-
# advanced finder
|
216
|
-
|
217
|
-
users3 = User.find_by_banned(true)
|
218
|
-
assert users3.empty?
|
219
|
-
|
220
|
-
user3 = User.find_by_name('gmosx')
|
221
|
-
assert_equal 'gmosx', user3.name
|
222
|
-
|
223
|
-
user3.banned = true
|
224
|
-
user3.save
|
225
|
-
|
226
|
-
users3 = User.find_by_banned(true)
|
227
|
-
assert !users3.empty?
|
228
|
-
|
229
|
-
comment = Comment.new("This is a comment")
|
230
|
-
comment.article = article
|
231
|
-
comment.author = User["gmosx"]
|
232
|
-
comment.save!
|
233
|
-
|
234
|
-
# test automatically generated add_comment
|
235
|
-
comment = Comment.new("This is another comment")
|
236
|
-
comment.author = User["gmosx"]
|
237
|
-
article.add_comment(comment)
|
238
|
-
|
239
|
-
# test add_comment with block.
|
240
|
-
article.add_comment do |c|
|
241
|
-
c.body = 'Another one'
|
242
|
-
c.author = User['gmosx']
|
243
|
-
end
|
244
|
-
|
245
|
-
assert_equal(article.oid, comment.article_oid)
|
246
|
-
|
247
|
-
comments = article.comments
|
248
|
-
|
249
|
-
assert_equal(3, comments.size)
|
250
|
-
|
251
|
-
# test many_to_many relations.
|
252
|
-
|
253
|
-
category = Category.create
|
254
|
-
category.add_article(article)
|
255
|
-
|
256
|
-
assert_equal 1, category.articles.size
|
257
|
-
|
258
|
-
# bug: test many_to_many with non-saved object.
|
259
|
-
|
260
|
-
ans = Article.new
|
261
|
-
ans.title = 'non saved'
|
262
|
-
category.add_article(ans)
|
263
|
-
|
264
|
-
category.add_article do |a|
|
265
|
-
a.title = 'another'
|
266
|
-
end
|
267
|
-
|
268
|
-
assert_equal 3, category.articles.size
|
269
|
-
|
270
|
-
assert_equal 1, article.categories.size
|
271
|
-
|
272
|
-
assert_equal("gmosx", comments[0].author.name)
|
273
|
-
|
274
|
-
article.delete_all_comments
|
275
|
-
assert article.comments.empty?
|
276
|
-
|
277
|
-
# test cascading delete
|
278
|
-
|
279
|
-
article.add_comment(Comment.new("hello"))
|
280
|
-
article.add_comment(Comment.new("world"))
|
281
|
-
|
282
|
-
assert_equal 2, Comment.count
|
283
|
-
|
284
|
-
Article.delete(article)
|
285
|
-
|
286
|
-
assert Comment.all.empty?
|
287
|
-
|
288
|
-
comment.delete!
|
289
|
-
|
290
|
-
# test extra_sql
|
291
|
-
|
292
|
-
for p in Comment.__props
|
293
|
-
if :article_oid == p.symbol
|
294
|
-
assert_equal('NOT NULL', p.meta[:extra_sql])
|
295
|
-
break
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
assert(og.managed_classes.include?(Test::Article))
|
300
|
-
|
301
|
-
# bug: indirectly managed (includes managed Module)
|
302
|
-
assert(og.managed_classes.include?(Test::MyClass))
|
303
|
-
|
304
|
-
# test create
|
305
|
-
article = Article.create("title", "body")
|
306
|
-
# assert_equal(3, article.oid)
|
307
|
-
|
308
|
-
# test refers_to
|
309
|
-
|
310
|
-
oi = OrderItem.new
|
311
|
-
oi.article = article
|
312
|
-
oi.save
|
313
|
-
|
314
|
-
assert_equal article.oid, oi.article_oid
|
315
|
-
|
316
|
-
# bug
|
317
|
-
|
318
|
-
user = User['gmosx']
|
319
|
-
user.banned = true
|
320
|
-
user.save!
|
321
|
-
|
322
|
-
user = User['gmosx']
|
323
|
-
assert_equal true, user.banned
|
324
|
-
|
325
|
-
# test not null
|
326
|
-
|
327
|
-
role = Role.new
|
328
|
-
|
329
|
-
begin
|
330
|
-
role.save
|
331
|
-
rescue Exception, StandardError
|
332
|
-
# drink it
|
333
|
-
end
|
334
|
-
|
335
|
-
role = Role[1]
|
336
|
-
|
337
|
-
# not saved due to not nul constraint.
|
338
|
-
assert_equal nil, role
|
339
|
-
|
340
|
-
og.put_connection
|
341
|
-
og.shutdown
|
342
|
-
|
343
|
-
# Test database allready exists
|
344
|
-
|
345
|
-
og = Og::Database.new(config)
|
346
|
-
|
347
|
-
user = User.new("kokoriko")
|
348
|
-
user.save!
|
349
|
-
|
350
|
-
og.shutdown
|
351
|
-
end
|
352
|
-
|
353
|
-
end
|
354
|
-
|
355
|
-
end
|