sequel 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/CHANGELOG +64 -0
  2. data/Rakefile +1 -1
  3. data/lib/sequel_core/adapters/jdbc.rb +6 -2
  4. data/lib/sequel_core/adapters/jdbc/oracle.rb +23 -0
  5. data/lib/sequel_core/adapters/oracle.rb +4 -77
  6. data/lib/sequel_core/adapters/postgres.rb +39 -26
  7. data/lib/sequel_core/adapters/shared/mssql.rb +0 -1
  8. data/lib/sequel_core/adapters/shared/mysql.rb +1 -1
  9. data/lib/sequel_core/adapters/shared/oracle.rb +82 -0
  10. data/lib/sequel_core/adapters/shared/postgres.rb +65 -46
  11. data/lib/sequel_core/core_ext.rb +10 -0
  12. data/lib/sequel_core/core_sql.rb +7 -0
  13. data/lib/sequel_core/database.rb +22 -0
  14. data/lib/sequel_core/database/schema.rb +1 -1
  15. data/lib/sequel_core/dataset.rb +29 -11
  16. data/lib/sequel_core/dataset/sql.rb +27 -7
  17. data/lib/sequel_core/migration.rb +20 -2
  18. data/lib/sequel_core/object_graph.rb +24 -10
  19. data/lib/sequel_core/schema/generator.rb +22 -9
  20. data/lib/sequel_core/schema/sql.rb +13 -9
  21. data/lib/sequel_core/sql.rb +27 -2
  22. data/lib/sequel_model/association_reflection.rb +251 -141
  23. data/lib/sequel_model/associations.rb +114 -61
  24. data/lib/sequel_model/base.rb +25 -21
  25. data/lib/sequel_model/eager_loading.rb +17 -40
  26. data/lib/sequel_model/hooks.rb +25 -24
  27. data/lib/sequel_model/record.rb +29 -51
  28. data/lib/sequel_model/schema.rb +1 -1
  29. data/lib/sequel_model/validations.rb +13 -3
  30. data/spec/adapters/postgres_spec.rb +104 -18
  31. data/spec/adapters/spec_helper.rb +4 -1
  32. data/spec/integration/eager_loader_test.rb +5 -4
  33. data/spec/integration/spec_helper.rb +4 -1
  34. data/spec/sequel_core/connection_pool_spec.rb +24 -24
  35. data/spec/sequel_core/core_sql_spec.rb +12 -0
  36. data/spec/sequel_core/dataset_spec.rb +77 -2
  37. data/spec/sequel_core/expression_filters_spec.rb +6 -0
  38. data/spec/sequel_core/object_graph_spec.rb +40 -2
  39. data/spec/sequel_core/schema_spec.rb +13 -0
  40. data/spec/sequel_model/association_reflection_spec.rb +8 -8
  41. data/spec/sequel_model/associations_spec.rb +164 -3
  42. data/spec/sequel_model/caching_spec.rb +2 -1
  43. data/spec/sequel_model/eager_loading_spec.rb +107 -3
  44. data/spec/sequel_model/hooks_spec.rb +38 -22
  45. data/spec/sequel_model/model_spec.rb +11 -35
  46. data/spec/sequel_model/plugins_spec.rb +4 -2
  47. data/spec/sequel_model/record_spec.rb +8 -5
  48. data/spec/sequel_model/validations_spec.rb +25 -0
  49. data/spec/spec_config.rb +4 -3
  50. metadata +21 -19
@@ -17,7 +17,8 @@ describe "Model hooks" do
17
17
 
18
18
  specify "should be definable using a block" do
19
19
  $adds = []
20
- c = Class.new(Sequel::Model) do
20
+ c = Class.new(Sequel::Model)
21
+ c.class_eval do
21
22
  before_save {$adds << 'hi'}
22
23
  end
23
24
 
@@ -27,7 +28,8 @@ describe "Model hooks" do
27
28
 
28
29
  specify "should be definable using a method name" do
29
30
  $adds = []
30
- c = Class.new(Sequel::Model) do
31
+ c = Class.new(Sequel::Model)
32
+ c.class_eval do
31
33
  def bye; $adds << 'bye'; end
32
34
  before_save :bye
33
35
  end
@@ -38,7 +40,8 @@ describe "Model hooks" do
38
40
 
39
41
  specify "should be additive" do
40
42
  $adds = []
41
- c = Class.new(Sequel::Model) do
43
+ c = Class.new(Sequel::Model)
44
+ c.class_eval do
42
45
  before_save {$adds << 'hyiyie'}
43
46
  before_save {$adds << 'byiyie'}
44
47
  end
@@ -49,7 +52,8 @@ describe "Model hooks" do
49
52
 
50
53
  specify "should not be additive if the method or tag already exists" do
51
54
  $adds = []
52
- c = Class.new(Sequel::Model) do
55
+ c = Class.new(Sequel::Model)
56
+ c.class_eval do
53
57
  def bye; $adds << 'bye'; end
54
58
  before_save :bye
55
59
  before_save :bye
@@ -59,7 +63,8 @@ describe "Model hooks" do
59
63
  $adds.should == ['bye']
60
64
 
61
65
  $adds = []
62
- d = Class.new(Sequel::Model) do
66
+ d = Class.new(Sequel::Model)
67
+ d.class_eval do
63
68
  before_save(:bye){$adds << 'hyiyie'}
64
69
  before_save(:bye){$adds << 'byiyie'}
65
70
  end
@@ -68,7 +73,8 @@ describe "Model hooks" do
68
73
  $adds.should == ['byiyie']
69
74
 
70
75
  $adds = []
71
- e = Class.new(Sequel::Model) do
76
+ e = Class.new(Sequel::Model)
77
+ e.class_eval do
72
78
  def bye; $adds << 'bye'; end
73
79
  before_save :bye
74
80
  before_save(:bye){$adds << 'byiyie'}
@@ -78,7 +84,8 @@ describe "Model hooks" do
78
84
  $adds.should == ['byiyie']
79
85
 
80
86
  $adds = []
81
- e = Class.new(Sequel::Model) do
87
+ e = Class.new(Sequel::Model)
88
+ e.class_eval do
82
89
  def bye; $adds << 'bye'; end
83
90
  before_save(:bye){$adds << 'byiyie'}
84
91
  before_save :bye
@@ -92,11 +99,13 @@ describe "Model hooks" do
92
99
  # pending
93
100
 
94
101
  $adds = []
95
- a = Class.new(Sequel::Model) do
102
+ a = Class.new(Sequel::Model)
103
+ a.class_eval do
96
104
  before_save {$adds << '123'}
97
105
  end
98
106
 
99
- b = Class.new(a) do
107
+ b = Class.new(a)
108
+ b.class_eval do
100
109
  before_save {$adds << '456'}
101
110
  before_save {$adds << '789'}
102
111
  end
@@ -107,11 +116,13 @@ describe "Model hooks" do
107
116
 
108
117
  specify "should be overridable in descendant classes" do
109
118
  $adds = []
110
- a = Class.new(Sequel::Model) do
119
+ a = Class.new(Sequel::Model)
120
+ a.class_eval do
111
121
  before_save {$adds << '123'}
112
122
  end
113
123
 
114
- b = Class.new(a) do
124
+ b = Class.new(a)
125
+ b.class_eval do
115
126
  def before_save; $adds << '456'; end
116
127
  end
117
128
 
@@ -126,7 +137,8 @@ describe "Model hooks" do
126
137
  $flag = true
127
138
  $adds = []
128
139
 
129
- a = Class.new(Sequel::Model) do
140
+ a = Class.new(Sequel::Model)
141
+ a.class_eval do
130
142
  before_save {$adds << 'blah'; $flag}
131
143
  before_save {$adds << 'cruel'}
132
144
  end
@@ -145,7 +157,8 @@ describe "Model hooks" do
145
157
  a.new.before_save
146
158
  $adds.should == ['blah']
147
159
 
148
- b = Class.new(a) do
160
+ b = Class.new(a)
161
+ b.class_eval do
149
162
  before_save {$adds << 'mau'}
150
163
  end
151
164
 
@@ -160,7 +173,8 @@ describe "Model#after_initialize" do
160
173
  $values1 = nil
161
174
  $reached_after_initialized = false
162
175
 
163
- a = Class.new(Sequel::Model) do
176
+ a = Class.new(Sequel::Model)
177
+ a.class_eval do
164
178
  columns :x, :y
165
179
  after_initialize do
166
180
  $values1 = @values.clone
@@ -178,7 +192,8 @@ describe "Model#before_create && Model#after_create" do
178
192
  setup do
179
193
  MODEL_DB.reset
180
194
 
181
- @c = Class.new(Sequel::Model(:items)) do
195
+ @c = Class.new(Sequel::Model(:items))
196
+ @c.class_eval do
182
197
  columns :x
183
198
  no_primary_key
184
199
 
@@ -214,7 +229,8 @@ describe "Model#before_update && Model#after_update" do
214
229
  setup do
215
230
  MODEL_DB.reset
216
231
 
217
- @c = Class.new(Sequel::Model(:items)) do
232
+ @c = Class.new(Sequel::Model(:items))
233
+ @c.class_eval do
218
234
  after_update {MODEL_DB << "BLAH after"}
219
235
  end
220
236
  end
@@ -248,7 +264,8 @@ describe "Model#before_save && Model#after_save" do
248
264
  setup do
249
265
  MODEL_DB.reset
250
266
 
251
- @c = Class.new(Sequel::Model(:items)) do
267
+ @c = Class.new(Sequel::Model(:items))
268
+ @c.class_eval do
252
269
  columns :x
253
270
  after_save {MODEL_DB << "BLAH after"}
254
271
  end
@@ -294,7 +311,8 @@ describe "Model#before_destroy && Model#after_destroy" do
294
311
  setup do
295
312
  MODEL_DB.reset
296
313
 
297
- @c = Class.new(Sequel::Model(:items)) do
314
+ @c = Class.new(Sequel::Model(:items))
315
+ @c.class_eval do
298
316
  after_destroy {MODEL_DB << "BLAH after"}
299
317
 
300
318
  def delete
@@ -332,7 +350,8 @@ describe "Model#before_validation && Model#after_validation" do
332
350
  setup do
333
351
  MODEL_DB.reset
334
352
 
335
- @c = Class.new(Sequel::Model(:items)) do
353
+ @c = Class.new(Sequel::Model(:items))
354
+ @c.class_eval do
336
355
  after_validation{MODEL_DB << "BLAH after"}
337
356
 
338
357
  def self.validate(o)
@@ -403,8 +422,5 @@ describe "Model.has_hooks?" do
403
422
  specify "should return true if hooks are inherited" do
404
423
  @d = Class.new(@c)
405
424
  @d.has_hooks?(:before_save).should be_false
406
-
407
- @c.before_save :blah
408
- @d.has_hooks?(:before_save).should be_true
409
425
  end
410
426
  end
@@ -426,55 +426,31 @@ describe Sequel::Model, "A model class without a primary key" do
426
426
  end
427
427
 
428
428
  describe Sequel::Model, "attribute accessors" do
429
- after do
430
- Sequel::Model.lazy_load_schema = false
431
- end
432
-
433
429
  before do
434
430
  MODEL_DB.reset
435
-
436
- @c = Class.new(Sequel::Model) do
437
- def self.columns; orig_columns; end
438
- end
439
431
  @dataset = Sequel::Dataset.new(MODEL_DB)
440
- def @dataset.db; end
441
- def @dataset.set_model(blah); end
442
- def @dataset.naked; self; end
443
432
  def @dataset.columns; [:x, :y]; end
444
- def @dataset.def_mutation_method(*names); end
445
- end
446
-
447
- it "should be created on set_dataset unless lazy loading schema" do
448
- %w'x y x= y='.each do |x|
449
- @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
450
- end
451
- @c.set_dataset(@dataset)
452
- %w'x y x= y='.each do |x|
453
- @c.instance_methods.collect{|y| y.to_s}.should include(x)
454
- end
455
- o = @c.new
456
- %w'x y x= y='.each do |x|
457
- o.methods.collect{|y| y.to_s}.should include(x)
433
+ @c = Class.new(Sequel::Model) do
434
+ def self.db_schema
435
+ set_columns(Array(@columns))
436
+ @db_schema = {:x=>{}, :y=>{}}
437
+ end
438
+ def self.set_dataset(ds, opts={})
439
+ @columns = ds.columns
440
+ db_schema
441
+ end
458
442
  end
459
-
460
- o.x.should be_nil
461
- o.x = 34
462
- o.x.should == 34
463
443
  end
464
444
 
465
- it "should be created on first initialization if lazy loading schema" do
466
- Sequel::Model.lazy_load_schema = true
445
+ it "should be created on set_dataset" do
467
446
  %w'x y x= y='.each do |x|
468
447
  @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
469
448
  end
470
449
  @c.set_dataset(@dataset)
471
- %w'x y x= y='.each do |x|
472
- @c.instance_methods.collect{|y| y.to_s}.should_not include(x)
473
- end
474
- o = @c.new
475
450
  %w'x y x= y='.each do |x|
476
451
  @c.instance_methods.collect{|y| y.to_s}.should include(x)
477
452
  end
453
+ o = @c.new
478
454
  %w'x y x= y='.each do |x|
479
455
  o.methods.collect{|y| y.to_s}.should include(x)
480
456
  end
@@ -28,7 +28,8 @@ describe Sequel::Model, "using a plugin" do
28
28
 
29
29
  it "should fail if the plugin is not found" do
30
30
  proc do
31
- c = Class.new(Sequel::Model) do
31
+ c = Class.new(Sequel::Model)
32
+ c.class_eval do
32
33
  is :something_or_other
33
34
  end
34
35
  end.should raise_error(LoadError)
@@ -37,7 +38,8 @@ describe Sequel::Model, "using a plugin" do
37
38
  it "should apply the plugin to the class" do
38
39
  c = nil
39
40
  proc do
40
- c = Class.new(Sequel::Model) do
41
+ c = Class.new(Sequel::Model)
42
+ c.class_eval do
41
43
  set_dataset MODEL_DB[:items]
42
44
  is :timestamped, :a => 1, :b => 2
43
45
  end
@@ -750,11 +750,6 @@ describe Sequel::Model, "#initialize" do
750
750
  m.values.should == {}
751
751
  end
752
752
 
753
- specify "should accept nil values" do
754
- m = @c.new(nil)
755
- m.values.should == {}
756
- end
757
-
758
753
  specify "should accept a block to execute" do
759
754
  m = @c.new {|o| o[:id] = 1234}
760
755
  m.id.should == 1234
@@ -874,6 +869,14 @@ describe Sequel::Model, "typecasting" do
874
869
  m.x.should == '1'
875
870
  end
876
871
 
872
+ specify "should not convert if serializing the field" do
873
+ @c.serialize :x
874
+ @c.instance_variable_set(:@db_schema, {:x=>{:type=>:string}})
875
+ m = @c.new
876
+ m.x =[1, 2]
877
+ m.x.should == [1, 2]
878
+ end
879
+
877
880
  specify "should convert to integer for an integer field" do
878
881
  @c.instance_variable_set(:@db_schema, {:x=>{:type=>:integer}})
879
882
  m = @c.new
@@ -48,6 +48,31 @@ describe Sequel::Model::Validation::Errors do
48
48
  msgs.size.should == 3
49
49
  msgs.should include('blow blieuh', 'blow blich', 'blay bliu')
50
50
  end
51
+
52
+ specify "should return the number of error messages using #count" do
53
+ @errors.count.should == 0
54
+ @errors.add(:a, 'b')
55
+ @errors.count.should == 1
56
+ @errors.add(:a, 'c')
57
+ @errors.count.should == 2
58
+ @errors.add(:b, 'c')
59
+ @errors.count.should == 3
60
+ end
61
+
62
+ specify "should return the array of error messages for a given attribute using #on" do
63
+ @errors.add(:a, 'b')
64
+ @errors.on(:a).should == ['b']
65
+ @errors.add(:a, 'c')
66
+ @errors.on(:a).should == ['b', 'c']
67
+ @errors.add(:b, 'c')
68
+ @errors.on(:a).should == ['b', 'c']
69
+ end
70
+
71
+ specify "should return nil if there are no error messages for a given attribute using #on" do
72
+ @errors.on(:a).should == nil
73
+ @errors.add(:b, 'b')
74
+ @errors.on(:a).should == nil
75
+ end
51
76
  end
52
77
 
53
78
  describe Sequel::Model do
@@ -1,9 +1,10 @@
1
1
  # database objects for running adapter specs
2
+ # ADO_DB = Sequel.connect(:adapter => 'ado', :driver => "{Microsoft Access Driver (*.mdb)}; DBQ=c:\\Nwind.mdb")
2
3
  # INFORMIX_DB = Sequel.connect('informix://localhost/mydb')
3
4
  # INTEGRATION_URL = 'sqlite:/'
4
5
  # MYSQL_USER = 'root'
5
- MYSQL_URL = "mysql://agp:sequel++@sql.mit.edu/agp+sequel"
6
+ # MYSQL_URL = "mysql://#{MYSQL_USER}@localhost/sandbox"
6
7
  # MYSQL_SOCKET_FILE = '/tmp/mysql.sock'
7
8
  # ORACLE_DB = Sequel.connect('oracle://hr:hr@localhost/XE')
8
- POSTGRES_URL = "postgres://_postgresql@postgresql/sequel_test"
9
- # SQLITE_DB = Sequel.connect('sqlite:/')
9
+ POSTGRES_URL = 'postgres:///sequel_test?user=_postgresql'
10
+ # SQLITE_URL = 'sqlite:/'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-11 00:00:00 -07:00
12
+ date: 2008-11-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,8 +27,8 @@ extra_rdoc_files:
27
27
  - doc/cheat_sheet.rdoc
28
28
  - doc/dataset_filtering.rdoc
29
29
  - doc/prepared_statements.rdoc
30
- - doc/sharding.rdoc
31
30
  - doc/schema.rdoc
31
+ - doc/sharding.rdoc
32
32
  files:
33
33
  - COPYING
34
34
  - CHANGELOG
@@ -39,16 +39,23 @@ files:
39
39
  - doc/cheat_sheet.rdoc
40
40
  - doc/dataset_filtering.rdoc
41
41
  - doc/prepared_statements.rdoc
42
- - doc/sharding.rdoc
43
42
  - doc/schema.rdoc
43
+ - doc/sharding.rdoc
44
44
  - spec/adapters
45
+ - spec/adapters/ado_spec.rb
45
46
  - spec/adapters/informix_spec.rb
46
47
  - spec/adapters/mysql_spec.rb
47
48
  - spec/adapters/oracle_spec.rb
48
49
  - spec/adapters/postgres_spec.rb
49
50
  - spec/adapters/spec_helper.rb
50
51
  - spec/adapters/sqlite_spec.rb
51
- - spec/adapters/ado_spec.rb
52
+ - spec/integration
53
+ - spec/integration/dataset_test.rb
54
+ - spec/integration/eager_loader_test.rb
55
+ - spec/integration/prepared_statement_test.rb
56
+ - spec/integration/schema_test.rb
57
+ - spec/integration/spec_helper.rb
58
+ - spec/integration/type_test.rb
52
59
  - spec/rcov.opts
53
60
  - spec/sequel_core
54
61
  - spec/sequel_core/connection_pool_spec.rb
@@ -81,13 +88,6 @@ files:
81
88
  - spec/spec.opts
82
89
  - spec/spec_config.rb.example
83
90
  - spec/spec_config.rb
84
- - spec/integration
85
- - spec/integration/eager_loader_test.rb
86
- - spec/integration/spec_helper.rb
87
- - spec/integration/dataset_test.rb
88
- - spec/integration/schema_test.rb
89
- - spec/integration/type_test.rb
90
- - spec/integration/prepared_statement_test.rb
91
91
  - lib/sequel.rb
92
92
  - lib/sequel_core.rb
93
93
  - lib/sequel_core
@@ -97,21 +97,23 @@ files:
97
97
  - lib/sequel_core/adapters/dbi.rb
98
98
  - lib/sequel_core/adapters/informix.rb
99
99
  - lib/sequel_core/adapters/jdbc.rb
100
+ - lib/sequel_core/adapters/jdbc
101
+ - lib/sequel_core/adapters/jdbc/mysql.rb
102
+ - lib/sequel_core/adapters/jdbc/oracle.rb
103
+ - lib/sequel_core/adapters/jdbc/postgresql.rb
104
+ - lib/sequel_core/adapters/jdbc/sqlite.rb
100
105
  - lib/sequel_core/adapters/mysql.rb
101
106
  - lib/sequel_core/adapters/odbc.rb
102
107
  - lib/sequel_core/adapters/openbase.rb
103
108
  - lib/sequel_core/adapters/oracle.rb
104
109
  - lib/sequel_core/adapters/postgres.rb
105
- - lib/sequel_core/adapters/sqlite.rb
106
110
  - lib/sequel_core/adapters/shared
107
- - lib/sequel_core/adapters/shared/mysql.rb
108
111
  - lib/sequel_core/adapters/shared/mssql.rb
112
+ - lib/sequel_core/adapters/shared/mysql.rb
113
+ - lib/sequel_core/adapters/shared/oracle.rb
109
114
  - lib/sequel_core/adapters/shared/postgres.rb
110
115
  - lib/sequel_core/adapters/shared/sqlite.rb
111
- - lib/sequel_core/adapters/jdbc
112
- - lib/sequel_core/adapters/jdbc/mysql.rb
113
- - lib/sequel_core/adapters/jdbc/postgresql.rb
114
- - lib/sequel_core/adapters/jdbc/sqlite.rb
116
+ - lib/sequel_core/adapters/sqlite.rb
115
117
  - lib/sequel_core/connection_pool.rb
116
118
  - lib/sequel_core/core_ext.rb
117
119
  - lib/sequel_core/core_sql.rb
@@ -123,10 +125,10 @@ files:
123
125
  - lib/sequel_core/dataset/callback.rb
124
126
  - lib/sequel_core/dataset/convenience.rb
125
127
  - lib/sequel_core/dataset/pagination.rb
128
+ - lib/sequel_core/dataset/prepared_statements.rb
126
129
  - lib/sequel_core/dataset/query.rb
127
130
  - lib/sequel_core/dataset/schema.rb
128
131
  - lib/sequel_core/dataset/sql.rb
129
- - lib/sequel_core/dataset/prepared_statements.rb
130
132
  - lib/sequel_core/deprecated.rb
131
133
  - lib/sequel_core/exceptions.rb
132
134
  - lib/sequel_core/migration.rb