og 0.16.0 → 0.17.0
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/CHANGELOG +485 -0
- data/README +35 -12
- data/Rakefile +4 -7
- data/benchmark/bench.rb +1 -1
- data/doc/AUTHORS +3 -3
- data/doc/RELEASES +153 -2
- data/doc/config.txt +0 -7
- data/doc/tutorial.txt +7 -0
- data/examples/README +5 -0
- data/examples/mysql_to_psql.rb +25 -50
- data/examples/run.rb +62 -77
- data/install.rb +1 -1
- data/lib/og.rb +45 -106
- data/lib/og/collection.rb +156 -0
- data/lib/og/entity.rb +131 -0
- data/lib/og/errors.rb +10 -15
- data/lib/og/manager.rb +115 -0
- data/lib/og/{mixins → mixin}/hierarchical.rb +43 -37
- data/lib/og/{mixins → mixin}/orderable.rb +35 -35
- data/lib/og/{mixins → mixin}/timestamped.rb +0 -6
- data/lib/og/{mixins → mixin}/tree.rb +0 -4
- data/lib/og/relation.rb +178 -0
- data/lib/og/relation/belongs_to.rb +14 -0
- data/lib/og/relation/has_many.rb +62 -0
- data/lib/og/relation/has_one.rb +17 -0
- data/lib/og/relation/joins_many.rb +69 -0
- data/lib/og/relation/many_to_many.rb +17 -0
- data/lib/og/relation/refers_to.rb +31 -0
- data/lib/og/store.rb +223 -0
- data/lib/og/store/filesys.rb +113 -0
- data/lib/og/store/madeleine.rb +4 -0
- data/lib/og/store/memory.rb +291 -0
- data/lib/og/store/mysql.rb +283 -0
- data/lib/og/store/psql.rb +238 -0
- data/lib/og/store/sql.rb +599 -0
- data/lib/og/store/sqlite.rb +190 -0
- data/lib/og/store/sqlserver.rb +262 -0
- data/lib/og/types.rb +19 -0
- data/lib/og/validation.rb +0 -4
- data/test/og/{mixins → mixin}/tc_hierarchical.rb +21 -23
- data/test/og/{mixins → mixin}/tc_orderable.rb +15 -14
- data/test/og/mixin/tc_timestamped.rb +38 -0
- data/test/og/store/tc_filesys.rb +71 -0
- data/test/og/tc_relation.rb +36 -0
- data/test/og/tc_store.rb +290 -0
- data/test/og/tc_types.rb +21 -0
- metadata +54 -40
- data/examples/mock_example.rb +0 -50
- data/lib/og/adapters/base.rb +0 -706
- data/lib/og/adapters/filesys.rb +0 -117
- data/lib/og/adapters/mysql.rb +0 -350
- data/lib/og/adapters/oracle.rb +0 -368
- data/lib/og/adapters/psql.rb +0 -272
- data/lib/og/adapters/sqlite.rb +0 -265
- data/lib/og/adapters/sqlserver.rb +0 -356
- data/lib/og/database.rb +0 -290
- data/lib/og/enchant.rb +0 -149
- data/lib/og/meta.rb +0 -407
- data/lib/og/testing/mock.rb +0 -165
- data/lib/og/typemacros.rb +0 -24
- data/test/og/adapters/tc_filesys.rb +0 -83
- data/test/og/adapters/tc_sqlite.rb +0 -86
- data/test/og/adapters/tc_sqlserver.rb +0 -96
- data/test/og/tc_automanage.rb +0 -46
- data/test/og/tc_lifecycle.rb +0 -105
- data/test/og/tc_many_to_many.rb +0 -61
- data/test/og/tc_meta.rb +0 -55
- data/test/og/tc_validation.rb +0 -89
- data/test/tc_og.rb +0 -364
data/test/og/tc_automanage.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
require 'og'
|
7
|
-
|
8
|
-
$og = Og::Database.new(
|
9
|
-
:adapter => 'psql',
|
10
|
-
:database => 'test',
|
11
|
-
:user => 'postgres',
|
12
|
-
:password => 'navelrulez',
|
13
|
-
:drop => true
|
14
|
-
)
|
15
|
-
|
16
|
-
class TestCaseOgObserver < Test::Unit::TestCase # :nodoc: all
|
17
|
-
|
18
|
-
# Define a class after the Database is created.
|
19
|
-
|
20
|
-
class Article; end
|
21
|
-
|
22
|
-
class User
|
23
|
-
property :name
|
24
|
-
|
25
|
-
# auto forward ref.
|
26
|
-
has_many :articles, Article
|
27
|
-
end
|
28
|
-
|
29
|
-
class Article
|
30
|
-
property :name, String
|
31
|
-
property :age, Fixnum
|
32
|
-
|
33
|
-
def initialize (name = nil, age = nil)
|
34
|
-
@name, @age = name, age
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_all
|
39
|
-
assert_equal 0, $og.managed_classes.size
|
40
|
-
$og.auto_manage_classes
|
41
|
-
assert_equal 2, $og.managed_classes.size
|
42
|
-
assert $og.managed_classes.include?(User)
|
43
|
-
assert $og.managed_classes.include?(Article)
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/test/og/tc_lifecycle.rb
DELETED
@@ -1,105 +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: tc_lifecycle.rb 17 2005-04-14 16:03:40Z gmosx $
|
7
|
-
|
8
|
-
$LOAD_PATH.unshift 'lib'
|
9
|
-
|
10
|
-
require 'test/unit'
|
11
|
-
require 'glue/logger'
|
12
|
-
require 'og/testing/mock'
|
13
|
-
|
14
|
-
$DBG = false
|
15
|
-
|
16
|
-
class Dummy
|
17
|
-
include Aspects
|
18
|
-
|
19
|
-
prop_accessor :date, Time
|
20
|
-
attr_accessor :call_stack
|
21
|
-
|
22
|
-
pre(:on => :og_insert) { |this| this.call_stack << 'pre_insert' }
|
23
|
-
post(:on => :og_insert) { |this| this.call_stack << 'post_insert' }
|
24
|
-
|
25
|
-
def og_pre_update
|
26
|
-
@call_stack << 'pre_update'
|
27
|
-
end
|
28
|
-
pre :og_pre_update, :on => :og_update
|
29
|
-
|
30
|
-
post(:on => :og_update) { |this| this.call_stack << 'post_update' }
|
31
|
-
|
32
|
-
# faster :)
|
33
|
-
|
34
|
-
post "@call_stack << 'post_update2'", :on => :og_update
|
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.shift == "post_update2" )
|
67
|
-
assert( obj.call_stack.empty? )
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_delete
|
71
|
-
obj = Dummy.new
|
72
|
-
obj.save!
|
73
|
-
obj.call_stack.shift
|
74
|
-
obj.call_stack.shift
|
75
|
-
|
76
|
-
assert_raise( RuntimeError, 'undeletable' ) { obj.delete! }
|
77
|
-
end
|
78
|
-
|
79
|
-
def setup
|
80
|
-
psql = true
|
81
|
-
|
82
|
-
if psql
|
83
|
-
config = {
|
84
|
-
:adapter => 'psql',
|
85
|
-
# :address => 'localhost',
|
86
|
-
:database => 'test',
|
87
|
-
:user => 'postgres',
|
88
|
-
:password => 'navelrulez',
|
89
|
-
:connection_count => 1
|
90
|
-
}
|
91
|
-
else
|
92
|
-
config = {
|
93
|
-
:adapter => 'mysql',
|
94
|
-
# :address => 'localhost',
|
95
|
-
:database => 'test',
|
96
|
-
:user => 'root',
|
97
|
-
:password => 'navelrulez',
|
98
|
-
:connection_count => 1
|
99
|
-
}
|
100
|
-
end
|
101
|
-
Og::Database.drop_db!(config)
|
102
|
-
$og = Og::Database.new(config)
|
103
|
-
$og.get_connection()
|
104
|
-
end
|
105
|
-
end
|
data/test/og/tc_many_to_many.rb
DELETED
@@ -1,61 +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
|
-
|
10
|
-
class Attribute
|
11
|
-
property :name, String
|
12
|
-
|
13
|
-
def initialize(name = nil)
|
14
|
-
@name = name
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Klass
|
19
|
-
property :name, String
|
20
|
-
many_to_many :observed_attributes, Attribute, :linkback => :klass_observers
|
21
|
-
many_to_many :controlled_attributes, Attribute, :linkback => :klass_controllers
|
22
|
-
|
23
|
-
def initialize(name = nil)
|
24
|
-
@name = name
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_all
|
29
|
-
config = {
|
30
|
-
:adapter => 'psql',
|
31
|
-
:database => 'test',
|
32
|
-
:user => 'postgres',
|
33
|
-
:password => 'navelrulez',
|
34
|
-
:connection_count => 2
|
35
|
-
}
|
36
|
-
|
37
|
-
Og::Database.drop_db!(config)
|
38
|
-
og = Og::Database.new(config)
|
39
|
-
|
40
|
-
og.get_connection
|
41
|
-
|
42
|
-
k = Klass.create('klass1')
|
43
|
-
a1 = Attribute.create('attr1')
|
44
|
-
a2 = Attribute.create('attr2')
|
45
|
-
|
46
|
-
k.add_observed_attribute(a1)
|
47
|
-
k.add_observed_attribute(a2)
|
48
|
-
|
49
|
-
assert_equal 2, k.observed_attributes.size
|
50
|
-
assert_equal 1, a1.klass_observers.size
|
51
|
-
|
52
|
-
k.add_controlled_attribute(a1)
|
53
|
-
|
54
|
-
assert_equal 1, k.controlled_attributes.size
|
55
|
-
assert_equal 1, a1.klass_controllers.size
|
56
|
-
|
57
|
-
og.put_connection
|
58
|
-
og.shutdown
|
59
|
-
end
|
60
|
-
|
61
|
-
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 Og
|
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 Property, par[1].class
|
44
|
-
assert_equal HasMany, par[2].class
|
45
|
-
|
46
|
-
par = Comment.__meta[:props_and_relations]
|
47
|
-
assert_equal 3, par.size
|
48
|
-
assert_equal Property, par[0].class
|
49
|
-
assert_equal 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_validation.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
|
5
|
-
require 'og'
|
6
|
-
require 'og/validation'
|
7
|
-
|
8
|
-
Property.type_checking = false
|
9
|
-
|
10
|
-
class TC_OgValidation < Test::Unit::TestCase # :nodoc: all
|
11
|
-
|
12
|
-
class Group; end
|
13
|
-
|
14
|
-
class User
|
15
|
-
property :name, String
|
16
|
-
validate_unique :name
|
17
|
-
|
18
|
-
def initialize(name = nil)
|
19
|
-
@name = name
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Filler
|
24
|
-
property :name, String
|
25
|
-
validate_length :name, :min => 3
|
26
|
-
|
27
|
-
belongs_to :group, Group
|
28
|
-
|
29
|
-
def initialize(name = nil)
|
30
|
-
@name = name
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Group
|
35
|
-
property :name, String
|
36
|
-
|
37
|
-
has_many :fillers, Filler
|
38
|
-
validate_related :fillers
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_all
|
42
|
-
config = {
|
43
|
-
:adapter => 'psql',
|
44
|
-
:database => 'test',
|
45
|
-
:user => 'postgres',
|
46
|
-
:password => 'navelrulez',
|
47
|
-
:connection_count => 2
|
48
|
-
}
|
49
|
-
|
50
|
-
Og::Database.drop_db!(config)
|
51
|
-
og = Og::Database.new(config)
|
52
|
-
|
53
|
-
og.get_connection
|
54
|
-
|
55
|
-
# validate_unique
|
56
|
-
|
57
|
-
u1 = User.create('gmosx')
|
58
|
-
|
59
|
-
u2 = User.new('gmosx')
|
60
|
-
assert !u2.valid?
|
61
|
-
assert_equal 1, u2.errors.count
|
62
|
-
|
63
|
-
u2.name = 'stella'
|
64
|
-
u2.valid?
|
65
|
-
assert u2.valid?
|
66
|
-
|
67
|
-
# validate_related
|
68
|
-
|
69
|
-
f1 = Filler.new('g')
|
70
|
-
f2 = Filler.new('ok')
|
71
|
-
|
72
|
-
g = Group.create
|
73
|
-
g.add_filler(f1)
|
74
|
-
g.add_filler(f2)
|
75
|
-
|
76
|
-
assert !g.valid?
|
77
|
-
|
78
|
-
f1.name = 'george'
|
79
|
-
f1.save
|
80
|
-
f2.name = 'stella'
|
81
|
-
f2.save
|
82
|
-
|
83
|
-
assert g.valid?
|
84
|
-
|
85
|
-
og.put_connection
|
86
|
-
og.shutdown
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/test/tc_og.rb
DELETED
@@ -1,364 +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
|
-
end
|
52
|
-
|
53
|
-
class Comment
|
54
|
-
prop_accessor :body, String
|
55
|
-
prop_accessor :create_time, Time
|
56
|
-
belongs_to :article, Test::Article, :extra_sql => 'NOT NULL'
|
57
|
-
belongs_to :author, Test::User
|
58
|
-
|
59
|
-
def initialize(body = nil)
|
60
|
-
@create_time = Time.now
|
61
|
-
@body = body
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
module MyMixin
|
66
|
-
prop_accessor :title, String
|
67
|
-
end
|
68
|
-
|
69
|
-
class MyClass
|
70
|
-
include Test::MyMixin
|
71
|
-
end
|
72
|
-
|
73
|
-
class OrderItem
|
74
|
-
prop_accessor :onumber, Fixnum
|
75
|
-
refers_to :article, Article
|
76
|
-
end
|
77
|
-
|
78
|
-
class TC_N_OG < Test::Unit::TestCase
|
79
|
-
|
80
|
-
@@adapter = :psql
|
81
|
-
|
82
|
-
case @@adapter
|
83
|
-
|
84
|
-
when :psql
|
85
|
-
def test_psql
|
86
|
-
config = {
|
87
|
-
:adapter => 'psql',
|
88
|
-
# :address => 'localhost',
|
89
|
-
:database => 'test',
|
90
|
-
:user => 'postgres',
|
91
|
-
:password => 'navelrulez',
|
92
|
-
:connection_count => 2
|
93
|
-
}
|
94
|
-
|
95
|
-
run_all_tests(config)
|
96
|
-
end
|
97
|
-
|
98
|
-
when :mysql
|
99
|
-
def test_mysql
|
100
|
-
config = {
|
101
|
-
:adapter => 'mysql',
|
102
|
-
# :address => 'localhost',
|
103
|
-
:database => 'test',
|
104
|
-
:user => 'root',
|
105
|
-
:password => 'navelrulez',
|
106
|
-
:connection_count => 2
|
107
|
-
}
|
108
|
-
|
109
|
-
run_all_tests(config)
|
110
|
-
end
|
111
|
-
|
112
|
-
when :oracle
|
113
|
-
def test_oracle
|
114
|
-
config = {
|
115
|
-
:adapter => 'oracle',
|
116
|
-
# :address => 'localhost',
|
117
|
-
:database => 'test',
|
118
|
-
:user => 'root',
|
119
|
-
:password => 'navelrulez',
|
120
|
-
:connection_count => 2
|
121
|
-
}
|
122
|
-
|
123
|
-
run_all_tests(config)
|
124
|
-
end
|
125
|
-
|
126
|
-
when :sqlite
|
127
|
-
def test_sqlite
|
128
|
-
config = {
|
129
|
-
:adapter => 'sqlite',
|
130
|
-
:database => 'test',
|
131
|
-
:connection_count => 2
|
132
|
-
}
|
133
|
-
|
134
|
-
run_all_tests(config)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# gmosx: hmm, implemented in one method to enforce order.
|
139
|
-
|
140
|
-
def run_all_tests(config)
|
141
|
-
Og::Database.drop_db!(config)
|
142
|
-
og = Og::Database.new(config)
|
143
|
-
|
144
|
-
og.get_connection
|
145
|
-
|
146
|
-
article = Article.new("Title", "Here comes the body")
|
147
|
-
article.create_time = now = Time.now
|
148
|
-
article.rate = rate = 12.33
|
149
|
-
og << article
|
150
|
-
|
151
|
-
article.title = "Changed"
|
152
|
-
article.save!
|
153
|
-
|
154
|
-
og.pupdate("body='Hello'", article)
|
155
|
-
|
156
|
-
article.update_properties "body='Hello'"
|
157
|
-
|
158
|
-
another = Article[1]
|
159
|
-
assert_equal(1, another.oid)
|
160
|
-
assert_equal now.to_i, another.create_time.to_i
|
161
|
-
assert_equal rate, another.rate
|
162
|
-
|
163
|
-
# bug: yaml load problem.
|
164
|
-
assert_equal("world", another.options["hello"])
|
165
|
-
|
166
|
-
# bug: YAMLing nil property
|
167
|
-
another.options = nil
|
168
|
-
another.save!
|
169
|
-
|
170
|
-
assert_equal(nil, og.load(30000, Article))
|
171
|
-
|
172
|
-
articles = og.load_all(Article)
|
173
|
-
|
174
|
-
# p articles
|
175
|
-
# p Article[23]
|
176
|
-
|
177
|
-
user = User.new("gmosx")
|
178
|
-
user.save!
|
179
|
-
|
180
|
-
user = User["gmosx"]
|
181
|
-
|
182
|
-
assert_equal("gmosx", user.name)
|
183
|
-
|
184
|
-
users1 = og.select("name='gmosx' ORDER BY oid", User)
|
185
|
-
|
186
|
-
users = og.select("SELECT * FROM #{User::DBTABLE} WHERE name='gmosx' ORDER BY oid", User)
|
187
|
-
|
188
|
-
users2 = User.select "name='gmosx' ORDER BY oid"
|
189
|
-
|
190
|
-
assert_equal(users1.size, users2.size)
|
191
|
-
|
192
|
-
article = Article.new("Title", "Body")
|
193
|
-
article.save!
|
194
|
-
|
195
|
-
# advanced finder
|
196
|
-
|
197
|
-
users3 = User.find_by_banned(true)
|
198
|
-
assert users3.empty?
|
199
|
-
|
200
|
-
user3 = User.find_by_name('gmosx')
|
201
|
-
assert_equal 'gmosx', user3.name
|
202
|
-
|
203
|
-
user3.banned = true
|
204
|
-
user3.save
|
205
|
-
|
206
|
-
users3 = User.find_by_banned(true)
|
207
|
-
assert !users3.empty?
|
208
|
-
|
209
|
-
comment = Comment.new("This is a comment")
|
210
|
-
comment.article = article
|
211
|
-
comment.author = User["gmosx"]
|
212
|
-
comment.save!
|
213
|
-
|
214
|
-
# test automatically generated add_comment
|
215
|
-
comment = Comment.new("This is another comment")
|
216
|
-
comment.author = User["gmosx"]
|
217
|
-
article.add_comment(comment)
|
218
|
-
|
219
|
-
# test add_comment with block.
|
220
|
-
article.add_comment do |c|
|
221
|
-
c.body = 'Another one'
|
222
|
-
c.author = User['gmosx']
|
223
|
-
end
|
224
|
-
|
225
|
-
assert_equal(article.oid, comment.article_oid)
|
226
|
-
|
227
|
-
comments = article.comments
|
228
|
-
|
229
|
-
assert_equal(3, comments.size)
|
230
|
-
|
231
|
-
# test many_to_many relations.
|
232
|
-
|
233
|
-
category = Category.create
|
234
|
-
category.add_article(article)
|
235
|
-
|
236
|
-
assert_equal 1, category.articles.size
|
237
|
-
|
238
|
-
# bug: test many_to_many with non-saved object.
|
239
|
-
|
240
|
-
ans = Article.new
|
241
|
-
ans.title = 'non saved'
|
242
|
-
category.add_article(ans)
|
243
|
-
|
244
|
-
category.add_article do |a|
|
245
|
-
a.title = 'another'
|
246
|
-
end
|
247
|
-
|
248
|
-
assert_equal 3, category.articles.size
|
249
|
-
|
250
|
-
assert_equal 1, article.categories.size
|
251
|
-
|
252
|
-
assert_equal("gmosx", comments[0].author.name)
|
253
|
-
|
254
|
-
article.delete_all_comments
|
255
|
-
assert article.comments.empty?
|
256
|
-
|
257
|
-
# test cascading delete
|
258
|
-
|
259
|
-
article.add_comment(Comment.new("hello"))
|
260
|
-
article.add_comment(Comment.new("world"))
|
261
|
-
|
262
|
-
assert_equal 2, Comment.count
|
263
|
-
|
264
|
-
Article.delete(article)
|
265
|
-
|
266
|
-
assert Comment.all.empty?
|
267
|
-
|
268
|
-
comment.delete!
|
269
|
-
|
270
|
-
# test extra_sql
|
271
|
-
|
272
|
-
for p in Comment.__props
|
273
|
-
if :article_oid == p.symbol
|
274
|
-
assert_equal('NOT NULL', p.meta[:extra_sql])
|
275
|
-
break
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
assert(og.managed_classes.include?(Test::Article))
|
280
|
-
|
281
|
-
# bug: indirectly managed (includes managed Module)
|
282
|
-
assert(og.managed_classes.include?(Test::MyClass))
|
283
|
-
|
284
|
-
# test create
|
285
|
-
article = Article.create("title", "body")
|
286
|
-
# assert_equal(3, article.oid)
|
287
|
-
|
288
|
-
# test refers_to
|
289
|
-
|
290
|
-
oi = OrderItem.new
|
291
|
-
oi.article = article
|
292
|
-
oi.save
|
293
|
-
|
294
|
-
assert_equal article.oid, oi.article_oid
|
295
|
-
|
296
|
-
# bug
|
297
|
-
|
298
|
-
user = User['gmosx']
|
299
|
-
user.banned = true
|
300
|
-
user.save!
|
301
|
-
|
302
|
-
user = User['gmosx']
|
303
|
-
assert_equal true, user.banned
|
304
|
-
|
305
|
-
# test not null
|
306
|
-
|
307
|
-
role = Role.new
|
308
|
-
|
309
|
-
begin
|
310
|
-
role.save
|
311
|
-
rescue Exception, StandardError
|
312
|
-
# drink it
|
313
|
-
end
|
314
|
-
|
315
|
-
role = Role[1]
|
316
|
-
|
317
|
-
# not saved due to not nul constraint.
|
318
|
-
assert_equal nil, role
|
319
|
-
|
320
|
-
# test reload.
|
321
|
-
|
322
|
-
User.create('karras')
|
323
|
-
|
324
|
-
u1 = User['karras']
|
325
|
-
u2 = User['karras']
|
326
|
-
|
327
|
-
u1.name = 'vaio'
|
328
|
-
u1.save
|
329
|
-
|
330
|
-
assert_equal 'vaio', u1.name
|
331
|
-
assert_equal 'karras', u2.name
|
332
|
-
|
333
|
-
u2.reload!
|
334
|
-
|
335
|
-
assert_equal 'vaio', u2.name
|
336
|
-
|
337
|
-
# test raise db exception.
|
338
|
-
|
339
|
-
assert_raises(Og::SqlException) {
|
340
|
-
User.select('SEGECT *')
|
341
|
-
}
|
342
|
-
|
343
|
-
Og.raise_db_exceptions = false
|
344
|
-
|
345
|
-
assert_nothing_raised {
|
346
|
-
User.select('SEGECT *')
|
347
|
-
}
|
348
|
-
|
349
|
-
og.put_connection
|
350
|
-
og.shutdown
|
351
|
-
|
352
|
-
# Test database allready exists
|
353
|
-
|
354
|
-
og = Og::Database.new(config)
|
355
|
-
|
356
|
-
user = User.new("kokoriko")
|
357
|
-
user.save!
|
358
|
-
|
359
|
-
og.shutdown
|
360
|
-
end
|
361
|
-
|
362
|
-
end
|
363
|
-
|
364
|
-
end
|