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
@@ -11,37 +11,42 @@ describe "column_conflicts plugin" do
11
11
 
12
12
  it "should have mass assignment work correctly" do
13
13
  @o.set_fields({:use_transactions=>3}, [:use_transactions])
14
- @o.get_column_value(:use_transactions).should == 3
14
+ @o.get_column_value(:use_transactions).must_equal 3
15
15
  end
16
16
 
17
17
  it "should handle both symbols and strings" do
18
- @o.get_column_value(:model).should == 1
19
- @o.get_column_value("model").should == 1
18
+ @o.get_column_value(:model).must_equal 1
19
+ @o.get_column_value("model").must_equal 1
20
20
  @o.set_column_value(:use_transactions=, 3)
21
- @o.get_column_value(:use_transactions).should == 3
21
+ @o.get_column_value(:use_transactions).must_equal 3
22
22
  @o.set_column_value(:use_transactions=, 4)
23
- @o.get_column_value(:use_transactions).should == 4
23
+ @o.get_column_value(:use_transactions).must_equal 4
24
+ end
25
+
26
+ it "should work correctly if there are no conflicts" do
27
+ @o.get_column_value(:foo).must_equal 4
28
+ @o.set_column_value(:model=, 2).must_equal 2
24
29
  end
25
30
 
26
31
  it "should allow manual setting of conflicted columns" do
27
32
  @c.send(:define_method, :foo){raise}
28
33
  @c.get_column_conflict!(:foo)
29
- @o.get_column_value(:foo).should == 4
34
+ @o.get_column_value(:foo).must_equal 4
30
35
 
31
36
  @c.send(:define_method, :model=){raise}
32
37
  @c.set_column_conflict!(:model)
33
- @o.set_column_value(:model=, 2).should == 2
34
- @o.get_column_value(:model).should == 2
38
+ @o.set_column_value(:model=, 2).must_equal 2
39
+ @o.get_column_value(:model).must_equal 2
35
40
  end
36
41
 
37
42
  it "should work correctly in subclasses" do
38
43
  @o = Class.new(@c).load(:model=>1, :use_transactions=>2)
39
- @o.get_column_value(:model).should == 1
40
- @o.get_column_value("model").should == 1
44
+ @o.get_column_value(:model).must_equal 1
45
+ @o.get_column_value("model").must_equal 1
41
46
  @o.set_column_value(:use_transactions=, 3)
42
- @o.get_column_value(:use_transactions).should == 3
47
+ @o.get_column_value(:use_transactions).must_equal 3
43
48
  @o.set_column_value(:use_transactions=, 4)
44
- @o.get_column_value(:use_transactions).should == 4
49
+ @o.get_column_value(:use_transactions).must_equal 4
45
50
  end
46
51
 
47
52
  it "should work correctly for dataset changes" do
@@ -49,7 +54,7 @@ describe "column_conflicts plugin" do
49
54
  def ds.columns; [:object_id] end
50
55
  @c.dataset = ds
51
56
  o = @c.load(:object_id=>3)
52
- o.get_column_value(:object_id).should == 3
53
- o.object_id.should_not == 3
57
+ o.get_column_value(:object_id).must_equal 3
58
+ o.object_id.wont_equal 3
54
59
  end
55
60
  end
@@ -15,71 +15,71 @@ describe "Sequel::Plugins::ColumnSelect" do
15
15
 
16
16
  it "should add a explicit column selections to existing dataset without explicit selection" do
17
17
  @Album.plugin :column_select
18
- @Album.dataset.sql.should == 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
18
+ @Album.dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
19
19
 
20
20
  @Album.dataset = :albs
21
- @Album.dataset.sql.should == 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
21
+ @Album.dataset.sql.must_equal 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
22
22
 
23
23
  @Album.dataset = Sequel.identifier(:albs)
24
- @Album.dataset.sql.should == 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
24
+ @Album.dataset.sql.must_equal 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
25
25
  end
26
26
 
27
27
  it "should handle qualified tables" do
28
28
  @Album.dataset = :s__albums
29
29
  @Album.plugin :column_select
30
- @Album.dataset.sql.should == 'SELECT s.albums.id, s.albums.a, s.albums.b, s.albums.c FROM s.albums'
30
+ @Album.dataset.sql.must_equal 'SELECT s.albums.id, s.albums.a, s.albums.b, s.albums.c FROM s.albums'
31
31
 
32
32
  @Album.dataset = Sequel.qualify(:s2, :albums)
33
- @Album.dataset.sql.should == 'SELECT s2.albums.id, s2.albums.a, s2.albums.b, s2.albums.c FROM s2.albums'
33
+ @Album.dataset.sql.must_equal 'SELECT s2.albums.id, s2.albums.a, s2.albums.b, s2.albums.c FROM s2.albums'
34
34
  end
35
35
 
36
36
  it "should handle aliases" do
37
37
  @Album.dataset = :albums___a
38
38
  @Album.plugin :column_select
39
- @Album.dataset.sql.should == 'SELECT a.id, a.a, a.b, a.c FROM albums AS a'
39
+ @Album.dataset.sql.must_equal 'SELECT a.id, a.a, a.b, a.c FROM albums AS a'
40
40
 
41
41
  @Album.dataset = Sequel.as(:albums, :b)
42
- @Album.dataset.sql.should == 'SELECT b.id, b.a, b.b, b.c FROM albums AS b'
42
+ @Album.dataset.sql.must_equal 'SELECT b.id, b.a, b.b, b.c FROM albums AS b'
43
43
 
44
44
  @Album.dataset = :s__albums___a
45
- @Album.dataset.sql.should == 'SELECT a.id, a.a, a.b, a.c FROM s.albums AS a'
45
+ @Album.dataset.sql.must_equal 'SELECT a.id, a.a, a.b, a.c FROM s.albums AS a'
46
46
 
47
47
  @Album.dataset = @Album.db[:albums].from_self
48
- @Album.dataset.sql.should == 'SELECT t1.id, t1.a, t1.b, t1.c FROM (SELECT * FROM albums) AS t1'
48
+ @Album.dataset.sql.must_equal 'SELECT t1.id, t1.a, t1.b, t1.c FROM (SELECT * FROM albums) AS t1'
49
49
 
50
50
  @Album.dataset = Sequel.as(@Album.db[:albums], :b)
51
- @Album.dataset.sql.should == 'SELECT b.id, b.a, b.b, b.c FROM (SELECT * FROM albums) AS b'
51
+ @Album.dataset.sql.must_equal 'SELECT b.id, b.a, b.b, b.c FROM (SELECT * FROM albums) AS b'
52
52
  end
53
53
 
54
54
  it "should not add a explicit column selection selection on existing dataset with explicit selection" do
55
55
  @Album.dataset = @Album.dataset.select(:name)
56
56
  @Album.plugin :column_select
57
- @Album.dataset.sql.should == 'SELECT name FROM albums'
57
+ @Album.dataset.sql.must_equal 'SELECT name FROM albums'
58
58
 
59
59
  @Album.dataset = @Album.dataset.select(:name, :artist)
60
- @Album.dataset.sql.should == 'SELECT name, artist FROM albums'
60
+ @Album.dataset.sql.must_equal 'SELECT name, artist FROM albums'
61
61
  end
62
62
 
63
63
  it "should not add a explicit column selection on existing dataset with multiple tables" do
64
64
  @Album.dataset = @Album.db.from(:a1, :a2)
65
65
  @Album.plugin :column_select
66
- @Album.dataset.sql.should == 'SELECT * FROM a1, a2'
66
+ @Album.dataset.sql.must_equal 'SELECT * FROM a1, a2'
67
67
 
68
68
  @Album.dataset = @Album.db.from(:a1).cross_join(:a2)
69
- @Album.dataset.sql.should == 'SELECT * FROM a1 CROSS JOIN a2'
69
+ @Album.dataset.sql.must_equal 'SELECT * FROM a1 CROSS JOIN a2'
70
70
  end
71
71
 
72
72
  it "should use explicit column selection for many_to_many associations" do
73
73
  @Album.plugin :column_select
74
74
  @Album.many_to_many :albums, :class=>@Album, :left_key=>:l, :right_key=>:r, :join_table=>:j
75
- @Album.load(:id=>1).albums_dataset.sql.should == 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
75
+ @Album.load(:id=>1).albums_dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
76
76
  end
77
77
 
78
78
  it "should set not explicit column selection for many_to_many associations when overriding select" do
79
79
  @Album.plugin :column_select
80
80
  @Album.dataset = @Album.dataset.select(:a)
81
81
  @Album.many_to_many :albums, :class=>@Album, :left_key=>:l, :right_key=>:r, :join_table=>:j
82
- @Album.load(:id=>1).albums_dataset.sql.should == 'SELECT albums.* FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
82
+ @Album.load(:id=>1).albums_dataset.sql.must_equal 'SELECT albums.* FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
83
83
  end
84
84
 
85
85
  it "should use the schema to get columns if available" do
@@ -88,14 +88,14 @@ describe "Sequel::Plugins::ColumnSelect" do
88
88
  [[:t, {}], [:d, {}]]
89
89
  end
90
90
  @Album.plugin :column_select
91
- @Album.dataset.sql.should == 'SELECT albums.t, albums.d FROM albums'
91
+ @Album.dataset.sql.must_equal 'SELECT albums.t, albums.d FROM albums'
92
92
  end
93
93
 
94
94
  it "should handle case where schema parsing does not produce results" do
95
95
  def @db.supports_schema_parsing?() true end
96
96
  def @db.schema_parse_table(t, *) [] end
97
97
  @Album.plugin :column_select
98
- @Album.dataset.sql.should == 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
98
+ @Album.dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
99
99
  end
100
100
 
101
101
  it "works correctly when loaded on model without a dataset" do
@@ -103,6 +103,6 @@ describe "Sequel::Plugins::ColumnSelect" do
103
103
  c.plugin :column_select
104
104
  sc = Class.new(c)
105
105
  sc.dataset = @db[:a]
106
- sc.dataset.sql.should == "SELECT a.id, a.a, a.b, a.c FROM a"
106
+ sc.dataset.sql.must_equal "SELECT a.id, a.a, a.b, a.c FROM a"
107
107
  end
108
108
  end
@@ -9,83 +9,83 @@ describe "columns_introspection extension" do
9
9
  @db.sqls
10
10
  end
11
11
 
12
- specify "should not issue a database query if the columns are already loaded" do
12
+ it "should not issue a database query if the columns are already loaded" do
13
13
  @ds.instance_variable_set(:@columns, [:x])
14
- @ds.columns.should == [:x]
15
- @db.sqls.length.should == 0
14
+ @ds.columns.must_equal [:x]
15
+ @db.sqls.length.must_equal 0
16
16
  end
17
17
 
18
- specify "should handle plain symbols without a database query" do
19
- @ds.select(:x).columns.should == [:x]
20
- @db.sqls.length.should == 0
18
+ it "should handle plain symbols without a database query" do
19
+ @ds.select(:x).columns.must_equal [:x]
20
+ @db.sqls.length.must_equal 0
21
21
  end
22
22
 
23
- specify "should handle qualified symbols without a database query" do
24
- @ds.select(:t__x).columns.should == [:x]
25
- @db.sqls.length.should == 0
23
+ it "should handle qualified symbols without a database query" do
24
+ @ds.select(:t__x).columns.must_equal [:x]
25
+ @db.sqls.length.must_equal 0
26
26
  end
27
27
 
28
- specify "should handle aliased symbols without a database query" do
29
- @ds.select(:x___a).columns.should == [:a]
30
- @db.sqls.length.should == 0
28
+ it "should handle aliased symbols without a database query" do
29
+ @ds.select(:x___a).columns.must_equal [:a]
30
+ @db.sqls.length.must_equal 0
31
31
  end
32
32
 
33
- specify "should handle qualified and aliased symbols without a database query" do
34
- @ds.select(:t__x___a).columns.should == [:a]
35
- @db.sqls.length.should == 0
33
+ it "should handle qualified and aliased symbols without a database query" do
34
+ @ds.select(:t__x___a).columns.must_equal [:a]
35
+ @db.sqls.length.must_equal 0
36
36
  end
37
37
 
38
- specify "should handle SQL::Identifiers " do
39
- @ds.select(Sequel.identifier(:x)).columns.should == [:x]
40
- @db.sqls.length.should == 0
38
+ it "should handle SQL::Identifiers " do
39
+ @ds.select(Sequel.identifier(:x)).columns.must_equal [:x]
40
+ @db.sqls.length.must_equal 0
41
41
  end
42
42
 
43
- specify "should handle SQL::QualifiedIdentifiers" do
44
- @ds.select(Sequel.qualify(:t, :x)).columns.should == [:x]
45
- @ds.select(Sequel.identifier(:x).qualify(:t)).columns.should == [:x]
46
- @db.sqls.length.should == 0
43
+ it "should handle SQL::QualifiedIdentifiers" do
44
+ @ds.select(Sequel.qualify(:t, :x)).columns.must_equal [:x]
45
+ @ds.select(Sequel.identifier(:x).qualify(:t)).columns.must_equal [:x]
46
+ @db.sqls.length.must_equal 0
47
47
  end
48
48
 
49
- specify "should handle SQL::AliasedExpressions" do
50
- @ds.select(Sequel.as(:x, :a)).columns.should == [:a]
51
- @ds.select(Sequel.as(:x, Sequel.identifier(:a))).columns.should == [:a]
52
- @db.sqls.length.should == 0
49
+ it "should handle SQL::AliasedExpressions" do
50
+ @ds.select(Sequel.as(:x, :a)).columns.must_equal [:a]
51
+ @ds.select(Sequel.as(:x, Sequel.identifier(:a))).columns.must_equal [:a]
52
+ @db.sqls.length.must_equal 0
53
53
  end
54
54
 
55
- specify "should handle selecting * from a single subselect with no joins without a database query if the subselect's columns can be handled" do
56
- @ds.select(:x).from_self.columns.should == [:x]
57
- @db.sqls.length.should == 0
58
- @ds.select(:x).from_self.from_self.columns.should == [:x]
59
- @db.sqls.length.should == 0
55
+ it "should handle selecting * from a single subselect with no joins without a database query if the subselect's columns can be handled" do
56
+ @ds.select(:x).from_self.columns.must_equal [:x]
57
+ @db.sqls.length.must_equal 0
58
+ @ds.select(:x).from_self.from_self.columns.must_equal [:x]
59
+ @db.sqls.length.must_equal 0
60
60
  end
61
61
 
62
- specify "should handle selecting * from a single table with no joins without a database query if the database has cached schema columns for the table" do
62
+ it "should handle selecting * from a single table with no joins without a database query if the database has cached schema columns for the table" do
63
63
  @db.instance_variable_set(:@schemas, "a"=>[[:x, {}]])
64
- @ds.columns.should == [:x]
65
- @db.sqls.length.should == 0
64
+ @ds.columns.must_equal [:x]
65
+ @db.sqls.length.must_equal 0
66
66
  end
67
67
 
68
- specify "should issue a database query for multiple subselects or joins" do
68
+ it "should issue a database query for multiple subselects or joins" do
69
69
  @ds.from(@ds.select(:x), @ds.select(:y)).columns
70
- @db.sqls.length.should == 1
70
+ @db.sqls.length.must_equal 1
71
71
  @ds.select(:x).from_self.natural_join(:a).columns
72
- @db.sqls.length.should == 1
72
+ @db.sqls.length.must_equal 1
73
73
  end
74
74
 
75
- specify "should issue a database query when common table expressions are used" do
75
+ it "should issue a database query when common table expressions are used" do
76
76
  @db.instance_variable_set(:@schemas, "a"=>[[:x, {}]])
77
77
  def @ds.supports_cte?(*) true end
78
78
  @ds.with(:a, @ds).columns
79
- @db.sqls.length.should == 1
79
+ @db.sqls.length.must_equal 1
80
80
  end
81
81
 
82
- specify "should issue a database query if the wildcard is selected" do
82
+ it "should issue a database query if the wildcard is selected" do
83
83
  @ds.columns
84
- @db.sqls.length.should == 1
84
+ @db.sqls.length.must_equal 1
85
85
  end
86
86
 
87
- specify "should issue a database query if an unsupported type is used" do
87
+ it "should issue a database query if an unsupported type is used" do
88
88
  @ds.select(1).columns
89
- @db.sqls.length.should == 1
89
+ @db.sqls.length.must_equal 1
90
90
  end
91
91
  end
@@ -10,21 +10,21 @@ describe "Composition plugin" do
10
10
  end
11
11
 
12
12
  it ".composition should add compositions" do
13
- @o.should_not respond_to(:date)
13
+ @o.wont_respond_to(:date)
14
14
  @c.composition :date, :mapping=>[:year, :month, :day]
15
- @o.date.should == Date.new(1, 2, 3)
15
+ @o.date.must_equal Date.new(1, 2, 3)
16
16
  end
17
17
 
18
18
  it "loading the plugin twice should not remove existing compositions" do
19
19
  @c.composition :date, :mapping=>[:year, :month, :day]
20
20
  @c.plugin :composition
21
- @c.compositions.keys.should == [:date]
21
+ @c.compositions.keys.must_equal [:date]
22
22
  end
23
23
 
24
24
  it ".composition should raise an error if :composer and :decomposer options are not present and :mapping option is not provided" do
25
- proc{@c.composition :date}.should raise_error(Sequel::Error)
26
- proc{@c.composition :date, :composer=>proc{}, :decomposer=>proc{}}.should_not raise_error
27
- proc{@c.composition :date, :mapping=>[]}.should_not raise_error
25
+ proc{@c.composition :date}.must_raise(Sequel::Error)
26
+ @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
27
+ @c.composition :date, :mapping=>[]
28
28
  end
29
29
 
30
30
  it "should handle validations of underlying columns" do
@@ -33,45 +33,45 @@ describe "Composition plugin" do
33
33
  def o.validate
34
34
  [:year, :month, :day].each{|c| errors.add(c, "not present") unless send(c)}
35
35
  end
36
- o.valid?.should == false
36
+ o.valid?.must_equal false
37
37
  o.date = Date.new(1, 2, 3)
38
- o.valid?.should == true
38
+ o.valid?.must_equal true
39
39
  end
40
40
 
41
41
  it "should set column values even when not validating" do
42
42
  @c.composition :date, :mapping=>[:year, :month, :day]
43
43
  @c.load({}).set(:date=>Date.new(4, 8, 12)).save(:validate=>false)
44
44
  sql = DB.sqls.last
45
- sql.should include("year = 4")
46
- sql.should include("month = 8")
47
- sql.should include("day = 12")
45
+ sql.must_include("year = 4")
46
+ sql.must_include("month = 8")
47
+ sql.must_include("day = 12")
48
48
  end
49
49
 
50
50
  it ".compositions should return the reflection hash of compositions" do
51
- @c.compositions.should == {}
51
+ @c.compositions.must_equal({})
52
52
  @c.composition :date, :mapping=>[:year, :month, :day]
53
- @c.compositions.keys.should == [:date]
53
+ @c.compositions.keys.must_equal [:date]
54
54
  r = @c.compositions.values.first
55
- r[:mapping].should == [:year, :month, :day]
56
- r[:composer].should be_a_kind_of(Proc)
57
- r[:decomposer].should be_a_kind_of(Proc)
55
+ r[:mapping].must_equal [:year, :month, :day]
56
+ r[:composer].must_be_kind_of Proc
57
+ r[:decomposer].must_be_kind_of Proc
58
58
  end
59
59
 
60
60
  it "#compositions should be a hash of cached values of compositions" do
61
- @o.compositions.should == {}
61
+ @o.compositions.must_equal({})
62
62
  @c.composition :date, :mapping=>[:year, :month, :day]
63
63
  @o.date
64
- @o.compositions.should == {:date=>Date.new(1, 2, 3)}
64
+ @o.compositions.must_equal(:date=>Date.new(1, 2, 3))
65
65
  end
66
66
 
67
67
  it "should work with custom :composer and :decomposer options" do
68
68
  @c.composition :date, :composer=>proc{Date.new(year+1, month+2, day+3)}, :decomposer=>proc{[:year, :month, :day].each{|s| self.send("#{s}=", date.send(s) * 2)}}
69
- @o.date.should == Date.new(2, 4, 6)
69
+ @o.date.must_equal Date.new(2, 4, 6)
70
70
  @o.save
71
71
  sql = DB.sqls.last
72
- sql.should include("year = 4")
73
- sql.should include("month = 8")
74
- sql.should include("day = 12")
72
+ sql.must_include("year = 4")
73
+ sql.must_include("month = 8")
74
+ sql.must_include("day = 12")
75
75
  end
76
76
 
77
77
  it "should allow call super in composition getter and setter method definition in class" do
@@ -84,75 +84,75 @@ describe "Composition plugin" do
84
84
  super(v - 3)
85
85
  end
86
86
  end
87
- @o.date.should == Date.new(1, 2, 4)
88
- @o.compositions[:date].should == Date.new(1, 2, 3)
87
+ @o.date.must_equal Date.new(1, 2, 4)
88
+ @o.compositions[:date].must_equal Date.new(1, 2, 3)
89
89
  @o.date = Date.new(1, 3, 5)
90
- @o.compositions[:date].should == Date.new(1, 3, 2)
91
- @o.date.should == Date.new(1, 3, 3)
90
+ @o.compositions[:date].must_equal Date.new(1, 3, 2)
91
+ @o.date.must_equal Date.new(1, 3, 3)
92
92
  end
93
93
 
94
94
  it "should mark the object as modified whenever the composition is set" do
95
95
  @c.composition :date, :mapping=>[:year, :month, :day]
96
- @o.modified?.should == false
96
+ @o.modified?.must_equal false
97
97
  @o.date = Date.new(3, 4, 5)
98
- @o.modified?.should == true
98
+ @o.modified?.must_equal true
99
99
  end
100
100
 
101
101
  it "should only decompose existing compositions" do
102
102
  called = false
103
103
  @c.composition :date, :composer=>proc{}, :decomposer=>proc{called = true}
104
- called.should == false
104
+ called.must_equal false
105
105
  @o.save
106
- called.should == false
106
+ called.must_equal false
107
107
  @o.date = Date.new(1,2,3)
108
- called.should == false
108
+ called.must_equal false
109
109
  @o.save_changes
110
- called.should == true
110
+ called.must_equal true
111
111
  end
112
112
 
113
113
  it "should clear compositions cache when refreshing" do
114
114
  @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
115
115
  @o.date = Date.new(3, 4, 5)
116
116
  @o.refresh
117
- @o.compositions.should == {}
117
+ @o.compositions.must_equal({})
118
118
  end
119
119
 
120
120
  it "should not clear compositions cache when refreshing after save" do
121
121
  @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
122
- @c.create(:date=>Date.new(3, 4, 5)).compositions.should == {:date=>Date.new(3, 4, 5)}
122
+ @c.create(:date=>Date.new(3, 4, 5)).compositions.must_equal(:date=>Date.new(3, 4, 5))
123
123
  end
124
124
 
125
125
  it "should not clear compositions cache when saving with insert_select" do
126
126
  def (@c.instance_dataset).supports_insert_select?() true end
127
127
  def (@c.instance_dataset).insert_select(*) {:id=>1} end
128
128
  @c.composition :date, :composer=>proc{}, :decomposer=>proc{}
129
- @c.create(:date=>Date.new(3, 4, 5)).compositions.should == {:date=>Date.new(3, 4, 5)}
129
+ @c.create(:date=>Date.new(3, 4, 5)).compositions.must_equal(:date=>Date.new(3, 4, 5))
130
130
  end
131
131
 
132
132
  it "should instantiate compositions lazily" do
133
133
  @c.composition :date, :mapping=>[:year, :month, :day]
134
- @o.compositions.should == {}
134
+ @o.compositions.must_equal({})
135
135
  @o.date
136
- @o.compositions.should == {:date=>Date.new(1,2,3)}
136
+ @o.compositions.must_equal(:date=>Date.new(1,2,3))
137
137
  end
138
138
 
139
139
  it "should cache value of composition" do
140
140
  times = 0
141
141
  @c.composition :date, :composer=>proc{times+=1}, :decomposer=>proc{}
142
- times.should == 0
142
+ times.must_equal 0
143
143
  @o.date
144
- times.should == 1
144
+ times.must_equal 1
145
145
  @o.date
146
- times.should == 1
146
+ times.must_equal 1
147
147
  end
148
148
 
149
149
  it ":class option should take an string, symbol, or class" do
150
150
  @c.composition :date1, :class=>'Date', :mapping=>[:year, :month, :day]
151
151
  @c.composition :date2, :class=>:Date, :mapping=>[:year, :month, :day]
152
152
  @c.composition :date3, :class=>Date, :mapping=>[:year, :month, :day]
153
- @o.date1.should == Date.new(1, 2, 3)
154
- @o.date2.should == Date.new(1, 2, 3)
155
- @o.date3.should == Date.new(1, 2, 3)
153
+ @o.date1.must_equal Date.new(1, 2, 3)
154
+ @o.date2.must_equal Date.new(1, 2, 3)
155
+ @o.date3.must_equal Date.new(1, 2, 3)
156
156
  end
157
157
 
158
158
  it ":mapping option should work with a single array of symbols" do
@@ -168,13 +168,13 @@ describe "Composition plugin" do
168
168
  end
169
169
  end
170
170
  @c.composition :date, :class=>c, :mapping=>[:year, :month]
171
- @o.date.year.should == 2
172
- @o.date.month.should == 6
171
+ @o.date.year.must_equal 2
172
+ @o.date.month.must_equal 6
173
173
  @o.date = c.new(3, 4)
174
174
  @o.save
175
175
  sql = DB.sqls.last
176
- sql.should include("year = 6")
177
- sql.should include("month = 12")
176
+ sql.must_include("year = 6")
177
+ sql.must_include("month = 12")
178
178
  end
179
179
 
180
180
  it ":mapping option should work with an array of two pairs of symbols" do
@@ -190,18 +190,18 @@ describe "Composition plugin" do
190
190
  end
191
191
  end
192
192
  @c.composition :date, :class=>c, :mapping=>[[:year, :y], [:month, :m]]
193
- @o.date.y.should == 2
194
- @o.date.m.should == 6
193
+ @o.date.y.must_equal 2
194
+ @o.date.m.must_equal 6
195
195
  @o.date = c.new(3, 4)
196
196
  @o.save
197
197
  sql = DB.sqls.last
198
- sql.should include("year = 6")
199
- sql.should include("month = 12")
198
+ sql.must_include("year = 6")
199
+ sql.must_include("month = 12")
200
200
  end
201
201
 
202
202
  it ":mapping option :composer should return nil if all values are nil" do
203
203
  @c.composition :date, :mapping=>[:year, :month, :day]
204
- @c.new.date.should == nil
204
+ @c.new.date.must_equal nil
205
205
  end
206
206
 
207
207
  it ":mapping option :decomposer should set all related fields to nil if nil" do
@@ -209,34 +209,34 @@ describe "Composition plugin" do
209
209
  @o.date = nil
210
210
  @o.save
211
211
  sql = DB.sqls.last
212
- sql.should include("year = NULL")
213
- sql.should include("month = NULL")
214
- sql.should include("day = NULL")
212
+ sql.must_include("year = NULL")
213
+ sql.must_include("month = NULL")
214
+ sql.must_include("day = NULL")
215
215
  end
216
216
 
217
217
  it "should work with frozen instances" do
218
218
  @c.composition :date, :mapping=>[:year, :month, :day]
219
219
  @o.freeze
220
- @o.date.should == Date.new(1, 2, 3)
221
- proc{@o.date = Date.today}.should raise_error
220
+ @o.date.must_equal Date.new(1, 2, 3)
221
+ proc{@o.date = Date.today}.must_raise
222
222
  end
223
223
 
224
224
  it "should have #dup duplicate compositions" do
225
225
  @c.composition :date, :mapping=>[:year, :month, :day]
226
- @o.date.should == Date.new(1, 2, 3)
227
- @o.dup.compositions.should == @o.compositions
228
- @o.dup.compositions.should_not equal(@o.compositions)
226
+ @o.date.must_equal Date.new(1, 2, 3)
227
+ @o.dup.compositions.must_equal @o.compositions
228
+ @o.dup.compositions.wont_be_same_as(@o.compositions)
229
229
  end
230
230
 
231
231
  it "should work correctly with subclasses" do
232
232
  @c.composition :date, :mapping=>[:year, :month, :day]
233
233
  c = Class.new(@c)
234
234
  o = c.load(:id=>1, :year=>1, :month=>2, :day=>3)
235
- o.date.should == Date.new(1, 2, 3)
235
+ o.date.must_equal Date.new(1, 2, 3)
236
236
  o.save
237
237
  sql = DB.sqls.last
238
- sql.should include("year = 1")
239
- sql.should include("month = 2")
240
- sql.should include("day = 3")
238
+ sql.must_include("year = 1")
239
+ sql.must_include("month = 2")
240
+ sql.must_include("day = 3")
241
241
  end
242
242
  end