sequel 4.22.0 → 4.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +22 -0
  3. data/README.rdoc +6 -0
  4. data/Rakefile +59 -81
  5. data/doc/migration.rdoc +2 -0
  6. data/doc/release_notes/4.23.0.txt +65 -0
  7. data/doc/sharding.rdoc +16 -14
  8. data/doc/testing.rdoc +61 -77
  9. data/lib/sequel/adapters/jdbc.rb +1 -0
  10. data/lib/sequel/adapters/mock.rb +0 -1
  11. data/lib/sequel/adapters/postgres.rb +1 -0
  12. data/lib/sequel/adapters/postgresql.rb +1 -0
  13. data/lib/sequel/adapters/shared/postgres.rb +3 -3
  14. data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
  15. data/lib/sequel/connection_pool/threaded.rb +9 -1
  16. data/lib/sequel/database/connecting.rb +1 -1
  17. data/lib/sequel/database/transactions.rb +2 -1
  18. data/lib/sequel/dataset/prepared_statements.rb +1 -1
  19. data/lib/sequel/extensions/constraint_validations.rb +12 -12
  20. data/lib/sequel/extensions/date_arithmetic.rb +0 -4
  21. data/lib/sequel/extensions/pagination.rb +14 -2
  22. data/lib/sequel/extensions/pg_enum.rb +2 -2
  23. data/lib/sequel/extensions/pg_hstore.rb +1 -1
  24. data/lib/sequel/extensions/pg_json_ops.rb +2 -2
  25. data/lib/sequel/plugins/csv_serializer.rb +2 -0
  26. data/lib/sequel/plugins/delay_add_association.rb +50 -0
  27. data/lib/sequel/plugins/list.rb +2 -2
  28. data/lib/sequel/plugins/nested_attributes.rb +8 -28
  29. data/lib/sequel/plugins/update_refresh.rb +50 -0
  30. data/lib/sequel/plugins/validate_associated.rb +55 -0
  31. data/lib/sequel/version.rb +1 -1
  32. data/spec/adapters/db2_spec.rb +29 -29
  33. data/spec/adapters/firebird_spec.rb +97 -103
  34. data/spec/adapters/informix_spec.rb +25 -25
  35. data/spec/adapters/mssql_spec.rb +156 -172
  36. data/spec/adapters/mysql_spec.rb +334 -359
  37. data/spec/adapters/oracle_spec.rb +67 -69
  38. data/spec/adapters/postgres_spec.rb +1298 -1249
  39. data/spec/adapters/spec_helper.rb +2 -35
  40. data/spec/adapters/sqlanywhere_spec.rb +39 -39
  41. data/spec/adapters/sqlite_spec.rb +203 -200
  42. data/spec/bin_spec.rb +57 -59
  43. data/spec/core/connection_pool_spec.rb +402 -401
  44. data/spec/core/database_spec.rb +953 -944
  45. data/spec/core/dataset_spec.rb +2178 -2168
  46. data/spec/core/deprecated_spec.rb +19 -19
  47. data/spec/core/expression_filters_spec.rb +415 -415
  48. data/spec/core/mock_adapter_spec.rb +212 -212
  49. data/spec/core/object_graph_spec.rb +73 -73
  50. data/spec/core/placeholder_literalizer_spec.rb +71 -71
  51. data/spec/core/schema_generator_spec.rb +44 -44
  52. data/spec/core/schema_spec.rb +470 -472
  53. data/spec/core/spec_helper.rb +5 -20
  54. data/spec/core/version_spec.rb +2 -2
  55. data/spec/core_extensions_spec.rb +320 -320
  56. data/spec/extensions/accessed_columns_spec.rb +12 -12
  57. data/spec/extensions/active_model_spec.rb +3 -3
  58. data/spec/extensions/after_initialize_spec.rb +2 -2
  59. data/spec/extensions/arbitrary_servers_spec.rb +23 -23
  60. data/spec/extensions/association_dependencies_spec.rb +34 -34
  61. data/spec/extensions/association_pks_spec.rb +98 -98
  62. data/spec/extensions/association_proxies_spec.rb +33 -33
  63. data/spec/extensions/auto_validations_spec.rb +46 -46
  64. data/spec/extensions/blacklist_security_spec.rb +19 -18
  65. data/spec/extensions/blank_spec.rb +36 -36
  66. data/spec/extensions/boolean_readers_spec.rb +36 -36
  67. data/spec/extensions/caching_spec.rb +82 -82
  68. data/spec/extensions/class_table_inheritance_spec.rb +72 -72
  69. data/spec/extensions/column_conflicts_spec.rb +19 -14
  70. data/spec/extensions/column_select_spec.rb +19 -19
  71. data/spec/extensions/columns_introspection_spec.rb +43 -43
  72. data/spec/extensions/composition_spec.rb +64 -64
  73. data/spec/extensions/connection_validator_spec.rb +92 -90
  74. data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
  75. data/spec/extensions/constraint_validations_spec.rb +80 -80
  76. data/spec/extensions/core_refinements_spec.rb +220 -220
  77. data/spec/extensions/csv_serializer_spec.rb +44 -44
  78. data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
  79. data/spec/extensions/dataset_associations_spec.rb +65 -65
  80. data/spec/extensions/dataset_source_alias_spec.rb +16 -16
  81. data/spec/extensions/date_arithmetic_spec.rb +51 -58
  82. data/spec/extensions/defaults_setter_spec.rb +19 -19
  83. data/spec/extensions/delay_add_association_spec.rb +52 -0
  84. data/spec/extensions/dirty_spec.rb +51 -51
  85. data/spec/extensions/eager_each_spec.rb +8 -8
  86. data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
  87. data/spec/extensions/error_splitter_spec.rb +2 -2
  88. data/spec/extensions/error_sql_spec.rb +4 -4
  89. data/spec/extensions/eval_inspect_spec.rb +3 -3
  90. data/spec/extensions/filter_having_spec.rb +8 -8
  91. data/spec/extensions/force_encoding_spec.rb +30 -30
  92. data/spec/extensions/from_block_spec.rb +7 -7
  93. data/spec/extensions/graph_each_spec.rb +19 -19
  94. data/spec/extensions/hash_aliases_spec.rb +5 -5
  95. data/spec/extensions/hook_class_methods_spec.rb +100 -100
  96. data/spec/extensions/inflector_spec.rb +54 -54
  97. data/spec/extensions/input_transformer_spec.rb +10 -10
  98. data/spec/extensions/insert_returning_select_spec.rb +8 -8
  99. data/spec/extensions/instance_filters_spec.rb +26 -26
  100. data/spec/extensions/instance_hooks_spec.rb +85 -85
  101. data/spec/extensions/json_serializer_spec.rb +68 -68
  102. data/spec/extensions/lazy_attributes_spec.rb +49 -49
  103. data/spec/extensions/list_spec.rb +77 -75
  104. data/spec/extensions/looser_typecasting_spec.rb +16 -16
  105. data/spec/extensions/many_through_many_spec.rb +627 -627
  106. data/spec/extensions/meta_def_spec.rb +7 -7
  107. data/spec/extensions/migration_spec.rb +217 -217
  108. data/spec/extensions/modification_detection_spec.rb +20 -20
  109. data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
  110. data/spec/extensions/named_timezones_spec.rb +18 -18
  111. data/spec/extensions/nested_attributes_spec.rb +107 -107
  112. data/spec/extensions/null_dataset_spec.rb +24 -24
  113. data/spec/extensions/optimistic_locking_spec.rb +21 -21
  114. data/spec/extensions/pagination_spec.rb +52 -52
  115. data/spec/extensions/pg_array_associations_spec.rb +273 -273
  116. data/spec/extensions/pg_array_ops_spec.rb +52 -52
  117. data/spec/extensions/pg_array_spec.rb +152 -152
  118. data/spec/extensions/pg_enum_spec.rb +13 -13
  119. data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
  120. data/spec/extensions/pg_hstore_spec.rb +84 -84
  121. data/spec/extensions/pg_inet_spec.rb +15 -15
  122. data/spec/extensions/pg_interval_spec.rb +29 -29
  123. data/spec/extensions/pg_json_ops_spec.rb +86 -84
  124. data/spec/extensions/pg_json_spec.rb +104 -104
  125. data/spec/extensions/pg_loose_count_spec.rb +6 -6
  126. data/spec/extensions/pg_range_ops_spec.rb +24 -24
  127. data/spec/extensions/pg_range_spec.rb +143 -143
  128. data/spec/extensions/pg_row_ops_spec.rb +14 -14
  129. data/spec/extensions/pg_row_plugin_spec.rb +12 -12
  130. data/spec/extensions/pg_row_spec.rb +118 -118
  131. data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
  132. data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
  133. data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
  134. data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
  135. data/spec/extensions/prepared_statements_spec.rb +28 -28
  136. data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
  137. data/spec/extensions/pretty_table_spec.rb +16 -16
  138. data/spec/extensions/query_literals_spec.rb +37 -37
  139. data/spec/extensions/query_spec.rb +32 -32
  140. data/spec/extensions/rcte_tree_spec.rb +141 -141
  141. data/spec/extensions/round_timestamps_spec.rb +21 -21
  142. data/spec/extensions/schema_caching_spec.rb +8 -8
  143. data/spec/extensions/schema_dumper_spec.rb +78 -78
  144. data/spec/extensions/schema_spec.rb +31 -27
  145. data/spec/extensions/scissors_spec.rb +3 -3
  146. data/spec/extensions/select_remove_spec.rb +14 -14
  147. data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
  148. data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
  149. data/spec/extensions/serialization_spec.rb +79 -78
  150. data/spec/extensions/server_block_spec.rb +17 -17
  151. data/spec/extensions/set_overrides_spec.rb +30 -30
  152. data/spec/extensions/sharding_spec.rb +65 -65
  153. data/spec/extensions/shared_caching_spec.rb +29 -29
  154. data/spec/extensions/single_table_inheritance_spec.rb +79 -79
  155. data/spec/extensions/skip_create_refresh_spec.rb +3 -3
  156. data/spec/extensions/spec_helper.rb +4 -29
  157. data/spec/extensions/split_array_nil_spec.rb +9 -9
  158. data/spec/extensions/split_values_spec.rb +7 -7
  159. data/spec/extensions/sql_expr_spec.rb +32 -32
  160. data/spec/extensions/static_cache_spec.rb +123 -123
  161. data/spec/extensions/string_date_time_spec.rb +34 -34
  162. data/spec/extensions/string_stripper_spec.rb +15 -15
  163. data/spec/extensions/subclasses_spec.rb +31 -31
  164. data/spec/extensions/table_select_spec.rb +15 -15
  165. data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
  166. data/spec/extensions/thread_local_timezones_spec.rb +13 -13
  167. data/spec/extensions/timestamps_spec.rb +40 -40
  168. data/spec/extensions/to_dot_spec.rb +34 -34
  169. data/spec/extensions/touch_spec.rb +52 -52
  170. data/spec/extensions/tree_spec.rb +72 -72
  171. data/spec/extensions/typecast_on_load_spec.rb +25 -25
  172. data/spec/extensions/unlimited_update_spec.rb +2 -2
  173. data/spec/extensions/update_or_create_spec.rb +36 -36
  174. data/spec/extensions/update_primary_key_spec.rb +35 -35
  175. data/spec/extensions/update_refresh_spec.rb +41 -0
  176. data/spec/extensions/validate_associated_spec.rb +52 -0
  177. data/spec/extensions/validation_class_methods_spec.rb +314 -317
  178. data/spec/extensions/validation_helpers_spec.rb +195 -195
  179. data/spec/extensions/xml_serializer_spec.rb +48 -48
  180. data/spec/guards_helper.rb +55 -0
  181. data/spec/integration/associations_test.rb +1089 -1088
  182. data/spec/integration/database_test.rb +29 -29
  183. data/spec/integration/dataset_test.rb +661 -661
  184. data/spec/integration/eager_loader_test.rb +147 -147
  185. data/spec/integration/migrator_test.rb +122 -122
  186. data/spec/integration/model_test.rb +70 -70
  187. data/spec/integration/plugin_test.rb +682 -640
  188. data/spec/integration/prepared_statement_test.rb +172 -172
  189. data/spec/integration/schema_test.rb +245 -245
  190. data/spec/integration/spec_helper.rb +1 -64
  191. data/spec/integration/timezone_test.rb +17 -17
  192. data/spec/integration/transaction_test.rb +87 -87
  193. data/spec/integration/type_test.rb +33 -33
  194. data/spec/model/association_reflection_spec.rb +130 -121
  195. data/spec/model/associations_spec.rb +1112 -1113
  196. data/spec/model/base_spec.rb +197 -196
  197. data/spec/model/class_dataset_methods_spec.rb +118 -118
  198. data/spec/model/dataset_methods_spec.rb +49 -49
  199. data/spec/model/eager_loading_spec.rb +705 -702
  200. data/spec/model/hooks_spec.rb +169 -168
  201. data/spec/model/inflector_spec.rb +5 -5
  202. data/spec/model/model_spec.rb +287 -297
  203. data/spec/model/plugins_spec.rb +47 -47
  204. data/spec/model/record_spec.rb +534 -535
  205. data/spec/model/spec_helper.rb +3 -21
  206. data/spec/model/validations_spec.rb +72 -70
  207. data/spec/spec_config.rb +8 -0
  208. metadata +41 -9
  209. data/lib/sequel/adapters/fdbsql.rb +0 -286
  210. data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
  211. data/lib/sequel/adapters/openbase.rb +0 -54
  212. data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
  213. data/spec/adapters/fdbsql_spec.rb +0 -429
  214. data/spec/rspec_helper.rb +0 -22
@@ -10,22 +10,22 @@ describe "prepared_statements_with_pk plugin" do
10
10
  @db.sqls
11
11
  end
12
12
 
13
- specify "should load the prepared_statements plugin" do
14
- @c.plugins.should include(Sequel::Plugins::PreparedStatements)
13
+ it "should load the prepared_statements plugin" do
14
+ @c.plugins.must_include(Sequel::Plugins::PreparedStatements)
15
15
  end
16
16
 
17
- specify "should correctly lookup by primary key from dataset" do
18
- @c.dataset.filter(:name=>'foo')[1].should == @p
19
- @c.db.sqls.should == ["SELECT * FROM people WHERE ((name = 'foo') AND (people.id = 1)) LIMIT 1 -- read_only"]
17
+ it "should correctly lookup by primary key from dataset" do
18
+ @c.dataset.filter(:name=>'foo')[1].must_equal @p
19
+ @c.db.sqls.must_equal ["SELECT * FROM people WHERE ((name = 'foo') AND (people.id = 1)) LIMIT 1 -- read_only"]
20
20
  end
21
21
 
22
- specify "should still work correctly if there are multiple conflicting variables" do
23
- @c.dataset.filter(:name=>'foo').or(:name=>'bar')[1].should == @p
24
- @c.db.sqls.should == ["SELECT * FROM people WHERE (((name = 'foo') OR (name = 'bar')) AND (people.id = 1)) LIMIT 1 -- read_only"]
22
+ it "should still work correctly if there are multiple conflicting variables" do
23
+ @c.dataset.filter(:name=>'foo').or(:name=>'bar')[1].must_equal @p
24
+ @c.db.sqls.must_equal ["SELECT * FROM people WHERE (((name = 'foo') OR (name = 'bar')) AND (people.id = 1)) LIMIT 1 -- read_only"]
25
25
  end
26
26
 
27
- specify "should still work correctly if the primary key is used elsewhere in the query" do
28
- @c.dataset.filter{id > 2}[1].should == @p
29
- @c.db.sqls.should == ["SELECT * FROM people WHERE ((id > 2) AND (people.id = 1)) LIMIT 1 -- read_only"]
27
+ it "should still work correctly if the primary key is used elsewhere in the query" do
28
+ @c.dataset.filter{id > 2}[1].must_equal @p
29
+ @c.db.sqls.must_equal ["SELECT * FROM people WHERE ((id > 2) AND (people.id = 1)) LIMIT 1 -- read_only"]
30
30
  end
31
31
  end
@@ -1,6 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper')
2
2
 
3
3
  require 'stringio'
4
+ Sequel.extension :pretty_table
4
5
 
5
6
  describe "Dataset#print" do
6
7
  before do
@@ -14,18 +15,18 @@ describe "Dataset#print" do
14
15
  $stdout = @orig_stdout
15
16
  end
16
17
 
17
- specify "should print out a table with the values" do
18
+ it "should print out a table with the values" do
18
19
  @dataset.print(:a, :b)
19
20
  @output.rewind
20
- @output.read.should == \
21
+ @output.read.must_equal \
21
22
  "+-+-+\n|a|b|\n+-+-+\n|1|2|\n|3|4|\n|5|6|\n+-+-+\n"
22
23
  end
23
24
 
24
- specify "should default to the dataset's columns" do
25
+ it "should default to the dataset's columns" do
25
26
  @dataset.meta_def(:columns) {[:a, :b]}
26
27
  @dataset.print
27
28
  @output.rewind
28
- @output.read.should == \
29
+ @output.read.must_equal \
29
30
  "+-+-+\n|a|b|\n+-+-+\n|1|2|\n|3|4|\n|5|6|\n+-+-+\n"
30
31
  end
31
32
  end
@@ -56,37 +57,36 @@ describe "PrettyTable" do
56
57
  $stdout = @orig_stdout
57
58
  end
58
59
 
59
- specify "should infer the columns if not given" do
60
+ it "should infer the columns if not given" do
60
61
  Sequel::PrettyTable.print(@data1)
61
62
  @output.rewind
62
- @output.read.should =~ \
63
- /\n(\|x\|y\|)|(\|y\|x\|)\n/
63
+ @output.read.must_match(/\n(\|x\|y\|)|(\|y\|x\|)\n/)
64
64
  end
65
65
 
66
- specify "should have #string return the string without printing" do
67
- Sequel::PrettyTable.string(@data1).should =~ /\n(\|x\|y\|)|(\|y\|x\|)\n/
66
+ it "should have #string return the string without printing" do
67
+ Sequel::PrettyTable.string(@data1).must_match(/\n(\|x\|y\|)|(\|y\|x\|)\n/)
68
68
  @output.rewind
69
- @output.read.should == ''
69
+ @output.read.must_equal ''
70
70
  end
71
71
 
72
- specify "should calculate the maximum width of each column correctly" do
72
+ it "should calculate the maximum width of each column correctly" do
73
73
  Sequel::PrettyTable.print(@data2, [:a, :b])
74
74
  @output.rewind
75
- @output.read.should == \
75
+ @output.read.must_equal \
76
76
  "+--+----+\n|a |b |\n+--+----+\n|23| 45|\n|45|2377|\n+--+----+\n"
77
77
  end
78
78
 
79
- specify "should also take header width into account" do
79
+ it "should also take header width into account" do
80
80
  Sequel::PrettyTable.print(@data3, [:aaa, :bb, :c])
81
81
  @output.rewind
82
- @output.read.should == \
82
+ @output.read.must_equal \
83
83
  "+---+--+---+\n|aaa|bb|c |\n+---+--+---+\n| 1| | |\n| | 2| |\n| | |3.1|\n+---+--+---+\n"
84
84
  end
85
85
 
86
- specify "should print only the specified columns" do
86
+ it "should print only the specified columns" do
87
87
  Sequel::PrettyTable.print(@data2, [:a])
88
88
  @output.rewind
89
- @output.read.should == \
89
+ @output.read.must_equal \
90
90
  "+--+\n|a |\n+--+\n|23|\n|45|\n+--+\n"
91
91
  end
92
92
  end
@@ -6,23 +6,23 @@ describe "query_literals extension" do
6
6
  end
7
7
 
8
8
  it "should not use special support if given a block" do
9
- @ds.select('a, b, c'){d}.sql.should == 'SELECT \'a, b, c\', d FROM t'
9
+ @ds.select('a, b, c'){d}.sql.must_equal 'SELECT \'a, b, c\', d FROM t'
10
10
  end
11
11
 
12
12
  it "should have #select use literal string if given a single string" do
13
- @ds.select('a, b, c').sql.should == 'SELECT a, b, c FROM t'
13
+ @ds.select('a, b, c').sql.must_equal 'SELECT a, b, c FROM t'
14
14
  end
15
15
 
16
16
  it "should have #select use placeholder literal string if given a string and additional arguments" do
17
- @ds.select('a, b, ?', 1).sql.should == 'SELECT a, b, 1 FROM t'
17
+ @ds.select('a, b, ?', 1).sql.must_equal 'SELECT a, b, 1 FROM t'
18
18
  end
19
19
 
20
20
  it "should have #select work the standard way if initial string is a literal string already" do
21
- @ds.select(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT a, b, ?, 1 FROM t'
21
+ @ds.select(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT a, b, ?, 1 FROM t'
22
22
  end
23
23
 
24
24
  it "should have #select work regularly if not given a string as the first argument" do
25
- @ds.select(:a, 1).sql.should == 'SELECT a, 1 FROM t'
25
+ @ds.select(:a, 1).sql.must_equal 'SELECT a, 1 FROM t'
26
26
  end
27
27
 
28
28
  describe 'with existing selection' do
@@ -31,100 +31,100 @@ describe "query_literals extension" do
31
31
  end
32
32
 
33
33
  it "should have #select_more use literal string if given a single string" do
34
- @ds.select_more('a, b, c').sql.should == 'SELECT d, a, b, c FROM t'
34
+ @ds.select_more('a, b, c').sql.must_equal 'SELECT d, a, b, c FROM t'
35
35
  end
36
36
 
37
37
  it "should have #select_more use placeholder literal string if given a string and additional arguments" do
38
- @ds.select_more('a, b, ?', 1).sql.should == 'SELECT d, a, b, 1 FROM t'
38
+ @ds.select_more('a, b, ?', 1).sql.must_equal 'SELECT d, a, b, 1 FROM t'
39
39
  end
40
40
 
41
41
  it "should have #select_more work the standard way if initial string is a literal string already" do
42
- @ds.select_more(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT d, a, b, ?, 1 FROM t'
42
+ @ds.select_more(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT d, a, b, ?, 1 FROM t'
43
43
  end
44
44
 
45
45
  it "should have #select_more work regularly if not given a string as the first argument" do
46
- @ds.select_more(:a, 1).sql.should == 'SELECT d, a, 1 FROM t'
46
+ @ds.select_more(:a, 1).sql.must_equal 'SELECT d, a, 1 FROM t'
47
47
  end
48
48
  end
49
49
 
50
50
  it "should have #select_append use literal string if given a single string" do
51
- @ds.select_append('a, b, c').sql.should == 'SELECT *, a, b, c FROM t'
51
+ @ds.select_append('a, b, c').sql.must_equal 'SELECT *, a, b, c FROM t'
52
52
  end
53
53
 
54
54
  it "should have #select_append use placeholder literal string if given a string and additional arguments" do
55
- @ds.select_append('a, b, ?', 1).sql.should == 'SELECT *, a, b, 1 FROM t'
55
+ @ds.select_append('a, b, ?', 1).sql.must_equal 'SELECT *, a, b, 1 FROM t'
56
56
  end
57
57
 
58
58
  it "should have #select_append work the standard way if initial string is a literal string already" do
59
- @ds.select_append(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT *, a, b, ?, 1 FROM t'
59
+ @ds.select_append(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT *, a, b, ?, 1 FROM t'
60
60
  end
61
61
 
62
62
  it "should have #select_append work regularly if not given a string as the first argument" do
63
- @ds.select_append(:a, 1).sql.should == 'SELECT *, a, 1 FROM t'
63
+ @ds.select_append(:a, 1).sql.must_equal 'SELECT *, a, 1 FROM t'
64
64
  end
65
65
 
66
66
  it "should have #select_group use literal string if given a single string" do
67
- @ds.select_group('a, b, c').sql.should == 'SELECT a, b, c FROM t GROUP BY a, b, c'
67
+ @ds.select_group('a, b, c').sql.must_equal 'SELECT a, b, c FROM t GROUP BY a, b, c'
68
68
  end
69
69
 
70
70
  it "should have #select_group use placeholder literal string if given a string and additional arguments" do
71
- @ds.select_group('a, b, ?', 1).sql.should == 'SELECT a, b, 1 FROM t GROUP BY a, b, 1'
71
+ @ds.select_group('a, b, ?', 1).sql.must_equal 'SELECT a, b, 1 FROM t GROUP BY a, b, 1'
72
72
  end
73
73
 
74
74
  it "should have #select_group work the standard way if initial string is a literal string already" do
75
- @ds.select_group(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT a, b, ?, 1 FROM t GROUP BY a, b, ?, 1'
75
+ @ds.select_group(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT a, b, ?, 1 FROM t GROUP BY a, b, ?, 1'
76
76
  end
77
77
 
78
78
  it "should have #select_group work regularly if not given a string as the first argument" do
79
- @ds.select_group(:a, 1).sql.should == 'SELECT a, 1 FROM t GROUP BY a, 1'
79
+ @ds.select_group(:a, 1).sql.must_equal 'SELECT a, 1 FROM t GROUP BY a, 1'
80
80
  end
81
81
 
82
82
  it "should have #group use literal string if given a single string" do
83
- @ds.group('a, b, c').sql.should == 'SELECT * FROM t GROUP BY a, b, c'
83
+ @ds.group('a, b, c').sql.must_equal 'SELECT * FROM t GROUP BY a, b, c'
84
84
  end
85
85
 
86
86
  it "should have #group use placeholder literal string if given a string and additional arguments" do
87
- @ds.group('a, b, ?', 1).sql.should == 'SELECT * FROM t GROUP BY a, b, 1'
87
+ @ds.group('a, b, ?', 1).sql.must_equal 'SELECT * FROM t GROUP BY a, b, 1'
88
88
  end
89
89
 
90
90
  it "should have #group work the standard way if initial string is a literal string already" do
91
- @ds.group(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT * FROM t GROUP BY a, b, ?, 1'
91
+ @ds.group(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT * FROM t GROUP BY a, b, ?, 1'
92
92
  end
93
93
 
94
94
  it "should have #group work regularly if not given a string as the first argument" do
95
- @ds.group(:a, 1).sql.should == 'SELECT * FROM t GROUP BY a, 1'
95
+ @ds.group(:a, 1).sql.must_equal 'SELECT * FROM t GROUP BY a, 1'
96
96
  end
97
97
 
98
98
  it "should have #group_and_count use literal string if given a single string" do
99
- @ds.group_and_count('a, b, c').sql.should == 'SELECT a, b, c, count(*) AS count FROM t GROUP BY a, b, c'
99
+ @ds.group_and_count('a, b, c').sql.must_equal 'SELECT a, b, c, count(*) AS count FROM t GROUP BY a, b, c'
100
100
  end
101
101
 
102
102
  it "should have #group_and_count use placeholder literal string if given a string and additional arguments" do
103
- @ds.group_and_count('a, b, ?', 1).sql.should == 'SELECT a, b, 1, count(*) AS count FROM t GROUP BY a, b, 1'
103
+ @ds.group_and_count('a, b, ?', 1).sql.must_equal 'SELECT a, b, 1, count(*) AS count FROM t GROUP BY a, b, 1'
104
104
  end
105
105
 
106
106
  it "should have #group_and_count work the standard way if initial string is a literal string already" do
107
- @ds.group_and_count(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT a, b, ?, 1, count(*) AS count FROM t GROUP BY a, b, ?, 1'
107
+ @ds.group_and_count(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT a, b, ?, 1, count(*) AS count FROM t GROUP BY a, b, ?, 1'
108
108
  end
109
109
 
110
110
  it "should have #group_and_count work regularly if not given a string as the first argument" do
111
- @ds.group_and_count(:a, 1).sql.should == 'SELECT a, 1, count(*) AS count FROM t GROUP BY a, 1'
111
+ @ds.group_and_count(:a, 1).sql.must_equal 'SELECT a, 1, count(*) AS count FROM t GROUP BY a, 1'
112
112
  end
113
113
 
114
114
  it "should have #order use literal string if given a single string" do
115
- @ds.order('a, b, c').sql.should == 'SELECT * FROM t ORDER BY a, b, c'
115
+ @ds.order('a, b, c').sql.must_equal 'SELECT * FROM t ORDER BY a, b, c'
116
116
  end
117
117
 
118
118
  it "should have #order use placeholder literal string if given a string and additional arguments" do
119
- @ds.order('a, b, ?', 1).sql.should == 'SELECT * FROM t ORDER BY a, b, 1'
119
+ @ds.order('a, b, ?', 1).sql.must_equal 'SELECT * FROM t ORDER BY a, b, 1'
120
120
  end
121
121
 
122
122
  it "should have #order work the standard way if initial string is a literal string already" do
123
- @ds.order(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT * FROM t ORDER BY a, b, ?, 1'
123
+ @ds.order(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT * FROM t ORDER BY a, b, ?, 1'
124
124
  end
125
125
 
126
126
  it "should have #order work regularly if not given a string as the first argument" do
127
- @ds.order(:a, 1).sql.should == 'SELECT * FROM t ORDER BY a, 1'
127
+ @ds.order(:a, 1).sql.must_equal 'SELECT * FROM t ORDER BY a, 1'
128
128
  end
129
129
 
130
130
  describe 'with existing order' do
@@ -133,35 +133,35 @@ describe "query_literals extension" do
133
133
  end
134
134
 
135
135
  it "should have #order_more use literal string if given a single string" do
136
- @ds.order_more('a, b, c').sql.should == 'SELECT * FROM t ORDER BY d, a, b, c'
136
+ @ds.order_more('a, b, c').sql.must_equal 'SELECT * FROM t ORDER BY d, a, b, c'
137
137
  end
138
138
 
139
139
  it "should have #order_more use placeholder literal string if given a string and additional arguments" do
140
- @ds.order_more('a, b, ?', 1).sql.should == 'SELECT * FROM t ORDER BY d, a, b, 1'
140
+ @ds.order_more('a, b, ?', 1).sql.must_equal 'SELECT * FROM t ORDER BY d, a, b, 1'
141
141
  end
142
142
 
143
143
  it "should have #order_more work the standard way if initial string is a literal string already" do
144
- @ds.order_more(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT * FROM t ORDER BY d, a, b, ?, 1'
144
+ @ds.order_more(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT * FROM t ORDER BY d, a, b, ?, 1'
145
145
  end
146
146
 
147
147
  it "should have #order_more work regularly if not given a string as the first argument" do
148
- @ds.order_more(:a, 1).sql.should == 'SELECT * FROM t ORDER BY d, a, 1'
148
+ @ds.order_more(:a, 1).sql.must_equal 'SELECT * FROM t ORDER BY d, a, 1'
149
149
  end
150
150
 
151
151
  it "should have #order_prepend use literal string if given a single string" do
152
- @ds.order_prepend('a, b, c').sql.should == 'SELECT * FROM t ORDER BY a, b, c, d'
152
+ @ds.order_prepend('a, b, c').sql.must_equal 'SELECT * FROM t ORDER BY a, b, c, d'
153
153
  end
154
154
 
155
155
  it "should have #order_append use placeholder literal string if given a string and additional arguments" do
156
- @ds.order_prepend('a, b, ?', 1).sql.should == 'SELECT * FROM t ORDER BY a, b, 1, d'
156
+ @ds.order_prepend('a, b, ?', 1).sql.must_equal 'SELECT * FROM t ORDER BY a, b, 1, d'
157
157
  end
158
158
 
159
159
  it "should have #order_append work the standard way if initial string is a literal string already" do
160
- @ds.order_prepend(Sequel.lit('a, b, ?'), 1).sql.should == 'SELECT * FROM t ORDER BY a, b, ?, 1, d'
160
+ @ds.order_prepend(Sequel.lit('a, b, ?'), 1).sql.must_equal 'SELECT * FROM t ORDER BY a, b, ?, 1, d'
161
161
  end
162
162
 
163
163
  it "should have #order_append work regularly if not given a string as the first argument" do
164
- @ds.order_prepend(:a, 1).sql.should == 'SELECT * FROM t ORDER BY a, 1, d'
164
+ @ds.order_prepend(:a, 1).sql.must_equal 'SELECT * FROM t ORDER BY a, 1, d'
165
165
  end
166
166
  end
167
167
  end
@@ -5,10 +5,10 @@ describe "Database#query" do
5
5
  @db = Sequel.mock.extension(:query)
6
6
  end
7
7
 
8
- specify "should delegate to Dataset#query if block is provided" do
8
+ it "should delegate to Dataset#query if block is provided" do
9
9
  @d = @db.query {select :x; from :y}
10
- @d.should be_a_kind_of(Sequel::Dataset)
11
- @d.sql.should == "SELECT x FROM y"
10
+ @d.must_be_kind_of(Sequel::Dataset)
11
+ @d.sql.must_equal "SELECT x FROM y"
12
12
  end
13
13
  end
14
14
 
@@ -17,86 +17,86 @@ describe "Dataset#query" do
17
17
  @d = Sequel.mock.dataset.extension(:query)
18
18
  end
19
19
 
20
- specify "should allow cloning without arguments" do
20
+ it "should allow cloning without arguments" do
21
21
  q = @d.query {clone}
22
- q.class.should == @d.class
23
- q.sql.should == "SELECT *"
22
+ q.class.must_equal @d.class
23
+ q.sql.must_equal "SELECT *"
24
24
  end
25
25
 
26
- specify "should support #from" do
26
+ it "should support #from" do
27
27
  q = @d.query {from :xxx}
28
- q.class.should == @d.class
29
- q.sql.should == "SELECT * FROM xxx"
28
+ q.class.must_equal @d.class
29
+ q.sql.must_equal "SELECT * FROM xxx"
30
30
  end
31
31
 
32
- specify "should support #select" do
32
+ it "should support #select" do
33
33
  q = @d.query do
34
34
  select :a, :b___mongo
35
35
  from :yyy
36
36
  end
37
- q.class.should == @d.class
38
- q.sql.should == "SELECT a, b AS mongo FROM yyy"
37
+ q.class.must_equal @d.class
38
+ q.sql.must_equal "SELECT a, b AS mongo FROM yyy"
39
39
  end
40
40
 
41
- specify "should support #where" do
41
+ it "should support #where" do
42
42
  q = @d.query do
43
43
  from :zzz
44
44
  where{x + 2 > Sequel.expr(:y) + 3}
45
45
  end
46
- q.class.should == @d.class
47
- q.sql.should == "SELECT * FROM zzz WHERE ((x + 2) > (y + 3))"
46
+ q.class.must_equal @d.class
47
+ q.sql.must_equal "SELECT * FROM zzz WHERE ((x + 2) > (y + 3))"
48
48
 
49
49
  q = @d.from(:zzz).query do
50
50
  where{(x > 1) & (Sequel.expr(:y) > 2)}
51
51
  end
52
- q.class.should == @d.class
53
- q.sql.should == "SELECT * FROM zzz WHERE ((x > 1) AND (y > 2))"
52
+ q.class.must_equal @d.class
53
+ q.sql.must_equal "SELECT * FROM zzz WHERE ((x > 1) AND (y > 2))"
54
54
 
55
55
  q = @d.from(:zzz).query do
56
56
  where :x => 33
57
57
  end
58
- q.class.should == @d.class
59
- q.sql.should == "SELECT * FROM zzz WHERE (x = 33)"
58
+ q.class.must_equal @d.class
59
+ q.sql.must_equal "SELECT * FROM zzz WHERE (x = 33)"
60
60
  end
61
61
 
62
- specify "should support #group_by and #having" do
62
+ it "should support #group_by and #having" do
63
63
  q = @d.query do
64
64
  from :abc
65
65
  group_by :id
66
66
  having{x >= 2}
67
67
  end
68
- q.class.should == @d.class
69
- q.sql.should == "SELECT * FROM abc GROUP BY id HAVING (x >= 2)"
68
+ q.class.must_equal @d.class
69
+ q.sql.must_equal "SELECT * FROM abc GROUP BY id HAVING (x >= 2)"
70
70
  end
71
71
 
72
- specify "should support #order, #order_by" do
72
+ it "should support #order, #order_by" do
73
73
  q = @d.query do
74
74
  from :xyz
75
75
  order_by :stamp
76
76
  end
77
- q.class.should == @d.class
78
- q.sql.should == "SELECT * FROM xyz ORDER BY stamp"
77
+ q.class.must_equal @d.class
78
+ q.sql.must_equal "SELECT * FROM xyz ORDER BY stamp"
79
79
  end
80
80
 
81
- specify "should support blocks that end in nil" do
81
+ it "should support blocks that end in nil" do
82
82
  condition = false
83
83
  q = @d.query do
84
84
  from :xyz
85
85
  order_by :stamp if condition
86
86
  end
87
- q.sql.should == "SELECT * FROM xyz"
87
+ q.sql.must_equal "SELECT * FROM xyz"
88
88
  end
89
89
 
90
- specify "should have an appropriate mutation method" do
90
+ it "should have an appropriate mutation method" do
91
91
  @d.query! do
92
92
  select :a, :b___mongo
93
93
  from :yyy
94
94
  end
95
- @d.sql.should == "SELECT a, b AS mongo FROM yyy"
95
+ @d.sql.must_equal "SELECT a, b AS mongo FROM yyy"
96
96
  end
97
97
 
98
- specify "should raise on non-chainable method calls" do
99
- proc {@d.query {row_proc}}.should raise_error(Sequel::Error)
100
- proc {@d.query {all}}.should raise_error(Sequel::Error)
98
+ it "should raise on non-chainable method calls" do
99
+ proc {@d.query {row_proc}}.must_raise(Sequel::Error)
100
+ proc {@d.query {all}}.must_raise(Sequel::Error)
101
101
  end
102
102
  end
@@ -18,29 +18,29 @@ describe Sequel::Model, "rcte_tree" do
18
18
 
19
19
  it "should define the correct associations" do
20
20
  @c.plugin :rcte_tree
21
- @c.associations.sort_by{|x| x.to_s}.should == [:ancestors, :children, :descendants, :parent]
21
+ @c.associations.sort_by{|x| x.to_s}.must_equal [:ancestors, :children, :descendants, :parent]
22
22
  end
23
23
 
24
24
  it "should define the correct associations when giving options" do
25
25
  @c.plugin :rcte_tree, :ancestors=>{:name=>:as}, :children=>{:name=>:cs}, :descendants=>{:name=>:ds}, :parent=>{:name=>:p}
26
- @c.associations.sort_by{|x| x.to_s}.should == [:as, :cs, :ds, :p]
26
+ @c.associations.sort_by{|x| x.to_s}.must_equal [:as, :cs, :ds, :p]
27
27
  end
28
28
 
29
29
  it "should use the correct SQL for lazy associations" do
30
30
  @c.plugin :rcte_tree
31
- @o.parent_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1'
32
- @o.children_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.parent_id = 2)'
33
- @o.ancestors_dataset.sql.should == 'WITH t AS (SELECT * FROM nodes WHERE (id = 1) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.parent_id = nodes.id)) SELECT * FROM t AS nodes'
34
- @o.descendants_dataset.sql.should == 'WITH t AS (SELECT * FROM nodes WHERE (parent_id = 2) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.id = nodes.parent_id)) SELECT * FROM t AS nodes'
31
+ @o.parent_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1'
32
+ @o.children_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.parent_id = 2)'
33
+ @o.ancestors_dataset.sql.must_equal 'WITH t AS (SELECT * FROM nodes WHERE (id = 1) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.parent_id = nodes.id)) SELECT * FROM t AS nodes'
34
+ @o.descendants_dataset.sql.must_equal 'WITH t AS (SELECT * FROM nodes WHERE (parent_id = 2) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.id = nodes.parent_id)) SELECT * FROM t AS nodes'
35
35
  end
36
36
 
37
37
  it "should use the correct SQL for lazy associations when recursive CTEs require column aliases" do
38
38
  @c.dataset.meta_def(:recursive_cte_requires_column_aliases?){true}
39
39
  @c.plugin :rcte_tree
40
- @o.parent_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1'
41
- @o.children_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.parent_id = 2)'
42
- @o.ancestors_dataset.sql.should == 'WITH t(id, name, parent_id, i, pi) AS (SELECT id, name, parent_id, i, pi FROM nodes WHERE (id = 1) UNION ALL SELECT nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.parent_id = nodes.id)) SELECT * FROM t AS nodes'
43
- @o.descendants_dataset.sql.should == 'WITH t(id, name, parent_id, i, pi) AS (SELECT id, name, parent_id, i, pi FROM nodes WHERE (parent_id = 2) UNION ALL SELECT nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.id = nodes.parent_id)) SELECT * FROM t AS nodes'
40
+ @o.parent_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.id = 1) LIMIT 1'
41
+ @o.children_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.parent_id = 2)'
42
+ @o.ancestors_dataset.sql.must_equal 'WITH t(id, name, parent_id, i, pi) AS (SELECT id, name, parent_id, i, pi FROM nodes WHERE (id = 1) UNION ALL SELECT nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.parent_id = nodes.id)) SELECT * FROM t AS nodes'
43
+ @o.descendants_dataset.sql.must_equal 'WITH t(id, name, parent_id, i, pi) AS (SELECT id, name, parent_id, i, pi FROM nodes WHERE (parent_id = 2) UNION ALL SELECT nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.id = nodes.parent_id)) SELECT * FROM t AS nodes'
44
44
  end
45
45
 
46
46
  it "should use the correct SQL for eager loading when recursive CTEs require column aliases" do
@@ -48,70 +48,70 @@ describe Sequel::Model, "rcte_tree" do
48
48
  @c.plugin :rcte_tree
49
49
  @ds._fetch = [[{:id=>1, :name=>'A', :parent_id=>3}]]
50
50
  @c.eager(:ancestors).all
51
- @db.sqls.should == ["SELECT * FROM nodes", "WITH t(x_root_x, id, name, parent_id, i, pi) AS (SELECT id AS x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes WHERE (id IN (3)) UNION ALL SELECT t.x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.parent_id = nodes.id)) SELECT * FROM t AS nodes"]
51
+ @db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x, id, name, parent_id, i, pi) AS (SELECT id AS x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes WHERE (id IN (3)) UNION ALL SELECT t.x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.parent_id = nodes.id)) SELECT * FROM t AS nodes"]
52
52
 
53
53
  @ds._fetch = [[{:id=>1, :name=>'A', :parent_id=>3}]]
54
54
  @c.eager(:descendants).all
55
- @db.sqls.should == ["SELECT * FROM nodes", "WITH t(x_root_x, id, name, parent_id, i, pi) AS (SELECT parent_id AS x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes WHERE (parent_id IN (1)) UNION ALL SELECT t.x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.id = nodes.parent_id)) SELECT * FROM t AS nodes"]
55
+ @db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x, id, name, parent_id, i, pi) AS (SELECT parent_id AS x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes WHERE (parent_id IN (1)) UNION ALL SELECT t.x_root_x, nodes.id, nodes.name, nodes.parent_id, nodes.i, nodes.pi FROM nodes INNER JOIN t ON (t.id = nodes.parent_id)) SELECT * FROM t AS nodes"]
56
56
  end
57
57
 
58
58
  it "should use the correct SQL for lazy associations when giving options" do
59
59
  @c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :cte_name=>:cte, :order=>:name, :ancestors=>{:name=>:as}, :children=>{:name=>:cs}, :descendants=>{:name=>:ds}, :parent=>{:name=>:p}
60
- @o.p_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1'
61
- @o.cs_dataset.sql.should == 'SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name'
62
- @o.as_dataset.sql.should == 'WITH cte AS (SELECT * FROM nodes WHERE (i = 4) UNION ALL SELECT nodes.* FROM nodes INNER JOIN cte ON (cte.pi = nodes.i)) SELECT * FROM cte AS nodes ORDER BY name'
63
- @o.ds_dataset.sql.should == 'WITH cte AS (SELECT * FROM nodes WHERE (pi = 3) UNION ALL SELECT nodes.* FROM nodes INNER JOIN cte ON (cte.i = nodes.pi)) SELECT * FROM cte AS nodes ORDER BY name'
60
+ @o.p_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.i = 4) ORDER BY name LIMIT 1'
61
+ @o.cs_dataset.sql.must_equal 'SELECT * FROM nodes WHERE (nodes.pi = 3) ORDER BY name'
62
+ @o.as_dataset.sql.must_equal 'WITH cte AS (SELECT * FROM nodes WHERE (i = 4) UNION ALL SELECT nodes.* FROM nodes INNER JOIN cte ON (cte.pi = nodes.i)) SELECT * FROM cte AS nodes ORDER BY name'
63
+ @o.ds_dataset.sql.must_equal 'WITH cte AS (SELECT * FROM nodes WHERE (pi = 3) UNION ALL SELECT nodes.* FROM nodes INNER JOIN cte ON (cte.i = nodes.pi)) SELECT * FROM cte AS nodes ORDER BY name'
64
64
  end
65
65
 
66
66
  it "should use the correct SQL for lazy associations with :conditions option" do
67
67
  @c.plugin :rcte_tree, :conditions => {:i => 1}
68
- @o.parent_dataset.sql.should == 'SELECT * FROM nodes WHERE ((i = 1) AND (nodes.id = 1)) LIMIT 1'
69
- @o.children_dataset.sql.should == 'SELECT * FROM nodes WHERE ((i = 1) AND (nodes.parent_id = 2))'
70
- @o.ancestors_dataset.sql.should == 'WITH t AS (SELECT * FROM nodes WHERE ((id = 1) AND (i = 1)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.parent_id = nodes.id) WHERE (i = 1)) SELECT * FROM t AS nodes WHERE (i = 1)'
71
- @o.descendants_dataset.sql.should == 'WITH t AS (SELECT * FROM nodes WHERE ((parent_id = 2) AND (i = 1)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.id = nodes.parent_id) WHERE (i = 1)) SELECT * FROM t AS nodes WHERE (i = 1)'
68
+ @o.parent_dataset.sql.must_equal 'SELECT * FROM nodes WHERE ((i = 1) AND (nodes.id = 1)) LIMIT 1'
69
+ @o.children_dataset.sql.must_equal 'SELECT * FROM nodes WHERE ((i = 1) AND (nodes.parent_id = 2))'
70
+ @o.ancestors_dataset.sql.must_equal 'WITH t AS (SELECT * FROM nodes WHERE ((id = 1) AND (i = 1)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.parent_id = nodes.id) WHERE (i = 1)) SELECT * FROM t AS nodes WHERE (i = 1)'
71
+ @o.descendants_dataset.sql.must_equal 'WITH t AS (SELECT * FROM nodes WHERE ((parent_id = 2) AND (i = 1)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON (t.id = nodes.parent_id) WHERE (i = 1)) SELECT * FROM t AS nodes WHERE (i = 1)'
72
72
  end
73
73
 
74
74
  it "should add all parent associations when lazily loading ancestors" do
75
75
  @c.plugin :rcte_tree
76
76
  @ds._fetch = [[{:id=>1, :name=>'A', :parent_id=>3}, {:id=>4, :name=>'B', :parent_id=>nil}, {:id=>3, :name=>'?', :parent_id=>4}]]
77
- @o.ancestors.should == [@c.load(:id=>1, :name=>'A', :parent_id=>3), @c.load(:id=>4, :name=>'B', :parent_id=>nil), @c.load(:id=>3, :name=>'?', :parent_id=>4)]
78
- @o.associations[:parent].should == @c.load(:id=>1, :name=>'A', :parent_id=>3)
79
- @o.associations[:parent].associations[:parent].should == @c.load(:id=>3, :name=>'?', :parent_id=>4)
80
- @o.associations[:parent].associations[:parent].associations[:parent].should == @c.load(:id=>4, :name=>'B', :parent_id=>nil)
81
- @o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).should == nil
77
+ @o.ancestors.must_equal [@c.load(:id=>1, :name=>'A', :parent_id=>3), @c.load(:id=>4, :name=>'B', :parent_id=>nil), @c.load(:id=>3, :name=>'?', :parent_id=>4)]
78
+ @o.associations[:parent].must_equal @c.load(:id=>1, :name=>'A', :parent_id=>3)
79
+ @o.associations[:parent].associations[:parent].must_equal @c.load(:id=>3, :name=>'?', :parent_id=>4)
80
+ @o.associations[:parent].associations[:parent].associations[:parent].must_equal @c.load(:id=>4, :name=>'B', :parent_id=>nil)
81
+ @o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).must_equal nil
82
82
  end
83
83
 
84
84
  it "should add all parent associations when lazily loading ancestors and giving options" do
85
85
  @c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :ancestors=>{:name=>:as}, :parent=>{:name=>:p}
86
86
  @ds._fetch = [[{:i=>4, :name=>'A', :pi=>5}, {:i=>6, :name=>'B', :pi=>nil}, {:i=>5, :name=>'?', :pi=>6}]]
87
- @o.as.should == [@c.load(:i=>4, :name=>'A', :pi=>5), @c.load(:i=>6, :name=>'B', :pi=>nil), @c.load(:i=>5, :name=>'?', :pi=>6)]
88
- @o.associations[:p].should == @c.load(:i=>4, :name=>'A', :pi=>5)
89
- @o.associations[:p].associations[:p].should == @c.load(:i=>5, :name=>'?', :pi=>6)
90
- @o.associations[:p].associations[:p].associations[:p].should == @c.load(:i=>6, :name=>'B', :pi=>nil)
91
- @o.associations[:p].associations[:p].associations[:p].associations.fetch(:p, 1).should == nil
87
+ @o.as.must_equal [@c.load(:i=>4, :name=>'A', :pi=>5), @c.load(:i=>6, :name=>'B', :pi=>nil), @c.load(:i=>5, :name=>'?', :pi=>6)]
88
+ @o.associations[:p].must_equal @c.load(:i=>4, :name=>'A', :pi=>5)
89
+ @o.associations[:p].associations[:p].must_equal @c.load(:i=>5, :name=>'?', :pi=>6)
90
+ @o.associations[:p].associations[:p].associations[:p].must_equal @c.load(:i=>6, :name=>'B', :pi=>nil)
91
+ @o.associations[:p].associations[:p].associations[:p].associations.fetch(:p, 1).must_equal nil
92
92
  end
93
93
 
94
94
  it "should add all parent and children associations when lazily loading descendants" do
95
95
  @c.plugin :rcte_tree
96
96
  @ds._fetch = [[{:id=>3, :name=>'??', :parent_id=>1}, {:id=>1, :name=>'A', :parent_id=>2}, {:id=>4, :name=>'B', :parent_id=>2}, {:id=>5, :name=>'?', :parent_id=>3}]]
97
- @o.descendants.should == [@c.load(:id=>3, :name=>'??', :parent_id=>1), @c.load(:id=>1, :name=>'A', :parent_id=>2), @c.load(:id=>4, :name=>'B', :parent_id=>2), @c.load(:id=>5, :name=>'?', :parent_id=>3)]
98
- @o.associations[:children].should == [@c.load(:id=>1, :name=>'A', :parent_id=>2), @c.load(:id=>4, :name=>'B', :parent_id=>2)]
99
- @o.associations[:children].map{|c1| c1.associations[:children]}.should == [[@c.load(:id=>3, :name=>'??', :parent_id=>1)], []]
100
- @o.associations[:children].map{|c1| c1.associations[:parent]}.should == [@o, @o]
101
- @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.should == [[[@c.load(:id=>5, :name=>'?', :parent_id=>3)]], []]
102
- @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:parent]}}.should == [[@o.children.first], []]
103
- @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.should == [[[[]]], []]
104
- @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:parent]}}}.should == [[[@o.children.first.children.first]], []]
97
+ @o.descendants.must_equal [@c.load(:id=>3, :name=>'??', :parent_id=>1), @c.load(:id=>1, :name=>'A', :parent_id=>2), @c.load(:id=>4, :name=>'B', :parent_id=>2), @c.load(:id=>5, :name=>'?', :parent_id=>3)]
98
+ @o.associations[:children].must_equal [@c.load(:id=>1, :name=>'A', :parent_id=>2), @c.load(:id=>4, :name=>'B', :parent_id=>2)]
99
+ @o.associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@c.load(:id=>3, :name=>'??', :parent_id=>1)], []]
100
+ @o.associations[:children].map{|c1| c1.associations[:parent]}.must_equal [@o, @o]
101
+ @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[[@c.load(:id=>5, :name=>'?', :parent_id=>3)]], []]
102
+ @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:parent]}}.must_equal [[@o.children.first], []]
103
+ @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.must_equal [[[[]]], []]
104
+ @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:parent]}}}.must_equal [[[@o.children.first.children.first]], []]
105
105
  end
106
106
 
107
107
  it "should add all children associations when lazily loading descendants and giving options" do
108
108
  @c.plugin :rcte_tree, :primary_key=>:i, :key=>:pi, :children=>{:name=>:cs}, :descendants=>{:name=>:ds}
109
109
  @ds._fetch = [[{:i=>7, :name=>'??', :pi=>5}, {:i=>5, :name=>'A', :pi=>3}, {:i=>6, :name=>'B', :pi=>3}, {:i=>8, :name=>'?', :pi=>7}]]
110
- @o.ds.should == [@c.load(:i=>7, :name=>'??', :pi=>5), @c.load(:i=>5, :name=>'A', :pi=>3), @c.load(:i=>6, :name=>'B', :pi=>3), @c.load(:i=>8, :name=>'?', :pi=>7)]
111
- @o.associations[:cs].should == [@c.load(:i=>5, :name=>'A', :pi=>3), @c.load(:i=>6, :name=>'B', :pi=>3)]
112
- @o.associations[:cs].map{|c1| c1.associations[:cs]}.should == [[@c.load(:i=>7, :name=>'??', :pi=>5)], []]
113
- @o.associations[:cs].map{|c1| c1.associations[:cs].map{|c2| c2.associations[:cs]}}.should == [[[@c.load(:i=>8, :name=>'?', :pi=>7)]], []]
114
- @o.associations[:cs].map{|c1| c1.associations[:cs].map{|c2| c2.associations[:cs].map{|c3| c3.associations[:cs]}}}.should == [[[[]]], []]
110
+ @o.ds.must_equal [@c.load(:i=>7, :name=>'??', :pi=>5), @c.load(:i=>5, :name=>'A', :pi=>3), @c.load(:i=>6, :name=>'B', :pi=>3), @c.load(:i=>8, :name=>'?', :pi=>7)]
111
+ @o.associations[:cs].must_equal [@c.load(:i=>5, :name=>'A', :pi=>3), @c.load(:i=>6, :name=>'B', :pi=>3)]
112
+ @o.associations[:cs].map{|c1| c1.associations[:cs]}.must_equal [[@c.load(:i=>7, :name=>'??', :pi=>5)], []]
113
+ @o.associations[:cs].map{|c1| c1.associations[:cs].map{|c2| c2.associations[:cs]}}.must_equal [[[@c.load(:i=>8, :name=>'?', :pi=>7)]], []]
114
+ @o.associations[:cs].map{|c1| c1.associations[:cs].map{|c2| c2.associations[:cs].map{|c3| c3.associations[:cs]}}}.must_equal [[[[]]], []]
115
115
  end
116
116
 
117
117
  it "should eagerly load ancestors" do
@@ -122,18 +122,18 @@ describe Sequel::Model, "rcte_tree" do
122
122
  {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>2}, {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>1}]]
123
123
  os = @ds.eager(:ancestors).all
124
124
  sqls = @db.sqls
125
- sqls.first.should == "SELECT * FROM nodes"
126
- sqls.last.should =~ /WITH t AS \(SELECT id AS x_root_x, nodes\.\* FROM nodes WHERE \(id IN \([12], [12]\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.parent_id = nodes\.id\)\) SELECT \* FROM t AS nodes/
127
- os.should == [@c.load(:id=>2, :parent_id=>1, :name=>'AA'), @c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>7, :parent_id=>1, :name=>'D'), @c.load(:id=>9, :parent_id=>nil, :name=>'E')]
128
- os.map{|o| o.ancestors}.should == [[@c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>8, :name=>'?', :parent_id=>nil)],
125
+ sqls.first.must_equal "SELECT * FROM nodes"
126
+ sqls.last.must_match(/WITH t AS \(SELECT id AS x_root_x, nodes\.\* FROM nodes WHERE \(id IN \([12], [12]\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.parent_id = nodes\.id\)\) SELECT \* FROM t AS nodes/)
127
+ os.must_equal [@c.load(:id=>2, :parent_id=>1, :name=>'AA'), @c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>7, :parent_id=>1, :name=>'D'), @c.load(:id=>9, :parent_id=>nil, :name=>'E')]
128
+ os.map{|o| o.ancestors}.must_equal [[@c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>8, :name=>'?', :parent_id=>nil)],
129
129
  [@c.load(:id=>2, :name=>'AA', :parent_id=>1), @c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>8, :name=>'?', :parent_id=>nil)],
130
130
  [@c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>8, :name=>'?', :parent_id=>nil)],
131
131
  []]
132
- os.map{|o| o.parent}.should == [@c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>2, :name=>'AA', :parent_id=>1), @c.load(:id=>1, :name=>'00', :parent_id=>8), nil]
133
- os.map{|o| o.parent.parent if o.parent}.should == [@c.load(:id=>8, :name=>'?', :parent_id=>nil), @c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>8, :name=>'?', :parent_id=>nil), nil]
134
- os.map{|o| o.parent.parent.parent if o.parent and o.parent.parent}.should == [nil, @c.load(:id=>8, :name=>'?', :parent_id=>nil), nil, nil]
135
- os.map{|o| o.parent.parent.parent.parent if o.parent and o.parent.parent and o.parent.parent.parent}.should == [nil, nil, nil, nil]
136
- @db.sqls.should == []
132
+ os.map{|o| o.parent}.must_equal [@c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>2, :name=>'AA', :parent_id=>1), @c.load(:id=>1, :name=>'00', :parent_id=>8), nil]
133
+ os.map{|o| o.parent.parent if o.parent}.must_equal [@c.load(:id=>8, :name=>'?', :parent_id=>nil), @c.load(:id=>1, :name=>'00', :parent_id=>8), @c.load(:id=>8, :name=>'?', :parent_id=>nil), nil]
134
+ os.map{|o| o.parent.parent.parent if o.parent and o.parent.parent}.must_equal [nil, @c.load(:id=>8, :name=>'?', :parent_id=>nil), nil, nil]
135
+ os.map{|o| o.parent.parent.parent.parent if o.parent and o.parent.parent and o.parent.parent.parent}.must_equal [nil, nil, nil, nil]
136
+ @db.sqls.must_equal []
137
137
  end
138
138
 
139
139
  it "should eagerly load ancestors when giving options" do
@@ -144,17 +144,17 @@ describe Sequel::Model, "rcte_tree" do
144
144
  {:i=>8, :name=>'?', :pi=>nil, :kal=>2}, {:i=>8, :name=>'?', :pi=>nil, :kal=>1}]]
145
145
  os = @ds.eager(:as).all
146
146
  sqls = @db.sqls
147
- sqls.first.should == "SELECT * FROM nodes"
148
- sqls.last.should =~ /WITH cte AS \(SELECT i AS kal, nodes\.\* FROM nodes WHERE \(i IN \([12], [12]\)\) UNION ALL SELECT cte\.kal, nodes\.\* FROM nodes INNER JOIN cte ON \(cte\.pi = nodes\.i\)\) SELECT \* FROM cte/
149
- os.should == [@c.load(:i=>2, :pi=>1, :name=>'AA'), @c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>7, :pi=>1, :name=>'D'), @c.load(:i=>9, :pi=>nil, :name=>'E')]
150
- os.map{|o| o.as}.should == [[@c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>8, :name=>'?', :pi=>nil)],
147
+ sqls.first.must_equal "SELECT * FROM nodes"
148
+ sqls.last.must_match(/WITH cte AS \(SELECT i AS kal, nodes\.\* FROM nodes WHERE \(i IN \([12], [12]\)\) UNION ALL SELECT cte\.kal, nodes\.\* FROM nodes INNER JOIN cte ON \(cte\.pi = nodes\.i\)\) SELECT \* FROM cte/)
149
+ os.must_equal [@c.load(:i=>2, :pi=>1, :name=>'AA'), @c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>7, :pi=>1, :name=>'D'), @c.load(:i=>9, :pi=>nil, :name=>'E')]
150
+ os.map{|o| o.as}.must_equal [[@c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>8, :name=>'?', :pi=>nil)],
151
151
  [@c.load(:i=>2, :name=>'AA', :pi=>1), @c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>8, :name=>'?', :pi=>nil)],
152
152
  [@c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>8, :name=>'?', :pi=>nil)],
153
153
  []]
154
- os.map{|o| o.p}.should == [@c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>2, :name=>'AA', :pi=>1), @c.load(:i=>1, :name=>'00', :pi=>8), nil]
155
- os.map{|o| o.p.p if o.p}.should == [@c.load(:i=>8, :name=>'?', :pi=>nil), @c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>8, :name=>'?', :pi=>nil), nil]
156
- os.map{|o| o.p.p.p if o.p and o.p.p}.should == [nil, @c.load(:i=>8, :name=>'?', :pi=>nil), nil, nil]
157
- os.map{|o| o.p.p.p.p if o.p and o.p.p and o.p.p.p}.should == [nil, nil, nil, nil]
154
+ os.map{|o| o.p}.must_equal [@c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>2, :name=>'AA', :pi=>1), @c.load(:i=>1, :name=>'00', :pi=>8), nil]
155
+ os.map{|o| o.p.p if o.p}.must_equal [@c.load(:i=>8, :name=>'?', :pi=>nil), @c.load(:i=>1, :name=>'00', :pi=>8), @c.load(:i=>8, :name=>'?', :pi=>nil), nil]
156
+ os.map{|o| o.p.p.p if o.p and o.p.p}.must_equal [nil, @c.load(:i=>8, :name=>'?', :pi=>nil), nil, nil]
157
+ os.map{|o| o.p.p.p.p if o.p and o.p.p and o.p.p.p}.must_equal [nil, nil, nil, nil]
158
158
  end
159
159
 
160
160
  it "should eagerly load ancestors respecting association option :conditions" do
@@ -165,8 +165,8 @@ describe Sequel::Model, "rcte_tree" do
165
165
  {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>2}, {:id=>8, :name=>'?', :parent_id=>nil, :x_root_x=>1}]]
166
166
  @ds.eager(:ancestors).all
167
167
  sqls = @db.sqls
168
- sqls.first.should == "SELECT * FROM nodes"
169
- sqls.last.should =~ /WITH t AS \(SELECT id AS x_root_x, nodes\.\* FROM nodes WHERE \(\(id IN \([12], [12]\)\) AND \(i = 1\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.parent_id = nodes\.id\) WHERE \(i = 1\)\) SELECT \* FROM t AS nodes WHERE \(i = 1\)/
168
+ sqls.first.must_equal "SELECT * FROM nodes"
169
+ sqls.last.must_match(/WITH t AS \(SELECT id AS x_root_x, nodes\.\* FROM nodes WHERE \(\(id IN \([12], [12]\)\) AND \(i = 1\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.parent_id = nodes\.id\) WHERE \(i = 1\)\) SELECT \* FROM t AS nodes WHERE \(i = 1\)/)
170
170
  end
171
171
 
172
172
  it "should eagerly load descendants" do
@@ -177,18 +177,18 @@ describe Sequel::Model, "rcte_tree" do
177
177
  {:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7}]]
178
178
  os = @ds.eager(:descendants).all
179
179
  sqls = @db.sqls
180
- sqls.first.should == "SELECT * FROM nodes"
181
- sqls.last.should =~ /WITH t AS \(SELECT parent_id AS x_root_x, nodes\.\* FROM nodes WHERE \(parent_id IN \([267], [267], [267]\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.id = nodes\.parent_id\)\) SELECT \* FROM t AS nodes/
182
- os.should == [@c.load(:id=>2, :parent_id=>1, :name=>'AA'), @c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>7, :parent_id=>1, :name=>'D')]
183
- os.map{|o| o.descendants}.should == [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E'), @c.load(:id=>3, :name=>'00', :parent_id=>6)],
180
+ sqls.first.must_equal "SELECT * FROM nodes"
181
+ sqls.last.must_match(/WITH t AS \(SELECT parent_id AS x_root_x, nodes\.\* FROM nodes WHERE \(parent_id IN \([267], [267], [267]\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.id = nodes\.parent_id\)\) SELECT \* FROM t AS nodes/)
182
+ os.must_equal [@c.load(:id=>2, :parent_id=>1, :name=>'AA'), @c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>7, :parent_id=>1, :name=>'D')]
183
+ os.map{|o| o.descendants}.must_equal [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E'), @c.load(:id=>3, :name=>'00', :parent_id=>6)],
184
184
  [@c.load(:id=>3, :name=>'00', :parent_id=>6)],
185
185
  [@c.load(:id=>4, :name=>'?', :parent_id=>7), @c.load(:id=>5, :name=>'?', :parent_id=>4)]]
186
- os.map{|o| o.children}.should == [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E')], [@c.load(:id=>3, :name=>'00', :parent_id=>6)], [@c.load(:id=>4, :name=>'?', :parent_id=>7)]]
187
- os.map{|o1| o1.children.map{|o2| o2.children}}.should == [[[@c.load(:id=>3, :name=>'00', :parent_id=>6)], []], [[]], [[@c.load(:id=>5, :name=>'?', :parent_id=>4)]]]
188
- os.map{|o1| o1.children.map{|o2| o2.parent}}.should == [[os[0], os[0]], [os[1]], [os[2]]]
189
- os.map{|o1| o1.children.map{|o2| o2.children.map{|o3| o3.children}}}.should == [[[[]], []], [[]], [[[]]]]
190
- os.map{|o1| o1.children.map{|o2| o2.children.map{|o3| o3.parent}}}.should == [[[os[0].children[0]], []], [[]], [[os[2].children[0]]]]
191
- @db.sqls.should == []
186
+ os.map{|o| o.children}.must_equal [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E')], [@c.load(:id=>3, :name=>'00', :parent_id=>6)], [@c.load(:id=>4, :name=>'?', :parent_id=>7)]]
187
+ os.map{|o1| o1.children.map{|o2| o2.children}}.must_equal [[[@c.load(:id=>3, :name=>'00', :parent_id=>6)], []], [[]], [[@c.load(:id=>5, :name=>'?', :parent_id=>4)]]]
188
+ os.map{|o1| o1.children.map{|o2| o2.parent}}.must_equal [[os[0], os[0]], [os[1]], [os[2]]]
189
+ os.map{|o1| o1.children.map{|o2| o2.children.map{|o3| o3.children}}}.must_equal [[[[]], []], [[]], [[[]]]]
190
+ os.map{|o1| o1.children.map{|o2| o2.children.map{|o3| o3.parent}}}.must_equal [[[os[0].children[0]], []], [[]], [[os[2].children[0]]]]
191
+ @db.sqls.must_equal []
192
192
  end
193
193
 
194
194
  it "should eagerly load descendants when giving options" do
@@ -199,16 +199,16 @@ describe Sequel::Model, "rcte_tree" do
199
199
  {:i=>4, :name=>'?', :pi=>7, :kal=>7}, {:i=>5, :name=>'?', :pi=>4, :kal=>7}]]
200
200
  os = @ds.eager(:ds).all
201
201
  sqls = @db.sqls
202
- sqls.first.should == "SELECT * FROM nodes"
203
- sqls.last.should =~ /WITH cte AS \(SELECT pi AS kal, nodes\.\* FROM nodes WHERE \(pi IN \([267], [267], [267]\)\) UNION ALL SELECT cte\.kal, nodes\.\* FROM nodes INNER JOIN cte ON \(cte\.i = nodes\.pi\)\) SELECT \* FROM cte/
204
- os.should == [@c.load(:i=>2, :pi=>1, :name=>'AA'), @c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>7, :pi=>1, :name=>'D')]
205
- os.map{|o| o.ds}.should == [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E'), @c.load(:i=>3, :name=>'00', :pi=>6)],
202
+ sqls.first.must_equal "SELECT * FROM nodes"
203
+ sqls.last.must_match(/WITH cte AS \(SELECT pi AS kal, nodes\.\* FROM nodes WHERE \(pi IN \([267], [267], [267]\)\) UNION ALL SELECT cte\.kal, nodes\.\* FROM nodes INNER JOIN cte ON \(cte\.i = nodes\.pi\)\) SELECT \* FROM cte/)
204
+ os.must_equal [@c.load(:i=>2, :pi=>1, :name=>'AA'), @c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>7, :pi=>1, :name=>'D')]
205
+ os.map{|o| o.ds}.must_equal [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E'), @c.load(:i=>3, :name=>'00', :pi=>6)],
206
206
  [@c.load(:i=>3, :name=>'00', :pi=>6)],
207
207
  [@c.load(:i=>4, :name=>'?', :pi=>7), @c.load(:i=>5, :name=>'?', :pi=>4)]]
208
- os.map{|o| o.cs}.should == [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E')], [@c.load(:i=>3, :name=>'00', :pi=>6)], [@c.load(:i=>4, :name=>'?', :pi=>7)]]
209
- os.map{|o1| o1.cs.map{|o2| o2.cs}}.should == [[[@c.load(:i=>3, :name=>'00', :pi=>6)], []], [[]], [[@c.load(:i=>5, :name=>'?', :pi=>4)]]]
210
- os.map{|o1| o1.cs.map{|o2| o2.cs.map{|o3| o3.cs}}}.should == [[[[]], []], [[]], [[[]]]]
211
- @db.sqls.should == []
208
+ os.map{|o| o.cs}.must_equal [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E')], [@c.load(:i=>3, :name=>'00', :pi=>6)], [@c.load(:i=>4, :name=>'?', :pi=>7)]]
209
+ os.map{|o1| o1.cs.map{|o2| o2.cs}}.must_equal [[[@c.load(:i=>3, :name=>'00', :pi=>6)], []], [[]], [[@c.load(:i=>5, :name=>'?', :pi=>4)]]]
210
+ os.map{|o1| o1.cs.map{|o2| o2.cs.map{|o3| o3.cs}}}.must_equal [[[[]], []], [[]], [[[]]]]
211
+ @db.sqls.must_equal []
212
212
  end
213
213
 
214
214
  it "should eagerly load descendants to a given level" do
@@ -219,16 +219,16 @@ describe Sequel::Model, "rcte_tree" do
219
219
  {:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7, :x_level_x=>0}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7, :x_level_x=>1}]]
220
220
  os = @ds.eager(:descendants=>2).all
221
221
  sqls = @db.sqls
222
- sqls.first.should == "SELECT * FROM nodes"
223
- sqls.last.should =~ /WITH t AS \(SELECT parent_id AS x_root_x, nodes\.\*, CAST\(0 AS integer\) AS x_level_x FROM nodes WHERE \(parent_id IN \([267], [267], [267]\)\) UNION ALL SELECT t\.x_root_x, nodes\.\*, \(t\.x_level_x \+ 1\) AS x_level_x FROM nodes INNER JOIN t ON \(t\.id = nodes\.parent_id\) WHERE \(t\.x_level_x < 1\)\) SELECT \* FROM t AS nodes/
224
- os.should == [@c.load(:id=>2, :parent_id=>1, :name=>'AA'), @c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>7, :parent_id=>1, :name=>'D')]
225
- os.map{|o| o.descendants}.should == [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E'), @c.load(:id=>3, :name=>'00', :parent_id=>6)],
222
+ sqls.first.must_equal "SELECT * FROM nodes"
223
+ sqls.last.must_match(/WITH t AS \(SELECT parent_id AS x_root_x, nodes\.\*, CAST\(0 AS integer\) AS x_level_x FROM nodes WHERE \(parent_id IN \([267], [267], [267]\)\) UNION ALL SELECT t\.x_root_x, nodes\.\*, \(t\.x_level_x \+ 1\) AS x_level_x FROM nodes INNER JOIN t ON \(t\.id = nodes\.parent_id\) WHERE \(t\.x_level_x < 1\)\) SELECT \* FROM t AS nodes/)
224
+ os.must_equal [@c.load(:id=>2, :parent_id=>1, :name=>'AA'), @c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>7, :parent_id=>1, :name=>'D')]
225
+ os.map{|o| o.descendants}.must_equal [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E'), @c.load(:id=>3, :name=>'00', :parent_id=>6)],
226
226
  [@c.load(:id=>3, :name=>'00', :parent_id=>6)],
227
227
  [@c.load(:id=>4, :name=>'?', :parent_id=>7), @c.load(:id=>5, :name=>'?', :parent_id=>4)]]
228
- os.map{|o| o.associations[:children]}.should == [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E')], [@c.load(:id=>3, :name=>'00', :parent_id=>6)], [@c.load(:id=>4, :name=>'?', :parent_id=>7)]]
229
- os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children]}}.should == [[[@c.load(:id=>3, :name=>'00', :parent_id=>6)], []], [[]], [[@c.load(:id=>5, :name=>'?', :parent_id=>4)]]]
230
- os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children].map{|o3| o3.associations[:children]}}}.should == [[[[]], []], [[]], [[nil]]]
231
- @db.sqls.should == []
228
+ os.map{|o| o.associations[:children]}.must_equal [[@c.load(:id=>6, :parent_id=>2, :name=>'C'), @c.load(:id=>9, :parent_id=>2, :name=>'E')], [@c.load(:id=>3, :name=>'00', :parent_id=>6)], [@c.load(:id=>4, :name=>'?', :parent_id=>7)]]
229
+ os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children]}}.must_equal [[[@c.load(:id=>3, :name=>'00', :parent_id=>6)], []], [[]], [[@c.load(:id=>5, :name=>'?', :parent_id=>4)]]]
230
+ os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children].map{|o3| o3.associations[:children]}}}.must_equal [[[[]], []], [[]], [[nil]]]
231
+ @db.sqls.must_equal []
232
232
  end
233
233
 
234
234
  it "should eagerly load descendants to a given level when giving options" do
@@ -239,16 +239,16 @@ describe Sequel::Model, "rcte_tree" do
239
239
  {:i=>4, :name=>'?', :pi=>7, :kal=>7, :lal=>0}, {:i=>5, :name=>'?', :pi=>4, :kal=>7, :lal=>1}]]
240
240
  os = @ds.eager(:ds=>2).all
241
241
  sqls = @db.sqls
242
- sqls.first.should == "SELECT * FROM nodes"
243
- sqls.last.should =~ /WITH cte AS \(SELECT pi AS kal, nodes\.\*, CAST\(0 AS integer\) AS lal FROM nodes WHERE \(pi IN \([267], [267], [267]\)\) UNION ALL SELECT cte\.kal, nodes\.\*, \(cte\.lal \+ 1\) AS lal FROM nodes INNER JOIN cte ON \(cte\.i = nodes\.pi\) WHERE \(cte\.lal < 1\)\) SELECT \* FROM cte/
244
- os.should == [@c.load(:i=>2, :pi=>1, :name=>'AA'), @c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>7, :pi=>1, :name=>'D')]
245
- os.map{|o| o.ds}.should == [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E'), @c.load(:i=>3, :name=>'00', :pi=>6)],
242
+ sqls.first.must_equal "SELECT * FROM nodes"
243
+ sqls.last.must_match(/WITH cte AS \(SELECT pi AS kal, nodes\.\*, CAST\(0 AS integer\) AS lal FROM nodes WHERE \(pi IN \([267], [267], [267]\)\) UNION ALL SELECT cte\.kal, nodes\.\*, \(cte\.lal \+ 1\) AS lal FROM nodes INNER JOIN cte ON \(cte\.i = nodes\.pi\) WHERE \(cte\.lal < 1\)\) SELECT \* FROM cte/)
244
+ os.must_equal [@c.load(:i=>2, :pi=>1, :name=>'AA'), @c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>7, :pi=>1, :name=>'D')]
245
+ os.map{|o| o.ds}.must_equal [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E'), @c.load(:i=>3, :name=>'00', :pi=>6)],
246
246
  [@c.load(:i=>3, :name=>'00', :pi=>6)],
247
247
  [@c.load(:i=>4, :name=>'?', :pi=>7), @c.load(:i=>5, :name=>'?', :pi=>4)]]
248
- os.map{|o| o.associations[:cs]}.should == [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E')], [@c.load(:i=>3, :name=>'00', :pi=>6)], [@c.load(:i=>4, :name=>'?', :pi=>7)]]
249
- os.map{|o1| o1.associations[:cs].map{|o2| o2.associations[:cs]}}.should == [[[@c.load(:i=>3, :name=>'00', :pi=>6)], []], [[]], [[@c.load(:i=>5, :name=>'?', :pi=>4)]]]
250
- os.map{|o1| o1.associations[:cs].map{|o2| o2.associations[:cs].map{|o3| o3.associations[:cs]}}}.should == [[[[]], []], [[]], [[nil]]]
251
- @db.sqls.should == []
248
+ os.map{|o| o.associations[:cs]}.must_equal [[@c.load(:i=>6, :pi=>2, :name=>'C'), @c.load(:i=>9, :pi=>2, :name=>'E')], [@c.load(:i=>3, :name=>'00', :pi=>6)], [@c.load(:i=>4, :name=>'?', :pi=>7)]]
249
+ os.map{|o1| o1.associations[:cs].map{|o2| o2.associations[:cs]}}.must_equal [[[@c.load(:i=>3, :name=>'00', :pi=>6)], []], [[]], [[@c.load(:i=>5, :name=>'?', :pi=>4)]]]
250
+ os.map{|o1| o1.associations[:cs].map{|o2| o2.associations[:cs].map{|o3| o3.associations[:cs]}}}.must_equal [[[[]], []], [[]], [[nil]]]
251
+ @db.sqls.must_equal []
252
252
  end
253
253
 
254
254
  it "should eagerly load descendants respecting association option :conditions" do
@@ -259,8 +259,8 @@ describe Sequel::Model, "rcte_tree" do
259
259
  {:id=>4, :name=>'?', :parent_id=>7, :x_root_x=>7}, {:id=>5, :name=>'?', :parent_id=>4, :x_root_x=>7}]]
260
260
  @ds.eager(:descendants).all
261
261
  sqls = @db.sqls
262
- sqls.first.should == "SELECT * FROM nodes"
263
- sqls.last.should =~ /WITH t AS \(SELECT parent_id AS x_root_x, nodes\.\* FROM nodes WHERE \(\(parent_id IN \([267], [267], [267]\)\) AND \(i = 1\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.id = nodes\.parent_id\) WHERE \(i = 1\)\) SELECT \* FROM t AS nodes WHERE \(i = 1\)/
262
+ sqls.first.must_equal "SELECT * FROM nodes"
263
+ sqls.last.must_match(/WITH t AS \(SELECT parent_id AS x_root_x, nodes\.\* FROM nodes WHERE \(\(parent_id IN \([267], [267], [267]\)\) AND \(i = 1\)\) UNION ALL SELECT t\.x_root_x, nodes\.\* FROM nodes INNER JOIN t ON \(t\.id = nodes\.parent_id\) WHERE \(i = 1\)\) SELECT \* FROM t AS nodes WHERE \(i = 1\)/)
264
264
  end
265
265
  end
266
266
 
@@ -283,17 +283,17 @@ describe Sequel::Model, "rcte_tree with composite keys" do
283
283
 
284
284
  it "should use the correct SQL for lazy associations" do
285
285
  @c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
286
- @o.parent_dataset.sql.should == 'SELECT * FROM nodes WHERE ((nodes.id = 1) AND (nodes.id2 = 6)) LIMIT 1'
287
- @o.children_dataset.sql.should == 'SELECT * FROM nodes WHERE ((nodes.parent_id = 2) AND (nodes.parent_id2 = 5))'
288
- @o.ancestors_dataset.sql.should == 'WITH t AS (SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes'
289
- @o.descendants_dataset.sql.should == 'WITH t AS (SELECT * FROM nodes WHERE ((parent_id = 2) AND (parent_id2 = 5)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes'
286
+ @o.parent_dataset.sql.must_equal 'SELECT * FROM nodes WHERE ((nodes.id = 1) AND (nodes.id2 = 6)) LIMIT 1'
287
+ @o.children_dataset.sql.must_equal 'SELECT * FROM nodes WHERE ((nodes.parent_id = 2) AND (nodes.parent_id2 = 5))'
288
+ @o.ancestors_dataset.sql.must_equal 'WITH t AS (SELECT * FROM nodes WHERE ((id = 1) AND (id2 = 6)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes'
289
+ @o.descendants_dataset.sql.must_equal 'WITH t AS (SELECT * FROM nodes WHERE ((parent_id = 2) AND (parent_id2 = 5)) UNION ALL SELECT nodes.* FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes'
290
290
  end
291
291
 
292
292
  it "should use the correct SQL for lazy associations when recursive CTEs require column aliases" do
293
293
  @c.dataset.meta_def(:recursive_cte_requires_column_aliases?){true}
294
294
  @c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
295
- @o.ancestors_dataset.sql.should == 'WITH t(id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id, id2, name, parent_id, parent_id2, i, pi FROM nodes WHERE ((id = 1) AND (id2 = 6)) UNION ALL SELECT nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes'
296
- @o.descendants_dataset.sql.should == 'WITH t(id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id, id2, name, parent_id, parent_id2, i, pi FROM nodes WHERE ((parent_id = 2) AND (parent_id2 = 5)) UNION ALL SELECT nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes'
295
+ @o.ancestors_dataset.sql.must_equal 'WITH t(id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id, id2, name, parent_id, parent_id2, i, pi FROM nodes WHERE ((id = 1) AND (id2 = 6)) UNION ALL SELECT nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes'
296
+ @o.descendants_dataset.sql.must_equal 'WITH t(id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id, id2, name, parent_id, parent_id2, i, pi FROM nodes WHERE ((parent_id = 2) AND (parent_id2 = 5)) UNION ALL SELECT nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes'
297
297
  end
298
298
 
299
299
  it "should use the correct SQL for eager loading when recursive CTEs require column aliases" do
@@ -301,31 +301,31 @@ describe Sequel::Model, "rcte_tree with composite keys" do
301
301
  @c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
302
302
  @ds._fetch = [[{:id=>1, :id2=>2, :name=>'A', :parent_id=>3, :parent_id2=>4}]]
303
303
  @c.eager(:ancestors).all
304
- @db.sqls.should == ["SELECT * FROM nodes", "WITH t(x_root_x_0, x_root_x_1, id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id AS x_root_x_0, id2 AS x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes WHERE ((id, id2) IN ((3, 4))) UNION ALL SELECT t.x_root_x_0, t.x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes"]
304
+ @db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x_0, x_root_x_1, id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT id AS x_root_x_0, id2 AS x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes WHERE ((id, id2) IN ((3, 4))) UNION ALL SELECT t.x_root_x_0, t.x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.parent_id = nodes.id) AND (t.parent_id2 = nodes.id2))) SELECT * FROM t AS nodes"]
305
305
 
306
306
  @ds._fetch = [[{:id=>1, :id2=>2, :name=>'A', :parent_id=>3, :parent_id2=>4}]]
307
307
  @c.eager(:descendants).all
308
- @db.sqls.should == ["SELECT * FROM nodes", "WITH t(x_root_x_0, x_root_x_1, id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT parent_id AS x_root_x_0, parent_id2 AS x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes WHERE ((parent_id, parent_id2) IN ((1, 2))) UNION ALL SELECT t.x_root_x_0, t.x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes"]
308
+ @db.sqls.must_equal ["SELECT * FROM nodes", "WITH t(x_root_x_0, x_root_x_1, id, id2, name, parent_id, parent_id2, i, pi) AS (SELECT parent_id AS x_root_x_0, parent_id2 AS x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes WHERE ((parent_id, parent_id2) IN ((1, 2))) UNION ALL SELECT t.x_root_x_0, t.x_root_x_1, nodes.id, nodes.id2, nodes.name, nodes.parent_id, nodes.parent_id2, nodes.i, nodes.pi FROM nodes INNER JOIN t ON ((t.id = nodes.parent_id) AND (t.id2 = nodes.parent_id2))) SELECT * FROM t AS nodes"]
309
309
  end
310
310
 
311
311
  it "should add all parent associations when lazily loading ancestors" do
312
312
  @c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
313
313
  @ds._fetch = [[{:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5}, {:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil}, {:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8}]]
314
- @o.ancestors.should == [@c.load(:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5), @c.load(:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil), @c.load(:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8)]
315
- @o.associations[:parent].should == @c.load(:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5)
316
- @o.associations[:parent].associations[:parent].should == @c.load(:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8)
317
- @o.associations[:parent].associations[:parent].associations[:parent].should == @c.load(:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil)
318
- @o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).should == nil
314
+ @o.ancestors.must_equal [@c.load(:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5), @c.load(:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil), @c.load(:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8)]
315
+ @o.associations[:parent].must_equal @c.load(:id=>1, :id2=>6, :name=>'A', :parent_id=>3, :parent_id2=>5)
316
+ @o.associations[:parent].associations[:parent].must_equal @c.load(:id=>3, :id2=>5, :name=>'?', :parent_id=>4, :parent_id2=>8)
317
+ @o.associations[:parent].associations[:parent].associations[:parent].must_equal @c.load(:id=>4, :id2=>8, :name=>'B', :parent_id=>nil, :parent_id2=>nil)
318
+ @o.associations[:parent].associations[:parent].associations[:parent].associations.fetch(:parent, 1).must_equal nil
319
319
  end
320
320
 
321
321
  it "should add all children associations when lazily loading descendants" do
322
322
  @c.plugin :rcte_tree, :key=>[:parent_id, :parent_id2]
323
323
  @ds._fetch = [[{:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2}, {:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5}, {:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5}, {:id=>5, :id2=>7, :name=>'?', :parent_id=>3, :parent_id2=>4}]]
324
- @o.descendants.should == [@c.load(:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2), @c.load(:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5), @c.load(:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5), @c.load(:id=>5, :id2=>7, :name=>'?', :parent_id=>3, :parent_id2=>4)]
325
- @o.associations[:children].should == [@c.load(:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5), @c.load(:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5)]
326
- @o.associations[:children].map{|c1| c1.associations[:children]}.should == [[@c.load(:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2)], []]
327
- @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.should == [[[@c.load(:id=>5, :id2=>7, :name=>'?', :parent_id=>3, :parent_id2=>4)]], []]
328
- @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.should == [[[[]]], []]
324
+ @o.descendants.must_equal [@c.load(:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2), @c.load(:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5), @c.load(:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5), @c.load(:id=>5, :id2=>7, :name=>'?', :parent_id=>3, :parent_id2=>4)]
325
+ @o.associations[:children].must_equal [@c.load(:id=>1, :id2=>2, :name=>'A', :parent_id=>2, :parent_id2=>5), @c.load(:id=>4, :id2=>5, :name=>'B', :parent_id=>2, :parent_id2=>5)]
326
+ @o.associations[:children].map{|c1| c1.associations[:children]}.must_equal [[@c.load(:id=>3, :id2=>4, :name=>'??', :parent_id=>1, :parent_id2=>2)], []]
327
+ @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children]}}.must_equal [[[@c.load(:id=>5, :id2=>7, :name=>'?', :parent_id=>3, :parent_id2=>4)]], []]
328
+ @o.associations[:children].map{|c1| c1.associations[:children].map{|c2| c2.associations[:children].map{|c3| c3.associations[:children]}}}.must_equal [[[[]]], []]
329
329
  end
330
330
 
331
331
  it "should eagerly load ancestors" do
@@ -336,18 +336,18 @@ describe Sequel::Model, "rcte_tree with composite keys" do
336
336
  {:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil, :x_root_x_0=>2, :x_root_x_1=>3}, {:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil, :x_root_x_0=>1, :x_root_x_1=>2}]]
337
337
  os = @ds.eager(:ancestors).all
338
338
  sqls = @db.sqls
339
- sqls.first.should == "SELECT * FROM nodes"
340
- sqls.last.should =~ /WITH t AS \(SELECT id AS x_root_x_0, id2 AS x_root_x_1, nodes\.\* FROM nodes WHERE \(\(id, id2\) IN \(\([12], [23]\), \([12], [23]\)\)\) UNION ALL SELECT t\.x_root_x_0, t\.x_root_x_1, nodes\.\* FROM nodes INNER JOIN t ON \(\(t\.parent_id = nodes\.id\) AND \(t\.parent_id2 = nodes\.id2\)\)\) SELECT \* FROM t AS nodes/
341
- os.should == [@c.load(:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'), @c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D'), @c.load(:id=>9, :id2=>10, :parent_id=>nil, :parent_id2=>nil, :name=>'E')]
342
- os.map{|o| o.ancestors}.should == [[@c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil)],
339
+ sqls.first.must_equal "SELECT * FROM nodes"
340
+ sqls.last.must_match(/WITH t AS \(SELECT id AS x_root_x_0, id2 AS x_root_x_1, nodes\.\* FROM nodes WHERE \(\(id, id2\) IN \(\([12], [23]\), \([12], [23]\)\)\) UNION ALL SELECT t\.x_root_x_0, t\.x_root_x_1, nodes\.\* FROM nodes INNER JOIN t ON \(\(t\.parent_id = nodes\.id\) AND \(t\.parent_id2 = nodes\.id2\)\)\) SELECT \* FROM t AS nodes/)
341
+ os.must_equal [@c.load(:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'), @c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D'), @c.load(:id=>9, :id2=>10, :parent_id=>nil, :parent_id2=>nil, :name=>'E')]
342
+ os.map{|o| o.ancestors}.must_equal [[@c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil)],
343
343
  [@c.load(:id=>2, :id2=>3, :name=>'AA', :parent_id=>1, :parent_id2=>2), @c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil)],
344
344
  [@c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil)],
345
345
  []]
346
- os.map{|o| o.parent}.should == [@c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>2, :id2=>3, :name=>'AA', :parent_id=>1, :parent_id2=>2), @c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), nil]
347
- os.map{|o| o.parent.parent if o.parent}.should == [@c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil), @c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil), nil]
348
- os.map{|o| o.parent.parent.parent if o.parent and o.parent.parent}.should == [nil, @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil), nil, nil]
349
- os.map{|o| o.parent.parent.parent.parent if o.parent and o.parent.parent and o.parent.parent.parent}.should == [nil, nil, nil, nil]
350
- @db.sqls.should == []
346
+ os.map{|o| o.parent}.must_equal [@c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>2, :id2=>3, :name=>'AA', :parent_id=>1, :parent_id2=>2), @c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), nil]
347
+ os.map{|o| o.parent.parent if o.parent}.must_equal [@c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil), @c.load(:id=>1, :id2=>2, :name=>'00', :parent_id=>8, :parent_id2=>9), @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil), nil]
348
+ os.map{|o| o.parent.parent.parent if o.parent and o.parent.parent}.must_equal [nil, @c.load(:id=>8, :id2=>9, :name=>'?', :parent_id=>nil, :parent_id2=>nil), nil, nil]
349
+ os.map{|o| o.parent.parent.parent.parent if o.parent and o.parent.parent and o.parent.parent.parent}.must_equal [nil, nil, nil, nil]
350
+ @db.sqls.must_equal []
351
351
  end
352
352
 
353
353
  it "should eagerly load descendants" do
@@ -358,16 +358,16 @@ describe Sequel::Model, "rcte_tree with composite keys" do
358
358
  {:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8, :x_root_x_0=>7, :x_root_x_1=>8}, {:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5, :x_root_x_0=>7, :x_root_x_1=>8}]]
359
359
  os = @ds.eager(:descendants).all
360
360
  sqls = @db.sqls
361
- sqls.first.should == "SELECT * FROM nodes"
362
- sqls.last.should =~ /WITH t AS \(SELECT parent_id AS x_root_x_0, parent_id2 AS x_root_x_1, nodes\.\* FROM nodes WHERE \(\(parent_id, parent_id2\) IN \(\([267], [378]\), \([267], [378]\), \([267], [378]\)\)\) UNION ALL SELECT t\.x_root_x_0, t\.x_root_x_1, nodes\.\* FROM nodes INNER JOIN t ON \(\(t\.id = nodes\.parent_id\) AND \(t\.id2 = nodes\.parent_id2\)\)\) SELECT \* FROM t AS nodes/
363
- os.should == [@c.load(:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'), @c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D')]
364
- os.map{|o| o.descendants}.should == [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E'), @c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)],
361
+ sqls.first.must_equal "SELECT * FROM nodes"
362
+ sqls.last.must_match(/WITH t AS \(SELECT parent_id AS x_root_x_0, parent_id2 AS x_root_x_1, nodes\.\* FROM nodes WHERE \(\(parent_id, parent_id2\) IN \(\([267], [378]\), \([267], [378]\), \([267], [378]\)\)\) UNION ALL SELECT t\.x_root_x_0, t\.x_root_x_1, nodes\.\* FROM nodes INNER JOIN t ON \(\(t\.id = nodes\.parent_id\) AND \(t\.id2 = nodes\.parent_id2\)\)\) SELECT \* FROM t AS nodes/)
363
+ os.must_equal [@c.load(:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'), @c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D')]
364
+ os.map{|o| o.descendants}.must_equal [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E'), @c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)],
365
365
  [@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)],
366
366
  [@c.load(:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8), @c.load(:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5)]]
367
- os.map{|o| o.children}.should == [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E')], [@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], [@c.load(:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8)]]
368
- os.map{|o1| o1.children.map{|o2| o2.children}}.should == [[[@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], []], [[]], [[@c.load(:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5)]]]
369
- os.map{|o1| o1.children.map{|o2| o2.children.map{|o3| o3.children}}}.should == [[[[]], []], [[]], [[[]]]]
370
- @db.sqls.should == []
367
+ os.map{|o| o.children}.must_equal [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E')], [@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], [@c.load(:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8)]]
368
+ os.map{|o1| o1.children.map{|o2| o2.children}}.must_equal [[[@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], []], [[]], [[@c.load(:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5)]]]
369
+ os.map{|o1| o1.children.map{|o2| o2.children.map{|o3| o3.children}}}.must_equal [[[[]], []], [[]], [[[]]]]
370
+ @db.sqls.must_equal []
371
371
  end
372
372
 
373
373
  it "should eagerly load descendants to a given level" do
@@ -378,15 +378,15 @@ describe Sequel::Model, "rcte_tree with composite keys" do
378
378
  {:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8, :x_root_x_0=>7, :x_root_x_1=>8, :x_level_x=>0}, {:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5, :x_root_x_0=>7, :x_root_x_1=>8, :x_level_x=>1}]]
379
379
  os = @ds.eager(:descendants=>2).all
380
380
  sqls = @db.sqls
381
- sqls.first.should == "SELECT * FROM nodes"
382
- sqls.last.should =~ /WITH t AS \(SELECT parent_id AS x_root_x_0, parent_id2 AS x_root_x_1, nodes\.\*, CAST\(0 AS integer\) AS x_level_x FROM nodes WHERE \(\(parent_id, parent_id2\) IN \(\([267], [378]\), \([267], [378]\), \([267], [378]\)\)\) UNION ALL SELECT t\.x_root_x_0, t\.x_root_x_1, nodes\.\*, \(t\.x_level_x \+ 1\) AS x_level_x FROM nodes INNER JOIN t ON \(\(t\.id = nodes\.parent_id\) AND \(t\.id2 = nodes\.parent_id2\)\) WHERE \(t\.x_level_x < 1\)\) SELECT \* FROM t AS nodes/
383
- os.should == [@c.load(:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'), @c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D')]
384
- os.map{|o| o.descendants}.should == [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E'), @c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)],
381
+ sqls.first.must_equal "SELECT * FROM nodes"
382
+ sqls.last.must_match(/WITH t AS \(SELECT parent_id AS x_root_x_0, parent_id2 AS x_root_x_1, nodes\.\*, CAST\(0 AS integer\) AS x_level_x FROM nodes WHERE \(\(parent_id, parent_id2\) IN \(\([267], [378]\), \([267], [378]\), \([267], [378]\)\)\) UNION ALL SELECT t\.x_root_x_0, t\.x_root_x_1, nodes\.\*, \(t\.x_level_x \+ 1\) AS x_level_x FROM nodes INNER JOIN t ON \(\(t\.id = nodes\.parent_id\) AND \(t\.id2 = nodes\.parent_id2\)\) WHERE \(t\.x_level_x < 1\)\) SELECT \* FROM t AS nodes/)
383
+ os.must_equal [@c.load(:id=>2, :id2=>3, :parent_id=>1, :parent_id2=>2, :name=>'AA'), @c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>7, :id2=>8, :parent_id=>1, :parent_id2=>2, :name=>'D')]
384
+ os.map{|o| o.descendants}.must_equal [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E'), @c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)],
385
385
  [@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)],
386
386
  [@c.load(:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8), @c.load(:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5)]]
387
- os.map{|o| o.associations[:children]}.should == [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E')], [@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], [@c.load(:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8)]]
388
- os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children]}}.should == [[[@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], []], [[]], [[@c.load(:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5)]]]
389
- os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children].map{|o3| o3.associations[:children]}}}.should == [[[[]], []], [[]], [[nil]]]
390
- @db.sqls.should == []
387
+ os.map{|o| o.associations[:children]}.must_equal [[@c.load(:id=>6, :id2=>7, :parent_id=>2, :parent_id2=>3, :name=>'C'), @c.load(:id=>9, :id2=>10, :parent_id=>2, :parent_id2=>3, :name=>'E')], [@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], [@c.load(:id=>4, :id2=>5, :name=>'?', :parent_id=>7, :parent_id2=>8)]]
388
+ os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children]}}.must_equal [[[@c.load(:id=>3, :id2=>4, :name=>'00', :parent_id=>6, :parent_id2=>7)], []], [[]], [[@c.load(:id=>5, :id2=>6, :name=>'?', :parent_id=>4, :parent_id2=>5)]]]
389
+ os.map{|o1| o1.associations[:children].map{|o2| o2.associations[:children].map{|o3| o3.associations[:children]}}}.must_equal [[[[]], []], [[]], [[nil]]]
390
+ @db.sqls.must_equal []
391
391
  end
392
392
  end