og 0.8.0 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,6 @@
1
- # code:
2
1
  # * George Moschovitis <gm@navel.gr>
3
2
  # * Thomas Quas <tquas@yahoo.com>
4
- #
5
- # (c) 2004 Navel, all rights reserved.
3
+ # (c) 2004-2005 Navel, all rights reserved.
6
4
  # $Id$
7
5
 
8
6
  require 'og'
@@ -12,15 +10,12 @@ require_gem 'flexmock'
12
10
 
13
11
  class Og
14
12
 
15
- # = MockDatabase
16
- #
17
13
  # A utility object to Mock a Database in test units.
18
14
  # Extends the standard FlexMock object.
19
- #
20
15
  #--
21
16
  # TODO: Factor out common functionality with Database
22
17
  # to avoid code duplication.
23
- #++
18
+
24
19
  class MockDatabase < ::FlexMock
25
20
  include Og::Enchant
26
21
 
@@ -40,16 +35,19 @@ class MockDatabase < ::FlexMock
40
35
  end
41
36
 
42
37
  # hash of configuration options.
38
+
43
39
  attr_accessor :config
44
40
 
45
41
  # Pool of connections to the backend.
42
+
46
43
  attr_accessor :connection_pool
47
44
 
48
45
  # Managed classes.
46
+
49
47
  attr_accessor :managed_classes
50
48
 
51
49
  # Initialize the database interface.
52
- #
50
+
53
51
  def initialize
54
52
  # Initialize FlexMock
55
53
  super
@@ -61,6 +59,7 @@ class MockDatabase < ::FlexMock
61
59
  if Og.auto_manage_classes
62
60
  # automatically manage classes with properties and metadata.
63
61
  # gmosx: Any idea how to optimize this?
62
+
64
63
  classes_to_manage = []
65
64
  ObjectSpace.each_object(Class) do |c|
66
65
  if c.respond_to?(:__props) and c.__props
@@ -73,31 +72,32 @@ class MockDatabase < ::FlexMock
73
72
  end
74
73
 
75
74
  # use the newly created database.
75
+
76
76
  Og.use(self)
77
77
  end
78
78
 
79
79
  # Shutdown the database interface.
80
- #
80
+
81
81
  def shutdown
82
82
  end
83
83
  alias_method :close, :shutdown
84
84
 
85
85
  # Get a connection from the pool to access the database.
86
86
  # Stores the connection in a thread-local variable.
87
- #
87
+
88
88
  def get_connection
89
89
  # nop
90
90
  end
91
91
  alias_method :connection, :get_connection
92
92
 
93
93
  # Restore an unused connection to the pool.
94
- #
94
+
95
95
  def put_connection
96
96
  # nop
97
97
  end
98
98
 
99
99
  # Register a standard Ruby class as managed.
100
- #
100
+
101
101
  def manage(klass)
102
102
  return if managed?(klass) or klass.ancestors.include?(Og::Unmanageable)
103
103
 
@@ -111,7 +111,7 @@ class MockDatabase < ::FlexMock
111
111
  end
112
112
 
113
113
  # Helper method to set multiple managed classes.
114
- #
114
+
115
115
  def manage_classes(*klasses)
116
116
  for klass in klasses
117
117
  manage(klass)
@@ -119,19 +119,19 @@ class MockDatabase < ::FlexMock
119
119
  end
120
120
 
121
121
  # Stop managing a Ruby class
122
- #
122
+
123
123
  def unmanage(klass)
124
124
  @managed_classes.delete(klass)
125
125
  end
126
126
 
127
127
  # Is this class managed?
128
- #
128
+
129
129
  def managed?(klass)
130
130
  return @managed_classes.include?(klass)
131
131
  end
132
132
 
133
133
  # Add standard og functionality to the class
134
- #
134
+
135
135
  def convert(klass)
136
136
  klass.class_eval %{
137
137
  DBTABLE = "#{Og::Backend.table(klass)}"
@@ -144,7 +144,7 @@ class MockDatabase < ::FlexMock
144
144
  end
145
145
 
146
146
  # Automatically wrap connection methods.
147
- #
147
+
148
148
  def self.wrap_method(method, args)
149
149
  args = args.split(/,/)
150
150
  class_eval %{
@@ -163,4 +163,4 @@ class MockDatabase < ::FlexMock
163
163
  end
164
164
  end
165
165
 
166
- end # namespace
166
+ end
@@ -1,9 +1,9 @@
1
- #--
2
- # George Moschovitis <gm@navel.gr>
1
+ # * George Moschovitis <gm@navel.gr>
3
2
  # (c) 2004-2005 Navel, all rights reserved.
4
- # $Id: version.rb 198 2004-12-22 11:26:59Z gmosx $
5
- #++
3
+ # $Id: version.rb 248 2005-01-31 13:38:34Z gmosx $
6
4
 
7
- # The version of Og.
8
-
9
- $og_version = '0.8.0'
5
+ class Og
6
+ # The version of Og.
7
+
8
+ Version = '0.9.3'
9
+ end
@@ -1,6 +1,7 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
2
 
3
3
  require 'test/unit'
4
+
4
5
  require 'og'
5
6
 
6
7
  module Test # :nodoc: all
@@ -9,12 +10,17 @@ module Test # :nodoc: all
9
10
  # correctly escaped.
10
11
  class User
11
12
  prop_accessor :name, String
12
-
13
+ prop_accessor :banned, TrueClass
14
+
13
15
  def initialize(name = nil)
14
16
  @name = name
15
17
  end
16
18
  end
17
19
 
20
+ class Role
21
+ prop_accessor :title, String
22
+ end
23
+
18
24
  class Comment; end
19
25
 
20
26
  class Article
@@ -46,10 +52,10 @@ class Article
46
52
  end
47
53
 
48
54
  class Comment
49
- belongs_to :article, Test::Article, :extra_sql => 'NOT NULL'
50
- belongs_to :author, Test::User
51
55
  prop_accessor :body, String
52
56
  prop_accessor :create_time, Time
57
+ belongs_to :article, Test::Article, :extra_sql => 'NOT NULL'
58
+ belongs_to :author, Test::User
53
59
 
54
60
  def initialize(body = nil)
55
61
  @create_time = Time.now
@@ -73,6 +79,11 @@ class MyClass
73
79
  include Test::MyMixin
74
80
  end
75
81
 
82
+ class OrderItem
83
+ prop_accessor :number, Fixnum
84
+ refers_to :article, Article
85
+ end
86
+
76
87
  class TC_N_OG < Test::Unit::TestCase
77
88
 
78
89
  def setup
@@ -176,9 +187,17 @@ class TC_N_OG < Test::Unit::TestCase
176
187
 
177
188
  assert_equal("gmosx", comments[0].author.name)
178
189
 
190
+ article.delete_all_comments
191
+ assert article.comments.empty?
192
+
193
+ # test cascading delete
194
+
195
+ article.add_comment(Comment.new("hello"))
196
+ article.add_comment(Comment.new("world"))
197
+
179
198
  Article.delete(article)
180
199
 
181
- assert_equal(nil, Comment.all)
200
+ assert Comment.all.empty?
182
201
 
183
202
  comment.delete!
184
203
 
@@ -199,6 +218,24 @@ class TC_N_OG < Test::Unit::TestCase
199
218
  # test create
200
219
  article = Article.create("title", "body")
201
220
  assert_equal(3, article.oid)
221
+
222
+ # test refers_to
223
+
224
+ oi = OrderItem.new
225
+ oi.article = article
226
+ oi.save
227
+
228
+ assert_equal article.oid, oi.article_oid
229
+
230
+ # bug
231
+
232
+ user = User['gmosx']
233
+ user.banned = true
234
+ user.save!
235
+
236
+ user = User['gmosx']
237
+ assert_equal true, user.banned
238
+
202
239
  end
203
240
 
204
241
  end
metadata CHANGED
@@ -3,14 +3,14 @@ rubygems_version: 0.8.4
3
3
  specification_version: 1
4
4
  name: og
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.8.0
7
- date: 2005-01-12
6
+ version: 0.9.3
7
+ date: 2005-02-01
8
8
  summary: Og (ObjectGraph)
9
9
  require_paths:
10
10
  - lib
11
11
  email: gm@navel.gr
12
12
  homepage: http://www.navel.gr/og
13
- rubyforge_project: og-rml
13
+ rubyforge_project: nitro
14
14
  description: An efficient and transparent Object-Relational mapping library
15
15
  autorequire: og
16
16
  default_executable:
@@ -47,9 +47,12 @@ files:
47
47
  - lib/glue/number.rb
48
48
  - lib/glue/time.rb
49
49
  - lib/glue/property.rb
50
+ - lib/glue/misc.rb
50
51
  - lib/glue/macro.rb
52
+ - lib/glue/flexob.rb
51
53
  - lib/glue/cache.rb
52
54
  - lib/glue/string.rb
55
+ - lib/glue/object.rb
53
56
  - lib/glue/array.rb
54
57
  - lib/glue/validation.rb
55
58
  - lib/glue/attribute.rb