og 0.40.0 → 0.41.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module Og
7
7
  # Marker module. If included in a class, the Og automanager
8
8
  # ignores this class.
9
9
 
10
- module Unmanageable;
10
+ module Unmanageable
11
11
  def self.included(base)
12
12
  Og.unmanageable_classes << base
13
13
  end
@@ -18,6 +18,14 @@ end
18
18
  # pattern. Ie, all the subclasses of the base
19
19
  # class are stored in the same schema (table).
20
20
 
21
- module SchemaInheritanceBase; end
21
+ module SchemaInheritanceBase
22
+ def self.included(base)
23
+
24
+ # This class is a superclass in a single table inheritance
25
+ # chain. So inject a special class ogtype field that
26
+ # holds the class name.
27
+ base.attr_accessor :ogtype, String, :sql => 'VARCHAR(30)'
28
+ end
29
+ end
22
30
 
23
31
  end
@@ -350,7 +350,7 @@ class SqlStore < Store
350
350
  if table_type = @options[:table_type]
351
351
  sql << ") TYPE = #{table_type};"
352
352
  else
353
- sql << ");"
353
+ sql << ")"
354
354
  end
355
355
 
356
356
  # Create indices.
@@ -639,7 +639,7 @@ class SqlStore < Store
639
639
  if klass.schema_inheritance?
640
640
  for desc in klass.schema_inheritance_root_class.descendents
641
641
  attrs.concat desc.serializable_attributes
642
- end
642
+ end
643
643
  end
644
644
  return attrs.uniq
645
645
  end
@@ -679,15 +679,6 @@ class SqlStore < Store
679
679
  fields = []
680
680
  attrs = serializable_attributes_for_class(klass)
681
681
 
682
- # FIXME: move to serializable attributes.
683
-
684
- if klass.schema_inheritance?
685
- # This class is a superclass in a single table inheritance
686
- # chain. So inject a special class ogtype field that
687
- # holds the class name.
688
- fields << "ogtype VARCHAR(30)"
689
- end
690
-
691
682
  for a in attrs
692
683
  anno = klass.ann[a]
693
684
  if anno.null?
@@ -867,8 +858,7 @@ class SqlStore < Store
867
858
  # an ogtype serializable attribute.
868
859
 
869
860
  if klass.schema_inheritance?
870
- fields << :ogtype
871
- values << quote(klass.name)
861
+ values[fields.index(:ogtype)] = quote(klass.name)
872
862
  end
873
863
 
874
864
  fields = fields.join(', ')
@@ -1007,7 +997,14 @@ class SqlStore < Store
1007
997
  if klass.schema_inheritance?
1008
998
  klass.module_eval %{
1009
999
  def self.og_allocate(res, row = 0)
1010
- Object.constant(res[0]).allocate
1000
+ Object.constant(res['ogtype']).allocate
1001
+ rescue TypeError => e
1002
+ # TODO: use res['ogtype'] here, this is slow!
1003
+ # But res['ogtype'] isn't implemented in -pr and some mysql exts,
1004
+ # create compat layer
1005
+ col = ogmanager.store.create_field_map(self)[:ogtype]
1006
+ ogmanager.put_store
1007
+ Object.constant(res[col]).allocate
1011
1008
  end
1012
1009
  }
1013
1010
  else
@@ -60,7 +60,7 @@ module Evolution
60
60
  return unless @options[:evolve_schema]
61
61
 
62
62
  sql_fields = create_field_map(klass).keys
63
- attrs = klass.serializable_attributes
63
+ attrs = serializable_attributes_for_class(klass)
64
64
 
65
65
  # Add new fields to the table.
66
66
 
@@ -18,22 +18,38 @@ class TestOgTaggable < Test::Unit::TestCase # :nodoc: all
18
18
  @title = title
19
19
  end
20
20
  end
21
+
22
+ class Second
23
+ attr_accessor :haha, String
24
+ is Taggable
25
+ end
21
26
 
22
- $og1.manage_classes(Article, Tag)
23
-
24
- def test_all
25
- a1 = Article.create('Hello')
26
- a1.tag('great gmosx sexy')
27
- a1.save
27
+ $og1.manage_classes(Article, Tag, Second)
28
+
29
+ def setup
30
+ @a1 = Article.create('Hello')
31
+ @a1.tag('great gmosx sexy')
32
+ @a1.save
28
33
 
29
- a2 = Article.create('Other')
30
- a2.tag('gmosx rain')
31
- a2.save
34
+ @a2 = Article.create('Other')
35
+ @a2.tag('gmosx rain')
36
+ @a2.save
32
37
 
33
- a3 = Article.create('George')
34
- a3.tag('phd name')
35
- a3.save
38
+ @a3 = Article.create('George')
39
+ @a3.tag('phd name')
40
+ @a3.save
41
+
42
+ @s1 = Second.create
43
+ @s1.tag('gmosx')
44
+ @s1.save
45
+ end
46
+
47
+ def teardown
48
+ [Tag, Article, Second].each {|x| x.delete_all }
49
+ end
36
50
 
51
+ def test_all
52
+ a1, a2, a3 = @a1, @a2, @a3
37
53
 
38
54
  assert_equal 6, Tag.count
39
55
  assert_equal 3, a1.tags.size
@@ -71,6 +87,13 @@ class TestOgTaggable < Test::Unit::TestCase # :nodoc: all
71
87
  assert n, tag.count
72
88
  end
73
89
 
90
+ a = Second.create
91
+ b = Second.create
92
+ b.tag('hello world heh')
93
+ a.tag('hello heh george gmosx')
94
+
95
+ assert_equal 2, Second.find_with_tags('hello', 'heh').size
96
+
74
97
  =begin
75
98
  TODO:
76
99
  Article.fing_with_no_tag('gmosx')
@@ -78,5 +101,17 @@ class TestOgTaggable < Test::Unit::TestCase # :nodoc: all
78
101
  Article.find_by_tags(:with => '', :any => '', :no => '')
79
102
  =end
80
103
  end
104
+
105
+ def test_tag_tagged
106
+ t = Tag.find_by_name('gmosx')
107
+
108
+ assert_not_nil t
109
+ assert_equal 'gmosx', t.name
110
+
111
+ a = Article.relations.reject {|x| x.name != :tags }.first
112
+ assert_equal Article, a.owner_class
113
+
114
+ assert_equal [@a1, @a2, @s1], t.tagged
115
+ end
81
116
 
82
117
  end
@@ -43,7 +43,7 @@ og_mysql = {
43
43
 
44
44
  og_psql = {
45
45
  :destroy => true,
46
- :adapter => :psql,
46
+ :adapter => :postgresql,
47
47
  :user => 'postgres',
48
48
  :password => 'postgres',
49
49
  :name => 'test'
@@ -22,7 +22,7 @@ class TC_STI2 < Test::Unit::TestCase
22
22
  class Admin < User
23
23
  property :admin_praise, String
24
24
  end
25
-
25
+
26
26
  class Login
27
27
  property :pass, String
28
28
 
@@ -35,13 +35,23 @@ class TC_STI2 < Test::Unit::TestCase
35
35
  belongs_to User
36
36
  end
37
37
 
38
+ # This has .initialize overridden, Bugreport from Rayman
39
+ class PoorUser < User
40
+ property :poorness, Integer
41
+
42
+ def initialize(name = nil)
43
+ @poorness = 26
44
+ @name = name
45
+ end
46
+ end
47
+
38
48
  def request
39
49
  o = OpenStruct.new
40
50
  o.params = {:name => 'George', :pass => 'Secret'}
41
51
  return o
42
52
  end
43
53
 
44
- $og1.manage_classes User, Login, Admin, Pet
54
+ $og1.manage_classes User, Login, Admin, Pet, PoorUser
45
55
 
46
56
  def setup
47
57
  @user = Admin.create_with(request.params)
@@ -76,4 +86,15 @@ class TC_STI2 < Test::Unit::TestCase
76
86
  assert_equal 1, @user.pets(:reload => true).size
77
87
  end
78
88
 
89
+ def test_bugreport_rayman
90
+ p1 = PoorUser.create("JoJo")
91
+ p2 = PoorUser.find_one(:where => "name = 'JoJo'")
92
+ assert_equal p1.class, p2.class
93
+ assert_equal p1.oid, p2.oid
94
+
95
+ p3 = User.find_one(:where => "name = 'JoJo'")
96
+ assert_equal p1.class, p3.class
97
+ assert_equal p1.oid, p3.oid
98
+ end
99
+
79
100
  end
@@ -27,8 +27,10 @@ class TC_OgInheritance2 < Test::Unit::TestCase # :nodoc: all
27
27
  $og1.manage_classes(Project, FProject, DProject)
28
28
 
29
29
  def test_all
30
- Project.create
31
- FProject.create
32
- DProject.create
30
+ assert_nothing_raised do
31
+ Project.create
32
+ FProject.create
33
+ DProject.create
34
+ end
33
35
  end
34
36
  end
@@ -8,6 +8,15 @@ require 'og'
8
8
 
9
9
  class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all
10
10
  include Og
11
+
12
+ module Stuff
13
+ property :ahah, String
14
+ end
15
+
16
+ class Article
17
+ include Stuff
18
+ property :title, String
19
+ end
11
20
 
12
21
  # This class is a polymorphic parent. Ie' it acts as template
13
22
  # to generate customized versions of this class.
@@ -20,10 +29,22 @@ class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all
20
29
  @body = body
21
30
  end
22
31
  end
32
+
33
+ class Component
34
+ include Og::EntityMixin
35
+
36
+ belongs_to Article
37
+ end
23
38
 
24
39
  class Article
25
- property :title, String
26
40
  has_many Comment
41
+ has_many Component
42
+
43
+ class Comment < TC_OgPolymorphic::Comment
44
+ def to_href
45
+ '/article'
46
+ end
47
+ end
27
48
 
28
49
  def initialize(title)
29
50
  @title = title
@@ -40,21 +61,27 @@ class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all
40
61
  end
41
62
 
42
63
  $og1.manage_classes(Comment, Article, User)
43
-
44
- def test_all
45
- u = User.create('gmosx')
46
-
47
- u.comments << User::Comment.create('Hello')
48
- u.comments << User::Comment.create('World')
49
-
50
- assert_equal 2, u.comments.size
64
+
65
+ def setup
66
+ @u = User.create('gmosx')
51
67
 
52
- a = Article.create('test')
68
+ @u.comments << User::Comment.create('Hello')
69
+ @u.comments << User::Comment.create('World')
53
70
 
54
- a.comments << Article::Comment.create('Hello2')
55
- a.comments << Article::Comment.create('World2')
71
+ @a = Article.create('test')
56
72
 
57
- assert_equal 2, a.comments.size
73
+ @a.comments << Article::Comment.create('Hello2')
74
+ @a.comments << Article::Comment.create('World2')
75
+ end
76
+
77
+ def test_basic
78
+ assert_equal 2, @u.comments.size
79
+ assert_equal 2, @a.comments.size
80
+ end
81
+
82
+ def test_nested
83
+ assert_equal 2, Article.relations.size
84
+ assert_equal 3, Article.serializable_attributes.size
58
85
  end
59
86
 
60
87
  end
@@ -80,8 +80,8 @@ class TC_DeletesRelationship < Test::Unit::TestCase # :nodoc: all
80
80
 
81
81
  @u = User.create_with(:name => 'George')
82
82
 
83
- @i.category = @c
84
- @i.tag = @t
83
+ @i.category = @c; @c.save
84
+ @i.tag = @t; @t.save
85
85
 
86
86
  @i.pictures << @p1
87
87
  @p2.item = @i
@@ -160,4 +160,13 @@ class TC_DeletesRelationship < Test::Unit::TestCase # :nodoc: all
160
160
  assert_equal 0, n;
161
161
  end
162
162
 
163
+ #####
164
+ # Bug Reports
165
+ #####
166
+
167
+ def test_jo_category_foreign_key_na
168
+ assert_not_nil @i.category
169
+ assert_equal @i.pk, @i.category.item_oid
170
+ end
171
+
163
172
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: og
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.40.0
7
- date: 2006-11-13 10:56:16 +02:00
6
+ version: 0.41.0
7
+ date: 2006-12-12 12:36:44 +02:00
8
8
  summary: State of the art object-relational mapping system
9
9
  require_paths:
10
10
  - lib
@@ -65,6 +65,9 @@ files:
65
65
  - lib/og/adapter/postgresql.rb
66
66
  - lib/og/adapter/sqlite
67
67
  - lib/og/adapter/sqlite.rb
68
+ - lib/og/adapter/oracle
69
+ - lib/og/adapter/oracle.old.rb
70
+ - lib/og/adapter/oracle.rb
68
71
  - lib/og/adapter/mysql/override.rb
69
72
  - lib/og/adapter/mysql/script.rb
70
73
  - lib/og/adapter/mysql/utils.rb
@@ -73,6 +76,8 @@ files:
73
76
  - lib/og/adapter/postgresql/utils.rb
74
77
  - lib/og/adapter/sqlite/override.rb
75
78
  - lib/og/adapter/sqlite/script.rb
79
+ - lib/og/adapter/oracle/override.rb
80
+ - lib/og/adapter/oracle/utils.rb
76
81
  - lib/og/entity/clone.rb
77
82
  - lib/og/ez/clause.rb
78
83
  - lib/og/ez/condition.rb
@@ -141,10 +146,10 @@ files:
141
146
  - test/og/store/tc_sti.rb
142
147
  - test/og/store/tc_sti2.rb
143
148
  - doc/CHANGELOG.1
149
+ - doc/tutorial.txt
144
150
  - doc/CONTRIBUTORS
145
151
  - doc/LICENSE
146
152
  - doc/RELEASES
147
- - doc/tutorial.txt
148
153
  test_files: []
149
154
 
150
155
  rdoc_options: []
@@ -165,5 +170,5 @@ dependencies:
165
170
  requirements:
166
171
  - - "="
167
172
  - !ruby/object:Gem::Version
168
- version: 0.40.0
173
+ version: 0.41.0
169
174
  version: