og 0.31.0 → 0.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/doc/{AUTHORS → CONTRIBUTORS} +26 -10
  2. data/doc/LICENSE +2 -3
  3. data/doc/RELEASES +56 -7
  4. data/doc/tutorial.txt +15 -15
  5. data/lib/glue/cacheable.rb +2 -5
  6. data/lib/glue/hierarchical.rb +1 -4
  7. data/lib/glue/optimistic_locking.rb +0 -2
  8. data/lib/glue/orderable.rb +79 -75
  9. data/lib/glue/revisable.rb +19 -24
  10. data/lib/glue/searchable.rb +0 -2
  11. data/lib/glue/taggable.rb +31 -29
  12. data/lib/glue/timestamped.rb +4 -2
  13. data/lib/og.rb +50 -29
  14. data/lib/og/adapter.rb +19 -0
  15. data/lib/og/adapter/mysql.rb +212 -0
  16. data/lib/og/adapter/mysql/override.rb +34 -0
  17. data/lib/og/adapter/mysql/script.rb +15 -0
  18. data/lib/og/adapter/mysql/utils.rb +40 -0
  19. data/lib/og/adapter/postgresql.rb +231 -0
  20. data/lib/og/adapter/postgresql/override.rb +117 -0
  21. data/lib/og/adapter/postgresql/script.rb +15 -0
  22. data/lib/og/adapter/postgresql/utils.rb +35 -0
  23. data/lib/og/adapter/sqlite.rb +132 -0
  24. data/lib/og/adapter/sqlite/override.rb +33 -0
  25. data/lib/og/adapter/sqlite/script.rb +15 -0
  26. data/lib/og/collection.rb +35 -7
  27. data/lib/og/{evolution.rb → dump.rb} +4 -5
  28. data/lib/og/entity.rb +102 -173
  29. data/lib/og/entity/clone.rb +119 -0
  30. data/lib/og/errors.rb +0 -2
  31. data/lib/og/manager.rb +85 -37
  32. data/lib/og/relation.rb +52 -34
  33. data/lib/og/relation/belongs_to.rb +0 -2
  34. data/lib/og/relation/has_many.rb +27 -4
  35. data/lib/og/relation/joins_many.rb +41 -14
  36. data/lib/og/relation/many_to_many.rb +10 -0
  37. data/lib/og/relation/refers_to.rb +22 -5
  38. data/lib/og/store.rb +80 -86
  39. data/lib/og/store/sql.rb +710 -713
  40. data/lib/og/store/sql/evolution.rb +119 -0
  41. data/lib/og/store/sql/join.rb +155 -0
  42. data/lib/og/store/sql/utils.rb +149 -0
  43. data/lib/og/test/assertions.rb +1 -3
  44. data/lib/og/test/testcase.rb +0 -2
  45. data/lib/og/types.rb +2 -5
  46. data/lib/og/validation.rb +6 -9
  47. data/test/{og/mixin → glue}/tc_hierarchical.rb +3 -13
  48. data/test/glue/tc_og_paginate.rb +47 -0
  49. data/test/{og/mixin → glue}/tc_optimistic_locking.rb +2 -12
  50. data/test/{og/mixin → glue}/tc_orderable.rb +15 -23
  51. data/test/glue/tc_orderable2.rb +47 -0
  52. data/test/glue/tc_revisable.rb +3 -3
  53. data/test/{og/mixin → glue}/tc_taggable.rb +20 -10
  54. data/test/{og/mixin → glue}/tc_timestamped.rb +2 -12
  55. data/test/glue/tc_webfile.rb +36 -0
  56. data/test/og/CONFIG.rb +8 -11
  57. data/test/og/multi_validations_model.rb +14 -0
  58. data/test/og/store/tc_filesys.rb +3 -1
  59. data/test/og/store/tc_kirby.rb +16 -13
  60. data/test/og/store/tc_sti.rb +11 -11
  61. data/test/og/store/tc_sti2.rb +79 -0
  62. data/test/og/tc_build.rb +41 -0
  63. data/test/og/tc_cacheable.rb +3 -2
  64. data/test/og/tc_has_many.rb +96 -0
  65. data/test/og/tc_inheritance.rb +6 -4
  66. data/test/og/tc_joins_many.rb +93 -0
  67. data/test/og/tc_multi_validations.rb +5 -7
  68. data/test/og/tc_multiple.rb +7 -6
  69. data/test/og/tc_override.rb +13 -7
  70. data/test/og/tc_primary_key.rb +30 -0
  71. data/test/og/tc_relation.rb +8 -14
  72. data/test/og/tc_reldelete.rb +163 -0
  73. data/test/og/tc_reverse.rb +17 -14
  74. data/test/og/tc_scoped.rb +3 -11
  75. data/test/og/tc_setup.rb +13 -11
  76. data/test/og/tc_store.rb +21 -28
  77. data/test/og/tc_validation2.rb +2 -2
  78. data/test/og/tc_validation_loop.rb +17 -15
  79. metadata +109 -103
  80. data/INSTALL +0 -91
  81. data/ProjectInfo +0 -51
  82. data/README +0 -177
  83. data/doc/config.txt +0 -28
  84. data/examples/README +0 -23
  85. data/examples/mysql_to_psql.rb +0 -71
  86. data/examples/run.rb +0 -271
  87. data/lib/glue/tree.rb +0 -218
  88. data/lib/og/store/alpha/filesys.rb +0 -110
  89. data/lib/og/store/alpha/memory.rb +0 -295
  90. data/lib/og/store/alpha/sqlserver.rb +0 -256
  91. data/lib/og/store/kirby.rb +0 -490
  92. data/lib/og/store/mysql.rb +0 -415
  93. data/lib/og/store/psql.rb +0 -875
  94. data/lib/og/store/sqlite.rb +0 -348
  95. data/lib/og/store/sqlite2.rb +0 -241
  96. data/setup.rb +0 -1585
  97. data/test/og/tc_sti_find.rb +0 -35
@@ -2,15 +2,15 @@ require 'glue/validation'
2
2
 
3
3
  module Glue
4
4
 
5
- # Extend the Validation methods defined in glue/validation.rb with
6
- # extra db related options.
5
+ # Extend the Validation methods defined in glue/validation.rb
6
+ # with extra db related options.
7
7
 
8
8
  module Validation
9
9
 
10
10
  # Encapsulates a list of validation errors.
11
11
 
12
12
  class Errors
13
- setting :invalid_relation, :default => 'Invalid relations'
13
+ setting :invalid_relation, :default => "Undefined"
14
14
  setting :not_unique, :default => 'The value is already used'
15
15
  end
16
16
 
@@ -32,7 +32,7 @@ module Validation
32
32
  # validate_unique.
33
33
  #++
34
34
 
35
- def validate_unique(*params)
35
+ def validate_unique *params
36
36
  c = parse_config(params, :on => :save)
37
37
 
38
38
  params.each do |field|
@@ -72,7 +72,7 @@ module Validation
72
72
  # belongs_to :uncle, Uncle
73
73
  # end
74
74
 
75
- def validate_related(*params)
75
+ def validate_related *params
76
76
  c = parse_config(params,
77
77
  :msg => Glue::Validation::Errors.invalid_relation,
78
78
  :on => :save
@@ -93,13 +93,10 @@ module Validation
93
93
  end
94
94
  end
95
95
 
96
- alias_method :validate_associated, :validate_related
96
+ alias validate_associated validate_related
97
97
 
98
98
  end
99
99
 
100
100
  end
101
101
 
102
102
  end
103
-
104
- # * George Moschovitis <gm@navel.gr>
105
- # * Bryan Soto
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
2
2
 
3
3
  require 'rubygems'
4
4
  require 'facets'
@@ -8,21 +8,11 @@ require 'ostruct'
8
8
  require 'og'
9
9
  require 'glue/hierarchical'
10
10
 
11
- =begin
12
- $og = Og.setup(
13
- :store => 'mysql',
14
- :name => 'test',
15
- :user => 'root',
16
- :password => 'navelrulez',
17
- :destroy => true
18
- )
19
- =end
20
-
21
11
  class TC_OgHierarchical < Test::Unit::TestCase # :nodoc: all
22
12
 
23
13
  class Comment
24
- property :body, String
25
- property :create_time, Time
14
+ attr_accessor :body, String
15
+ attr_accessor :create_time, Time
26
16
 
27
17
  include Glue::NestedSets
28
18
 
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
2
+
3
+ require 'test/unit'
4
+
5
+ require 'nitro/helper/pager'
6
+
7
+ class TC_OgPaginate < Test::Unit::TestCase # :nodoc: all
8
+ include Nitro
9
+ include Nitro::PagerHelper
10
+
11
+ class RequestMock < Hash
12
+ attr_accessor :query
13
+
14
+ def initialize
15
+ @query = {}
16
+ end
17
+
18
+ def get(k, default)
19
+ return self[k] || default
20
+ end
21
+ end
22
+
23
+ def request
24
+ RequestMock.new
25
+ end
26
+
27
+ class Person
28
+ attr_accessor :name, String
29
+
30
+ def initialize(name)
31
+ @name = "Name #{name}"
32
+ end
33
+ end
34
+
35
+ $og1.manage_classes(Person)
36
+
37
+ def test_all
38
+ (1..5).each do |i|
39
+ Person.create(i)
40
+ end
41
+
42
+ items, pager = paginate(Person, :per_page => 2)
43
+ assert_equal 5, pager.total_count
44
+ assert_equal 2, items.size
45
+ end
46
+
47
+ end
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
2
2
 
3
3
  require 'rubygems'
4
4
  require 'facets'
@@ -7,21 +7,11 @@ require 'test/unit'
7
7
  require 'og'
8
8
  require 'glue/optimistic_locking'
9
9
 
10
- =begin
11
- $og = Og.setup(
12
- :store => 'psql',
13
- :name => 'test',
14
- :user => 'postgres',
15
- :password => 'navelrulez',
16
- :destroy => true
17
- )
18
- =end
19
-
20
10
  class TC_OgLocking < Test::Unit::TestCase # :nodoc: all
21
11
  include Og
22
12
 
23
13
  class Article
24
- property :body, String
14
+ attr_accessor :body, String
25
15
  include Glue::Locking
26
16
 
27
17
  def initialize(body)
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
2
2
 
3
3
  require 'rubygems'
4
4
  require 'facets'
@@ -8,21 +8,11 @@ require 'ostruct'
8
8
  require 'og'
9
9
  require 'glue/orderable'
10
10
 
11
- =begin
12
- $og = Og.setup(
13
- :store => 'psql',
14
- # :store => :memory,
15
- :name => 'test',
16
- :user => 'postgres',
17
- :password => 'navelrulez',
18
- :destroy => true
19
- )
20
- =end
21
-
22
11
  class TestCaseOgOrderable < Test::Unit::TestCase # :nodoc: all
23
-
12
+ include Glue
13
+
24
14
  class Article
25
- property :title, :body, String
15
+ attr_accessor :title, :body, String
26
16
  has_many :comments, Comment, :list => true, :order => 'position DESC'
27
17
 
28
18
  def initialize(title = nil)
@@ -31,10 +21,12 @@ class TestCaseOgOrderable < Test::Unit::TestCase # :nodoc: all
31
21
  end
32
22
 
33
23
  class Comment
34
- property :body, String
35
- belongs_to :article, Article
24
+ attr_accessor :body, String
25
+ belongs_to :article
36
26
 
37
- is Glue::Orderable, :scope => :article
27
+ # We have to set the parent before inserting the comment
28
+ # for the scope to work!
29
+ is Orderable #, :scope => :article
38
30
 
39
31
  def initialize(body = nil)
40
32
  @body = body
@@ -42,15 +34,15 @@ class TestCaseOgOrderable < Test::Unit::TestCase # :nodoc: all
42
34
  end
43
35
 
44
36
  class Playlist
45
- prop :name, String
46
- has_many Track
37
+ attr_accessor :name, String
38
+ has_many :tracks
47
39
  end
48
40
 
49
41
  class Track
50
- prop :name, String
51
- is Glue::Orderable, :scope => :playlist
42
+ attr_accessor :name, String
43
+ is Orderable, :scope => :playlist
52
44
 
53
- belongs_to Playlist
45
+ belongs_to :playlist
54
46
 
55
47
  def initialize(name, playlist)
56
48
  @name = name
@@ -143,7 +135,7 @@ class TestCaseOgOrderable < Test::Unit::TestCase # :nodoc: all
143
135
  tr.move_to(3)
144
136
  assert_equal(3, tr.position)
145
137
 
146
- assert_equal(%w{two three five four one six}, track_list() )
138
+ assert_equal( %w{two three five four one six}, track_list() )
147
139
  end
148
140
 
149
141
  end
@@ -0,0 +1,47 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
2
+
3
+ $DBG = true
4
+
5
+ require 'test/unit'
6
+
7
+ require 'og'
8
+ require 'glue/orderable'
9
+
10
+ class TestOgOrderable < Test::Unit::TestCase # :nodoc: all
11
+
12
+ class Article
13
+ is Glue::Orderable
14
+ attr_accessor :body, String, :revisable => true
15
+ attr_accessor :title, String
16
+
17
+ def initialize(t, b)
18
+ @title, @body = t, b
19
+ end
20
+ end
21
+
22
+ $og1.manage_classes(Article)
23
+
24
+ def test_all
25
+ a1 = Article.create('hello', 'world')
26
+ a2 = Article.create('another', 'one')
27
+ a3 = Article.create('great', 'stuff')
28
+
29
+ assert_equal 1, a1.position
30
+ assert_equal 2, a2.position
31
+ assert_equal 3, a3.position
32
+
33
+ a2.move_higher
34
+
35
+ a1 = Article.find_by_title('hello')
36
+ a2 = Article.find_by_title('another')
37
+
38
+ assert_equal 1, a2.position
39
+ assert_equal 2, a1.position
40
+
41
+ a1.orderable_position = 32
42
+ assert_equal 32, a1.position
43
+
44
+
45
+ end
46
+
47
+ end
@@ -9,15 +9,15 @@ class TestOgRevisable < Test::Unit::TestCase # :nodoc: all
9
9
 
10
10
  class Article
11
11
  is Glue::Revisable
12
- property :body, String, :revisable => true
13
- property :title, String
12
+ attr_accessor :body, String, :revisable => true
13
+ attr_accessor :title, String
14
14
 
15
15
  def initialize(t, b)
16
16
  @title, @body = t, b
17
17
  end
18
18
  end
19
19
 
20
- $og1.manage_classes(Article)
20
+ $og1.manage_classes(Article, Article::Revision)
21
21
 
22
22
  def test_all
23
23
  a = Article.create('hello', 'world')
@@ -1,6 +1,4 @@
1
- $DBG = true
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
4
2
 
5
3
  require 'rubygems'
6
4
  require 'facets'
@@ -13,7 +11,7 @@ require 'glue/taggable'
13
11
  class TestOgTaggable < Test::Unit::TestCase # :nodoc: all
14
12
 
15
13
  class Article
16
- property :title, :body, String
14
+ attr_accessor :title, :body, String
17
15
  is Taggable
18
16
 
19
17
  def initialize(title = nil)
@@ -21,11 +19,11 @@ class TestOgTaggable < Test::Unit::TestCase # :nodoc: all
21
19
  end
22
20
  end
23
21
 
24
- $og1.manage_classes(Article)
22
+ $og1.manage_classes(Article, Tag)
25
23
 
26
24
  def test_all
27
25
  a1 = Article.create('Hello')
28
- a1.tag('navel gmosx sexy')
26
+ a1.tag('great gmosx sexy')
29
27
  a1.save
30
28
 
31
29
  a2 = Article.create('Other')
@@ -39,13 +37,13 @@ class TestOgTaggable < Test::Unit::TestCase # :nodoc: all
39
37
 
40
38
  assert_equal 6, Tag.count
41
39
  assert_equal 3, a1.tags.size
42
- assert a1.tag_names.include?('navel')
40
+ assert a1.tag_names.include?('great')
43
41
 
44
- assert a1.tagged_with?('navel')
42
+ assert a1.tagged_with?('great')
45
43
 
46
44
  assert_equal false, a1.tagged_with?('photo')
47
45
 
48
- res = Article.find_with_tags('navel', 'gmosx')
46
+ res = Article.find_with_tags('great', 'gmosx')
49
47
  assert_equal 1, res.size
50
48
  assert_equal 'Hello', res[0].title
51
49
 
@@ -55,12 +53,24 @@ class TestOgTaggable < Test::Unit::TestCase # :nodoc: all
55
53
  assert res.include?('Hello')
56
54
  assert res.include?('Other')
57
55
 
58
- res = Article.find_with_any_tag('navel', 'gmosx', 'phd')
56
+ res = Article.find_with_any_tag('great', 'gmosx', 'phd')
59
57
  assert_equal 3, res.size
60
58
 
61
59
  a1.delete_all_tags
62
60
  assert_equal 0, a1.tags.size
63
61
 
62
+ assert_equal 4, Tag.count
63
+
64
+ Tag.all.each do |tag|
65
+ n = case tag.name
66
+ when 'rain', 'phd', 'name': 1
67
+ when 'gmosx': 1
68
+ else flunk tag.name + ' not expected'
69
+ end
70
+
71
+ assert n, tag.count
72
+ end
73
+
64
74
  =begin
65
75
  TODO:
66
76
  Article.fing_with_no_tag('gmosx')
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
2
2
 
3
3
  require 'rubygems'
4
4
  require 'facets'
@@ -8,21 +8,11 @@ require 'ostruct'
8
8
  require 'og'
9
9
  require 'glue/timestamped'
10
10
 
11
- =begin
12
- $og = Og.setup(
13
- :store => 'psql',
14
- :name => 'test',
15
- :user => 'postgres',
16
- :password => 'navelrulez',
17
- :destroy => true
18
- )
19
- =end
20
-
21
11
  class TestCaseOgTimestamped < Test::Unit::TestCase # :nodoc: all
22
12
 
23
13
  class Article
24
14
  is Glue::Timestamped
25
- property :body, String
15
+ attr_accessor :body, String
26
16
 
27
17
  def initialize(body = nil)
28
18
  @body = body
@@ -0,0 +1,36 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'og', 'CONFIG.rb')
2
+
3
+ require 'test/unit'
4
+
5
+ require 'nitro/cgi/request'
6
+ require 'og'
7
+ require 'glue/webfile'
8
+
9
+ class TC_Webfile < Test::Unit::TestCase # :nodoc: all
10
+
11
+ class Image
12
+ def self.webfile_path request, name
13
+ File.join(Uploads.public_root, request.user.name, 'icon.png')
14
+ end
15
+
16
+ attr_accessor :file, WebFile, :magick => { :small => '64x64', :medium => '96x96' }
17
+
18
+ def initialize(file)
19
+ @file = file
20
+ end
21
+ end
22
+
23
+ class NonImage
24
+ attr_accessor :file, WebFile
25
+ end
26
+
27
+ $og1.manage_classes(Image, NonImage)
28
+
29
+ def test_all
30
+ im = Image.new('me')
31
+ noim = NonImage.new
32
+
33
+ assert_equal 'me', im.file
34
+ assert noim
35
+ end
36
+ end
@@ -34,16 +34,16 @@ $DBG = debug
34
34
 
35
35
  og_mysql = {
36
36
  :destroy => true,
37
- :store => :mysql,
37
+ :adapter => :mysql,
38
38
  :user => 'root',
39
39
  :name => 'test',
40
- # :password => 'navelrulez',
40
+ # :password => 'gmrulez',
41
41
  # :socket => '/var/run/mysqld/mysqld.sock'
42
42
  }
43
43
 
44
44
  og_psql = {
45
45
  :destroy => true,
46
- :store => :psql,
46
+ :adapter => :psql,
47
47
  :user => 'postgres',
48
48
  :password => 'postgres',
49
49
  :name => 'test'
@@ -51,19 +51,19 @@ og_psql = {
51
51
 
52
52
  og_sqlite = {
53
53
  :destroy => true,
54
- :store => :sqlite,
54
+ :adapter => :sqlite,
55
55
  :name => 'test'
56
56
  }
57
57
 
58
58
  og_kirby = {
59
59
  :destroy => true,
60
- :store => :kirby,
60
+ :adapter => :kirby,
61
61
  :name => 'test',
62
62
  :embedded => true
63
63
  }
64
64
 
65
65
  og_memory = {
66
- :store => :memory,
66
+ :adapter => :memory,
67
67
  :name => :test,
68
68
  :destroy => true
69
69
  }
@@ -82,10 +82,7 @@ require 'og'
82
82
 
83
83
  Logger.get.level = Logger::WARN unless $DBG
84
84
 
85
- $og1 ||= Og.setup(@og_config1)
86
- $og2 ||= Og.setup(@og_config2)
85
+ $og1 ||= Og.start(@og_config1)
86
+ $og2 ||= Og.start(@og_config2)
87
87
 
88
88
  Og.thread_safe = false if Og.thread_safe
89
-
90
- # * Tom Sawyer <transfire@gmail.com>
91
- # * George Moschovitis <gm@navel.gr>