sequel 3.48.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +114 -0
  3. data/Rakefile +10 -7
  4. data/doc/association_basics.rdoc +25 -23
  5. data/doc/code_order.rdoc +7 -0
  6. data/doc/core_extensions.rdoc +0 -10
  7. data/doc/object_model.rdoc +4 -1
  8. data/doc/querying.rdoc +3 -3
  9. data/doc/release_notes/4.0.0.txt +262 -0
  10. data/doc/security.rdoc +0 -28
  11. data/doc/testing.rdoc +8 -14
  12. data/lib/sequel/adapters/ado.rb +7 -11
  13. data/lib/sequel/adapters/ado/access.rb +8 -8
  14. data/lib/sequel/adapters/ado/mssql.rb +4 -4
  15. data/lib/sequel/adapters/amalgalite.rb +6 -6
  16. data/lib/sequel/adapters/cubrid.rb +7 -7
  17. data/lib/sequel/adapters/db2.rb +5 -9
  18. data/lib/sequel/adapters/dbi.rb +2 -6
  19. data/lib/sequel/adapters/do.rb +4 -4
  20. data/lib/sequel/adapters/firebird.rb +4 -4
  21. data/lib/sequel/adapters/ibmdb.rb +8 -8
  22. data/lib/sequel/adapters/informix.rb +2 -10
  23. data/lib/sequel/adapters/jdbc.rb +17 -17
  24. data/lib/sequel/adapters/jdbc/as400.rb +2 -2
  25. data/lib/sequel/adapters/jdbc/cubrid.rb +1 -1
  26. data/lib/sequel/adapters/jdbc/db2.rb +1 -1
  27. data/lib/sequel/adapters/jdbc/derby.rb +1 -1
  28. data/lib/sequel/adapters/jdbc/h2.rb +2 -2
  29. data/lib/sequel/adapters/jdbc/hsqldb.rb +1 -1
  30. data/lib/sequel/adapters/jdbc/informix.rb +1 -1
  31. data/lib/sequel/adapters/jdbc/mssql.rb +2 -2
  32. data/lib/sequel/adapters/jdbc/mysql.rb +1 -1
  33. data/lib/sequel/adapters/jdbc/oracle.rb +5 -1
  34. data/lib/sequel/adapters/jdbc/postgresql.rb +3 -3
  35. data/lib/sequel/adapters/jdbc/sqlite.rb +3 -3
  36. data/lib/sequel/adapters/jdbc/transactions.rb +3 -3
  37. data/lib/sequel/adapters/mock.rb +7 -7
  38. data/lib/sequel/adapters/mysql.rb +3 -3
  39. data/lib/sequel/adapters/mysql2.rb +4 -4
  40. data/lib/sequel/adapters/odbc.rb +2 -6
  41. data/lib/sequel/adapters/odbc/mssql.rb +1 -1
  42. data/lib/sequel/adapters/openbase.rb +1 -5
  43. data/lib/sequel/adapters/oracle.rb +13 -17
  44. data/lib/sequel/adapters/postgres.rb +20 -25
  45. data/lib/sequel/adapters/shared/cubrid.rb +3 -3
  46. data/lib/sequel/adapters/shared/db2.rb +2 -2
  47. data/lib/sequel/adapters/shared/firebird.rb +7 -7
  48. data/lib/sequel/adapters/shared/mssql.rb +9 -9
  49. data/lib/sequel/adapters/shared/mysql.rb +29 -13
  50. data/lib/sequel/adapters/shared/mysql_prepared_statements.rb +7 -7
  51. data/lib/sequel/adapters/shared/oracle.rb +22 -13
  52. data/lib/sequel/adapters/shared/postgres.rb +61 -46
  53. data/lib/sequel/adapters/shared/sqlite.rb +9 -9
  54. data/lib/sequel/adapters/sqlite.rb +17 -11
  55. data/lib/sequel/adapters/swift.rb +3 -3
  56. data/lib/sequel/adapters/swift/mysql.rb +1 -1
  57. data/lib/sequel/adapters/swift/sqlite.rb +1 -1
  58. data/lib/sequel/adapters/tinytds.rb +8 -8
  59. data/lib/sequel/ast_transformer.rb +3 -1
  60. data/lib/sequel/connection_pool.rb +4 -2
  61. data/lib/sequel/connection_pool/sharded_single.rb +2 -2
  62. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -5
  63. data/lib/sequel/connection_pool/threaded.rb +7 -7
  64. data/lib/sequel/core.rb +4 -67
  65. data/lib/sequel/database.rb +1 -0
  66. data/lib/sequel/database/connecting.rb +2 -8
  67. data/lib/sequel/database/dataset.rb +2 -7
  68. data/lib/sequel/database/dataset_defaults.rb +0 -18
  69. data/lib/sequel/database/features.rb +4 -4
  70. data/lib/sequel/database/misc.rb +6 -8
  71. data/lib/sequel/database/query.rb +5 -61
  72. data/lib/sequel/database/schema_generator.rb +22 -20
  73. data/lib/sequel/database/schema_methods.rb +48 -20
  74. data/lib/sequel/database/transactions.rb +7 -17
  75. data/lib/sequel/dataset.rb +2 -0
  76. data/lib/sequel/dataset/actions.rb +23 -91
  77. data/lib/sequel/dataset/features.rb +1 -4
  78. data/lib/sequel/dataset/graph.rb +3 -47
  79. data/lib/sequel/dataset/misc.rb +4 -33
  80. data/lib/sequel/dataset/prepared_statements.rb +3 -1
  81. data/lib/sequel/dataset/query.rb +116 -240
  82. data/lib/sequel/dataset/sql.rb +19 -97
  83. data/lib/sequel/deprecated.rb +0 -16
  84. data/lib/sequel/exceptions.rb +0 -3
  85. data/lib/sequel/extensions/_pretty_table.rb +1 -1
  86. data/lib/sequel/extensions/columns_introspection.rb +1 -12
  87. data/lib/sequel/extensions/constraint_validations.rb +3 -3
  88. data/lib/sequel/extensions/core_extensions.rb +0 -9
  89. data/lib/sequel/extensions/date_arithmetic.rb +1 -2
  90. data/lib/sequel/extensions/graph_each.rb +11 -0
  91. data/lib/sequel/extensions/migration.rb +5 -5
  92. data/lib/sequel/extensions/null_dataset.rb +11 -13
  93. data/lib/sequel/extensions/pagination.rb +3 -6
  94. data/lib/sequel/extensions/pg_array.rb +6 -4
  95. data/lib/sequel/extensions/pg_array_ops.rb +35 -1
  96. data/lib/sequel/extensions/pg_json.rb +12 -2
  97. data/lib/sequel/extensions/pg_json_ops.rb +266 -0
  98. data/lib/sequel/extensions/pg_range.rb +2 -2
  99. data/lib/sequel/extensions/pg_range_ops.rb +0 -8
  100. data/lib/sequel/extensions/pg_row.rb +2 -2
  101. data/lib/sequel/extensions/pretty_table.rb +0 -4
  102. data/lib/sequel/extensions/query.rb +3 -8
  103. data/lib/sequel/extensions/schema_caching.rb +0 -7
  104. data/lib/sequel/extensions/schema_dumper.rb +10 -17
  105. data/lib/sequel/extensions/select_remove.rb +0 -4
  106. data/lib/sequel/extensions/set_overrides.rb +28 -0
  107. data/lib/sequel/extensions/to_dot.rb +6 -10
  108. data/lib/sequel/model.rb +6 -7
  109. data/lib/sequel/model/associations.rb +127 -182
  110. data/lib/sequel/model/base.rb +88 -211
  111. data/lib/sequel/model/errors.rb +0 -13
  112. data/lib/sequel/model/plugins.rb +2 -2
  113. data/lib/sequel/no_core_ext.rb +0 -1
  114. data/lib/sequel/plugins/after_initialize.rb +11 -17
  115. data/lib/sequel/plugins/association_autoreloading.rb +1 -47
  116. data/lib/sequel/plugins/association_dependencies.rb +2 -2
  117. data/lib/sequel/plugins/auto_validations.rb +2 -8
  118. data/lib/sequel/plugins/blacklist_security.rb +32 -2
  119. data/lib/sequel/plugins/caching.rb +1 -1
  120. data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
  121. data/lib/sequel/plugins/composition.rb +10 -8
  122. data/lib/sequel/plugins/constraint_validations.rb +2 -2
  123. data/lib/sequel/plugins/dataset_associations.rb +4 -0
  124. data/lib/sequel/plugins/defaults_setter.rb +8 -6
  125. data/lib/sequel/plugins/dirty.rb +6 -6
  126. data/lib/sequel/plugins/force_encoding.rb +13 -8
  127. data/lib/sequel/plugins/hook_class_methods.rb +1 -7
  128. data/lib/sequel/plugins/json_serializer.rb +13 -74
  129. data/lib/sequel/plugins/lazy_attributes.rb +2 -4
  130. data/lib/sequel/plugins/list.rb +1 -1
  131. data/lib/sequel/plugins/many_through_many.rb +4 -11
  132. data/lib/sequel/plugins/many_to_one_pk_lookup.rb +1 -49
  133. data/lib/sequel/plugins/nested_attributes.rb +1 -1
  134. data/lib/sequel/plugins/optimistic_locking.rb +3 -5
  135. data/lib/sequel/plugins/pg_array_associations.rb +453 -0
  136. data/lib/sequel/plugins/pg_typecast_on_load.rb +23 -7
  137. data/lib/sequel/plugins/prepared_statements.rb +1 -1
  138. data/lib/sequel/plugins/prepared_statements_associations.rb +20 -14
  139. data/lib/sequel/plugins/prepared_statements_safe.rb +2 -2
  140. data/lib/sequel/plugins/rcte_tree.rb +1 -1
  141. data/lib/sequel/plugins/serialization.rb +5 -4
  142. data/lib/sequel/plugins/serialization_modification_detection.rb +1 -1
  143. data/lib/sequel/plugins/sharding.rb +7 -1
  144. data/lib/sequel/plugins/single_table_inheritance.rb +1 -1
  145. data/lib/sequel/plugins/timestamps.rb +1 -1
  146. data/lib/sequel/plugins/touch.rb +2 -2
  147. data/lib/sequel/plugins/tree.rb +1 -1
  148. data/lib/sequel/plugins/typecast_on_load.rb +19 -4
  149. data/lib/sequel/plugins/validation_class_methods.rb +0 -30
  150. data/lib/sequel/plugins/validation_helpers.rb +13 -31
  151. data/lib/sequel/plugins/xml_serializer.rb +18 -57
  152. data/lib/sequel/sql.rb +20 -22
  153. data/lib/sequel/version.rb +2 -2
  154. data/spec/adapters/db2_spec.rb +14 -23
  155. data/spec/adapters/firebird_spec.rb +25 -29
  156. data/spec/adapters/informix_spec.rb +11 -14
  157. data/spec/adapters/mssql_spec.rb +71 -77
  158. data/spec/adapters/mysql_spec.rb +165 -172
  159. data/spec/adapters/oracle_spec.rb +36 -39
  160. data/spec/adapters/postgres_spec.rb +175 -100
  161. data/spec/adapters/spec_helper.rb +13 -11
  162. data/spec/adapters/sqlite_spec.rb +36 -44
  163. data/spec/core/connection_pool_spec.rb +2 -1
  164. data/spec/core/database_spec.rb +55 -55
  165. data/spec/core/dataset_spec.rb +45 -249
  166. data/spec/core/deprecated_spec.rb +0 -8
  167. data/spec/core/expression_filters_spec.rb +23 -5
  168. data/spec/core/object_graph_spec.rb +4 -66
  169. data/spec/core/schema_spec.rb +35 -12
  170. data/spec/core/spec_helper.rb +3 -2
  171. data/spec/core_extensions_spec.rb +17 -19
  172. data/spec/extensions/arbitrary_servers_spec.rb +2 -3
  173. data/spec/extensions/association_dependencies_spec.rb +14 -14
  174. data/spec/extensions/auto_validations_spec.rb +7 -0
  175. data/spec/extensions/blacklist_security_spec.rb +5 -5
  176. data/spec/extensions/blank_spec.rb +2 -0
  177. data/spec/extensions/class_table_inheritance_spec.rb +2 -2
  178. data/spec/extensions/columns_introspection_spec.rb +2 -29
  179. data/spec/extensions/composition_spec.rb +10 -17
  180. data/spec/extensions/core_refinements_spec.rb +5 -1
  181. data/spec/extensions/dataset_associations_spec.rb +18 -0
  182. data/spec/extensions/date_arithmetic_spec.rb +2 -2
  183. data/spec/extensions/defaults_setter_spec.rb +9 -9
  184. data/spec/extensions/dirty_spec.rb +0 -5
  185. data/spec/extensions/eval_inspect_spec.rb +2 -0
  186. data/spec/extensions/force_encoding_spec.rb +2 -18
  187. data/spec/extensions/hash_aliases_spec.rb +8 -0
  188. data/spec/extensions/hook_class_methods_spec.rb +39 -58
  189. data/spec/extensions/inflector_spec.rb +2 -0
  190. data/spec/extensions/instance_filters_spec.rb +8 -8
  191. data/spec/extensions/json_serializer_spec.rb +1 -41
  192. data/spec/extensions/list_spec.rb +1 -1
  193. data/spec/extensions/many_through_many_spec.rb +106 -109
  194. data/spec/extensions/migration_spec.rb +2 -0
  195. data/spec/extensions/named_timezones_spec.rb +1 -0
  196. data/spec/extensions/pg_array_associations_spec.rb +603 -0
  197. data/spec/extensions/pg_array_ops_spec.rb +25 -0
  198. data/spec/extensions/pg_array_spec.rb +9 -1
  199. data/spec/extensions/pg_hstore_ops_spec.rb +13 -0
  200. data/spec/extensions/pg_hstore_spec.rb +1 -0
  201. data/spec/extensions/pg_json_ops_spec.rb +131 -0
  202. data/spec/extensions/pg_json_spec.rb +10 -4
  203. data/spec/extensions/pg_range_ops_spec.rb +2 -5
  204. data/spec/extensions/pg_range_spec.rb +6 -2
  205. data/spec/extensions/pg_row_ops_spec.rb +2 -0
  206. data/spec/extensions/prepared_statements_associations_spec.rb +26 -5
  207. data/spec/extensions/rcte_tree_spec.rb +15 -15
  208. data/spec/extensions/schema_dumper_spec.rb +0 -1
  209. data/spec/extensions/schema_spec.rb +9 -9
  210. data/spec/extensions/serialization_modification_detection_spec.rb +1 -1
  211. data/spec/extensions/serialization_spec.rb +18 -29
  212. data/spec/extensions/set_overrides_spec.rb +4 -0
  213. data/spec/extensions/{many_to_one_pk_lookup_spec.rb → shared_caching_spec.rb} +1 -4
  214. data/spec/extensions/single_table_inheritance_spec.rb +4 -4
  215. data/spec/extensions/spec_helper.rb +8 -9
  216. data/spec/extensions/sql_expr_spec.rb +2 -0
  217. data/spec/extensions/string_date_time_spec.rb +2 -0
  218. data/spec/extensions/string_stripper_spec.rb +2 -0
  219. data/spec/extensions/tactical_eager_loading_spec.rb +12 -12
  220. data/spec/extensions/thread_local_timezones_spec.rb +2 -0
  221. data/spec/extensions/timestamps_spec.rb +1 -1
  222. data/spec/extensions/to_dot_spec.rb +1 -1
  223. data/spec/extensions/touch_spec.rb +24 -24
  224. data/spec/extensions/tree_spec.rb +7 -7
  225. data/spec/extensions/typecast_on_load_spec.rb +8 -1
  226. data/spec/extensions/update_primary_key_spec.rb +10 -10
  227. data/spec/extensions/validation_class_methods_spec.rb +10 -39
  228. data/spec/extensions/validation_helpers_spec.rb +29 -47
  229. data/spec/extensions/xml_serializer_spec.rb +1 -23
  230. data/spec/integration/associations_test.rb +231 -40
  231. data/spec/integration/database_test.rb +1 -1
  232. data/spec/integration/dataset_test.rb +64 -64
  233. data/spec/integration/eager_loader_test.rb +28 -28
  234. data/spec/integration/migrator_test.rb +1 -1
  235. data/spec/integration/model_test.rb +2 -2
  236. data/spec/integration/plugin_test.rb +21 -21
  237. data/spec/integration/prepared_statement_test.rb +7 -7
  238. data/spec/integration/schema_test.rb +115 -110
  239. data/spec/integration/spec_helper.rb +17 -27
  240. data/spec/integration/timezone_test.rb +1 -1
  241. data/spec/integration/transaction_test.rb +10 -10
  242. data/spec/integration/type_test.rb +2 -2
  243. data/spec/model/association_reflection_spec.rb +2 -28
  244. data/spec/model/associations_spec.rb +239 -188
  245. data/spec/model/base_spec.rb +27 -68
  246. data/spec/model/dataset_methods_spec.rb +4 -4
  247. data/spec/model/eager_loading_spec.rb +160 -172
  248. data/spec/model/hooks_spec.rb +62 -79
  249. data/spec/model/model_spec.rb +36 -51
  250. data/spec/model/plugins_spec.rb +5 -19
  251. data/spec/model/record_spec.rb +125 -151
  252. data/spec/model/spec_helper.rb +8 -6
  253. data/spec/model/validations_spec.rb +4 -17
  254. data/spec/spec_config.rb +2 -10
  255. metadata +50 -56
  256. data/lib/sequel/deprecated_core_extensions.rb +0 -135
  257. data/lib/sequel/extensions/pg_auto_parameterize.rb +0 -185
  258. data/lib/sequel/extensions/pg_statement_cache.rb +0 -318
  259. data/lib/sequel/plugins/identity_map.rb +0 -260
  260. data/lib/sequel_core.rb +0 -2
  261. data/lib/sequel_model.rb +0 -2
  262. data/spec/extensions/association_autoreloading_spec.rb +0 -102
  263. data/spec/extensions/identity_map_spec.rb +0 -337
  264. data/spec/extensions/pg_auto_parameterize_spec.rb +0 -70
  265. data/spec/extensions/pg_statement_cache_spec.rb +0 -208
  266. data/spec/rcov.opts +0 -8
  267. data/spec/spec_config.rb.example +0 -10
@@ -97,10 +97,6 @@ describe "Sequel::Plugins::XmlSerializer" do
97
97
  Album.from_xml(@album.to_xml(:include=>{:artist=>{:include=>{:albums=>{:only=>:name}}}}), :associations=>{:artist=>{:associations=>{:albums=>{:fields=>%w'name'}}}}).artist.albums.should == [Album.load(:name=>@album.name)]
98
98
  end
99
99
 
100
- qspecify "should automatically cascade parsing for all associations if :all_associations is used" do
101
- Artist.from_xml(@artist.to_xml(:include=>{:albums=>{:include=>:artist}}), :all_associations=>true).albums.map{|a| a.artist}.should == [@artist]
102
- end
103
-
104
100
  it "should handle the :include option cascading with an empty hash" do
105
101
  Album.from_xml(@album.to_xml(:include=>{:artist=>{}}), :associations=>:artist).artist.should == @artist
106
102
  Album.from_xml(@album.to_xml(:include=>{:blah=>{}})).blah.should == @album.blah
@@ -172,7 +168,7 @@ describe "Sequel::Plugins::XmlSerializer" do
172
168
  Album.array_from_xml(Album.to_xml(:array=>[a], :include=>:artist), :associations=>:artist).first.artist.should == artist
173
169
 
174
170
  artist.associations[:albums] = [a]
175
- x = Artist.array_from_xml(Artist.to_xml(:array=>[artist], :include=>:albums), :associations=>:albums)
171
+ x = Artist.array_from_xml(Artist.to_xml(:array=>[artist], :include=>:albums), :associations=>[:albums])
176
172
  x.should == [artist]
177
173
  x.first.albums.should == [a]
178
174
  end
@@ -181,29 +177,11 @@ describe "Sequel::Plugins::XmlSerializer" do
181
177
  proc{Album.dataset.naked.to_xml}.should raise_error(Sequel::Error)
182
178
  end
183
179
 
184
- qspecify "should have :associations option take precedence over :all_assocations" do
185
- Artist.from_xml(@artist.to_xml(:include=>:albums), :associations=>[], :all_associations=>true, :fields=>[]).associations.should == {}
186
- end
187
-
188
- qspecify "should allow overriding of :all_columns options in associated objects" do
189
- Album.restrict_primary_key
190
- Artist.from_xml(@artist.to_xml(:include=>:albums), :associations=>{:albums=>{:fields=>[:id, :name, :artist_id], :missing=>:raise}}, :all_columns=>true).albums
191
- end
192
-
193
- qspecify "should allow setting columns that are restricted if :all_columns is used" do
194
- Artist.restrict_primary_key
195
- Artist.from_xml(@artist.to_xml, :all_columns=>true).should == @artist
196
- end
197
-
198
180
  it "should raise an error if using parsing empty xml" do
199
181
  proc{Artist.from_xml("<?xml version=\"1.0\"?>\n")}.should raise_error(Sequel::Error)
200
182
  proc{Artist.array_from_xml("<?xml version=\"1.0\"?>\n")}.should raise_error(Sequel::Error)
201
183
  end
202
184
 
203
- qspecify "should raise an error if using :all_columns and non-column is in the XML" do
204
- proc{Artist.from_xml("<?xml version=\"1.0\"?>\n<artist>\n <foo>bar</foo>\n <id>2</id>\n</artist>\n", :all_columns=>true)}.should raise_error(Sequel::Error)
205
- end
206
-
207
185
  it "should raise an error if attempting to set a restricted column and :all_columns is not used" do
208
186
  Artist.restrict_primary_key
209
187
  proc{Artist.from_xml(@artist.to_xml)}.should raise_error(Sequel::Error)
@@ -1,23 +1,27 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
2
2
 
3
- shared_examples_for "eager limit strategies" do
3
+ shared_examples_for "one_to_one eager limit strategies" do
4
4
  specify "eager loading one_to_one associations should work correctly" do
5
5
  Artist.one_to_one :first_album, {:clone=>:first_album}.merge(@els) if @els
6
6
  Artist.one_to_one :last_album, {:clone=>:last_album}.merge(@els) if @els
7
+ Artist.one_to_one :second_album, {:clone=>:second_album}.merge(@els) if @els
7
8
  @album.update(:artist => @artist)
8
9
  diff_album = @diff_album.call
9
10
  ar = @pr.call[1]
10
11
 
11
- a = Artist.eager(:first_album, :last_album).order(:name).all
12
+ a = Artist.eager(:first_album, :last_album, :second_album).order(:name).all
12
13
  a.should == [@artist, ar]
13
14
  a.first.first_album.should == @album
14
15
  a.first.last_album.should == diff_album
16
+ a.first.second_album.should == diff_album
15
17
  a.last.first_album.should == nil
16
18
  a.last.last_album.should == nil
19
+ a.last.second_album.should == nil
17
20
 
18
21
  # Check that no extra columns got added by the eager loading
19
22
  a.first.first_album.values.should == @album.values
20
23
  a.first.last_album.values.should == diff_album.values
24
+ a.first.second_album.values.should == diff_album.values
21
25
 
22
26
  same_album = @same_album.call
23
27
  a = Artist.eager(:first_album).order(:name).all
@@ -25,42 +29,52 @@ shared_examples_for "eager limit strategies" do
25
29
  [@album, same_album].should include(a.first.first_album)
26
30
  a.last.first_album.should == nil
27
31
  end
32
+ end
28
33
 
34
+ shared_examples_for "one_to_many eager limit strategies" do
29
35
  specify "should correctly handle limits and offsets when eager loading one_to_many associations" do
30
36
  Artist.one_to_many :first_two_albums, {:clone=>:first_two_albums}.merge(@els) if @els
31
37
  Artist.one_to_many :second_two_albums, {:clone=>:second_two_albums}.merge(@els) if @els
38
+ Artist.one_to_many :not_first_albums, {:clone=>:not_first_albums}.merge(@els) if @els
32
39
  Artist.one_to_many :last_two_albums, {:clone=>:last_two_albums}.merge(@els) if @els
33
40
  @album.update(:artist => @artist)
34
41
  middle_album = @middle_album.call
35
42
  diff_album = @diff_album.call
36
43
  ar = @pr.call[1]
37
44
 
38
- ars = Artist.eager(:first_two_albums, :second_two_albums, :last_two_albums).order(:name).all
45
+ ars = Artist.eager(:first_two_albums, :second_two_albums, :not_first_albums, :last_two_albums).order(:name).all
39
46
  ars.should == [@artist, ar]
40
47
  ars.first.first_two_albums.should == [@album, middle_album]
41
48
  ars.first.second_two_albums.should == [middle_album, diff_album]
49
+ ars.first.not_first_albums.should == [middle_album, diff_album]
42
50
  ars.first.last_two_albums.should == [diff_album, middle_album]
43
51
  ars.last.first_two_albums.should == []
44
52
  ars.last.second_two_albums.should == []
53
+ ars.last.not_first_albums.should == []
45
54
  ars.last.last_two_albums.should == []
46
55
 
47
56
  # Check that no extra columns got added by the eager loading
48
57
  ars.first.first_two_albums.map{|x| x.values}.should == [@album, middle_album].map{|x| x.values}
49
58
  ars.first.second_two_albums.map{|x| x.values}.should == [middle_album, diff_album].map{|x| x.values}
59
+ ars.first.not_first_albums.map{|x| x.values}.should == [middle_album, diff_album].map{|x| x.values}
50
60
  ars.first.last_two_albums.map{|x| x.values}.should == [diff_album, middle_album].map{|x| x.values}
51
61
  end
52
-
62
+ end
63
+
64
+ shared_examples_for "many_to_many eager limit strategies" do
53
65
  specify "should correctly handle limits and offsets when eager loading many_to_many associations" do
54
- Album.many_to_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els) if @els
55
- Album.many_to_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els) if @els
56
- Album.many_to_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els) if @els
66
+ Album.send @many_to_many_method||:many_to_many, :first_two_tags, {:clone=>:first_two_tags}.merge(@els) if @els
67
+ Album.send @many_to_many_method||:many_to_many, :second_two_tags, {:clone=>:second_two_tags}.merge(@els) if @els
68
+ Album.send @many_to_many_method||:many_to_many, :not_first_tags, {:clone=>:not_first_tags}.merge(@els) if @els
69
+ Album.send @many_to_many_method||:many_to_many, :last_two_tags, {:clone=>:last_two_tags}.merge(@els) if @els
57
70
  tu, tv = @other_tags.call
58
71
  al = @pr.call.first
59
72
 
60
- als = Album.eager(:first_two_tags, :second_two_tags, :last_two_tags).order(:name).all
73
+ als = Album.eager(:first_two_tags, :second_two_tags, :not_first_tags, :last_two_tags).order(:name).all
61
74
  als.should == [@album, al]
62
75
  als.first.first_two_tags.should == [@tag, tu]
63
76
  als.first.second_two_tags.should == [tu, tv]
77
+ als.first.not_first_tags.should == [tu, tv]
64
78
  als.first.last_two_tags.should == [tv, tu]
65
79
  als.last.first_two_tags.should == []
66
80
  als.last.second_two_tags.should == []
@@ -69,21 +83,26 @@ shared_examples_for "eager limit strategies" do
69
83
  # Check that no extra columns got added by the eager loading
70
84
  als.first.first_two_tags.map{|x| x.values}.should == [@tag, tu].map{|x| x.values}
71
85
  als.first.second_two_tags.map{|x| x.values}.should == [tu, tv].map{|x| x.values}
86
+ als.first.not_first_tags.map{|x| x.values}.should == [tu, tv].map{|x| x.values}
72
87
  als.first.last_two_tags.map{|x| x.values}.should == [tv, tu].map{|x| x.values}
73
88
  end
74
-
89
+ end
90
+
91
+ shared_examples_for "many_through_many eager limit strategies" do
75
92
  specify "should correctly handle limits and offsets when eager loading many_through_many associations" do
76
93
  Artist.many_through_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els) if @els
77
94
  Artist.many_through_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els) if @els
95
+ Artist.many_through_many :not_first_tags, {:clone=>:not_first_tags}.merge(@els) if @els
78
96
  Artist.many_through_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els) if @els
79
97
  @album.update(:artist => @artist)
80
98
  tu, tv = @other_tags.call
81
99
  ar = @pr.call[1]
82
100
 
83
- ars = Artist.eager(:first_two_tags, :second_two_tags, :last_two_tags).order(:name).all
101
+ ars = Artist.eager(:first_two_tags, :second_two_tags, :not_first_tags, :last_two_tags).order(:name).all
84
102
  ars.should == [@artist, ar]
85
103
  ars.first.first_two_tags.should == [@tag, tu]
86
104
  ars.first.second_two_tags.should == [tu, tv]
105
+ ars.first.not_first_tags.should == [tu, tv]
87
106
  ars.first.last_two_tags.should == [tv, tu]
88
107
  ars.last.first_two_tags.should == []
89
108
  ars.last.second_two_tags.should == []
@@ -92,10 +111,18 @@ shared_examples_for "eager limit strategies" do
92
111
  # Check that no extra columns got added by the eager loading
93
112
  ars.first.first_two_tags.map{|x| x.values}.should == [@tag, tu].map{|x| x.values}
94
113
  ars.first.second_two_tags.map{|x| x.values}.should == [tu, tv].map{|x| x.values}
114
+ ars.first.not_first_tags.map{|x| x.values}.should == [tu, tv].map{|x| x.values}
95
115
  ars.first.last_two_tags.map{|x| x.values}.should == [tv, tu].map{|x| x.values}
96
116
  end
97
117
  end
98
118
 
119
+ shared_examples_for "eager limit strategies" do
120
+ it_should_behave_like "one_to_one eager limit strategies"
121
+ it_should_behave_like "one_to_many eager limit strategies"
122
+ it_should_behave_like "many_to_many eager limit strategies"
123
+ it_should_behave_like "many_through_many eager limit strategies"
124
+ end
125
+
99
126
  shared_examples_for "filtering/excluding by associations" do
100
127
  specify "should work correctly when filtering by associations" do
101
128
  @album.update(:artist => @artist)
@@ -282,7 +309,7 @@ shared_examples_for "filtering/excluding by associations" do
282
309
  end
283
310
  end
284
311
 
285
- shared_examples_for "regular and composite key associations" do
312
+ shared_examples_for "basic regular and composite key associations" do
286
313
  specify "should return no objects if none are associated" do
287
314
  @album.artist.should == nil
288
315
  @artist.first_album.should == nil
@@ -333,7 +360,7 @@ shared_examples_for "regular and composite key associations" do
333
360
  Album.tags.all.should == []
334
361
  Album.alias_tags.all.should == []
335
362
  Artist.albums.all.should == []
336
- Artist.tags.all.should == []
363
+ Artist.tags.all.should == [] unless @no_many_through_many
337
364
  Artist.albums.tags.all.should == []
338
365
 
339
366
  @album.update(:artist => @artist)
@@ -344,7 +371,7 @@ shared_examples_for "regular and composite key associations" do
344
371
  Album.tags.all.should == [@tag]
345
372
  Album.alias_tags.all.should == [@tag]
346
373
  Artist.albums.all.should == [@album]
347
- Artist.tags.all.should == [@tag]
374
+ Artist.tags.all.should == [@tag] unless @no_many_through_many
348
375
  Artist.albums.tags.all.should == [@tag]
349
376
 
350
377
  album.add_tag(tag)
@@ -355,7 +382,7 @@ shared_examples_for "regular and composite key associations" do
355
382
  Album.tags.order(:name).all.should == [@tag, tag]
356
383
  Album.alias_tags.order(:name).all.should == [@tag, tag]
357
384
  Artist.albums.order(:name).all.should == [@album, album]
358
- Artist.tags.order(:name).all.should == [@tag, tag]
385
+ Artist.tags.order(:name).all.should == [@tag, tag] unless @no_many_through_many
359
386
  Artist.albums.tags.order(:name).all.should == [@tag, tag]
360
387
 
361
388
  Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).albums.all.should == [album]
@@ -363,7 +390,7 @@ shared_examples_for "regular and composite key associations" do
363
390
  Album.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.should == [tag]
364
391
  Album.filter(Album.qualified_primary_key_hash(album.pk)).alias_tags.all.should == [tag]
365
392
  Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.all.should == [album]
366
- Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).tags.all.should == [tag]
393
+ Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).tags.all.should == [tag] unless @no_many_through_many
367
394
  Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.tags.all.should == [tag]
368
395
 
369
396
  Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.should == [tag]
@@ -402,8 +429,8 @@ shared_examples_for "regular and composite key associations" do
402
429
  @artist.add_album(@album)
403
430
  @album.add_tag(@tag)
404
431
 
405
- @artist.remove_all_albums
406
432
  @album.remove_all_tags
433
+ @artist.remove_all_albums
407
434
 
408
435
  @album.reload
409
436
  @artist.reload
@@ -438,6 +465,23 @@ shared_examples_for "regular and composite key associations" do
438
465
  a.first.albums.first.artist.should == @artist
439
466
  end
440
467
 
468
+ specify "should eager load via eager_graph correctly" do
469
+ @album.update(:artist => @artist)
470
+ @album.add_tag(@tag)
471
+
472
+ a = Artist.eager_graph(:albums=>[:tags, :alias_tags]).eager_graph(:first_album).all
473
+ a.should == [@artist]
474
+ a.first.albums.should == [@album]
475
+ a.first.first_album.should == @album
476
+ a.first.albums.first.tags.should == [@tag]
477
+ a.first.albums.first.alias_tags.should == [@tag]
478
+
479
+ a = Tag.eager_graph(:albums=>:artist).all
480
+ a.should == [@tag]
481
+ a.first.albums.should == [@album]
482
+ a.first.albums.first.artist.should == @artist
483
+ end
484
+
441
485
  describe "when filtering/excluding by associations" do
442
486
  before do
443
487
  @Artist = Artist.dataset
@@ -447,6 +491,10 @@ shared_examples_for "regular and composite key associations" do
447
491
 
448
492
  it_should_behave_like "filtering/excluding by associations"
449
493
  end
494
+ end
495
+
496
+ shared_examples_for "regular and composite key associations" do
497
+ it_should_behave_like "basic regular and composite key associations"
450
498
 
451
499
  describe "when filtering/excluding by associations when joining" do
452
500
  def self_join(c)
@@ -462,7 +510,10 @@ shared_examples_for "regular and composite key associations" do
462
510
  it_should_behave_like "filtering/excluding by associations"
463
511
  end
464
512
 
465
- describe "with no :eager_limit_strategy" do
513
+ describe "with :eager_limit_strategy=>:ruby" do
514
+ before do
515
+ @els = {:eager_limit_strategy=>:ruby}
516
+ end
466
517
  it_should_behave_like "eager limit strategies"
467
518
  end
468
519
 
@@ -470,33 +521,16 @@ shared_examples_for "regular and composite key associations" do
470
521
  before do
471
522
  @els = {:eager_limit_strategy=>true}
472
523
  end
473
- it_should_behave_like "eager limit strategies"
474
- end
524
+ it_should_behave_like "one_to_one eager limit strategies"
525
+ end if DB.dataset.supports_ordered_distinct_on?
475
526
 
476
527
  describe "with :eager_limit_strategy=>:window_function" do
477
528
  before do
478
529
  @els = {:eager_limit_strategy=>:window_function}
479
530
  end
480
531
  it_should_behave_like "eager limit strategies"
481
- end if INTEGRATION_DB.dataset.supports_window_functions?
532
+ end if DB.dataset.supports_window_functions?
482
533
 
483
- specify "should eager load via eager_graph correctly" do
484
- @album.update(:artist => @artist)
485
- @album.add_tag(@tag)
486
-
487
- a = Artist.eager_graph(:albums=>[:tags, :alias_tags]).eager_graph(:first_album).all
488
- a.should == [@artist]
489
- a.first.albums.should == [@album]
490
- a.first.first_album.should == @album
491
- a.first.albums.first.tags.should == [@tag]
492
- a.first.albums.first.alias_tags.should == [@tag]
493
-
494
- a = Tag.eager_graph(:albums=>:artist).all
495
- a.should == [@tag]
496
- a.first.albums.should == [@album]
497
- a.first.albums.first.artist.should == @artist
498
- end
499
-
500
534
  specify "should work with a many_through_many association" do
501
535
  @album.update(:artist => @artist)
502
536
  @album.add_tag(@tag)
@@ -529,7 +563,7 @@ end
529
563
 
530
564
  describe "Sequel::Model Simple Associations" do
531
565
  before(:all) do
532
- @db = INTEGRATION_DB
566
+ @db = DB
533
567
  @db.drop_table?(:albums_tags, :tags, :albums, :artists)
534
568
  @db.create_table(:artists) do
535
569
  primary_key :id
@@ -555,14 +589,17 @@ describe "Sequel::Model Simple Associations" do
555
589
  plugin :dataset_associations
556
590
  one_to_many :albums, :order=>:name
557
591
  one_to_one :first_album, :class=>:Album, :order=>:name
592
+ one_to_one :second_album, :class=>:Album, :order=>:name, :limit=>[nil, 1]
558
593
  one_to_one :last_album, :class=>:Album, :order=>Sequel.desc(:name)
559
594
  one_to_many :first_two_albums, :class=>:Album, :order=>:name, :limit=>2
560
595
  one_to_many :second_two_albums, :class=>:Album, :order=>:name, :limit=>[2, 1]
596
+ one_to_many :not_first_albums, :class=>:Album, :order=>:name, :limit=>[nil, 1]
561
597
  one_to_many :last_two_albums, :class=>:Album, :order=>Sequel.desc(:name), :limit=>2
562
598
  plugin :many_through_many
563
599
  many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]]
564
600
  many_through_many :first_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>2
565
601
  many_through_many :second_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>[2, 1]
602
+ many_through_many :not_first_tags, :clone=>:tags, :order=>:tags__name, :limit=>[nil, 1]
566
603
  many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:tags__name), :limit=>2
567
604
  end
568
605
  class ::Album < Sequel::Model(@db)
@@ -572,6 +609,7 @@ describe "Sequel::Model Simple Associations" do
572
609
  many_to_many :alias_tags, :clone=>:tags, :join_table=>:albums_tags___at
573
610
  many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
574
611
  many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
612
+ many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
575
613
  many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
576
614
  end
577
615
  class ::Tag < Sequel::Model(@db)
@@ -717,7 +755,7 @@ end
717
755
 
718
756
  describe "Sequel::Model Composite Key Associations" do
719
757
  before(:all) do
720
- @db = INTEGRATION_DB
758
+ @db = DB
721
759
  @db.drop_table?(:albums_tags, :tags, :albums, :artists)
722
760
  @db.create_table(:artists) do
723
761
  Integer :id1
@@ -758,13 +796,16 @@ describe "Sequel::Model Composite Key Associations" do
758
796
  one_to_many :albums, :key=>[:artist_id1, :artist_id2], :order=>:name
759
797
  one_to_one :first_album, :clone=>:albums, :order=>:name
760
798
  one_to_one :last_album, :clone=>:albums, :order=>Sequel.desc(:name)
799
+ one_to_one :second_album, :clone=>:albums, :limit=>[nil, 1]
761
800
  one_to_many :first_two_albums, :clone=>:albums, :order=>:name, :limit=>2
762
801
  one_to_many :second_two_albums, :clone=>:albums, :order=>:name, :limit=>[2, 1]
802
+ one_to_many :not_first_albums, :clone=>:albums, :order=>:name, :limit=>[nil, 1]
763
803
  one_to_many :last_two_albums, :clone=>:albums, :order=>Sequel.desc(:name), :limit=>2
764
804
  plugin :many_through_many
765
805
  many_through_many :tags, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]]
766
806
  many_through_many :first_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>2
767
807
  many_through_many :second_two_tags, :clone=>:tags, :order=>:tags__name, :limit=>[2, 1]
808
+ many_through_many :not_first_tags, :clone=>:tags, :order=>:tags__name, :limit=>[nil, 1]
768
809
  many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:tags__name), :limit=>2
769
810
  end
770
811
  class ::Album < Sequel::Model(@db)
@@ -776,6 +817,7 @@ describe "Sequel::Model Composite Key Associations" do
776
817
  many_to_many :alias_tags, :clone=>:tags, :join_table=>:albums_tags___at
777
818
  many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
778
819
  many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
820
+ many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
779
821
  many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
780
822
  end
781
823
  class ::Tag < Sequel::Model(@db)
@@ -843,9 +885,158 @@ describe "Sequel::Model Composite Key Associations" do
843
885
  end
844
886
  end
845
887
 
888
+ describe "Sequel::Model pg_array_to_many" do
889
+ before(:all) do
890
+ @db = DB
891
+ @db.extension :pg_array
892
+ Sequel.extension :pg_array_ops
893
+ @db.drop_table?(:tags, :albums, :artists)
894
+ @db.create_table(:artists) do
895
+ primary_key :id
896
+ String :name
897
+ end
898
+ @db.create_table(:albums) do
899
+ primary_key :id
900
+ String :name
901
+ foreign_key :artist_id, :artists
902
+ column :tag_ids, 'int4[]'
903
+ end
904
+ @db.create_table(:tags) do
905
+ primary_key :id
906
+ String :name
907
+ end
908
+ end
909
+ before do
910
+ [:tags, :albums, :artists].each{|t| @db[t].delete}
911
+ class ::Artist < Sequel::Model(@db)
912
+ plugin :dataset_associations
913
+ one_to_many :albums, :order=>:name
914
+ one_to_one :first_album, :class=>:Album, :order=>:name
915
+ end
916
+ class ::Album < Sequel::Model(@db)
917
+ plugin :dataset_associations
918
+ plugin :pg_array_associations
919
+ many_to_one :artist, :reciprocal=>nil
920
+ pg_array_to_many :tags, :key=>:tag_ids, :save_after_modify=>true
921
+ pg_array_to_many :alias_tags, :clone=>:tags
922
+ pg_array_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
923
+ pg_array_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
924
+ pg_array_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
925
+ pg_array_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
926
+ end
927
+ class ::Tag < Sequel::Model(@db)
928
+ plugin :dataset_associations
929
+ plugin :pg_array_associations
930
+ many_to_pg_array :albums
931
+ end
932
+ @album = Album.create(:name=>'Al')
933
+ @artist = Artist.create(:name=>'Ar')
934
+ @tag = Tag.create(:name=>'T')
935
+ @many_to_many_method = :pg_array_to_many
936
+ @no_many_through_many = true
937
+ @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
938
+ @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
939
+ @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
940
+ @other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; Tag.all{|x| @album.add_tag(x)}; t}
941
+ @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
942
+ @ins = lambda{}
943
+ end
944
+ after do
945
+ [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
946
+ end
947
+ after(:all) do
948
+ @db.drop_table?(:tags, :albums, :artists)
949
+ end
950
+
951
+ it_should_behave_like "basic regular and composite key associations"
952
+ it_should_behave_like "many_to_many eager limit strategies"
953
+
954
+ it "should handle adding and removing entries in array" do
955
+ a = Album.create
956
+ a.typecast_on_assignment = false
957
+ a.add_tag(@tag)
958
+ a.remove_tag(@tag)
959
+ a.save
960
+ end
961
+ end if DB.database_type == :postgres && DB.adapter_scheme == :postgres && DB.server_version >= 90300
962
+
963
+ describe "Sequel::Model many_to_pg_array" do
964
+ before(:all) do
965
+ @db = DB
966
+ @db.extension :pg_array
967
+ Sequel.extension :pg_array_ops
968
+ @db.drop_table?(:tags, :albums, :artists)
969
+ @db.create_table(:artists) do
970
+ primary_key :id
971
+ String :name
972
+ end
973
+ @db.create_table(:albums) do
974
+ primary_key :id
975
+ String :name
976
+ foreign_key :artist_id, :artists
977
+ end
978
+ @db.create_table(:tags) do
979
+ primary_key :id
980
+ String :name
981
+ column :album_ids, 'int4[]'
982
+ end
983
+ end
984
+ before do
985
+ [:tags, :albums, :artists].each{|t| @db[t].delete}
986
+ class ::Artist < Sequel::Model(@db)
987
+ plugin :dataset_associations
988
+ one_to_many :albums, :order=>:name
989
+ one_to_one :first_album, :class=>:Album, :order=>:name
990
+ end
991
+ class ::Album < Sequel::Model(@db)
992
+ plugin :dataset_associations
993
+ plugin :pg_array_associations
994
+ many_to_one :artist, :reciprocal=>nil
995
+ many_to_pg_array :tags
996
+ many_to_pg_array :alias_tags, :clone=>:tags
997
+ many_to_pg_array :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
998
+ many_to_pg_array :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
999
+ many_to_pg_array :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
1000
+ many_to_pg_array :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
1001
+ end
1002
+ class ::Tag < Sequel::Model(@db)
1003
+ plugin :dataset_associations
1004
+ plugin :pg_array_associations
1005
+ pg_array_to_many :albums
1006
+ end
1007
+ @album = Album.create(:name=>'Al')
1008
+ @artist = Artist.create(:name=>'Ar')
1009
+ @tag = Tag.create(:name=>'T')
1010
+ @many_to_many_method = :pg_array_to_many
1011
+ @no_many_through_many = true
1012
+ @same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
1013
+ @diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
1014
+ @middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
1015
+ @other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; Tag.all{|x| @album.add_tag(x)}; @tag.refresh; t.each{|x| x.refresh}; t}
1016
+ @pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
1017
+ @ins = lambda{}
1018
+ end
1019
+ after do
1020
+ [:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
1021
+ end
1022
+ after(:all) do
1023
+ @db.drop_table?(:tags, :albums, :artists)
1024
+ end
1025
+
1026
+ it_should_behave_like "basic regular and composite key associations"
1027
+ it_should_behave_like "many_to_many eager limit strategies"
1028
+
1029
+ it "should handle adding and removing entries in array" do
1030
+ a = Album.create
1031
+ @tag.typecast_on_assignment = false
1032
+ a.add_tag(@tag)
1033
+ a.remove_tag(@tag)
1034
+ end
1035
+ end if DB.database_type == :postgres && DB.adapter_scheme == :postgres && DB.server_version >= 90300
1036
+
846
1037
  describe "Sequel::Model Associations with clashing column names" do
847
1038
  before(:all) do
848
- @db = INTEGRATION_DB
1039
+ @db = DB
849
1040
  @db.drop_table?(:bars_foos, :bars, :foos)
850
1041
  @db.create_table(:foos) do
851
1042
  primary_key :id