sequel 3.29.0 → 3.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/CHANGELOG +35 -3
  2. data/Rakefile +2 -1
  3. data/doc/association_basics.rdoc +11 -0
  4. data/doc/opening_databases.rdoc +2 -0
  5. data/doc/release_notes/3.30.0.txt +135 -0
  6. data/doc/testing.rdoc +17 -3
  7. data/lib/sequel/adapters/amalgalite.rb +2 -2
  8. data/lib/sequel/adapters/do/mysql.rb +5 -2
  9. data/lib/sequel/adapters/ibmdb.rb +2 -2
  10. data/lib/sequel/adapters/jdbc.rb +126 -43
  11. data/lib/sequel/adapters/jdbc/as400.rb +11 -3
  12. data/lib/sequel/adapters/jdbc/db2.rb +2 -1
  13. data/lib/sequel/adapters/jdbc/derby.rb +44 -19
  14. data/lib/sequel/adapters/jdbc/h2.rb +32 -19
  15. data/lib/sequel/adapters/jdbc/hsqldb.rb +21 -17
  16. data/lib/sequel/adapters/jdbc/jtds.rb +9 -4
  17. data/lib/sequel/adapters/jdbc/mssql.rb +3 -1
  18. data/lib/sequel/adapters/jdbc/mysql.rb +2 -1
  19. data/lib/sequel/adapters/jdbc/oracle.rb +21 -7
  20. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -2
  21. data/lib/sequel/adapters/jdbc/sqlite.rb +2 -1
  22. data/lib/sequel/adapters/jdbc/sqlserver.rb +48 -18
  23. data/lib/sequel/adapters/mock.rb +2 -1
  24. data/lib/sequel/adapters/mysql.rb +4 -2
  25. data/lib/sequel/adapters/mysql2.rb +2 -2
  26. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  27. data/lib/sequel/adapters/openbase.rb +1 -1
  28. data/lib/sequel/adapters/oracle.rb +6 -6
  29. data/lib/sequel/adapters/postgres.rb +25 -12
  30. data/lib/sequel/adapters/shared/access.rb +14 -6
  31. data/lib/sequel/adapters/shared/db2.rb +36 -13
  32. data/lib/sequel/adapters/shared/firebird.rb +12 -5
  33. data/lib/sequel/adapters/shared/informix.rb +11 -3
  34. data/lib/sequel/adapters/shared/mssql.rb +94 -47
  35. data/lib/sequel/adapters/shared/mysql.rb +107 -49
  36. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +2 -2
  37. data/lib/sequel/adapters/shared/oracle.rb +54 -27
  38. data/lib/sequel/adapters/shared/postgres.rb +65 -26
  39. data/lib/sequel/adapters/shared/progress.rb +4 -1
  40. data/lib/sequel/adapters/shared/sqlite.rb +36 -20
  41. data/lib/sequel/adapters/sqlite.rb +2 -3
  42. data/lib/sequel/adapters/swift/mysql.rb +3 -2
  43. data/lib/sequel/adapters/swift/sqlite.rb +2 -2
  44. data/lib/sequel/adapters/tinytds.rb +14 -8
  45. data/lib/sequel/adapters/utils/emulate_offset_with_row_number.rb +7 -4
  46. data/lib/sequel/database/misc.rb +6 -2
  47. data/lib/sequel/dataset/graph.rb +33 -7
  48. data/lib/sequel/dataset/prepared_statements.rb +19 -5
  49. data/lib/sequel/dataset/sql.rb +611 -201
  50. data/lib/sequel/model/associations.rb +12 -5
  51. data/lib/sequel/model/base.rb +20 -5
  52. data/lib/sequel/plugins/sharding.rb +9 -29
  53. data/lib/sequel/sql.rb +2 -1
  54. data/lib/sequel/timezones.rb +14 -4
  55. data/lib/sequel/version.rb +1 -1
  56. data/spec/adapters/mysql_spec.rb +10 -0
  57. data/spec/adapters/oracle_spec.rb +1 -1
  58. data/spec/core/core_sql_spec.rb +3 -1
  59. data/spec/core/database_spec.rb +42 -0
  60. data/spec/core/dataset_spec.rb +10 -3
  61. data/spec/core/mock_adapter_spec.rb +4 -0
  62. data/spec/core/object_graph_spec.rb +38 -0
  63. data/spec/extensions/association_autoreloading_spec.rb +1 -10
  64. data/spec/extensions/association_dependencies_spec.rb +2 -12
  65. data/spec/extensions/association_pks_spec.rb +35 -39
  66. data/spec/extensions/caching_spec.rb +23 -50
  67. data/spec/extensions/class_table_inheritance_spec.rb +30 -82
  68. data/spec/extensions/composition_spec.rb +18 -13
  69. data/spec/extensions/hook_class_methods_spec.rb +65 -91
  70. data/spec/extensions/identity_map_spec.rb +33 -103
  71. data/spec/extensions/instance_filters_spec.rb +10 -21
  72. data/spec/extensions/instance_hooks_spec.rb +6 -24
  73. data/spec/extensions/json_serializer_spec.rb +4 -5
  74. data/spec/extensions/lazy_attributes_spec.rb +16 -20
  75. data/spec/extensions/list_spec.rb +17 -39
  76. data/spec/extensions/many_through_many_spec.rb +135 -277
  77. data/spec/extensions/migration_spec.rb +18 -15
  78. data/spec/extensions/named_timezones_spec.rb +1 -1
  79. data/spec/extensions/nested_attributes_spec.rb +97 -92
  80. data/spec/extensions/optimistic_locking_spec.rb +9 -20
  81. data/spec/extensions/prepared_statements_associations_spec.rb +22 -37
  82. data/spec/extensions/prepared_statements_safe_spec.rb +9 -27
  83. data/spec/extensions/prepared_statements_spec.rb +11 -30
  84. data/spec/extensions/prepared_statements_with_pk_spec.rb +6 -13
  85. data/spec/extensions/pretty_table_spec.rb +1 -6
  86. data/spec/extensions/rcte_tree_spec.rb +41 -43
  87. data/spec/extensions/schema_dumper_spec.rb +3 -6
  88. data/spec/extensions/serialization_spec.rb +20 -32
  89. data/spec/extensions/sharding_spec.rb +66 -140
  90. data/spec/extensions/single_table_inheritance_spec.rb +14 -36
  91. data/spec/extensions/spec_helper.rb +10 -64
  92. data/spec/extensions/sql_expr_spec.rb +20 -60
  93. data/spec/extensions/tactical_eager_loading_spec.rb +9 -19
  94. data/spec/extensions/timestamps_spec.rb +6 -6
  95. data/spec/extensions/to_dot_spec.rb +1 -2
  96. data/spec/extensions/touch_spec.rb +13 -14
  97. data/spec/extensions/tree_spec.rb +11 -26
  98. data/spec/extensions/update_primary_key_spec.rb +30 -24
  99. data/spec/extensions/validation_class_methods_spec.rb +30 -51
  100. data/spec/extensions/validation_helpers_spec.rb +16 -35
  101. data/spec/integration/dataset_test.rb +16 -4
  102. data/spec/integration/prepared_statement_test.rb +4 -2
  103. data/spec/model/eager_loading_spec.rb +16 -0
  104. data/spec/model/model_spec.rb +15 -1
  105. data/spec/model/record_spec.rb +60 -0
  106. metadata +23 -40
@@ -48,9 +48,10 @@ describe "Composition plugin" do
48
48
  @c.composition :date, :composer=>proc{Date.new(year+1, month+2, day+3)}, :decomposer=>proc{[:year, :month, :day].each{|s| self.send("#{s}=", date.send(s) * 2)}}
49
49
  @o.date.should == Date.new(2, 4, 6)
50
50
  @o.save
51
- MODEL_DB.sqls.last.should include("year = 4")
52
- MODEL_DB.sqls.last.should include("month = 8")
53
- MODEL_DB.sqls.last.should include("day = 12")
51
+ sql = MODEL_DB.sqls.last
52
+ sql.should include("year = 4")
53
+ sql.should include("month = 8")
54
+ sql.should include("day = 12")
54
55
  end
55
56
 
56
57
  it "should allow call super in composition getter and setter method definition in class" do
@@ -139,8 +140,9 @@ describe "Composition plugin" do
139
140
  @o.date.month.should == 6
140
141
  @o.date = c.new(3, 4)
141
142
  @o.save
142
- MODEL_DB.sqls.last.should include("year = 6")
143
- MODEL_DB.sqls.last.should include("month = 12")
143
+ sql = MODEL_DB.sqls.last
144
+ sql.should include("year = 6")
145
+ sql.should include("month = 12")
144
146
  end
145
147
 
146
148
  it ":mapping option should work with an array of two pairs of symbols" do
@@ -160,8 +162,9 @@ describe "Composition plugin" do
160
162
  @o.date.m.should == 6
161
163
  @o.date = c.new(3, 4)
162
164
  @o.save
163
- MODEL_DB.sqls.last.should include("year = 6")
164
- MODEL_DB.sqls.last.should include("month = 12")
165
+ sql = MODEL_DB.sqls.last
166
+ sql.should include("year = 6")
167
+ sql.should include("month = 12")
165
168
  end
166
169
 
167
170
  it ":mapping option :composer should return nil if all values are nil" do
@@ -173,9 +176,10 @@ describe "Composition plugin" do
173
176
  @c.composition :date, :mapping=>[:year, :month, :day]
174
177
  @o.date = nil
175
178
  @o.save
176
- MODEL_DB.sqls.last.should include("year = NULL")
177
- MODEL_DB.sqls.last.should include("month = NULL")
178
- MODEL_DB.sqls.last.should include("day = NULL")
179
+ sql = MODEL_DB.sqls.last
180
+ sql.should include("year = NULL")
181
+ sql.should include("month = NULL")
182
+ sql.should include("day = NULL")
179
183
  end
180
184
 
181
185
  it "should work correctly with subclasses" do
@@ -184,8 +188,9 @@ describe "Composition plugin" do
184
188
  o = c.load(:id=>1, :year=>1, :month=>2, :day=>3)
185
189
  o.date.should == Date.new(1, 2, 3)
186
190
  o.save
187
- MODEL_DB.sqls.last.should include("year = 1")
188
- MODEL_DB.sqls.last.should include("month = 2")
189
- MODEL_DB.sqls.last.should include("day = 3")
191
+ sql = MODEL_DB.sqls.last
192
+ sql.should include("year = 1")
193
+ sql.should include("month = 2")
194
+ sql.should include("day = 3")
190
195
  end
191
196
  end
@@ -6,187 +6,185 @@ describe "Model hooks" do
6
6
  end
7
7
 
8
8
  specify "should be definable using a block" do
9
- $adds = []
9
+ adds = []
10
10
  c = Class.new(Sequel::Model)
11
11
  c.class_eval do
12
- before_save {$adds << 'hi'}
12
+ before_save{adds << 'hi'}
13
13
  end
14
14
 
15
15
  c.new.before_save
16
- $adds.should == ['hi']
16
+ adds.should == ['hi']
17
17
  end
18
18
 
19
19
  specify "should be definable using a method name" do
20
- $adds = []
20
+ adds = []
21
21
  c = Class.new(Sequel::Model)
22
22
  c.class_eval do
23
- def bye; $adds << 'bye'; end
23
+ define_method(:bye){adds << 'bye'}
24
24
  before_save :bye
25
25
  end
26
26
 
27
27
  c.new.before_save
28
- $adds.should == ['bye']
28
+ adds.should == ['bye']
29
29
  end
30
30
 
31
31
  specify "should be additive" do
32
- $adds = []
32
+ adds = []
33
33
  c = Class.new(Sequel::Model)
34
34
  c.class_eval do
35
- after_save {$adds << 'hyiyie'}
36
- after_save {$adds << 'byiyie'}
35
+ after_save{adds << 'hyiyie'}
36
+ after_save{adds << 'byiyie'}
37
37
  end
38
38
 
39
39
  c.new.after_save
40
- $adds.should == ['hyiyie', 'byiyie']
40
+ adds.should == ['hyiyie', 'byiyie']
41
41
  end
42
42
 
43
43
  specify "before hooks should run in reverse order" do
44
- $adds = []
44
+ adds = []
45
45
  c = Class.new(Sequel::Model)
46
46
  c.class_eval do
47
- before_save {$adds << 'hyiyie'}
48
- before_save {$adds << 'byiyie'}
47
+ before_save{adds << 'hyiyie'}
48
+ before_save{adds << 'byiyie'}
49
49
  end
50
50
 
51
51
  c.new.before_save
52
- $adds.should == ['byiyie', 'hyiyie']
52
+ adds.should == ['byiyie', 'hyiyie']
53
53
  end
54
54
 
55
55
  specify "should not be additive if the method or tag already exists" do
56
- $adds = []
56
+ adds = []
57
57
  c = Class.new(Sequel::Model)
58
58
  c.class_eval do
59
- def bye; $adds << 'bye'; end
59
+ define_method(:bye){adds << 'bye'}
60
60
  before_save :bye
61
61
  before_save :bye
62
62
  end
63
63
 
64
64
  c.new.before_save
65
- $adds.should == ['bye']
65
+ adds.should == ['bye']
66
66
 
67
- $adds = []
67
+ adds = []
68
68
  d = Class.new(Sequel::Model)
69
69
  d.class_eval do
70
- before_save(:bye){$adds << 'hyiyie'}
71
- before_save(:bye){$adds << 'byiyie'}
70
+ before_save(:bye){adds << 'hyiyie'}
71
+ before_save(:bye){adds << 'byiyie'}
72
72
  end
73
73
 
74
74
  d.new.before_save
75
- $adds.should == ['byiyie']
75
+ adds.should == ['byiyie']
76
76
 
77
- $adds = []
77
+ adds = []
78
78
  e = Class.new(Sequel::Model)
79
79
  e.class_eval do
80
- def bye; $adds << 'bye'; end
80
+ define_method(:bye){adds << 'bye'}
81
81
  before_save :bye
82
- before_save(:bye){$adds << 'byiyie'}
82
+ before_save(:bye){adds << 'byiyie'}
83
83
  end
84
84
 
85
85
  e.new.before_save
86
- $adds.should == ['byiyie']
86
+ adds.should == ['byiyie']
87
87
 
88
- $adds = []
88
+ adds = []
89
89
  e = Class.new(Sequel::Model)
90
90
  e.class_eval do
91
- def bye; $adds << 'bye'; end
92
- before_save(:bye){$adds << 'byiyie'}
91
+ define_method(:bye){adds << 'bye'}
92
+ before_save(:bye){adds << 'byiyie'}
93
93
  before_save :bye
94
94
  end
95
95
 
96
96
  e.new.before_save
97
- $adds.should == ['bye']
97
+ adds.should == ['bye']
98
98
  end
99
99
 
100
100
  specify "should be inheritable" do
101
- # pending
102
-
103
- $adds = []
101
+ adds = []
104
102
  a = Class.new(Sequel::Model)
105
103
  a.class_eval do
106
- after_save {$adds << '123'}
104
+ after_save{adds << '123'}
107
105
  end
108
106
 
109
107
  b = Class.new(a)
110
108
  b.class_eval do
111
- after_save {$adds << '456'}
112
- after_save {$adds << '789'}
109
+ after_save{adds << '456'}
110
+ after_save{adds << '789'}
113
111
  end
114
112
 
115
113
  b.new.after_save
116
- $adds.should == ['123', '456', '789']
114
+ adds.should == ['123', '456', '789']
117
115
  end
118
116
 
119
117
  specify "should be overridable in descendant classes" do
120
- $adds = []
118
+ adds = []
121
119
  a = Class.new(Sequel::Model)
122
120
  a.class_eval do
123
- before_save {$adds << '123'}
121
+ before_save{adds << '123'}
124
122
  end
125
123
 
126
124
  b = Class.new(a)
127
125
  b.class_eval do
128
- def before_save; $adds << '456'; end
126
+ define_method(:before_save){adds << '456'}
129
127
  end
130
128
 
131
129
  a.new.before_save
132
- $adds.should == ['123']
133
- $adds = []
130
+ adds.should == ['123']
131
+ adds = []
134
132
  b.new.before_save
135
- $adds.should == ['456']
133
+ adds.should == ['456']
136
134
  end
137
135
 
138
136
  specify "should stop processing if a before hook returns false" do
139
- $flag = true
140
- $adds = []
137
+ flag = true
138
+ adds = []
141
139
 
142
140
  a = Class.new(Sequel::Model)
143
141
  a.class_eval do
144
- before_save {$adds << 'cruel'; $flag}
145
- before_save {$adds << 'blah'; $flag}
142
+ before_save{adds << 'cruel'; flag}
143
+ before_save{adds << 'blah'; flag}
146
144
  end
147
145
 
148
146
  a.new.before_save
149
- $adds.should == ['blah', 'cruel']
147
+ adds.should == ['blah', 'cruel']
150
148
 
151
149
  # chain should not break on nil
152
- $adds = []
153
- $flag = nil
150
+ adds = []
151
+ flag = nil
154
152
  a.new.before_save
155
- $adds.should == ['blah', 'cruel']
153
+ adds.should == ['blah', 'cruel']
156
154
 
157
- $adds = []
158
- $flag = false
155
+ adds = []
156
+ flag = false
159
157
  a.new.before_save
160
- $adds.should == ['blah']
158
+ adds.should == ['blah']
161
159
 
162
160
  b = Class.new(a)
163
161
  b.class_eval do
164
- before_save {$adds << 'mau'}
162
+ before_save{adds << 'mau'}
165
163
  end
166
164
 
167
- $adds = []
165
+ adds = []
168
166
  b.new.before_save
169
- $adds.should == ['mau', 'blah']
167
+ adds.should == ['mau', 'blah']
170
168
  end
171
169
  end
172
170
 
173
171
  describe "Model#after_initialize" do
174
172
  specify "should be called after initialization" do
175
- $values1 = nil
176
- $reached_after_initialized = false
173
+ values1 = nil
174
+ reached_after_initialized = false
177
175
 
178
176
  a = Class.new(Sequel::Model)
179
177
  a.class_eval do
180
178
  columns :x, :y
181
179
  after_initialize do
182
- $values1 = @values.clone
183
- $reached_after_initialized = true
180
+ values1 = @values.clone
181
+ reached_after_initialized = true
184
182
  end
185
183
  end
186
184
 
187
185
  a.new(:x => 1, :y => 2)
188
- $values1.should == {:x => 1, :y => 2}
189
- $reached_after_initialized.should == true
186
+ values1.should == {:x => 1, :y => 2}
187
+ reached_after_initialized.should == true
190
188
  end
191
189
  end
192
190
 
@@ -206,11 +204,7 @@ describe "Model#before_create && Model#after_create" do
206
204
  specify "should be called around new record creation" do
207
205
  @c.before_create {MODEL_DB << "BLAH before"}
208
206
  @c.create(:x => 2)
209
- MODEL_DB.sqls.should == [
210
- 'BLAH before',
211
- 'INSERT INTO items (x) VALUES (2)',
212
- 'BLAH after'
213
- ]
207
+ MODEL_DB.sqls.should == ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
214
208
  end
215
209
 
216
210
  specify ".create should cancel the save and raise an error if before_create returns false and raise_on_save_failure is true" do
@@ -242,11 +236,7 @@ describe "Model#before_update && Model#after_update" do
242
236
  @c.before_update {MODEL_DB << "BLAH before"}
243
237
  m = @c.load(:id => 2233, :x=>123)
244
238
  m.save
245
- MODEL_DB.sqls.should == [
246
- 'BLAH before',
247
- 'UPDATE items SET x = 123 WHERE (id = 2233)',
248
- 'BLAH after'
249
- ]
239
+ MODEL_DB.sqls.should == ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
250
240
  end
251
241
 
252
242
  specify "#save should cancel the save and raise an error if before_update returns false and raise_on_save_failure is true" do
@@ -279,22 +269,14 @@ describe "Model#before_save && Model#after_save" do
279
269
  @c.before_save {MODEL_DB << "BLAH before"}
280
270
  m = @c.load(:id => 2233, :x=>123)
281
271
  m.save
282
- MODEL_DB.sqls.should == [
283
- 'BLAH before',
284
- 'UPDATE items SET x = 123 WHERE (id = 2233)',
285
- 'BLAH after'
286
- ]
272
+ MODEL_DB.sqls.should == ['BLAH before', 'UPDATE items SET x = 123 WHERE (id = 2233)', 'BLAH after']
287
273
  end
288
274
 
289
275
  specify "should be called around record creation" do
290
276
  @c.before_save {MODEL_DB << "BLAH before"}
291
277
  @c.no_primary_key
292
278
  @c.create(:x => 2)
293
- MODEL_DB.sqls.should == [
294
- 'BLAH before',
295
- 'INSERT INTO items (x) VALUES (2)',
296
- 'BLAH after'
297
- ]
279
+ MODEL_DB.sqls.should == ['BLAH before', 'INSERT INTO items (x) VALUES (2)', 'BLAH after']
298
280
  end
299
281
 
300
282
  specify "#save should cancel the save and raise an error if before_save returns false and raise_on_save_failure is true" do
@@ -319,10 +301,6 @@ describe "Model#before_destroy && Model#after_destroy" do
319
301
  @c = Class.new(Sequel::Model(:items))
320
302
  @c.class_eval do
321
303
  after_destroy {MODEL_DB << "BLAH after"}
322
-
323
- def delete
324
- MODEL_DB << "DELETE BLAH"
325
- end
326
304
  end
327
305
  end
328
306
 
@@ -330,11 +308,7 @@ describe "Model#before_destroy && Model#after_destroy" do
330
308
  @c.before_destroy {MODEL_DB << "BLAH before"}
331
309
  m = @c.load(:id => 2233)
332
310
  m.destroy
333
- MODEL_DB.sqls.should == [
334
- 'BLAH before',
335
- 'DELETE BLAH',
336
- 'BLAH after'
337
- ]
311
+ MODEL_DB.sqls.should == ['BLAH before', "DELETE FROM items WHERE (id = 2233)", 'BLAH after']
338
312
  end
339
313
 
340
314
  specify "#destroy should cancel the destroy and raise an error if before_destroy returns false and raise_on_save_failure is true" do
@@ -5,13 +5,9 @@ describe "Sequel::Plugins::IdentityMap" do
5
5
  class ::IdentityMapModel < Sequel::Model
6
6
  plugin :identity_map
7
7
  attr_accessor :foo
8
- ds = dataset
9
- def ds.fetch_rows(sql)
10
- c = @opts[:where].args.first
11
- c = c.column if c.is_a?(Sequel::SQL::QualifiedIdentifier)
12
- h = {c=>@opts[:where].args.last}
13
- execute(sql)
14
- yield h
8
+ dataset._fetch = proc do |sql|
9
+ sql =~ /WHERE \(?(\w+\.)?(\w+) = (\d)\)?/
10
+ {$2.to_sym=>$3.to_i}
15
11
  end
16
12
  def self.waw_identity_map(&block) # with and without
17
13
  with_identity_map(&block)
@@ -110,9 +106,9 @@ describe "Sequel::Plugins::IdentityMap" do
110
106
  MODEL_DB.sqls.length.should == 1
111
107
  o.foo = 1
112
108
  @c[1].foo.should == o.foo
113
- MODEL_DB.sqls.length.should == 1
109
+ MODEL_DB.sqls.length.should == 0
114
110
  @c[2].foo.should_not == o.foo
115
- MODEL_DB.sqls.length.should == 2
111
+ MODEL_DB.sqls.length.should == 1
116
112
  end
117
113
  end
118
114
 
@@ -123,22 +119,22 @@ describe "Sequel::Plugins::IdentityMap" do
123
119
  MODEL_DB.sqls.length.should == 1
124
120
  o.foo = 1
125
121
  @c[1].should == o
126
- MODEL_DB.sqls.length.should == 1
122
+ MODEL_DB.sqls.length.should == 0
127
123
  o.destroy
128
- MODEL_DB.sqls.length.should == 2
124
+ MODEL_DB.sqls.length.should == 1
129
125
  @c[1].foo.should_not == o.foo
130
- MODEL_DB.sqls.length.should == 3
126
+ MODEL_DB.sqls.length.should == 1
131
127
 
132
128
  MODEL_DB.reset
133
129
  o = @c[2]
134
130
  MODEL_DB.sqls.length.should == 1
135
131
  o.foo = 1
136
132
  @c[2].should == o
137
- MODEL_DB.sqls.length.should == 1
133
+ MODEL_DB.sqls.length.should == 0
138
134
  o.delete
139
- MODEL_DB.sqls.length.should == 2
135
+ MODEL_DB.sqls.length.should == 1
140
136
  @c[2].foo.should_not == o.foo
141
- MODEL_DB.sqls.length.should == 3
137
+ MODEL_DB.sqls.length.should == 1
142
138
  end
143
139
  end
144
140
 
@@ -153,10 +149,10 @@ describe "Sequel::Plugins::IdentityMap" do
153
149
  MODEL_DB.sqls.length.should == 1
154
150
  o = @c1.load(:id=>1, :another_id=>2, :artist_id=>2)
155
151
  o.artist.should == a
156
- MODEL_DB.sqls.length.should == 1
152
+ MODEL_DB.sqls.length.should == 0
157
153
  o = @c1.load(:id=>3, :another_id=>3, :artist_id=>3)
158
154
  o.artist.should_not == a
159
- MODEL_DB.sqls.length.should == 2
155
+ MODEL_DB.sqls.length.should == 1
160
156
  end
161
157
  end
162
158
 
@@ -170,10 +166,10 @@ describe "Sequel::Plugins::IdentityMap" do
170
166
  MODEL_DB.sqls.length.should == 1
171
167
  o = @c1.load(:id=>2, :artist_id=>2)
172
168
  o.artist.should == a
173
- MODEL_DB.sqls.length.should == 1
169
+ MODEL_DB.sqls.length.should == 0
174
170
  o = @c1.load(:id=>3, :artist_id=>3)
175
171
  o.artist.should_not == a
176
- MODEL_DB.sqls.length.should == 2
172
+ MODEL_DB.sqls.length.should == 1
177
173
  end
178
174
  end
179
175
 
@@ -187,9 +183,9 @@ describe "Sequel::Plugins::IdentityMap" do
187
183
  a.should be_a_kind_of(@c1)
188
184
  MODEL_DB.sqls.length.should == 1
189
185
  o.reload
190
- MODEL_DB.sqls.length.should == 2
186
+ MODEL_DB.sqls.length.should == 1
191
187
  o.artist.should == a
192
- MODEL_DB.sqls.length.should == 3
188
+ MODEL_DB.sqls.length.should == 1
193
189
  end
194
190
  end
195
191
 
@@ -204,7 +200,7 @@ describe "Sequel::Plugins::IdentityMap" do
204
200
  MODEL_DB.sqls.length.should == 1
205
201
  o = @c1.load(:id=>2, :artist_id=>2)
206
202
  o.artist.should == a
207
- MODEL_DB.sqls.length.should == 2
203
+ MODEL_DB.sqls.length.should == 1
208
204
  end
209
205
  end
210
206
 
@@ -218,7 +214,7 @@ describe "Sequel::Plugins::IdentityMap" do
218
214
  MODEL_DB.sqls.length.should == 1
219
215
  o = @c1.load(:id=>2, :artist_id=>2)
220
216
  o.artist.should == a
221
- MODEL_DB.sqls.length.should == 2
217
+ MODEL_DB.sqls.length.should == 1
222
218
  end
223
219
  end
224
220
 
@@ -229,13 +225,7 @@ describe "Sequel::Plugins::IdentityMap" do
229
225
  @c1.many_to_many :artists, :class=>@c2, :left_key=>:album_id, :right_key=>:artist_id, :join_table=>:aa, :eager_loader=>(proc do |eo|
230
226
  eo[:rows].each{|object| object.associations[:artists] = [c.load(:id=>object.id)]}
231
227
  end)
232
- ds = @c1.dataset
233
- def ds.fetch_rows(sql)
234
- execute(sql)
235
- yield({:id=>1})
236
- yield({:id=>2})
237
- yield({:id=>3})
238
- end
228
+ @c1.dataset._fetch = [{:id=>1}, {:id=>2}, {:id=>3}]
239
229
 
240
230
  @c.waw_identity_map do
241
231
  MODEL_DB.sqls.length.should == 0
@@ -243,7 +233,7 @@ describe "Sequel::Plugins::IdentityMap" do
243
233
  MODEL_DB.sqls.length.should == 1
244
234
  a.should == [@c1.load(:id=>1), @c1.load(:id=>2), @c1.load(:id=>3)]
245
235
  a.map{|x| x.artists}.should == [[@c2.load(:id=>1)], [@c2.load(:id=>2)], [@c2.load(:id=>3)]]
246
- MODEL_DB.sqls.length.should == 1
236
+ MODEL_DB.sqls.length.should == 0
247
237
  end
248
238
  end
249
239
 
@@ -251,23 +241,8 @@ describe "Sequel::Plugins::IdentityMap" do
251
241
  @c1.columns :id
252
242
  @c2.columns :id
253
243
  @c1.many_to_many :artists, :class=>@c2, :left_key=>:album_id, :right_key=>:artist_id, :join_table=>:aa
254
- ds = @c1.dataset
255
- def ds.fetch_rows(sql)
256
- execute(sql)
257
- yield({:id=>1})
258
- yield({:id=>2})
259
- yield({:id=>3})
260
- end
261
- ds = @c2.dataset
262
- def ds.fetch_rows(sql)
263
- execute(sql)
264
- yield({:id=>1, :x_foreign_key_x=>1})
265
- yield({:id=>1, :x_foreign_key_x=>2})
266
- yield({:id=>2, :x_foreign_key_x=>1})
267
- yield({:id=>2, :x_foreign_key_x=>2})
268
- yield({:id=>3, :x_foreign_key_x=>1})
269
- yield({:id=>3, :x_foreign_key_x=>1})
270
- end
244
+ @c1.dataset._fetch = [{:id=>1}, {:id=>2}, {:id=>3}]
245
+ @c2.dataset._fetch = [{:id=>1, :x_foreign_key_x=>1}, {:id=>1, :x_foreign_key_x=>2}, {:id=>2, :x_foreign_key_x=>1}, {:id=>2, :x_foreign_key_x=>2}, {:id=>3, :x_foreign_key_x=>1}, {:id=>3, :x_foreign_key_x=>1}]
271
246
 
272
247
  @c.waw_identity_map do
273
248
  MODEL_DB.sqls.length.should == 0
@@ -275,7 +250,7 @@ describe "Sequel::Plugins::IdentityMap" do
275
250
  MODEL_DB.sqls.length.should == 2
276
251
  a.should == [@c1.load(:id=>1), @c1.load(:id=>2), @c1.load(:id=>3)]
277
252
  a.map{|x| x.artists}.should == [[@c2.load(:id=>1), @c2.load(:id=>2), @c2.load(:id=>3), @c2.load(:id=>3)], [@c2.load(:id=>1), @c2.load(:id=>2)], []]
278
- MODEL_DB.sqls.length.should == 2
253
+ MODEL_DB.sqls.length.should == 0
279
254
  end
280
255
  end
281
256
 
@@ -284,23 +259,8 @@ describe "Sequel::Plugins::IdentityMap" do
284
259
  @c2.columns :id
285
260
  @c1.set_primary_key :id, :id2
286
261
  @c1.many_to_many :artists, :class=>@c2, :left_key=>[:album_id1, :album_id2], :right_key=>:artist_id, :join_table=>:aa
287
- ds = @c1.dataset
288
- def ds.fetch_rows(sql)
289
- execute(sql)
290
- yield({:id=>1, :id2=>4})
291
- yield({:id=>2, :id2=>5})
292
- yield({:id=>3, :id2=>6})
293
- end
294
- ds = @c2.dataset
295
- def ds.fetch_rows(sql)
296
- execute(sql)
297
- yield({:id=>1, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
298
- yield({:id=>1, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5})
299
- yield({:id=>2, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
300
- yield({:id=>2, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5})
301
- yield({:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
302
- yield({:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
303
- end
262
+ @c1.dataset._fetch = [{:id=>1, :id2=>4}, {:id=>2, :id2=>5}, {:id=>3, :id2=>6}]
263
+ @c2.dataset._fetch = [ {:id=>1, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}, {:id=>1, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5}, {:id=>2, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}, {:id=>2, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5}, {:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}, {:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}]
304
264
 
305
265
  @c.waw_identity_map do
306
266
  MODEL_DB.sqls.length.should == 0
@@ -308,7 +268,7 @@ describe "Sequel::Plugins::IdentityMap" do
308
268
  MODEL_DB.sqls.length.should == 2
309
269
  a.should == [@c1.load(:id=>1, :id2=>4), @c1.load(:id=>2, :id2=>5), @c1.load(:id=>3, :id2=>6)]
310
270
  a.map{|x| x.artists}.should == [[@c2.load(:id=>1), @c2.load(:id=>2), @c2.load(:id=>3), @c2.load(:id=>3)], [@c2.load(:id=>1), @c2.load(:id=>2)], []]
311
- MODEL_DB.sqls.length.should == 2
271
+ MODEL_DB.sqls.length.should == 0
312
272
  end
313
273
  end
314
274
 
@@ -317,23 +277,8 @@ describe "Sequel::Plugins::IdentityMap" do
317
277
  @c2.columns :id
318
278
  @c1.plugin :many_through_many
319
279
  @c1.many_through_many :artists, [[:aa, :album_id, :artist_id]], :class=>@c2
320
- ds = @c1.dataset
321
- def ds.fetch_rows(sql)
322
- execute(sql)
323
- yield({:id=>1})
324
- yield({:id=>2})
325
- yield({:id=>3})
326
- end
327
- ds = @c2.dataset
328
- def ds.fetch_rows(sql)
329
- execute(sql)
330
- yield({:id=>1, :x_foreign_key_x=>1})
331
- yield({:id=>1, :x_foreign_key_x=>2})
332
- yield({:id=>2, :x_foreign_key_x=>1})
333
- yield({:id=>2, :x_foreign_key_x=>2})
334
- yield({:id=>3, :x_foreign_key_x=>1})
335
- yield({:id=>3, :x_foreign_key_x=>1})
336
- end
280
+ @c1.dataset._fetch = [{:id=>1}, {:id=>2}, {:id=>3}]
281
+ @c2.dataset._fetch = [{:id=>1, :x_foreign_key_x=>1}, {:id=>1, :x_foreign_key_x=>2}, {:id=>2, :x_foreign_key_x=>1}, {:id=>2, :x_foreign_key_x=>2}, {:id=>3, :x_foreign_key_x=>1}, {:id=>3, :x_foreign_key_x=>1}]
337
282
 
338
283
  @c.waw_identity_map do
339
284
  MODEL_DB.sqls.length.should == 0
@@ -341,7 +286,7 @@ describe "Sequel::Plugins::IdentityMap" do
341
286
  MODEL_DB.sqls.length.should == 2
342
287
  a.should == [@c1.load(:id=>1), @c1.load(:id=>2), @c1.load(:id=>3)]
343
288
  a.map{|x| x.artists}.should == [[@c2.load(:id=>1), @c2.load(:id=>2), @c2.load(:id=>3), @c2.load(:id=>3)], [@c2.load(:id=>1), @c2.load(:id=>2)], []]
344
- MODEL_DB.sqls.length.should == 2
289
+ MODEL_DB.sqls.length.should == 0
345
290
  end
346
291
  end
347
292
 
@@ -351,23 +296,8 @@ describe "Sequel::Plugins::IdentityMap" do
351
296
  @c1.set_primary_key :id, :id2
352
297
  @c1.plugin :many_through_many
353
298
  @c1.many_through_many :artists, [[:aa, [:album_id1, :album_id2], :artist_id]], :class=>@c2
354
- ds = @c1.dataset
355
- def ds.fetch_rows(sql)
356
- execute(sql)
357
- yield({:id=>1, :id2=>4})
358
- yield({:id=>2, :id2=>5})
359
- yield({:id=>3, :id2=>6})
360
- end
361
- ds = @c2.dataset
362
- def ds.fetch_rows(sql)
363
- execute(sql)
364
- yield({:id=>1, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
365
- yield({:id=>1, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5})
366
- yield({:id=>2, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
367
- yield({:id=>2, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5})
368
- yield({:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
369
- yield({:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4})
370
- end
299
+ @c1.dataset._fetch = [{:id=>1, :id2=>4}, {:id=>2, :id2=>5}, {:id=>3, :id2=>6}]
300
+ @c2.dataset._fetch = [ {:id=>1, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}, {:id=>1, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5}, {:id=>2, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}, {:id=>2, :x_foreign_key_0_x=>2, :x_foreign_key_1_x=>5}, {:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}, {:id=>3, :x_foreign_key_0_x=>1, :x_foreign_key_1_x=>4}]
371
301
 
372
302
  @c.waw_identity_map do
373
303
  MODEL_DB.sqls.length.should == 0
@@ -375,7 +305,7 @@ describe "Sequel::Plugins::IdentityMap" do
375
305
  MODEL_DB.sqls.length.should == 2
376
306
  a.should == [@c1.load(:id=>1, :id2=>4), @c1.load(:id=>2, :id2=>5), @c1.load(:id=>3, :id2=>6)]
377
307
  a.map{|x| x.artists}.should == [[@c2.load(:id=>1), @c2.load(:id=>2), @c2.load(:id=>3), @c2.load(:id=>3)], [@c2.load(:id=>1), @c2.load(:id=>2)], []]
378
- MODEL_DB.sqls.length.should == 2
308
+ MODEL_DB.sqls.length.should == 0
379
309
  end
380
310
  end
381
311
  end