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
@@ -1,8 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
+
3
+ require 'test/unit'
4
+
5
+ require 'glue'
6
+ require 'glue/validation'
7
+ require 'og/validation'
8
+
1
9
  class TC_MultiValidation < Test::Unit::TestCase # :nodoc: all
2
10
  class User
11
+ include Glue::Validation
12
+
3
13
  property :name
4
14
 
5
15
  validate_value :name
6
16
  validate_unique :name
7
17
  end
18
+
19
+ def test_empty
20
+ assert TC_MultiValidation.const_defined?('User')
21
+ end
8
22
  end
@@ -1,10 +1,11 @@
1
+ =begin FileSys is currently not available.
2
+
1
3
  require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
2
4
  require 'rubygems'
3
5
  require 'facets'
4
6
  require 'test/unit'
5
7
  require 'og'
6
8
 
7
- =begin FileSys is currently inaccessible through Og.setup?
8
9
  class TestCaseOgFilesys < Test::Unit::TestCase # :nodoc: all
9
10
  include Og
10
11
 
@@ -72,4 +73,5 @@ class TestCaseOgFilesys < Test::Unit::TestCase # :nodoc: all
72
73
  end
73
74
 
74
75
  end
76
+
75
77
  =end
@@ -1,22 +1,22 @@
1
- require 'rubygems'
2
- require 'facets'
3
- require 'test/unit'
4
- require 'og'
1
+ =begin KirbyBase is currently not available.
5
2
 
6
- # $DBG = true
3
+ require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
7
4
 
8
- =begin
9
- class TC_Kirby < Test::Unit::TestCase # :nodoc: all
5
+ require 'test/unit'
10
6
 
11
- og = Og.setup( :destroy => true, :store => :kirby, :manual_management => true)
7
+ begin
12
8
 
9
+ og = Og.setup( :destroy => true, :store => :kirby, :manual_management => true)
10
+
11
+ class TC_Kirby < Test::Unit::TestCase # :nodoc: all
12
+
13
13
  class Track
14
- prop_accessor :name, String
14
+ attr_accessor :name, String
15
15
  belongs_to Disc
16
16
  end
17
17
 
18
18
  class Disc
19
- prop_accessor :name, String
19
+ attr_accessor :name, String
20
20
  has_many Track
21
21
  end
22
22
 
@@ -26,11 +26,14 @@ class TC_Kirby < Test::Unit::TestCase # :nodoc: all
26
26
  d = Disc.create
27
27
  t = Track.create
28
28
  d.tracks << t
29
-
29
+
30
30
  assert_equal 1, d.tracks.size
31
31
  end
32
32
 
33
33
  end
34
- =end
35
34
 
36
- # * Guillaume Pierronnet <guillaume.pierronnet@gmail.com>
35
+ rescue LoadError => e
36
+ puts 'Skipping Kirby test, adapter not found.'
37
+ end
38
+
39
+ =end
@@ -7,20 +7,20 @@ require 'og/store/sql'
7
7
 
8
8
  class TC_Sti < Test::Unit::TestCase
9
9
  class StiParent
10
- property :one
11
- property :two
12
-
13
- schema_inheritance
10
+ is Og::SchemaInheritanceBase
11
+
12
+ property :one, String
13
+ property :two, String
14
14
  end
15
15
 
16
16
  class StiChild < StiParent
17
- property :three
17
+ property :three, String
18
18
  end
19
19
 
20
20
  $og1.manage_classes(StiParent, StiChild)
21
21
 
22
22
  def setup
23
- @store = Og::SqlStore.new(nil)
23
+ @store = $og1.store
24
24
  end
25
25
 
26
26
  def teardown
@@ -56,9 +56,9 @@ end
56
56
 
57
57
  class TC_Sti_OgType < Test::Unit::TestCase
58
58
  class Human
59
- property :name
60
-
61
- schema_inheritance
59
+ is Og::SchemaInheritanceBase
60
+
61
+ property :name, String
62
62
 
63
63
  def initialize(name)
64
64
  @name = name
@@ -66,11 +66,11 @@ class TC_Sti_OgType < Test::Unit::TestCase
66
66
  end
67
67
 
68
68
  class Parent < Human
69
- property :job
69
+ property :job, String
70
70
  end
71
71
 
72
72
  class Child < Human
73
- property :toys
73
+ property :toys, String
74
74
  end
75
75
 
76
76
  $og1.manage_classes(Human, Parent, Child)
@@ -0,0 +1,79 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
2
+
3
+ require 'rubygems'
4
+ require 'test/unit'
5
+ require 'ostruct'
6
+
7
+ require 'og'
8
+
9
+ class TC_STI2 < Test::Unit::TestCase
10
+
11
+ class User
12
+ is Og::SchemaInheritanceBase
13
+
14
+ property :name, String
15
+
16
+ has_one Login
17
+
18
+ # This triggered a bug when called from a subclass
19
+ has_many :pets, Pet#, :foreign_name => 'user'
20
+ end
21
+
22
+ class Admin < User
23
+ property :admin_praise, String
24
+ end
25
+
26
+ class Login
27
+ property :pass, String
28
+
29
+ belongs_to User
30
+ end
31
+
32
+ class Pet
33
+ property :name, String
34
+
35
+ belongs_to User
36
+ end
37
+
38
+ def request
39
+ o = OpenStruct.new
40
+ o.params = {:name => 'George', :pass => 'Secret'}
41
+ return o
42
+ end
43
+
44
+ $og1.manage_classes User, Login, Admin, Pet
45
+
46
+ def setup
47
+ @user = Admin.create_with(request.params)
48
+ @login = Login.create_with(request.params)
49
+ end
50
+
51
+ def teardown
52
+ [User, Login, Pet].map {|x| x.delete_all}
53
+ end
54
+
55
+ def test_setup
56
+ assert_equal 1, User.count
57
+ assert_equal 1, Login.count
58
+ end
59
+
60
+ def test_assign
61
+ @user.login = @login
62
+ end
63
+
64
+ def test_has_many
65
+ pets = nil
66
+ assert_nothing_raised do
67
+ pets = @user.pets.size
68
+ end
69
+
70
+ assert_equal 0, pets
71
+
72
+ p1 = Pet.create_with(:name => 'Ziza')
73
+
74
+ @user.pets << p1
75
+
76
+ assert_equal 1, @user.pets(:reload => true).size
77
+ end
78
+
79
+ end
@@ -0,0 +1,41 @@
1
+ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
+
3
+ require 'rubygems'
4
+ require 'facets'
5
+
6
+ require 'test/unit'
7
+ require 'og'
8
+ require 'glue/timestamped'
9
+
10
+ class TC_OgAggrCalc < Test::Unit::TestCase # :nodoc: all
11
+ include Og
12
+
13
+ class Category
14
+ attr_accessor :name, String
15
+ end
16
+
17
+ class User
18
+ attr_accessor :name, String
19
+ joins_many Category
20
+
21
+ def initialize name
22
+ @name = name
23
+ end
24
+ end
25
+
26
+ $og1.manage_classes(User, Category)
27
+
28
+ def test_all
29
+ c1 = Category.create_with :name => 'one'
30
+ c2 = Category.create_with :name => 'two'
31
+
32
+ u = User.new 'gmosx'
33
+ u.categories << c1
34
+ u.categories << c2
35
+ u.save
36
+
37
+ g = User[1]
38
+ assert_equal 2, g.categories.size
39
+ end
40
+
41
+ end
@@ -191,7 +191,8 @@ begin
191
191
  end
192
192
  end
193
193
  end
194
- rescue Object
195
- puts 'MemCached sever not running, skipping test'
194
+ rescue Errno::ECONNREFUSED => ex # FIXME: Lookup Win32/Linux/BSD error
195
+ Logger.warn "skipping memcached test: server not running"
196
+ #Logger.warn ex.class # FIXME: remove when all error types listed above
196
197
  end
197
198
 
@@ -0,0 +1,96 @@
1
+ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
+
3
+ require 'rubygems'
4
+ require 'facets'
5
+
6
+ require 'test/unit'
7
+ require 'og'
8
+ require 'glue/timestamped'
9
+
10
+ class TC_JoinsMany < Test::Unit::TestCase # :nodoc: all
11
+ include Og
12
+
13
+ class Item
14
+ property :name, String
15
+
16
+ has_many Tag
17
+ end
18
+
19
+ class Tag
20
+ property :name, String
21
+
22
+ belongs_to Item
23
+ end
24
+
25
+ $og1.manage_classes(Item, Tag)
26
+
27
+ def setup
28
+ @conn = $og1.conn
29
+
30
+ @name = 'George'
31
+ end
32
+
33
+ def teardown
34
+ Item.delete_all
35
+ Tag.delete_all
36
+ end
37
+
38
+ def test_assign_with_name
39
+ i = Item.create_with(:name => @name)
40
+
41
+ assert_equal @name, i.name
42
+ end
43
+
44
+ def test_concat
45
+ tag = Tag.create_with(:name => 'Nitro')
46
+ i = Item.create_with(:name => @name)
47
+
48
+ i.tags << tag
49
+
50
+ assert_equal 1, i.tags.size
51
+ assert_equal tag, i.tags.first
52
+ end
53
+
54
+ def test_add
55
+ tag = Tag.create_with(:name => 'Facets')
56
+ i = Item.create_with(:name => @name)
57
+
58
+ i.add_tag tag
59
+
60
+ assert_equal 1, i.tags.size
61
+ assert_equal tag, i.tags.first
62
+ end
63
+
64
+ def test_assign_with_tag
65
+ tag = Tag.create_with(:name => 'Nitro')
66
+
67
+ assert_not_nil tag.saved?
68
+
69
+ i = Item.create_with(:name => @name, :tags => tag)
70
+
71
+ assert_not_nil i.saved?
72
+ assert_equal tag, i.tags.first
73
+ end
74
+
75
+ def test_assign_with_tags
76
+ tags = [Tag.create_with(:name => 'Glue'), Tag.create_with(:name => 'Og')]
77
+ i = Item.create_with(:name => @name, :tags => tags)
78
+
79
+ assert_equal tags, i.tags.to_ary
80
+ end
81
+
82
+ def test_assign_with_collection
83
+ coll = HasManyCollection.new(
84
+ Item,
85
+ Tag,
86
+ :add_tag,
87
+ :remove_tag,
88
+ :find_tags,
89
+ :count_tags
90
+ )
91
+ i = Item.create_with(:name => @name, :tags => coll)
92
+
93
+ assert_equal coll, i.instance_variable_get("@tags")
94
+ end
95
+
96
+ end
@@ -37,7 +37,7 @@ class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all
37
37
  end
38
38
 
39
39
  class Car
40
- property :name
40
+ property :name, String
41
41
  belongs_to :admin
42
42
  end
43
43
 
@@ -49,7 +49,7 @@ class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all
49
49
 
50
50
  class Admin < User
51
51
  property :password, String
52
- has_one Car
52
+ #has_one Car
53
53
  end
54
54
 
55
55
  $og1.manage_classes(Document, Article, Document, Photo, Car, User, Admin)
@@ -102,7 +102,9 @@ class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all
102
102
  assert_equal 2, articles.size
103
103
 
104
104
  # Bug report.
105
- Admin.create
106
- Admin.create.car
105
+ # This happens when creating a has_one Car in Admin, which is wrong
106
+ # because it overrides the joins_many from User.
107
+ #Admin.create
108
+ #Admin.create.car
107
109
  end
108
110
  end
@@ -0,0 +1,93 @@
1
+ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
+
3
+ require 'rubygems'
4
+ require 'facets'
5
+
6
+ require 'test/unit'
7
+ require 'og'
8
+ require 'glue/timestamped'
9
+
10
+ class TC_JoinsMany < Test::Unit::TestCase # :nodoc: all
11
+ include Og
12
+
13
+ class Item
14
+ property :name, String
15
+
16
+ joins_many Tag
17
+
18
+ def to_s
19
+ @name
20
+ end
21
+ end
22
+
23
+ class Tag
24
+ property :name, String
25
+
26
+ def to_s
27
+ @name
28
+ end
29
+ end
30
+
31
+ def setup
32
+ $og1.manage_classes(Item, Tag)
33
+ @conn = $og1.conn
34
+ end
35
+
36
+ def test_all
37
+ (1..3).each do |n|
38
+ t = Tag.new
39
+ t.name = "Tag_#{n}"
40
+ t.save
41
+ end
42
+
43
+ assert_equal 3, Tag.all.size
44
+
45
+ # see if i can get a tag back from th db
46
+ t = Tag.find_by_name("Tag_1")
47
+
48
+ assert_not_nil t
49
+
50
+ i1 = Item.new
51
+ i1.name = "Item_1"
52
+ i1.save
53
+ i1.add_tag(Tag.find_by_name("Tag_1"))
54
+ i1.add_tag(Tag.find_by_name("Tag_2"))
55
+ i1.save
56
+
57
+ i2 = Item.new
58
+ i2.name = "Item_2"
59
+ i2.save
60
+ i2.add_tag(Tag.find_by_name("Tag_2"))
61
+ i2.add_tag(Tag.find_by_name("Tag_3"))
62
+ i2.save
63
+
64
+ # count SQL, note that the join table will change when test class changes
65
+
66
+ sql = 'SELECT count(*) FROM ogj_tc_joinsmany_item_tc_joinsmany_tag'
67
+
68
+ # after inserting 2 tags into the each of the 2 items, 4 relations
69
+
70
+ assert_equal 4, @conn.query(sql).first_value.to_i
71
+
72
+ i1.delete(true)
73
+ i2.delete(true)
74
+
75
+ # after deleting the 2 items, the relations are invalid
76
+
77
+ assert_equal 0, @conn.query(sql).first_value.to_i
78
+
79
+ # the following code is new and should not trigger an exception due to
80
+ # existing items in the mapping table
81
+
82
+ assert_nothing_raised do
83
+ i3 = Item.new
84
+ i3.name = "Item_3"
85
+ i3.save
86
+ i3.add_tag(Tag.find_by_name("Tag_1"))
87
+ i3.add_tag(Tag.find_by_name("Tag_2"))
88
+ i3.save
89
+ end
90
+
91
+ end
92
+
93
+ end