og 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/INSTALL +10 -5
  2. data/ProjectInfo +9 -2
  3. data/README +3 -3
  4. data/Rakefile +5 -1
  5. data/doc/AUTHORS +3 -0
  6. data/doc/RELEASES +57 -0
  7. data/lib/glue/orderable.rb +8 -8
  8. data/lib/og.rb +6 -6
  9. data/lib/og/collection.rb +12 -3
  10. data/lib/og/entity.rb +2 -2
  11. data/lib/og/manager.rb +2 -1
  12. data/lib/og/store.rb +5 -8
  13. data/lib/og/store/kirby.rb +93 -12
  14. data/lib/og/store/mysql.rb +7 -21
  15. data/lib/og/store/psql.rb +9 -3
  16. data/lib/og/store/sql.rb +4 -2
  17. data/lib/og/store/sqlite.rb +3 -1
  18. data/lib/og/vendor/mysql.rb +1 -1
  19. data/setup.rb +1585 -0
  20. data/test/og/mixin/tc_hierarchical.rb +2 -0
  21. data/test/og/mixin/tc_optimistic_locking.rb +2 -0
  22. data/test/og/mixin/tc_orderable.rb +2 -0
  23. data/test/og/mixin/tc_taggable.rb +2 -0
  24. data/test/og/mixin/tc_timestamped.rb +2 -0
  25. data/test/og/store/tc_filesys.rb +2 -0
  26. data/test/og/store/tc_kirby.rb +2 -0
  27. data/test/og/tc_accumulator.rb +92 -0
  28. data/test/og/tc_delete_all.rb +2 -0
  29. data/test/og/tc_finder.rb +2 -0
  30. data/test/og/tc_inheritance.rb +2 -0
  31. data/test/og/tc_inheritance2.rb +35 -0
  32. data/test/og/tc_join.rb +2 -0
  33. data/test/og/tc_multi_validations.rb +19 -0
  34. data/test/og/tc_multiple.rb +2 -0
  35. data/test/og/tc_override.rb +2 -0
  36. data/test/og/tc_polymorphic.rb +3 -1
  37. data/test/og/tc_relation.rb +2 -0
  38. data/test/og/tc_reverse.rb +2 -0
  39. data/test/og/tc_scoped.rb +2 -0
  40. data/test/og/tc_select.rb +3 -0
  41. data/test/og/tc_store.rb +2 -0
  42. data/test/og/tc_types.rb +2 -0
  43. data/test/og/tc_validation.rb +2 -0
  44. data/test/og/tc_validation2.rb +207 -0
  45. data/test/og/tc_validation_loop.rb +36 -0
  46. metadata +124 -120
  47. data/benchmark/bench.rb +0 -75
  48. data/benchmark/sqlite-no-prepare.1.txt +0 -13
  49. data/benchmark/sqlite-no-prepare.2.txt +0 -13
  50. data/benchmark/sqlite-prepare.1.txt +0 -13
  51. data/benchmark/sqlite-prepare.2.txt +0 -13
  52. data/install.rb +0 -37
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'ostruct'
5
7
 
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
 
5
7
  require 'og'
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'ostruct'
5
7
 
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'ostruct'
5
7
 
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'ostruct'
5
7
 
@@ -1,5 +1,7 @@
1
1
 
2
2
  require File.join(File.dirname(__FILE__), '..', 'CONFIG.rb')
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'og'
5
7
 
@@ -1,3 +1,5 @@
1
+ require 'rubygems'
2
+ require 'facets'
1
3
  require 'test/unit'
2
4
  require 'og'
3
5
 
@@ -0,0 +1,92 @@
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
+
9
+ class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all
10
+ include Og
11
+
12
+ class Foo
13
+ property :name, String
14
+ has_many Bar
15
+ end
16
+
17
+ class Bar
18
+ property :name, String
19
+ belongs_to Foo
20
+ has_many Foobar
21
+ end
22
+
23
+ class Foobar
24
+ property :name, String
25
+ belongs_to Bar
26
+ end
27
+
28
+ def setup
29
+ @og = Og.setup($og_config)
30
+ end
31
+
32
+ def test_all
33
+ 2.times{|i|
34
+ foo = Foo.new
35
+ foo.name = "foo #{i}"
36
+ foo.save
37
+ }
38
+
39
+ assert_equal 2, Foo.all.length
40
+
41
+ 3.times{|i|
42
+ bar = Bar.new
43
+ bar.name = "bar #{i}"
44
+ bar.save
45
+ }
46
+
47
+ assert_equal 3, Bar.all.length
48
+
49
+ 6.times{|i|
50
+ foobar = Foobar.new
51
+ foobar.name = "foobar #{i}"
52
+ foobar.save
53
+ }
54
+
55
+ assert_equal 6, Foobar.all.length
56
+
57
+ foo1 = Foo[1]
58
+ bar1 = Bar[1]
59
+ bar1.add_foobar Foobar[1]
60
+ bar1.add_foobar Foobar[2]
61
+ bar1.add_foobar Foobar[3]
62
+ bar1.save
63
+ foo1.add_bar bar1
64
+ foo1.save
65
+
66
+ foo2 = Foo[2]
67
+ bar2 = Bar[2]
68
+ bar3 = Bar[3]
69
+ bar2.add_foobar Foobar[4]
70
+ bar3.add_foobar Foobar[5]
71
+ bar3.add_foobar Foobar[6]
72
+ bar2.save
73
+ bar3.save
74
+ foo2.add_bar bar2
75
+ foo2.add_bar bar3
76
+ foo2.save
77
+
78
+ # this work...
79
+
80
+ ar = Array.new
81
+ foo1.bars.each {|ii|
82
+ ar.push(ii.foobars)
83
+ }
84
+ ar.flatten!
85
+ ar.size
86
+
87
+ foo_foobars = foo1.bars.foobars
88
+ assert_equal 3, foo_foobars.size
89
+ assert_equal Foobar, foo_foobars.first.class
90
+ end
91
+
92
+ end
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require "og"
4
6
  require "pp"
5
7
  require "test/unit"
@@ -2,6 +2,8 @@ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
3
  $DBG = true
4
4
 
5
+ require 'rubygems'
6
+ require 'facets'
5
7
  require 'test/unit'
6
8
 
7
9
  require 'og'
@@ -2,6 +2,8 @@ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
3
  $DBG = true
4
4
 
5
+ require 'rubygems'
6
+ require 'facets'
5
7
  require 'test/unit'
6
8
 
7
9
  require 'og'
@@ -0,0 +1,35 @@
1
+ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
+
3
+ $DBG = true
4
+
5
+ require 'rubygems'
6
+ require 'facets'
7
+ require 'test/unit'
8
+
9
+ require 'og'
10
+
11
+ class TC_OgInheritance2 < Test::Unit::TestCase # :nodoc: all
12
+ include Og
13
+
14
+ class Project
15
+ property :koko, String
16
+ schema_inheritance
17
+ end
18
+
19
+ class FProject < Project
20
+ property :haha, String
21
+ end
22
+
23
+ class DProject < Project
24
+ property :kaka, String
25
+ end
26
+
27
+
28
+ def test_all
29
+ @og = Og.setup($og_config)
30
+
31
+ Project.create
32
+ FProject.create
33
+ DProject.create
34
+ end
35
+ end
@@ -2,6 +2,8 @@ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
3
  $DBG = true
4
4
 
5
+ require 'rubygems'
6
+ require 'facets'
5
7
  require 'test/unit'
6
8
 
7
9
  require 'og'
@@ -0,0 +1,19 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
2
+
3
+ require 'test/unit'
4
+
5
+ require 'glue'
6
+ require 'glue/property'
7
+ require 'glue/validation'
8
+
9
+ class TC_MultiValidation < Test::Unit::TestCase # :nodoc: all
10
+
11
+ def test_all
12
+ file = File.join(File.dirname($0), 'multi_validations_model.rb')
13
+ load file
14
+ assert_equal 2, User.validations.size
15
+ load file
16
+ assert_equal 2, User.validations.size
17
+ end
18
+
19
+ end
@@ -2,6 +2,8 @@ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
3
  $DBG = true
4
4
 
5
+ require 'rubygems'
6
+ require 'facets'
5
7
  require 'test/unit'
6
8
 
7
9
  require 'og'
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'og'
5
7
 
@@ -1,6 +1,8 @@
1
-
2
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
3
2
 
3
+ require 'rubygems'
4
+ require 'facets'
5
+
4
6
  require 'test/unit'
5
7
  require 'og'
6
8
 
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
 
5
7
  require 'og'
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'og'
5
7
 
@@ -2,6 +2,8 @@ require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
3
  $DBG = true
4
4
 
5
+ require 'rubygems'
6
+ require 'facets'
5
7
  require 'test/unit'
6
8
 
7
9
  require 'og'
@@ -1,4 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
+
3
+ require 'rubygems'
4
+ require 'facets'
2
5
  require 'test/unit'
3
6
  require 'og'
4
7
 
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'og'
5
7
 
@@ -1,5 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
+ require 'rubygems'
4
+ require 'facets'
3
5
  require 'test/unit'
4
6
  require 'og'
5
7
 
@@ -1,6 +1,8 @@
1
1
  require File.join(File.dirname(__FILE__), 'CONFIG.rb')
2
2
 
3
3
  $DBG = true
4
+ require 'rubygems'
5
+ require 'facets'
4
6
 
5
7
  require 'test/unit'
6
8
 
@@ -0,0 +1,207 @@
1
+ path = File.expand_path(File.dirname($0))
2
+ $: << path + '/og/lib'
3
+ $: << path + '/glue/lib'
4
+ require 'test/unit'
5
+ require 'og'
6
+
7
+ module UnitTestClasses
8
+ class NoValidation
9
+ property :prop, String
10
+
11
+ def initialize(prop)
12
+ @prop = prop
13
+ end
14
+ end
15
+
16
+ class UniqueValidation < NoValidation
17
+ property :slop, String
18
+ validate_unique :prop, :slop
19
+ end
20
+
21
+ class ValueValidation < NoValidation
22
+ validate_value :prop
23
+ end
24
+
25
+ class ConfirmValidation < NoValidation
26
+ validate_confirmation :prop
27
+ end
28
+
29
+ class FormatValidation < NoValidation
30
+ validate_format :prop, :format => /^\w\d\w-\d\w\d$/
31
+ end
32
+
33
+ class MinValidation < NoValidation
34
+ validate_length :prop, :min => 4
35
+ end
36
+
37
+ class MaxValidation < NoValidation
38
+ validate_length :prop, :max => 8
39
+ end
40
+
41
+ class RangeValidation < NoValidation
42
+ validate_length :prop, :range => 10..20
43
+ end
44
+
45
+ class LengthValidation < NoValidation
46
+ validate_length :prop, :length => 8
47
+ end
48
+
49
+ class InclusionValidation < NoValidation
50
+ validate_inclusion :prop, :in => %w{ Male Female }
51
+ end
52
+
53
+ class NumericValidation < NoValidation
54
+ property :prop, Fixnum
55
+ validate_numeric :prop, :integer => true
56
+
57
+ prop_accessor :prop2, Float
58
+ validate_numeric :prop2
59
+ end
60
+
61
+ class RelatedClass
62
+ prop_accessor :test, String
63
+ belongs_to :relation_validation, RelationValidation
64
+ end
65
+
66
+ class RelationValidation < NoValidation
67
+ has_many :relations, RelatedClass
68
+ validate_related :relations
69
+ end
70
+ end
71
+
72
+ config = {
73
+ :destroy => true,
74
+ :store => :sqlite,
75
+ :prop => 'dbtest_additions'
76
+ }
77
+
78
+ db = Og.setup(config)
79
+
80
+ module Test::Unit::Assertions
81
+ # Assert than an Og object is successfully saved and is error free.
82
+ def assert_saved_without_errors(obj)
83
+ assert_block(obj.class.to_s + ' was expected to save, but failed.') do
84
+ obj.save
85
+ obj.saved? && obj.errors.size == 0
86
+ end
87
+ end
88
+
89
+ # Assert that an Og object did not save and has errors.
90
+ def assert_save_failed(obj)
91
+ assert_block(obj.class.to_s + ' saving was expected to fail, but it succeeded.') do
92
+ obj.save
93
+ !obj.saved? && obj.errors.size > 0
94
+ end
95
+ end
96
+ end
97
+
98
+ # Unit tests for the Og validation system
99
+ class TestFixes < Test::Unit::TestCase
100
+ include UnitTestClasses
101
+
102
+ def test_no_validation
103
+ t = NoValidation.new('nochecking')
104
+ assert_saved_without_errors t
105
+ end
106
+
107
+ def test_validation_unique
108
+ assert_saved_without_errors UniqueValidation.new('test')
109
+ assert_save_failed UniqueValidation.new('test')
110
+ end
111
+
112
+ def test_value_validation
113
+ assert_saved_without_errors ValueValidation.new('value')
114
+ assert_save_failed ValueValidation.new(nil)
115
+ end
116
+
117
+ def test_confirmation
118
+ prop = 'confirm'
119
+ c = ConfirmValidation.new(prop)
120
+ c.prop_confirmation = prop
121
+ assert_saved_without_errors c
122
+
123
+ assert_save_failed ConfirmValidation.new(prop)
124
+ end
125
+
126
+ def test_format
127
+ assert_saved_without_errors FormatValidation.new('a1b-2c3')
128
+ assert_save_failed FormatValidation.new('banana_pudding')
129
+ end
130
+
131
+ def test_length_min
132
+ assert_saved_without_errors MinValidation.new('12345')
133
+ assert_save_failed MinValidation.new('1')
134
+ end
135
+
136
+ def test_length_max
137
+ assert_saved_without_errors MaxValidation.new('12345')
138
+ assert_save_failed MaxValidation.new('123456789012345')
139
+ end
140
+
141
+ def test_length_range
142
+ l = RangeValidation.new('12345678901234')
143
+ assert_saved_without_errors l
144
+
145
+ l = RangeValidation.new('12')
146
+ assert_save_failed l
147
+
148
+ l = RangeValidation.new('1234567890123456789012345')
149
+ assert_save_failed l
150
+ end
151
+
152
+ def test_length_length
153
+ assert_saved_without_errors LengthValidation.new('12345678')
154
+ assert_save_failed LengthValidation.new('1')
155
+ assert_save_failed LengthValidation.new('123456789012345')
156
+ end
157
+
158
+ def test_inclusion
159
+ assert_saved_without_errors InclusionValidation.new('Male')
160
+ assert_save_failed InclusionValidation.new('Shemale')
161
+ end
162
+
163
+ def test_numeric
164
+ # Both valid
165
+ n = NumericValidation.new(100)
166
+ n.prop2 = 1.52
167
+ assert_saved_without_errors n
168
+
169
+ # float for required integer
170
+ n = NumericValidation.new(1.52)
171
+ n.prop2 = 1.52
172
+ assert_save_failed n
173
+ assert_equal 1, n.errors.count
174
+
175
+ # string for required integer
176
+ n = NumericValidation.new('sausage')
177
+ n.prop2 = 1.52
178
+ assert_save_failed n
179
+ assert_equal 1, n.errors.count
180
+
181
+ # string for required integer and float
182
+ n = NumericValidation.new('sausage')
183
+ n.prop2 = 'cheese'
184
+ assert_save_failed n
185
+ assert_equal 2, n.errors.count
186
+
187
+ # string for float
188
+ n = NumericValidation.new(15)
189
+ n.prop2 = 'cheese'
190
+ assert_save_failed n
191
+ assert_equal 1, n.errors.count
192
+ end
193
+
194
+ def test_related
195
+ r = RelatedClass.new
196
+ test_prop = 'example string'
197
+ r.test = test_prop
198
+ rv = RelationValidation.new('relation')
199
+ rv.relations << r
200
+
201
+ assert_saved_without_errors rv
202
+ assert_equal test_prop, rv.relations.members[0].test
203
+
204
+ # Test bad
205
+ assert_save_failed RelationValidation.new('relation')
206
+ end
207
+ end