sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- 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
|
-
|
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
|
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).
|
12
|
-
t2.utc_offset.
|
13
|
-
t2.utc_offset.
|
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).
|
25
|
-
dt2.offset.
|
26
|
-
dt2.offset.
|
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
|
-
|
45
|
+
_test_timezone
|
46
46
|
Sequel.database_timezone = nil
|
47
47
|
@db.timezone = :utc
|
48
|
-
|
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
|
-
|
54
|
+
_test_timezone
|
55
55
|
Sequel.database_timezone = nil
|
56
56
|
@db.timezone = :local
|
57
|
-
|
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
|
-
|
62
|
+
_test_timezone
|
63
63
|
Sequel.database_timezone = :local
|
64
64
|
@db.timezone = :utc
|
65
|
-
|
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
|
-
|
70
|
+
_test_timezone
|
71
71
|
Sequel.database_timezone = :utc
|
72
72
|
@db.timezone = :local
|
73
|
-
|
73
|
+
_test_timezone
|
74
74
|
end
|
75
75
|
|
76
|
-
|
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.
|
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
|
-
|
16
|
+
it "should support transactions" do
|
17
17
|
@db.transaction{@d << {:name => 'abc', :value => 1}}
|
18
|
-
@d.count.
|
18
|
+
@d.count.must_equal 1
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
@db.transaction{|conn| conn.
|
21
|
+
it "should have #transaction yield the connection" do
|
22
|
+
@db.transaction{|conn| conn.wont_equal nil}
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
@db.in_transaction?.
|
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.
|
29
|
+
c.must_equal true
|
30
30
|
end
|
31
31
|
|
32
|
-
|
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.
|
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.
|
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.
|
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.
|
55
|
+
end.must_equal 2
|
56
56
|
|
57
|
-
@d.count.
|
57
|
+
@d.count.must_equal 0
|
58
58
|
end
|
59
59
|
|
60
|
-
|
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.
|
66
|
+
@d.count.must_equal 1
|
67
67
|
|
68
68
|
@d.delete
|
69
|
-
|
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
|
75
|
-
@d.count.
|
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}.
|
83
|
-
@d.count.
|
82
|
+
end}.must_raise(Interrupt)
|
83
|
+
@d.count.must_equal 0
|
84
84
|
end
|
85
85
|
|
86
86
|
if DB.supports_savepoints?
|
87
|
-
|
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).
|
108
|
+
@d.order(:name).map(:name).must_equal %w{1 4 5 6}
|
109
109
|
end
|
110
110
|
|
111
|
-
|
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).
|
132
|
+
@d.order(:name).map(:name).must_equal %w{1 4 5 6}
|
133
133
|
end
|
134
134
|
end
|
135
135
|
|
136
|
-
|
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.
|
144
|
+
@d.count.must_equal 0
|
145
145
|
@db.ret_commit
|
146
|
-
@d.count.
|
146
|
+
@d.count.must_equal 1
|
147
147
|
@db.ret_commit
|
148
|
-
@d.count.
|
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.
|
153
|
+
end.must_raise(Interrupt)
|
154
154
|
|
155
|
-
@d.count.
|
155
|
+
@d.count.must_equal 2
|
156
156
|
end
|
157
157
|
|
158
158
|
if DB.supports_prepared_transactions?
|
159
|
-
|
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).
|
166
|
+
@d.select_order_map(:name).must_equal ['1']
|
167
167
|
end
|
168
168
|
|
169
|
-
|
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).
|
172
|
+
@d.select_order_map(:name).must_equal ['1']
|
173
173
|
end
|
174
174
|
|
175
|
-
|
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).
|
178
|
+
@d.select_order_map(:name).must_equal []
|
179
179
|
end
|
180
180
|
|
181
181
|
if DB.supports_savepoints_in_prepared_transactions?
|
182
|
-
|
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).
|
185
|
+
@d.select_order_map(:name).must_equal ['1']
|
186
186
|
end
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
|
-
|
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.
|
193
|
+
@d.count.must_equal i + 1
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
|
197
|
+
it "should support after_commit outside transactions" do
|
198
198
|
c = nil
|
199
199
|
@db.after_commit{c = 1}
|
200
|
-
c.
|
200
|
+
c.must_equal 1
|
201
201
|
end
|
202
202
|
|
203
|
-
|
203
|
+
it "should support after_rollback outside transactions" do
|
204
204
|
c = nil
|
205
205
|
@db.after_rollback{c = 1}
|
206
|
-
c.
|
206
|
+
c.must_equal nil
|
207
207
|
end
|
208
208
|
|
209
|
-
|
209
|
+
it "should support after_commit inside transactions" do
|
210
210
|
c = nil
|
211
|
-
@db.transaction{@db.after_commit{c = 1}; c.
|
212
|
-
c.
|
211
|
+
@db.transaction{@db.after_commit{c = 1}; c.must_equal nil}
|
212
|
+
c.must_equal 1
|
213
213
|
end
|
214
214
|
|
215
|
-
|
215
|
+
it "should support after_rollback inside transactions" do
|
216
216
|
c = nil
|
217
|
-
@db.transaction{@db.after_rollback{c = 1}; c.
|
218
|
-
c.
|
217
|
+
@db.transaction{@db.after_rollback{c = 1}; c.must_equal nil}
|
218
|
+
c.must_equal nil
|
219
219
|
end
|
220
220
|
|
221
|
-
|
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.
|
224
|
-
c.
|
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
|
-
|
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.
|
230
|
-
c.
|
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
|
-
|
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.
|
236
|
-
c.
|
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
|
-
|
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.
|
242
|
-
c.
|
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
|
-
|
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.
|
248
|
-
c.
|
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
|
-
|
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.
|
254
|
-
c.
|
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
|
-
|
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.
|
261
|
-
c.
|
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
|
-
|
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.
|
267
|
-
c.
|
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
|
-
|
273
|
-
proc{@db.transaction(:prepare=>'XYZ'){@db.after_commit{}}}.
|
274
|
-
proc{@db.transaction(:prepare=>'XYZ'){@db.after_rollback{}}}.
|
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
|
-
|
279
|
-
proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_commit{}}}}.
|
280
|
-
proc{@db.transaction(:prepare=>'XYZ'){@db.transaction(:savepoint=>true){@db.after_rollback{}}}}.
|
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
|
-
|
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.
|
310
|
+
@d.count.must_equal 0
|
311
311
|
end
|
312
312
|
|
313
313
|
if DB.supports_savepoints?
|
314
|
-
|
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.
|
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).
|
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.
|
371
|
-
@d.select_order_map(:a).
|
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
|
|