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
@@ -21,70 +21,7 @@ Sequel::Model.cache_associations = false if ENV['SEQUEL_NO_CACHE_ASSOCIATIONS']
21
21
  Sequel::Model.use_transactions = false
22
22
  Sequel.cache_anonymous_models = false
23
23
 
24
- unless defined?(RSpec)
25
- module Spec::Matchers
26
- class BeWithin
27
- include Spec::Matchers
28
- def initialize(delta); @delta = delta; end
29
- def of(expected); be_close(expected, @delta); end
30
- end
31
- def be_within(delta)
32
- BeWithin.new(delta)
33
- end
34
- end
35
- end
36
-
37
- def Sequel.guarded?(*checked)
38
- unless ENV['SEQUEL_NO_PENDING']
39
- checked.each do |c|
40
- case c
41
- when DB.database_type
42
- return c
43
- when Array
44
- case c.length
45
- when 1
46
- return c if c.first == DB.adapter_scheme
47
- when 2
48
- if c.first.is_a?(Proc)
49
- return c if c.last == DB.database_type && c.first.call(DB)
50
- elsif c.last.is_a?(Proc)
51
- return c if c.first == DB.adapter_scheme && c.last.call(DB)
52
- else
53
- return c if c.first == DB.adapter_scheme && c.last == DB.database_type
54
- end
55
- when 3
56
- return c if c[0] == DB.adapter_scheme && c[1] == DB.database_type && c[2].call(DB)
57
- end
58
- end
59
- end
60
- end
61
- false
62
- end
63
-
64
- require File.join(File.dirname(File.expand_path(__FILE__)), "../rspec_helper.rb")
65
-
66
- RSPEC_EXAMPLE_GROUP.class_eval do
67
- def log
68
- begin
69
- DB.loggers << Logger.new(STDOUT)
70
- yield
71
- ensure
72
- DB.loggers.pop
73
- end
74
- end
75
-
76
- def self.cspecify(message, *checked, &block)
77
- if pending = Sequel.guarded?(*checked)
78
- specify(message) do
79
- method = RSPEC_SKIP_PENDING && !ENV['SEQUEL_NO_SKIP_PENDING'] ? :skip : :pending
80
- send(method, "Not yet working on #{Array(pending).map{|x| x.is_a?(Proc) ? :proc : x}.join(', ')}")
81
- instance_eval(&block)
82
- end
83
- else
84
- specify(message, &block)
85
- end
86
- end
87
- end
24
+ require './spec/guards_helper'
88
25
 
89
26
  unless defined?(DB)
90
27
  DB = Sequel.connect(ENV['SEQUEL_INTEGRATION_URL'])
@@ -1,16 +1,16 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
2
2
 
3
3
  describe "Sequel timezone support" do
4
- def test_timezone(timezone=Sequel.application_timezone)
4
+ def _test_timezone(timezone=Sequel.application_timezone)
5
5
  Sequel.datetime_class = Time
6
6
  # Tests should cover both DST and non-DST times.
7
7
  [Time.now, Time.local(2010,1,1,12), Time.local(2010,6,1,12)].each do |t|
8
8
  @db[:t].insert(t)
9
9
  t2 = @db[:t].single_value
10
10
  t2 = @db.to_application_timestamp(t2.to_s) unless t2.is_a?(Time)
11
- (t2 - t).should be_within(2).of(0)
12
- t2.utc_offset.should == 0 if timezone == :utc
13
- t2.utc_offset.should == t.getlocal.utc_offset if timezone == :local
11
+ (t2 - t).must_be_close_to 0, 2
12
+ t2.utc_offset.must_equal 0 if timezone == :utc
13
+ t2.utc_offset.must_equal t.getlocal.utc_offset if timezone == :local
14
14
  @db[:t].delete
15
15
  end
16
16
 
@@ -21,9 +21,9 @@ describe "Sequel timezone support" do
21
21
  @db[:t].insert(dt)
22
22
  dt2 = @db[:t].single_value
23
23
  dt2 = @db.to_application_timestamp(dt2.to_s) unless dt2.is_a?(DateTime)
24
- (dt2 - dt).should be_within(0.00002).of(0)
25
- dt2.offset.should == 0 if timezone == :utc
26
- dt2.offset.should == dt.offset if timezone == :local
24
+ (dt2 - dt).must_be_close_to 0, 0.00002
25
+ dt2.offset.must_equal 0 if timezone == :utc
26
+ dt2.offset.must_equal dt.offset if timezone == :local
27
27
  @db[:t].delete
28
28
  end
29
29
  end
@@ -42,45 +42,45 @@ describe "Sequel timezone support" do
42
42
  cspecify "should support using UTC for database storage and local time for the application", [:tinytds], [:do, :mysql], [:do, :postgres], [:oracle] do
43
43
  Sequel.database_timezone = :utc
44
44
  Sequel.application_timezone = :local
45
- test_timezone
45
+ _test_timezone
46
46
  Sequel.database_timezone = nil
47
47
  @db.timezone = :utc
48
- test_timezone
48
+ _test_timezone
49
49
  end
50
50
 
51
51
  cspecify "should support using local time for database storage and UTC for the application", [:tinytds], [:do, :mysql], [:do, :postgres], [:oracle] do
52
52
  Sequel.database_timezone = :local
53
53
  Sequel.application_timezone = :utc
54
- test_timezone
54
+ _test_timezone
55
55
  Sequel.database_timezone = nil
56
56
  @db.timezone = :local
57
- test_timezone
57
+ _test_timezone
58
58
  end
59
59
 
60
60
  cspecify "should support using UTC for both database storage and for application", [:do, :mysql], [:do, :postgres], [:oracle] do
61
61
  Sequel.default_timezone = :utc
62
- test_timezone
62
+ _test_timezone
63
63
  Sequel.database_timezone = :local
64
64
  @db.timezone = :utc
65
- test_timezone
65
+ _test_timezone
66
66
  end
67
67
 
68
68
  cspecify "should support using local time for both database storage and for application", [:do, :postgres], [:oracle] do
69
69
  Sequel.default_timezone = :local
70
- test_timezone
70
+ _test_timezone
71
71
  Sequel.database_timezone = :utc
72
72
  @db.timezone = :local
73
- test_timezone
73
+ _test_timezone
74
74
  end
75
75
 
76
- specify "should allow overriding the database_timezone on a per-database basis" do
76
+ it "should allow overriding the database_timezone on a per-database basis" do
77
77
  Sequel.database_timezone = :utc
78
78
  @db.timezone = :local
79
79
  t = Time.now
80
80
  @db[:t].insert(t)
81
81
  s = @db[:t].get(Sequel.cast(:t, String))
82
82
  if o = Date._parse(s)[:offset]
83
- o.should == t.utc_offset
83
+ o.must_equal t.utc_offset
84
84
  end
85
85
  end
86
86
  end
@@ -13,78 +13,78 @@ describe "Database transactions" do
13
13
  @db.drop_table?(:items)
14
14
  end
15
15
 
16
- specify "should support transactions" do
16
+ it "should support transactions" do
17
17
  @db.transaction{@d << {:name => 'abc', :value => 1}}
18
- @d.count.should == 1
18
+ @d.count.must_equal 1
19
19
  end
20
20
 
21
- specify "should have #transaction yield the connection" do
22
- @db.transaction{|conn| conn.should_not == nil}
21
+ it "should have #transaction yield the connection" do
22
+ @db.transaction{|conn| conn.wont_equal nil}
23
23
  end
24
24
 
25
- specify "should have #in_transaction? work correctly" do
26
- @db.in_transaction?.should == false
25
+ it "should have #in_transaction? work correctly" do
26
+ @db.in_transaction?.must_equal false
27
27
  c = nil
28
28
  @db.transaction{c = @db.in_transaction?}
29
- c.should == true
29
+ c.must_equal true
30
30
  end
31
31
 
32
- specify "should correctly rollback transactions" do
32
+ it "should correctly rollback transactions" do
33
33
  proc do
34
34
  @db.transaction do
35
35
  @d << {:name => 'abc', :value => 1}
36
36
  raise Interrupt, 'asdf'
37
37
  end
38
- end.should raise_error(Interrupt)
38
+ end.must_raise(Interrupt)
39
39
 
40
40
  @db.transaction do
41
41
  @d << {:name => 'abc', :value => 1}
42
42
  raise Sequel::Rollback
43
- end.should be_nil
43
+ end.must_equal nil
44
44
 
45
45
  proc do
46
46
  @db.transaction(:rollback=>:reraise) do
47
47
  @d << {:name => 'abc', :value => 1}
48
48
  raise Sequel::Rollback
49
49
  end
50
- end.should raise_error(Sequel::Rollback)
50
+ end.must_raise(Sequel::Rollback)
51
51
 
52
52
  @db.transaction(:rollback=>:always) do
53
53
  @d << {:name => 'abc', :value => 1}
54
54
  2
55
- end.should be_nil
55
+ end.must_equal 2
56
56
 
57
- @d.count.should == 0
57
+ @d.count.must_equal 0
58
58
  end
59
59
 
60
- specify "should support nested transactions" do
60
+ it "should support nested transactions" do
61
61
  @db.transaction do
62
62
  @db.transaction do
63
63
  @d << {:name => 'abc', :value => 1}
64
64
  end
65
65
  end
66
- @d.count.should == 1
66
+ @d.count.must_equal 1
67
67
 
68
68
  @d.delete
69
- proc {@db.transaction do
69
+ @db.transaction do
70
70
  @d << {:name => 'abc', :value => 1}
71
71
  @db.transaction do
72
72
  raise Sequel::Rollback
73
73
  end
74
- end}.should_not raise_error
75
- @d.count.should == 0
74
+ end
75
+ @d.count.must_equal 0
76
76
 
77
77
  proc {@db.transaction do
78
78
  @d << {:name => 'abc', :value => 1}
79
79
  @db.transaction do
80
80
  raise Interrupt, 'asdf'
81
81
  end
82
- end}.should raise_error(Interrupt)
83
- @d.count.should == 0
82
+ end}.must_raise(Interrupt)
83
+ @d.count.must_equal 0
84
84
  end
85
85
 
86
86
  if DB.supports_savepoints?
87
- specify "should support nested transactions through savepoints using the savepoint option" do
87
+ it "should support nested transactions through savepoints using the savepoint option" do
88
88
  @db.transaction do
89
89
  @d << {:name => '1'}
90
90
  @db.transaction(:savepoint=>true) do
@@ -105,10 +105,10 @@ describe "Database transactions" do
105
105
  @d << {:name => '5'}
106
106
  end
107
107
 
108
- @d.order(:name).map(:name).should == %w{1 4 5 6}
108
+ @d.order(:name).map(:name).must_equal %w{1 4 5 6}
109
109
  end
110
110
 
111
- specify "should support nested transactions through savepoints using the auto_savepoint option" do
111
+ it "should support nested transactions through savepoints using the auto_savepoint option" do
112
112
  @db.transaction(:auto_savepoint=>true) do
113
113
  @d << {:name => '1'}
114
114
  @db.transaction do
@@ -129,11 +129,11 @@ describe "Database transactions" do
129
129
  @d << {:name => '5'}
130
130
  end
131
131
 
132
- @d.order(:name).map(:name).should == %w{1 4 5 6}
132
+ @d.order(:name).map(:name).must_equal %w{1 4 5 6}
133
133
  end
134
134
  end
135
135
 
136
- specify "should handle returning inside of the block by committing" do
136
+ it "should handle returning inside of the block by committing" do
137
137
  def @db.ret_commit
138
138
  transaction do
139
139
  self[:items] << {:name => 'abc'}
@@ -141,143 +141,143 @@ describe "Database transactions" do
141
141
  end
142
142
  end
143
143
 
144
- @d.count.should == 0
144
+ @d.count.must_equal 0
145
145
  @db.ret_commit
146
- @d.count.should == 1
146
+ @d.count.must_equal 1
147
147
  @db.ret_commit
148
- @d.count.should == 2
148
+ @d.count.must_equal 2
149
149
  proc do
150
150
  @db.transaction do
151
151
  raise Interrupt, 'asdf'
152
152
  end
153
- end.should raise_error(Interrupt)
153
+ end.must_raise(Interrupt)
154
154
 
155
- @d.count.should == 2
155
+ @d.count.must_equal 2
156
156
  end
157
157
 
158
158
  if DB.supports_prepared_transactions?
159
- specify "should allow saving and destroying of model objects" do
159
+ it "should allow saving and destroying of model objects" do
160
160
  c = Class.new(Sequel::Model(@d))
161
161
  c.set_primary_key :name
162
162
  c.unrestrict_primary_key
163
163
  c.use_after_commit_rollback = false
164
164
  @db.transaction(:prepare=>'XYZ'){c.create(:name => '1'); c.create(:name => '2').destroy}
165
165
  @db.commit_prepared_transaction('XYZ')
166
- @d.select_order_map(:name).should == ['1']
166
+ @d.select_order_map(:name).must_equal ['1']
167
167
  end
168
168
 
169
- specify "should commit prepared transactions using commit_prepared_transaction" do
169
+ it "should commit prepared transactions using commit_prepared_transaction" do
170
170
  @db.transaction(:prepare=>'XYZ'){@d << {:name => '1'}}
171
171
  @db.commit_prepared_transaction('XYZ')
172
- @d.select_order_map(:name).should == ['1']
172
+ @d.select_order_map(:name).must_equal ['1']
173
173
  end
174
174
 
175
- specify "should rollback prepared transactions using rollback_prepared_transaction" do
175
+ it "should rollback prepared transactions using rollback_prepared_transaction" do
176
176
  @db.transaction(:prepare=>'XYZ'){@d << {:name => '1'}}
177
177
  @db.rollback_prepared_transaction('XYZ')
178
- @d.select_order_map(:name).should == []
178
+ @d.select_order_map(:name).must_equal []
179
179
  end
180
180
 
181
181
  if DB.supports_savepoints_in_prepared_transactions?
182
- specify "should support savepoints when using prepared transactions" do
182
+ it "should support savepoints when using prepared transactions" do
183
183
  @db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@d << {:name => '1'}}}
184
184
  @db.commit_prepared_transaction('XYZ')
185
- @d.select_order_map(:name).should == ['1']
185
+ @d.select_order_map(:name).must_equal ['1']
186
186
  end
187
187
  end
188
188
  end
189
189
 
190
- specify "should support all transaction isolation levels" do
190
+ it "should support all transaction isolation levels" do
191
191
  [:uncommitted, :committed, :repeatable, :serializable].each_with_index do |l, i|
192
192
  @db.transaction(:isolation=>l){@d << {:name => 'abc', :value => 1}}
193
- @d.count.should == i + 1
193
+ @d.count.must_equal i + 1
194
194
  end
195
195
  end
196
196
 
197
- specify "should support after_commit outside transactions" do
197
+ it "should support after_commit outside transactions" do
198
198
  c = nil
199
199
  @db.after_commit{c = 1}
200
- c.should == 1
200
+ c.must_equal 1
201
201
  end
202
202
 
203
- specify "should support after_rollback outside transactions" do
203
+ it "should support after_rollback outside transactions" do
204
204
  c = nil
205
205
  @db.after_rollback{c = 1}
206
- c.should be_nil
206
+ c.must_equal nil
207
207
  end
208
208
 
209
- specify "should support after_commit inside transactions" do
209
+ it "should support after_commit inside transactions" do
210
210
  c = nil
211
- @db.transaction{@db.after_commit{c = 1}; c.should be_nil}
212
- c.should == 1
211
+ @db.transaction{@db.after_commit{c = 1}; c.must_equal nil}
212
+ c.must_equal 1
213
213
  end
214
214
 
215
- specify "should support after_rollback inside transactions" do
215
+ it "should support after_rollback inside transactions" do
216
216
  c = nil
217
- @db.transaction{@db.after_rollback{c = 1}; c.should be_nil}
218
- c.should be_nil
217
+ @db.transaction{@db.after_rollback{c = 1}; c.must_equal nil}
218
+ c.must_equal nil
219
219
  end
220
220
 
221
- specify "should not call after_commit if the transaction rolls back" do
221
+ it "should not call after_commit if the transaction rolls back" do
222
222
  c = nil
223
- @db.transaction{@db.after_commit{c = 1}; c.should be_nil; raise Sequel::Rollback}
224
- c.should be_nil
223
+ @db.transaction{@db.after_commit{c = 1}; c.must_equal nil; raise Sequel::Rollback}
224
+ c.must_equal nil
225
225
  end
226
226
 
227
- specify "should call after_rollback if the transaction rolls back" do
227
+ it "should call after_rollback if the transaction rolls back" do
228
228
  c = nil
229
- @db.transaction{@db.after_rollback{c = 1}; c.should be_nil; raise Sequel::Rollback}
230
- c.should == 1
229
+ @db.transaction{@db.after_rollback{c = 1}; c.must_equal nil; raise Sequel::Rollback}
230
+ c.must_equal 1
231
231
  end
232
232
 
233
- specify "should support multiple after_commit blocks inside transactions" do
233
+ it "should support multiple after_commit blocks inside transactions" do
234
234
  c = []
235
- @db.transaction{@db.after_commit{c << 1}; @db.after_commit{c << 2}; c.should == []}
236
- c.should == [1, 2]
235
+ @db.transaction{@db.after_commit{c << 1}; @db.after_commit{c << 2}; c.must_equal []}
236
+ c.must_equal [1, 2]
237
237
  end
238
238
 
239
- specify "should support multiple after_rollback blocks inside transactions" do
239
+ it "should support multiple after_rollback blocks inside transactions" do
240
240
  c = []
241
- @db.transaction{@db.after_rollback{c << 1}; @db.after_rollback{c << 2}; c.should == []; raise Sequel::Rollback}
242
- c.should == [1, 2]
241
+ @db.transaction{@db.after_rollback{c << 1}; @db.after_rollback{c << 2}; c.must_equal []; raise Sequel::Rollback}
242
+ c.must_equal [1, 2]
243
243
  end
244
244
 
245
- specify "should support after_commit inside nested transactions" do
245
+ it "should support after_commit inside nested transactions" do
246
246
  c = nil
247
- @db.transaction{@db.transaction{@db.after_commit{c = 1}}; c.should be_nil}
248
- c.should == 1
247
+ @db.transaction{@db.transaction{@db.after_commit{c = 1}}; c.must_equal nil}
248
+ c.must_equal 1
249
249
  end
250
250
 
251
- specify "should support after_rollback inside nested transactions" do
251
+ it "should support after_rollback inside nested transactions" do
252
252
  c = nil
253
- @db.transaction{@db.transaction{@db.after_rollback{c = 1}}; c.should be_nil; raise Sequel::Rollback}
254
- c.should == 1
253
+ @db.transaction{@db.transaction{@db.after_rollback{c = 1}}; c.must_equal nil; raise Sequel::Rollback}
254
+ c.must_equal 1
255
255
  end
256
256
 
257
257
  if DB.supports_savepoints?
258
- specify "should support after_commit inside savepoints" do
258
+ it "should support after_commit inside savepoints" do
259
259
  c = nil
260
- @db.transaction{@db.transaction(:savepoint=>true){@db.after_commit{c = 1}}; c.should be_nil}
261
- c.should == 1
260
+ @db.transaction{@db.transaction(:savepoint=>true){@db.after_commit{c = 1}}; c.must_equal nil}
261
+ c.must_equal 1
262
262
  end
263
263
 
264
- specify "should support after_rollback inside savepoints" do
264
+ it "should support after_rollback inside savepoints" do
265
265
  c = nil
266
- @db.transaction{@db.transaction(:savepoint=>true){@db.after_rollback{c = 1}}; c.should be_nil; raise Sequel::Rollback}
267
- c.should == 1
266
+ @db.transaction{@db.transaction(:savepoint=>true){@db.after_rollback{c = 1}}; c.must_equal nil; raise Sequel::Rollback}
267
+ c.must_equal 1
268
268
  end
269
269
  end
270
270
 
271
271
  if DB.supports_prepared_transactions?
272
- specify "should raise an error if you attempt to use after_commit or after_rollback inside a prepared transaction" do
273
- proc{@db.transaction(:prepare=>'XYZ'){@db.after_commit{}}}.should raise_error(Sequel::Error)
274
- proc{@db.transaction(:prepare=>'XYZ'){@db.after_rollback{}}}.should raise_error(Sequel::Error)
272
+ it "should raise an error if you attempt to use after_commit or after_rollback inside a prepared transaction" do
273
+ proc{@db.transaction(:prepare=>'XYZ'){@db.after_commit{}}}.must_raise(Sequel::Error)
274
+ proc{@db.transaction(:prepare=>'XYZ'){@db.after_rollback{}}}.must_raise(Sequel::Error)
275
275
  end
276
276
 
277
277
  if DB.supports_savepoints_in_prepared_transactions?
278
- specify "should raise an error if you attempt to use after_commit or after rollback inside a savepoint in a prepared transaction" do
279
- proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_commit{}}}}.should raise_error(Sequel::Error)
280
- proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_rollback{}}}}.should raise_error(Sequel::Error)
278
+ it "should raise an error if you attempt to use after_commit or after rollback inside a savepoint in a prepared transaction" do
279
+ proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_commit{}}}}.must_raise(Sequel::Error)
280
+ proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_rollback{}}}}.must_raise(Sequel::Error)
281
281
  end
282
282
  end
283
283
  end
@@ -294,7 +294,7 @@ if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby' or (RUBY_ENGINE == 'rbx' &&
294
294
  @db.drop_table?(:items)
295
295
  end
296
296
 
297
- specify "should handle transactions inside threads" do
297
+ it "should handle transactions inside threads" do
298
298
  q = Queue.new
299
299
  q1 = Queue.new
300
300
  t = Thread.new do
@@ -307,11 +307,11 @@ if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby' or (RUBY_ENGINE == 'rbx' &&
307
307
  end
308
308
  q1.pop
309
309
  t.kill
310
- @d.count.should == 0
310
+ @d.count.must_equal 0
311
311
  end
312
312
 
313
313
  if DB.supports_savepoints?
314
- specify "should handle transactions with savepoints inside threads" do
314
+ it "should handle transactions with savepoints inside threads" do
315
315
  q = Queue.new
316
316
  q1 = Queue.new
317
317
  t = Thread.new do
@@ -328,7 +328,7 @@ if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby' or (RUBY_ENGINE == 'rbx' &&
328
328
  end
329
329
  q1.pop
330
330
  t.kill
331
- @d.count.should == 0
331
+ @d.count.must_equal 0
332
332
  end
333
333
  end
334
334
  end
@@ -355,7 +355,7 @@ describe "Database transaction retrying" do
355
355
  s = s.succ
356
356
  @d.insert(s)
357
357
  end
358
- @d.select_order_map(:a).should == %w'b c d'
358
+ @d.select_order_map(:a).must_equal %w'b c d'
359
359
  end
360
360
 
361
361
  cspecify "should limit number of retries via the :num_retries option", [:db2] do
@@ -367,8 +367,8 @@ describe "Database transaction retrying" do
367
367
  s = s.succ
368
368
  @d.insert(s)
369
369
  end
370
- end.should raise_error(Sequel::ConstraintViolation)
371
- @d.select_order_map(:a).should == %w'b c'
370
+ end.must_raise(Sequel::UniqueConstraintViolation, Sequel::ConstraintViolation)
371
+ @d.select_order_map(:a).must_equal %w'b c'
372
372
  end
373
373
  end
374
374