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
@@ -7,45 +7,45 @@ describe "dataset_source_alias extension" do
7
7
  end
8
8
 
9
9
  it "should automatically alias datasets to their first source in #from" do
10
- @db[@db[:a]].sql.should == 'SELECT * FROM (SELECT * FROM a) AS a'
11
- @db[:a, @db[:b]].sql.should == 'SELECT * FROM a, (SELECT * FROM b) AS b'
10
+ @db[@db[:a]].sql.must_equal 'SELECT * FROM (SELECT * FROM a) AS a'
11
+ @db[:a, @db[:b]].sql.must_equal 'SELECT * FROM a, (SELECT * FROM b) AS b'
12
12
  end
13
13
 
14
14
  it "should handle virtual row blocks in #from" do
15
- @db.dataset.from{|_| @db[:a]}.sql.should == 'SELECT * FROM (SELECT * FROM a) AS a'
16
- @db.dataset.from(:a){|_| @db[:b]}.sql.should == 'SELECT * FROM a, (SELECT * FROM b) AS b'
15
+ @db.dataset.from{|_| @db[:a]}.sql.must_equal 'SELECT * FROM (SELECT * FROM a) AS a'
16
+ @db.dataset.from(:a){|_| @db[:b]}.sql.must_equal 'SELECT * FROM a, (SELECT * FROM b) AS b'
17
17
  end
18
18
 
19
19
  it "should automatically alias datasets to their first source in #join" do
20
- @db[:a].cross_join(@db[:b]).sql.should == 'SELECT * FROM a CROSS JOIN (SELECT * FROM b) AS b'
20
+ @db[:a].cross_join(@db[:b]).sql.must_equal 'SELECT * FROM a CROSS JOIN (SELECT * FROM b) AS b'
21
21
  end
22
22
 
23
23
  it "should handle :table_alias option when joining" do
24
- @db[:a].cross_join(@db[:b], :table_alias=>:c).sql.should == 'SELECT * FROM a CROSS JOIN (SELECT * FROM b) AS c'
24
+ @db[:a].cross_join(@db[:b], :table_alias=>:c).sql.must_equal 'SELECT * FROM a CROSS JOIN (SELECT * FROM b) AS c'
25
25
  end
26
26
 
27
27
  it "should handle aliasing issues automatically" do
28
- @db[:a, @db[:a]].sql.should == 'SELECT * FROM a, (SELECT * FROM a) AS a_0'
29
- @db.dataset.from(:a, @db[:a]){|_| @db[:a]}.sql.should == 'SELECT * FROM a, (SELECT * FROM a) AS a_0, (SELECT * FROM a) AS a_1'
30
- @db.dataset.from(:a, @db[:a]){|_| @db[:a]}.cross_join(@db[:a]).sql.should == 'SELECT * FROM a, (SELECT * FROM a) AS a_0, (SELECT * FROM a) AS a_1 CROSS JOIN (SELECT * FROM a) AS a_2'
28
+ @db[:a, @db[:a]].sql.must_equal 'SELECT * FROM a, (SELECT * FROM a) AS a_0'
29
+ @db.dataset.from(:a, @db[:a]){|_| @db[:a]}.sql.must_equal 'SELECT * FROM a, (SELECT * FROM a) AS a_0, (SELECT * FROM a) AS a_1'
30
+ @db.dataset.from(:a, @db[:a]){|_| @db[:a]}.cross_join(@db[:a]).sql.must_equal 'SELECT * FROM a, (SELECT * FROM a) AS a_0, (SELECT * FROM a) AS a_1 CROSS JOIN (SELECT * FROM a) AS a_2'
31
31
  end
32
32
 
33
33
  it "should handle from_self" do
34
- @db[:a].from_self.sql.should == 'SELECT * FROM (SELECT * FROM a) AS a'
35
- @db[:a].from_self.from_self.sql.should == 'SELECT * FROM (SELECT * FROM (SELECT * FROM a) AS a) AS a'
34
+ @db[:a].from_self.sql.must_equal 'SELECT * FROM (SELECT * FROM a) AS a'
35
+ @db[:a].from_self.from_self.sql.must_equal 'SELECT * FROM (SELECT * FROM (SELECT * FROM a) AS a) AS a'
36
36
  end
37
37
 
38
38
  it "should handle datasets without sources" do
39
- @db[@db.select(1)].sql.should == 'SELECT * FROM (SELECT 1) AS t1'
40
- @db[:t, @db.select(1)].sql.should == 'SELECT * FROM t, (SELECT 1) AS t1'
41
- @db[:a].cross_join(@db.select(1)).sql.should == 'SELECT * FROM a CROSS JOIN (SELECT 1) AS t1'
39
+ @db[@db.select(1)].sql.must_equal 'SELECT * FROM (SELECT 1) AS t1'
40
+ @db[:t, @db.select(1)].sql.must_equal 'SELECT * FROM t, (SELECT 1) AS t1'
41
+ @db[:a].cross_join(@db.select(1)).sql.must_equal 'SELECT * FROM a CROSS JOIN (SELECT 1) AS t1'
42
42
  end
43
43
 
44
44
  it "should handle datasets selecting from functions" do
45
- @db.dataset.from{|o| @db[o.f(:a)]}.sql.should == 'SELECT * FROM (SELECT * FROM f(a)) AS t1'
45
+ @db.dataset.from{|o| @db[o.f(:a)]}.sql.must_equal 'SELECT * FROM (SELECT * FROM f(a)) AS t1'
46
46
  end
47
47
 
48
48
  it "should handle datasets with literal SQL" do
49
- @db.from(@db['SELECT c FROM d']).sql.should == 'SELECT * FROM (SELECT c FROM d) AS t1'
49
+ @db.from(@db['SELECT c FROM d']).sql.must_equal 'SELECT * FROM (SELECT c FROM d) AS t1'
50
50
  end
51
51
  end
@@ -25,133 +25,126 @@ describe "date_arithmetic extension" do
25
25
 
26
26
  it "should have Sequel.date_add with an interval hash return an appropriate Sequel::SQL::DateAdd expression" do
27
27
  da = Sequel.date_add(:a, :days=>1)
28
- da.should be_a_kind_of(Sequel::SQL::DateAdd)
29
- da.expr.should == :a
30
- da.interval.should == {:days=>1}
31
- Sequel.date_add(:a, :years=>1, :months=>2, :days=>3, :hours=>1, :minutes=>1, :seconds=>1).interval.should == {:years=>1, :months=>2, :days=>3, :hours=>1, :minutes=>1, :seconds=>1}
28
+ da.must_be_kind_of(Sequel::SQL::DateAdd)
29
+ da.expr.must_equal :a
30
+ da.interval.must_equal(:days=>1)
31
+ Sequel.date_add(:a, :years=>1, :months=>2, :days=>3, :hours=>1, :minutes=>1, :seconds=>1).interval.must_equal(:years=>1, :months=>2, :days=>3, :hours=>1, :minutes=>1, :seconds=>1)
32
32
  end
33
33
 
34
34
  it "should have Sequel.date_sub with an interval hash return an appropriate Sequel::SQL::DateAdd expression" do
35
35
  da = Sequel.date_sub(:a, :days=>1)
36
- da.should be_a_kind_of(Sequel::SQL::DateAdd)
37
- da.expr.should == :a
38
- da.interval.should == {:days=>-1}
39
- Sequel.date_sub(:a, :years=>1, :months=>2, :days=>3, :hours=>1, :minutes=>1, :seconds=>1).interval.should == {:years=>-1, :months=>-2, :days=>-3, :hours=>-1, :minutes=>-1, :seconds=>-1}
36
+ da.must_be_kind_of(Sequel::SQL::DateAdd)
37
+ da.expr.must_equal :a
38
+ da.interval.must_equal(:days=>-1)
39
+ Sequel.date_sub(:a, :years=>1, :months=>2, :days=>3, :hours=>1, :minutes=>1, :seconds=>1).interval.must_equal(:years=>-1, :months=>-2, :days=>-3, :hours=>-1, :minutes=>-1, :seconds=>-1)
40
40
  end
41
41
 
42
42
  it "should have Sequel.date_* with an interval hash handle nil values" do
43
- Sequel.date_sub(:a, :days=>1, :hours=>nil).interval.should == {:days=>-1}
43
+ Sequel.date_sub(:a, :days=>1, :hours=>nil).interval.must_equal(:days=>-1)
44
44
  end
45
45
 
46
46
  it "should raise an error if given string values in an interval hash" do
47
- lambda{Sequel.date_add(:a, :days=>'1')}.should raise_error(Sequel::InvalidValue)
47
+ lambda{Sequel.date_add(:a, :days=>'1')}.must_raise(Sequel::InvalidValue)
48
48
  end
49
49
 
50
50
  if asd
51
51
  it "should have Sequel.date_add with an ActiveSupport::Duration return an appropriate Sequel::SQL::DateAdd expression" do
52
52
  da = Sequel.date_add(:a, ActiveSupport::Duration.new(1, [[:days, 1]]))
53
- da.should be_a_kind_of(Sequel::SQL::DateAdd)
54
- da.expr.should == :a
55
- da.interval.should == {:days=>1}
56
- Sequel.date_add(:a, ActiveSupport::Duration.new(1, [[:years, 1], [:months, 1], [:days, 1], [:minutes, 61], [:seconds, 1]])).interval.should == {:years=>1, :months=>1, :days=>1, :minutes=>61, :seconds=>1}
53
+ da.must_be_kind_of(Sequel::SQL::DateAdd)
54
+ da.expr.must_equal :a
55
+ da.interval.must_equal(:days=>1)
56
+ Sequel.date_add(:a, ActiveSupport::Duration.new(1, [[:years, 1], [:months, 1], [:days, 1], [:minutes, 61], [:seconds, 1]])).interval.must_equal(:years=>1, :months=>1, :days=>1, :minutes=>61, :seconds=>1)
57
57
  end
58
58
 
59
59
  it "should have Sequel.date_sub with an ActiveSupport::Duration return an appropriate Sequel::SQL::DateAdd expression" do
60
60
  da = Sequel.date_sub(:a, ActiveSupport::Duration.new(1, [[:days, 1]]))
61
- da.should be_a_kind_of(Sequel::SQL::DateAdd)
62
- da.expr.should == :a
63
- da.interval.should == {:days=>-1}
64
- Sequel.date_sub(:a, ActiveSupport::Duration.new(1, [[:years, 1], [:months, 1], [:days, 1], [:minutes, 61], [:seconds, 1]])).interval.should == {:years=>-1, :months=>-1, :days=>-1, :minutes=>-61, :seconds=>-1}
61
+ da.must_be_kind_of(Sequel::SQL::DateAdd)
62
+ da.expr.must_equal :a
63
+ da.interval.must_equal(:days=>-1)
64
+ Sequel.date_sub(:a, ActiveSupport::Duration.new(1, [[:years, 1], [:months, 1], [:days, 1], [:minutes, 61], [:seconds, 1]])).interval.must_equal(:years=>-1, :months=>-1, :days=>-1, :minutes=>-61, :seconds=>-1)
65
65
  end
66
66
  end
67
67
 
68
68
  it "should correctly literalize on Postgres" do
69
69
  db = dbf.call(:postgres)
70
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS timestamp)"
71
- db.literal(Sequel.date_add(:a, @h1)).should == "(CAST(a AS timestamp) + CAST('1 days ' AS interval))"
72
- db.literal(Sequel.date_add(:a, @h2)).should == "(CAST(a AS timestamp) + CAST('1 years 1 months 1 days 1 hours 1 minutes 1 seconds ' AS interval))"
70
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(a AS timestamp)"
71
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "(CAST(a AS timestamp) + CAST('1 days ' AS interval))"
72
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "(CAST(a AS timestamp) + CAST('1 years 1 months 1 days 1 hours 1 minutes 1 seconds ' AS interval))"
73
73
  end
74
74
 
75
75
  it "should correctly literalize on SQLite" do
76
76
  db = dbf.call(:sqlite)
77
- db.literal(Sequel.date_add(:a, @h0)).should == "datetime(a)"
78
- db.literal(Sequel.date_add(:a, @h1)).should == "datetime(a, '1 days')"
79
- db.literal(Sequel.date_add(:a, @h2)).should == "datetime(a, '1 years', '1 months', '1 days', '1 hours', '1 minutes', '1 seconds')"
77
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "datetime(a)"
78
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "datetime(a, '1 days')"
79
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "datetime(a, '1 years', '1 months', '1 days', '1 hours', '1 minutes', '1 seconds')"
80
80
  end
81
81
 
82
82
  it "should correctly literalize on MySQL" do
83
83
  db = dbf.call(:mysql)
84
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS DATETIME)"
85
- db.literal(Sequel.date_add(:a, @h1)).should == "DATE_ADD(a, INTERVAL 1 DAY)"
86
- db.literal(Sequel.date_add(:a, @h2)).should == "DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(a, INTERVAL 1 YEAR), INTERVAL 1 MONTH), INTERVAL 1 DAY), INTERVAL 1 HOUR), INTERVAL 1 MINUTE), INTERVAL 1 SECOND)"
84
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(a AS DATETIME)"
85
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "DATE_ADD(a, INTERVAL 1 DAY)"
86
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(a, INTERVAL 1 YEAR), INTERVAL 1 MONTH), INTERVAL 1 DAY), INTERVAL 1 HOUR), INTERVAL 1 MINUTE), INTERVAL 1 SECOND)"
87
87
  end
88
88
 
89
89
  it "should correctly literalize on HSQLDB" do
90
90
  db = Sequel.mock
91
91
  def db.database_type; :hsqldb end
92
92
  db.extension :date_arithmetic
93
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(CAST(a AS timestamp) AS timestamp)"
94
- db.literal(Sequel.date_add(:a, @h1)).should == "DATE_ADD(CAST(a AS timestamp), INTERVAL 1 DAY)"
95
- db.literal(Sequel.date_add(:a, @h2)).should == "DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(CAST(a AS timestamp), INTERVAL 1 YEAR), INTERVAL 1 MONTH), INTERVAL 1 DAY), INTERVAL 1 HOUR), INTERVAL 1 MINUTE), INTERVAL 1 SECOND)"
93
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(CAST(a AS timestamp) AS timestamp)"
94
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "DATE_ADD(CAST(a AS timestamp), INTERVAL 1 DAY)"
95
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(DATE_ADD(CAST(a AS timestamp), INTERVAL 1 YEAR), INTERVAL 1 MONTH), INTERVAL 1 DAY), INTERVAL 1 HOUR), INTERVAL 1 MINUTE), INTERVAL 1 SECOND)"
96
96
  end
97
97
 
98
98
  it "should correctly literalize on MSSQL" do
99
99
  db = dbf.call(:mssql)
100
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS datetime)"
101
- db.literal(Sequel.date_add(:a, @h1)).should == "DATEADD(day, 1, a)"
102
- db.literal(Sequel.date_add(:a, @h2)).should == "DATEADD(second, 1, DATEADD(minute, 1, DATEADD(hour, 1, DATEADD(day, 1, DATEADD(month, 1, DATEADD(year, 1, a))))))"
100
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(a AS datetime)"
101
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "DATEADD(day, 1, a)"
102
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "DATEADD(second, 1, DATEADD(minute, 1, DATEADD(hour, 1, DATEADD(day, 1, DATEADD(month, 1, DATEADD(year, 1, a))))))"
103
103
  end
104
104
 
105
105
  it "should correctly literalize on H2" do
106
106
  db = Sequel.mock
107
107
  def db.database_type; :h2 end
108
108
  db.extension :date_arithmetic
109
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS timestamp)"
110
- db.literal(Sequel.date_add(:a, @h1)).should == "DATEADD('day', 1, a)"
111
- db.literal(Sequel.date_add(:a, @h2)).should == "DATEADD('second', 1, DATEADD('minute', 1, DATEADD('hour', 1, DATEADD('day', 1, DATEADD('month', 1, DATEADD('year', 1, a))))))"
109
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(a AS timestamp)"
110
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "DATEADD('day', 1, a)"
111
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "DATEADD('second', 1, DATEADD('minute', 1, DATEADD('hour', 1, DATEADD('day', 1, DATEADD('month', 1, DATEADD('year', 1, a))))))"
112
112
  end
113
113
 
114
114
  it "should correctly literalize on access" do
115
115
  db = dbf.call(:access)
116
- db.literal(Sequel.date_add(:a, @h0)).should == "CDate(a)"
117
- db.literal(Sequel.date_add(:a, @h1)).should == "DATEADD('d', 1, a)"
118
- db.literal(Sequel.date_add(:a, @h2)).should == "DATEADD('s', 1, DATEADD('n', 1, DATEADD('h', 1, DATEADD('d', 1, DATEADD('m', 1, DATEADD('yyyy', 1, a))))))"
116
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CDate(a)"
117
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "DATEADD('d', 1, a)"
118
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "DATEADD('s', 1, DATEADD('n', 1, DATEADD('h', 1, DATEADD('d', 1, DATEADD('m', 1, DATEADD('yyyy', 1, a))))))"
119
119
  end
120
120
 
121
121
  it "should correctly literalize on Derby" do
122
122
  db = Sequel.mock
123
123
  def db.database_type; :derby end
124
124
  db.extension :date_arithmetic
125
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS timestamp)"
126
- db.literal(Sequel.date_add(:a, @h1)).should == "{fn timestampadd(SQL_TSI_DAY, 1, timestamp(a))}"
127
- db.literal(Sequel.date_add(:a, @h2)).should == "{fn timestampadd(SQL_TSI_SECOND, 1, timestamp({fn timestampadd(SQL_TSI_MINUTE, 1, timestamp({fn timestampadd(SQL_TSI_HOUR, 1, timestamp({fn timestampadd(SQL_TSI_DAY, 1, timestamp({fn timestampadd(SQL_TSI_MONTH, 1, timestamp({fn timestampadd(SQL_TSI_YEAR, 1, timestamp(a))}))}))}))}))}))}"
128
- db.literal(Sequel.date_add(Date.civil(2012, 11, 12), @h1)).should == "{fn timestampadd(SQL_TSI_DAY, 1, timestamp((CAST('2012-11-12' AS varchar(255)) || ' 00:00:00')))}"
125
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(a AS timestamp)"
126
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "{fn timestampadd(SQL_TSI_DAY, 1, timestamp(a))}"
127
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "{fn timestampadd(SQL_TSI_SECOND, 1, timestamp({fn timestampadd(SQL_TSI_MINUTE, 1, timestamp({fn timestampadd(SQL_TSI_HOUR, 1, timestamp({fn timestampadd(SQL_TSI_DAY, 1, timestamp({fn timestampadd(SQL_TSI_MONTH, 1, timestamp({fn timestampadd(SQL_TSI_YEAR, 1, timestamp(a))}))}))}))}))}))}"
128
+ db.literal(Sequel.date_add(Date.civil(2012, 11, 12), @h1)).must_equal "{fn timestampadd(SQL_TSI_DAY, 1, timestamp((CAST('2012-11-12' AS varchar(255)) || ' 00:00:00')))}"
129
129
  end
130
130
 
131
131
  it "should correctly literalize on Oracle" do
132
132
  db = dbf.call(:oracle)
133
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS timestamp)"
134
- db.literal(Sequel.date_add(:a, @h1)).should == "(a + INTERVAL '1' DAY)"
135
- db.literal(Sequel.date_add(:a, @h2)).should == "(a + INTERVAL '1' YEAR + INTERVAL '1' MONTH + INTERVAL '1' DAY + INTERVAL '1' HOUR + INTERVAL '1' MINUTE + INTERVAL '1' SECOND)"
133
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(a AS timestamp)"
134
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "(a + INTERVAL '1' DAY)"
135
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "(a + INTERVAL '1' YEAR + INTERVAL '1' MONTH + INTERVAL '1' DAY + INTERVAL '1' HOUR + INTERVAL '1' MINUTE + INTERVAL '1' SECOND)"
136
136
  end
137
137
 
138
138
  it "should correctly literalize on DB2" do
139
139
  db = dbf.call(:db2)
140
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS timestamp)"
141
- db.literal(Sequel.date_add(:a, @h1)).should == "(CAST(a AS timestamp) + 1 days)"
142
- db.literal(Sequel.date_add(:a, @h2)).should == "(CAST(a AS timestamp) + 1 years + 1 months + 1 days + 1 hours + 1 minutes + 1 seconds)"
140
+ db.literal(Sequel.date_add(:a, @h0)).must_equal "CAST(a AS timestamp)"
141
+ db.literal(Sequel.date_add(:a, @h1)).must_equal "(CAST(a AS timestamp) + 1 days)"
142
+ db.literal(Sequel.date_add(:a, @h2)).must_equal "(CAST(a AS timestamp) + 1 years + 1 months + 1 days + 1 hours + 1 minutes + 1 seconds)"
143
143
  end
144
144
 
145
- it "should correctly literalize on Fdbsql" do
146
- db = dbf.call(:fdbsql)
147
- db.literal(Sequel.date_add(:a, @h0)).should == "CAST(a AS timestamp)"
148
- db.literal(Sequel.date_add(:a, @h1)).should == "(a + INTERVAL 1 day)"
149
- db.literal(Sequel.date_add(:a, @h2)).should == "(a + INTERVAL 1 year + INTERVAL 1 month + INTERVAL 1 day + INTERVAL 1 hour + INTERVAL 1 minute + INTERVAL 1 second)"
150
- end
151
-
152
- specify "should raise error if literalizing on an unsupported database" do
145
+ it "should raise error if literalizing on an unsupported database" do
153
146
  db = Sequel.mock
154
147
  db.extension :date_arithmetic
155
- lambda{db.literal(Sequel.date_add(:a, @h0))}.should raise_error(Sequel::Error)
148
+ lambda{db.literal(Sequel.date_add(:a, @h0))}.must_raise(Sequel::Error)
156
149
  end
157
150
  end
@@ -15,36 +15,36 @@ describe "Sequel::Plugins::DefaultsSetter" do
15
15
  end
16
16
 
17
17
  it "should set default value upon initialization" do
18
- @pr.call(2).new.a.should == 2
18
+ @pr.call(2).new.a.must_equal 2
19
19
  end
20
20
 
21
21
  it "should not mark the column as modified" do
22
- @pr.call(2).new.changed_columns.should == []
22
+ @pr.call(2).new.changed_columns.must_equal []
23
23
  end
24
24
 
25
25
  it "should not set a default of nil" do
26
- @pr.call(nil).new.class.default_values.should == {}
26
+ @pr.call(nil).new.class.default_values.must_equal({})
27
27
  end
28
28
 
29
29
  it "should set a default of false" do
30
- @pr.call(false).new.a.should == false
30
+ @pr.call(false).new.a.must_equal false
31
31
  end
32
32
 
33
33
  it "should handle Sequel::CURRENT_DATE default by using the current Date" do
34
- @pr.call(Sequel::CURRENT_DATE).new.a.should == Date.today
34
+ @pr.call(Sequel::CURRENT_DATE).new.a.must_equal Date.today
35
35
  end
36
36
 
37
37
  it "should handle Sequel::CURRENT_TIMESTAMP default by using the current Time" do
38
38
  t = @pr.call(Sequel::CURRENT_TIMESTAMP).new.a
39
- t.should be_a_kind_of(Time)
40
- (t - Time.now).should < 1
39
+ t.must_be_kind_of(Time)
40
+ (t - Time.now).must_be :<, 1
41
41
  end
42
42
 
43
43
  it "should handle Sequel::CURRENT_TIMESTAMP default by using the current DateTime if Sequel.datetime_class is DateTime" do
44
44
  Sequel.datetime_class = DateTime
45
45
  t = @pr.call(Sequel::CURRENT_TIMESTAMP).new.a
46
- t.should be_a_kind_of(DateTime)
47
- (t - DateTime.now).should < 1/86400.0
46
+ t.must_be_kind_of(DateTime)
47
+ (t - DateTime.now).must_be :<, 1/86400.0
48
48
  end
49
49
 
50
50
  it "should work correctly with the current_datetime_timestamp extension" do
@@ -56,46 +56,46 @@ describe "Sequel::Plugins::DefaultsSetter" do
56
56
  o = c.new
57
57
  o.a = o.a
58
58
  o.save
59
- @db.sqls.should == ["INSERT INTO foo (a) VALUES (CURRENT_TIMESTAMP)", "SELECT * FROM foo WHERE (id = 1) LIMIT 1"]
59
+ @db.sqls.must_equal ["INSERT INTO foo (a) VALUES (CURRENT_TIMESTAMP)", "SELECT * FROM foo WHERE (id = 1) LIMIT 1"]
60
60
  end
61
61
 
62
62
  it "should not override a given value" do
63
63
  @pr.call(2)
64
- @c.new('a'=>3).a.should == 3
65
- @c.new('a'=>nil).a.should == nil
64
+ @c.new('a'=>3).a.must_equal 3
65
+ @c.new('a'=>nil).a.must_equal nil
66
66
  end
67
67
 
68
68
  it "should work correctly when subclassing" do
69
- Class.new(@pr.call(2)).new.a.should == 2
69
+ Class.new(@pr.call(2)).new.a.must_equal 2
70
70
  end
71
71
 
72
72
  it "should contain the default values in default_values" do
73
- @pr.call(2).default_values.should == {:a=>2}
74
- @pr.call(nil).default_values.should == {}
73
+ @pr.call(2).default_values.must_equal(:a=>2)
74
+ @pr.call(nil).default_values.must_equal({})
75
75
  end
76
76
 
77
77
  it "should allow modifications of default values" do
78
78
  @pr.call(2)
79
79
  @c.default_values[:a] = 3
80
- @c.new.a.should == 3
80
+ @c.new.a.must_equal 3
81
81
  end
82
82
 
83
83
  it "should allow proc default values" do
84
84
  @pr.call(2)
85
85
  @c.default_values[:a] = proc{3}
86
- @c.new.a.should == 3
86
+ @c.new.a.must_equal 3
87
87
  end
88
88
 
89
89
  it "should have procs that set default values set them to nil" do
90
90
  @pr.call(2)
91
91
  @c.default_values[:a] = proc{nil}
92
- @c.new.a.should == nil
92
+ @c.new.a.must_equal nil
93
93
  end
94
94
 
95
95
  it "should work correctly on a model without a dataset" do
96
96
  @pr.call(2)
97
97
  c = Class.new(Sequel::Model(@db[:bar]))
98
98
  c.plugin :defaults_setter
99
- c.default_values.should == {:a=>2}
99
+ c.default_values.must_equal(:a=>2)
100
100
  end
101
101
  end
@@ -0,0 +1,52 @@
1
+ require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
2
+
3
+ describe "Sequel::Plugins::DelayAddAssociation" do
4
+ before do
5
+ @db = Sequel.mock(:autoid=>1, :numrows=>1, :fetch=>{:id=>1, :name=>'a', :c_id=>nil})
6
+ @c = Class.new(Sequel::Model(@db[:cs]))
7
+ @c.send(:define_method, :save){|*| super(:changed=>true)}
8
+ @c.plugin :delay_add_association
9
+ @c.columns :id, :name, :c_id
10
+ @c.one_to_many :cs, :class=>@c, :key=>:c_id
11
+ @db.sqls
12
+ end
13
+
14
+ it "should delay adding of the association until after creation" do
15
+ @o = @c.new(:name=>'a')
16
+ @o.add_c(@c.load(:id=>2, :name=>'b'))
17
+ @db.sqls.must_equal []
18
+ @o.save
19
+ @db.sqls.must_equal ["INSERT INTO cs (name) VALUES ('a')", "UPDATE cs SET c_id = 1 WHERE (id = 2)", "SELECT * FROM cs WHERE (id = 1) LIMIT 1"]
20
+ end
21
+
22
+ it "should immediately reflect changes in cached association" do
23
+ @o = @c.new(:name=>'a')
24
+ o = @c.load(:id=>2, :name=>'b')
25
+ @o.add_c(o)
26
+ @o.cs.must_equal [o]
27
+ @db.sqls.must_equal []
28
+ end
29
+
30
+ it "should not affect adding associations to existing rows" do
31
+ @o = @c.load(:id=>1, :name=>'a')
32
+ @o.add_c(@c.load(:id=>2, :name=>'b'))
33
+ @db.sqls.must_equal ["UPDATE cs SET c_id = 1 WHERE (id = 2)"]
34
+ end
35
+
36
+ it "should raise an error when saving if the associated object is invalid" do
37
+ @c.send(:define_method, :validate){|*| errors.add(:name, 'is b') if name == 'b'}
38
+ @o = @c.new(:name=>'a')
39
+ @o.add_c(@c.load(:id=>2, :name=>'b'))
40
+ proc{@o.save}.must_raise Sequel::ValidationFailed
41
+ end
42
+
43
+ it "should return nil when saving if the associated object is invalid when raise_on_save_failure is false" do
44
+ @c.raise_on_save_failure = false
45
+ @c.send(:define_method, :validate){|*| errors.add(:name, 'is b') if name == 'b'}
46
+ @o = @c.new(:name=>'a')
47
+ @o.add_c(@c.load(:id=>2, :name=>'b'))
48
+ @o.save.must_equal nil
49
+ @o.errors[:cs].must_equal ["name is b"]
50
+ @o.cs.first.errors[:name].must_equal ['is b']
51
+ end
52
+ end
@@ -8,104 +8,104 @@ describe "Sequel::Plugins::Dirty" do
8
8
  @c.columns :initial, :initial_changed, :missing, :missing_changed
9
9
  end
10
10
 
11
- shared_examples_for "dirty plugin" do
11
+ dirty_plugin_specs = shared_description do
12
12
  it "initial_value should be the current value if value has not changed" do
13
- @o.initial_value(:initial).should == 'i'
14
- @o.initial_value(:missing).should == nil
13
+ @o.initial_value(:initial).must_equal 'i'
14
+ @o.initial_value(:missing).must_equal nil
15
15
  end
16
16
 
17
17
  it "initial_value should be the intial value if value has changed" do
18
- @o.initial_value(:initial_changed).should == 'ic'
19
- @o.initial_value(:missing_changed).should == nil
18
+ @o.initial_value(:initial_changed).must_equal 'ic'
19
+ @o.initial_value(:missing_changed).must_equal nil
20
20
  end
21
21
 
22
22
  it "initial_value should handle case where initial value is reassigned later" do
23
23
  @o.initial_changed = 'ic'
24
- @o.initial_value(:initial_changed).should == 'ic'
24
+ @o.initial_value(:initial_changed).must_equal 'ic'
25
25
  @o.missing_changed = nil
26
- @o.initial_value(:missing_changed).should == nil
26
+ @o.initial_value(:missing_changed).must_equal nil
27
27
  end
28
28
 
29
29
  it "changed_columns should handle case where initial value is reassigned later" do
30
- @o.changed_columns.should == [:initial_changed, :missing_changed]
30
+ @o.changed_columns.must_equal [:initial_changed, :missing_changed]
31
31
  @o.initial_changed = 'ic'
32
- @o.changed_columns.should == [:missing_changed]
32
+ @o.changed_columns.must_equal [:missing_changed]
33
33
  @o.missing_changed = nil
34
- @o.changed_columns.should == [:missing_changed]
34
+ @o.changed_columns.must_equal [:missing_changed]
35
35
  end
36
36
 
37
37
  it "column_change should give initial and current values if there has been a change made" do
38
- @o.column_change(:initial_changed).should == ['ic', 'ic2']
39
- @o.column_change(:missing_changed).should == [nil, 'mc2']
38
+ @o.column_change(:initial_changed).must_equal ['ic', 'ic2']
39
+ @o.column_change(:missing_changed).must_equal [nil, 'mc2']
40
40
  end
41
41
 
42
42
  it "column_change should be nil if no change has been made" do
43
- @o.column_change(:initial).should == nil
44
- @o.column_change(:missing).should == nil
43
+ @o.column_change(:initial).must_equal nil
44
+ @o.column_change(:missing).must_equal nil
45
45
  end
46
46
 
47
47
  it "column_changed? should return whether the column has changed" do
48
- @o.column_changed?(:initial).should == false
49
- @o.column_changed?(:initial_changed).should == true
50
- @o.column_changed?(:missing).should == false
51
- @o.column_changed?(:missing_changed).should == true
48
+ @o.column_changed?(:initial).must_equal false
49
+ @o.column_changed?(:initial_changed).must_equal true
50
+ @o.column_changed?(:missing).must_equal false
51
+ @o.column_changed?(:missing_changed).must_equal true
52
52
  end
53
53
 
54
54
  it "column_changed? should handle case where initial value is reassigned later" do
55
55
  @o.initial_changed = 'ic'
56
- @o.column_changed?(:initial_changed).should == false
56
+ @o.column_changed?(:initial_changed).must_equal false
57
57
  @o.missing_changed = nil
58
- @o.column_changed?(:missing_changed).should == false
58
+ @o.column_changed?(:missing_changed).must_equal false
59
59
  end
60
60
 
61
61
  it "changed_columns should handle case where initial value is reassigned later" do
62
- @o.changed_columns.should == [:initial_changed, :missing_changed]
62
+ @o.changed_columns.must_equal [:initial_changed, :missing_changed]
63
63
  @o.initial_changed = 'ic'
64
- @o.changed_columns.should == [:missing_changed]
64
+ @o.changed_columns.must_equal [:missing_changed]
65
65
  @o.missing_changed = nil
66
- @o.changed_columns.should == [:missing_changed]
66
+ @o.changed_columns.must_equal [:missing_changed]
67
67
  end
68
68
 
69
69
  it "column_changes should give initial and current values" do
70
- @o.column_changes.should == {:initial_changed=>['ic', 'ic2'], :missing_changed=>[nil, 'mc2']}
70
+ @o.column_changes.must_equal(:initial_changed=>['ic', 'ic2'], :missing_changed=>[nil, 'mc2'])
71
71
  end
72
72
 
73
73
  it "reset_column should reset the column to its initial value" do
74
74
  @o.reset_column(:initial)
75
- @o.initial.should == 'i'
75
+ @o.initial.must_equal 'i'
76
76
  @o.reset_column(:initial_changed)
77
- @o.initial_changed.should == 'ic'
77
+ @o.initial_changed.must_equal 'ic'
78
78
  @o.reset_column(:missing)
79
- @o.missing.should == nil
79
+ @o.missing.must_equal nil
80
80
  @o.reset_column(:missing_changed)
81
- @o.missing_changed.should == nil
81
+ @o.missing_changed.must_equal nil
82
82
  end
83
83
 
84
84
  it "reset_column should remove missing values from the values" do
85
85
  @o.reset_column(:missing)
86
- @o.values.has_key?(:missing).should == false
86
+ @o.values.has_key?(:missing).must_equal false
87
87
  @o.reset_column(:missing_changed)
88
- @o.values.has_key?(:missing_changed).should == false
88
+ @o.values.has_key?(:missing_changed).must_equal false
89
89
  end
90
90
 
91
91
  it "refresh should clear the cached initial values" do
92
92
  @o.refresh
93
- @o.column_changes.should == {}
93
+ @o.column_changes.must_equal({})
94
94
  end
95
95
 
96
96
  it "will_change_column should be used to signal in-place modification to column" do
97
97
  @o.will_change_column(:initial)
98
98
  @o.initial << 'b'
99
- @o.column_change(:initial).should == ['i', 'ib']
99
+ @o.column_change(:initial).must_equal ['i', 'ib']
100
100
  @o.will_change_column(:initial_changed)
101
101
  @o.initial_changed << 'b'
102
- @o.column_change(:initial_changed).should == ['ic', 'ic2b']
102
+ @o.column_change(:initial_changed).must_equal ['ic', 'ic2b']
103
103
  @o.will_change_column(:missing)
104
104
  @o.values[:missing] = 'b'
105
- @o.column_change(:missing).should == [nil, 'b']
105
+ @o.column_change(:missing).must_equal [nil, 'b']
106
106
  @o.will_change_column(:missing_changed)
107
107
  @o.missing_changed << 'b'
108
- @o.column_change(:missing_changed).should == [nil, 'mc2b']
108
+ @o.column_change(:missing_changed).must_equal [nil, 'mc2b']
109
109
  end
110
110
 
111
111
  it "will_change_column should different types of existing objects" do
@@ -113,23 +113,23 @@ describe "Sequel::Plugins::Dirty" do
113
113
  o = @c.new(:initial=>v)
114
114
  o.will_change_column(:initial)
115
115
  o.initial = 'a'
116
- o.column_change(:initial).should == [v, 'a']
116
+ o.column_change(:initial).must_equal [v, 'a']
117
117
  end
118
118
  end
119
119
 
120
120
  it "should work when freezing objects" do
121
121
  @o.freeze
122
- @o.initial_value(:initial).should == 'i'
123
- proc{@o.initial = 'b'}.should raise_error
122
+ @o.initial_value(:initial).must_equal 'i'
123
+ proc{@o.initial = 'b'}.must_raise
124
124
  end
125
125
 
126
126
  it "should have #dup duplicate structures" do
127
- @o.dup.initial_values.should == @o.initial_values
128
- @o.dup.initial_values.should_not equal(@o.initial_values)
129
- @o.dup.instance_variable_get(:@missing_initial_values).should == @o.instance_variable_get(:@missing_initial_values)
130
- @o.dup.instance_variable_get(:@missing_initial_values).should_not equal(@o.instance_variable_get(:@missing_initial_values))
131
- @o.dup.previous_changes.should == @o.previous_changes
132
- @o.dup.previous_changes.should_not equal(@o.previous_changes) if @o.previous_changes
127
+ @o.dup.initial_values.must_equal @o.initial_values
128
+ @o.dup.initial_values.wont_be_same_as(@o.initial_values)
129
+ @o.dup.instance_variable_get(:@missing_initial_values).must_equal @o.instance_variable_get(:@missing_initial_values)
130
+ @o.dup.instance_variable_get(:@missing_initial_values).wont_be_same_as(@o.instance_variable_get(:@missing_initial_values))
131
+ @o.dup.previous_changes.must_equal @o.previous_changes
132
+ @o.dup.previous_changes.wont_be_same_as(@o.previous_changes) if @o.previous_changes
133
133
  end
134
134
  end
135
135
 
@@ -140,18 +140,18 @@ describe "Sequel::Plugins::Dirty" do
140
140
  @o.missing_changed = 'mc2'
141
141
  end
142
142
 
143
- it_should_behave_like "dirty plugin"
143
+ include dirty_plugin_specs
144
144
 
145
145
  it "save should clear the cached initial values" do
146
146
  @o.save
147
- @o.column_changes.should == {}
147
+ @o.column_changes.must_equal({})
148
148
  end
149
149
 
150
150
  it "save_changes should clear the cached initial values" do
151
151
  def (@c.instance_dataset).supports_insert_select?() true end
152
152
  def (@c.instance_dataset).insert_select(*) {:id=>1} end
153
153
  @o.save
154
- @o.column_changes.should == {}
154
+ @o.column_changes.must_equal({})
155
155
  end
156
156
  end
157
157
 
@@ -162,19 +162,19 @@ describe "Sequel::Plugins::Dirty" do
162
162
  @o.missing_changed = 'mc2'
163
163
  end
164
164
 
165
- it_should_behave_like "dirty plugin"
165
+ include dirty_plugin_specs
166
166
 
167
167
  it "previous_changes should be the previous changes after saving" do
168
168
  @o.save
169
- @o.previous_changes.should == {:initial_changed=>['ic', 'ic2'], :missing_changed=>[nil, 'mc2']}
169
+ @o.previous_changes.must_equal(:initial_changed=>['ic', 'ic2'], :missing_changed=>[nil, 'mc2'])
170
170
  end
171
171
 
172
172
  it "should work when freezing objects after saving" do
173
173
  @o.initial = 'a'
174
174
  @o.save
175
175
  @o.freeze
176
- @o.previous_changes[:initial].should == ['i', 'a']
177
- proc{@o.initial = 'b'}.should raise_error
176
+ @o.previous_changes[:initial].must_equal ['i', 'a']
177
+ proc{@o.initial = 'b'}.must_raise
178
178
  end
179
179
  end
180
180
  end