og 0.20.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/CHANGELOG +796 -664
  2. data/INSTALL +24 -24
  3. data/README +39 -32
  4. data/Rakefile +41 -42
  5. data/benchmark/bench.rb +36 -36
  6. data/doc/AUTHORS +15 -12
  7. data/doc/LICENSE +3 -3
  8. data/doc/RELEASES +311 -243
  9. data/doc/config.txt +1 -1
  10. data/examples/mysql_to_psql.rb +15 -15
  11. data/examples/run.rb +92 -92
  12. data/install.rb +7 -17
  13. data/lib/og.rb +76 -75
  14. data/lib/og/collection.rb +203 -160
  15. data/lib/og/entity.rb +168 -169
  16. data/lib/og/errors.rb +5 -5
  17. data/lib/og/manager.rb +179 -178
  18. data/lib/og/mixin/hierarchical.rb +107 -107
  19. data/lib/og/mixin/optimistic_locking.rb +36 -36
  20. data/lib/og/mixin/orderable.rb +148 -148
  21. data/lib/og/mixin/timestamped.rb +8 -8
  22. data/lib/og/mixin/tree.rb +124 -124
  23. data/lib/og/relation.rb +237 -213
  24. data/lib/og/relation/belongs_to.rb +5 -5
  25. data/lib/og/relation/has_many.rb +60 -58
  26. data/lib/og/relation/joins_many.rb +93 -47
  27. data/lib/og/relation/refers_to.rb +25 -21
  28. data/lib/og/store.rb +210 -207
  29. data/lib/og/store/filesys.rb +79 -79
  30. data/lib/og/store/kirby.rb +263 -258
  31. data/lib/og/store/memory.rb +261 -261
  32. data/lib/og/store/mysql.rb +288 -284
  33. data/lib/og/store/psql.rb +261 -244
  34. data/lib/og/store/sql.rb +873 -720
  35. data/lib/og/store/sqlite.rb +177 -175
  36. data/lib/og/store/sqlserver.rb +204 -214
  37. data/lib/og/types.rb +1 -1
  38. data/lib/og/validation.rb +57 -57
  39. data/lib/vendor/mysql.rb +376 -376
  40. data/lib/vendor/mysql411.rb +10 -10
  41. data/test/og/mixin/tc_hierarchical.rb +59 -59
  42. data/test/og/mixin/tc_optimistic_locking.rb +40 -40
  43. data/test/og/mixin/tc_orderable.rb +67 -67
  44. data/test/og/mixin/tc_timestamped.rb +19 -19
  45. data/test/og/store/tc_filesys.rb +46 -46
  46. data/test/og/tc_inheritance.rb +81 -81
  47. data/test/og/tc_join.rb +67 -0
  48. data/test/og/tc_polymorphic.rb +49 -49
  49. data/test/og/tc_relation.rb +57 -30
  50. data/test/og/tc_select.rb +49 -0
  51. data/test/og/tc_store.rb +345 -337
  52. data/test/og/tc_types.rb +11 -11
  53. metadata +11 -18
@@ -5,67 +5,67 @@ require 'test/unit'
5
5
  require 'og'
6
6
 
7
7
  class TestCaseOgFilesys < Test::Unit::TestCase # :nodoc: all
8
- include Og
8
+ include Og
9
9
 
10
- class Comment; end
10
+ class Comment; end
11
11
 
12
- class Article
13
- property :body, String
14
- has_many :comment, Comment
12
+ class Article
13
+ property :body, String
14
+ has_many :comment, Comment
15
15
 
16
- def initialize(body = nil)
17
- @body = body
18
- end
19
- end
16
+ def initialize(body = nil)
17
+ @body = body
18
+ end
19
+ end
20
20
 
21
- class Comment
22
- property :body, String
23
- belongs_to :article, Article
21
+ class Comment
22
+ property :body, String
23
+ belongs_to :article, Article
24
24
 
25
- def initialize(body = nil)
26
- @body = body
27
- end
28
- end
25
+ def initialize(body = nil)
26
+ @body = body
27
+ end
28
+ end
29
29
 
30
- class User
31
- property :name, :name_key => true
32
- end
33
-
34
- def setup
35
- @og = Og.setup(:store => 'filesys', :name => 'test')
36
- end
30
+ class User
31
+ property :name, :name_key => true
32
+ end
33
+
34
+ def setup
35
+ @og = Og.setup(:store => 'filesys', :name => 'test')
36
+ end
37
37
 
38
- def teardown
39
- @og = nil
40
- end
38
+ def teardown
39
+ @og = nil
40
+ end
41
41
 
42
- def test_all
43
- # p Comment.__meta
44
- # p Article.__meta
42
+ def test_all
43
+ # p Comment.__meta
44
+ # p Article.__meta
45
45
 
46
- a1 = Article.new('Article 1')
47
- @og.store.save(a1)
46
+ a1 = Article.new('Article 1')
47
+ @og.store.save(a1)
48
48
 
49
- a2 = @og.store.load(1, Article)
49
+ a2 = @og.store.load(1, Article)
50
50
 
51
- assert_equal a1.body, a2.body
51
+ assert_equal a1.body, a2.body
52
52
 
53
- a3 = Article.new('Article 3')
54
- a3.save
55
-
56
- @og.store.delete(a3)
53
+ a3 = Article.new('Article 3')
54
+ a3.save
55
+
56
+ @og.store.delete(a3)
57
57
 
58
- assert @og.store.load(1, Article)
59
- assert !@og.store.load(2, Article)
58
+ assert @og.store.load(1, Article)
59
+ assert !@og.store.load(2, Article)
60
60
 
61
- a2.delete
61
+ a2.delete
62
62
 
63
- # a.comments << Comment.new('Comment 1')
64
- # a.save
65
- # a = Article[1]
63
+ # a.comments << Comment.new('Comment 1')
64
+ # a.save
65
+ # a = Article[1]
66
66
 
67
- @og.store.close
68
- @og.store.class.destroy(@og.options)
69
- end
67
+ @og.store.close
68
+ @og.store.class.destroy(@og.options)
69
+ end
70
70
 
71
71
  end
@@ -7,97 +7,97 @@ require 'test/unit'
7
7
  require 'og'
8
8
 
9
9
  class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all
10
- include Og
10
+ include Og
11
11
 
12
- class Document
13
- property :title, String
14
- schema_inheritance
15
-
16
- def initialize(title)
17
- @title = title
18
- end
19
- end
12
+ class Document
13
+ property :title, String
14
+ schema_inheritance
15
+
16
+ def initialize(title)
17
+ @title = title
18
+ end
19
+ end
20
20
 
21
- class Article < Document
22
- property :body, String
23
-
24
- def initialize(title, body)
25
- @title, @body = title, body
26
- end
27
- end
21
+ class Article < Document
22
+ property :body, String
23
+
24
+ def initialize(title, body)
25
+ @title, @body = title, body
26
+ end
27
+ end
28
28
 
29
- class Photo < Document
30
- property :url, String
31
-
32
- def initialize(title, url)
33
- @title, @url = title, url
34
- end
35
- end
29
+ class Photo < Document
30
+ property :url, String
31
+
32
+ def initialize(title, url)
33
+ @title, @url = title, url
34
+ end
35
+ end
36
36
 
37
- def test_all
37
+ def test_all
38
38
  =begin
39
- @og = Og.setup(
40
- :store => :memory,
41
- :name => :test
42
- )
39
+ @og = Og.setup(
40
+ :store => :memory,
41
+ :name => :test
42
+ )
43
43
  =end
44
44
  #=begin
45
- @og = Og.setup(
46
- :destroy => true,
47
- :store => :sqlite,
48
- :name => 'test'
49
- )
45
+ @og = Og.setup(
46
+ :destroy => true,
47
+ :store => :sqlite,
48
+ :name => 'test'
49
+ )
50
50
  #=end
51
51
  =begin
52
- @og = Og.setup(
53
- :destroy => true,
54
- :store => :mysql,
55
- :name => 'test',
56
- :user => 'root',
57
- :password => 'navelrulez'
58
- )
59
- =end
60
- assert_equal [Document], Photo.metadata.superclass
61
- assert_equal [Photo, Article], Document.metadata.subclasses
62
-
63
- assert Document.metadata.schema_inheritance
52
+ @og = Og.setup(
53
+ :destroy => true,
54
+ :store => :mysql,
55
+ :name => 'test',
56
+ :user => 'root',
57
+ :password => 'navelrulez'
58
+ )
59
+ =end
60
+ assert_equal [Document], Photo.metadata.superclass
61
+ assert_equal [Photo, Article], Document.metadata.subclasses
62
+
63
+ assert Document.metadata.schema_inheritance
64
64
 
65
- # propagate schema_inheritance flag.
66
-
67
- assert Photo.metadata.schema_inheritance
68
-
69
- # subclasses reuse the same table.
70
-
71
- assert_equal Document.table, Photo.table
72
-
73
- doc = Document.create('doc1')
74
- Photo.create('photo1', 'http:/www.gmosx.com/photo/1')
75
- Photo.create('photo2', 'http:/www.gmosx.com/photo/2')
76
- Article.create('art1', 'here comes the body')
77
- Article.create('art2', 'this is cool')
78
- Article.create('art3', 'this is cooler')
79
-
80
- docs = Document.all
65
+ # propagate schema_inheritance flag.
66
+
67
+ assert Photo.metadata.schema_inheritance
68
+
69
+ # subclasses reuse the same table.
70
+
71
+ assert_equal Document.table, Photo.table
72
+
73
+ doc = Document.create('doc1')
74
+ Photo.create('photo1', 'http:/www.gmosx.com/photo/1')
75
+ Photo.create('photo2', 'http:/www.gmosx.com/photo/2')
76
+ Article.create('art1', 'here comes the body')
77
+ Article.create('art2', 'this is cool')
78
+ Article.create('art3', 'this is cooler')
79
+
80
+ docs = Document.all
81
81
 
82
- assert_equal 6, docs.size
83
- assert_equal 'art2', docs[4].title
82
+ assert_equal 6, docs.size
83
+ assert_equal 'art2', docs[4].title
84
84
 
85
- assert_equal Document, docs[0].class
86
- assert_equal Photo, docs[1].class
87
- assert_equal Article, docs[4].class
88
-
89
- photos = Photo.all
90
-
91
- assert_equal 2, photos.size
92
- assert_equal 'photo2', photos[1].title
93
- assert_equal 'http:/www.gmosx.com/photo/1', photos[0].url
94
-
95
- articles = Article.all
96
-
97
- assert_equal 3, articles.size
98
- assert_equal 'art3', articles[2].title
99
-
100
- articles = Article.all(:limit => 2)
101
- assert_equal 2, articles.size
102
- end
85
+ assert_equal Document, docs[0].class
86
+ assert_equal Photo, docs[1].class
87
+ assert_equal Article, docs[4].class
88
+
89
+ photos = Photo.all
90
+
91
+ assert_equal 2, photos.size
92
+ assert_equal 'photo2', photos[1].title
93
+ assert_equal 'http:/www.gmosx.com/photo/1', photos[0].url
94
+
95
+ articles = Article.all
96
+
97
+ assert_equal 3, articles.size
98
+ assert_equal 'art3', articles[2].title
99
+
100
+ articles = Article.all(:limit => 2)
101
+ assert_equal 2, articles.size
102
+ end
103
103
  end
@@ -0,0 +1,67 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+
3
+ $DBG = true
4
+
5
+ require 'test/unit'
6
+
7
+ require 'og'
8
+
9
+ class TC_Join < Test::Unit::TestCase # :nodoc: all
10
+ include Og
11
+
12
+ class Category
13
+ property :title, String
14
+
15
+ def initialize(title)
16
+ @title = title
17
+ end
18
+ end
19
+
20
+ class Article
21
+ property :title, String
22
+
23
+ joins_many Category, :through => ArticleToCategory
24
+
25
+ def initialize(title)
26
+ @title = title
27
+ end
28
+ end
29
+
30
+ class ArticleToCategory
31
+ property :rate, Float
32
+ property :hits, Fixnum
33
+ has_one Article
34
+ has_one Category
35
+ end
36
+
37
+ def setup
38
+ @og = Og.setup(
39
+ :destroy => true,
40
+ :store => :mysql,
41
+ # :store => :sqlite,
42
+ # :store => :psql,
43
+ # :user => 'postgres',
44
+ :user => 'root',
45
+ :password => 'navelrulez',
46
+ :name => 'test'
47
+ )
48
+ end
49
+
50
+ def test_all
51
+ c1 = Category.create('tech')
52
+ c2 = Category.create('funny')
53
+
54
+ a = Article.create('a1')
55
+ a.categories.push(c1, :hits =>3, :rate => 2.3)
56
+ a.categories.push(c2, :rate => 1.2)
57
+
58
+ join = a.category_join_data(c1)
59
+ assert_equal 2.3, join.rate
60
+ assert_equal 3, join.hits
61
+
62
+ join = a.category_join_data(c2)
63
+ assert_equal 1.2, join.rate
64
+ assert_equal nil, join.hits
65
+ end
66
+
67
+ end
@@ -5,60 +5,60 @@ require 'test/unit'
5
5
  require 'og'
6
6
 
7
7
  class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all
8
- include Og
8
+ include Og
9
9
 
10
- # This class is a polymorphic parent. Ie' it acts as template
11
- # to generate customized versions of this class.
12
-
13
- class Comment
14
- property :body, String
15
- belongs_to :parent, Object # polymorphic marker !
16
-
17
- def initialize(body)
18
- @body = body
19
- end
20
- end
10
+ # This class is a polymorphic parent. Ie' it acts as template
11
+ # to generate customized versions of this class.
12
+
13
+ class Comment
14
+ property :body, String
15
+ belongs_to :parent, Object # polymorphic marker !
16
+
17
+ def initialize(body)
18
+ @body = body
19
+ end
20
+ end
21
21
 
22
- class Article
23
- property :title, String
24
- has_many Comment
22
+ class Article
23
+ property :title, String
24
+ has_many Comment
25
25
 
26
- def initialize(title)
27
- @title = title
28
- end
29
- end
30
-
31
- class User
32
- property :name, String
33
- has_many Comment
26
+ def initialize(title)
27
+ @title = title
28
+ end
29
+ end
30
+
31
+ class User
32
+ property :name, String
33
+ has_many Comment
34
34
 
35
- def initialize(name)
36
- @name = name
37
- end
38
- end
35
+ def initialize(name)
36
+ @name = name
37
+ end
38
+ end
39
39
 
40
- def setup
41
- @og = Og.setup(
42
- :destroy => true,
43
- :store => :sqlite,
44
- :name => 'test'
45
- )
46
- end
40
+ def setup
41
+ @og = Og.setup(
42
+ :destroy => true,
43
+ :store => :sqlite,
44
+ :name => 'test'
45
+ )
46
+ end
47
47
 
48
- def test_all
49
- u = User.create('gmosx')
50
-
51
- u.comments << User::Comment.create('Hello')
52
- u.comments << User::Comment.create('World')
48
+ def test_all
49
+ u = User.create('gmosx')
50
+
51
+ u.comments << User::Comment.create('Hello')
52
+ u.comments << User::Comment.create('World')
53
53
 
54
- assert_equal 2, u.comments.size
55
-
56
- a = Article.create('test')
57
-
58
- a.comments << Article::Comment.create('Hello2')
59
- a.comments << Article::Comment.create('World2')
60
-
61
- assert_equal 2, a.comments.size
62
- end
63
-
54
+ assert_equal 2, u.comments.size
55
+
56
+ a = Article.create('test')
57
+
58
+ a.comments << Article::Comment.create('Hello2')
59
+ a.comments << Article::Comment.create('World2')
60
+
61
+ assert_equal 2, a.comments.size
62
+ end
63
+
64
64
  end