sequel 5.29.0 → 5.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -1922
- data/doc/release_notes/5.30.0.txt +20 -0
- data/lib/sequel/adapters/shared/sqlite.rb +7 -1
- data/lib/sequel/database/transactions.rb +5 -9
- data/lib/sequel/version.rb +1 -1
- metadata +4 -368
- data/Rakefile +0 -151
- data/doc/release_notes/4.0.0.txt +0 -262
- data/doc/release_notes/4.1.0.txt +0 -85
- data/doc/release_notes/4.10.0.txt +0 -226
- data/doc/release_notes/4.11.0.txt +0 -147
- data/doc/release_notes/4.12.0.txt +0 -105
- data/doc/release_notes/4.13.0.txt +0 -169
- data/doc/release_notes/4.14.0.txt +0 -68
- data/doc/release_notes/4.15.0.txt +0 -56
- data/doc/release_notes/4.16.0.txt +0 -36
- data/doc/release_notes/4.17.0.txt +0 -38
- data/doc/release_notes/4.18.0.txt +0 -36
- data/doc/release_notes/4.19.0.txt +0 -45
- data/doc/release_notes/4.2.0.txt +0 -129
- data/doc/release_notes/4.20.0.txt +0 -79
- data/doc/release_notes/4.21.0.txt +0 -94
- data/doc/release_notes/4.22.0.txt +0 -72
- data/doc/release_notes/4.23.0.txt +0 -65
- data/doc/release_notes/4.24.0.txt +0 -99
- data/doc/release_notes/4.25.0.txt +0 -181
- data/doc/release_notes/4.26.0.txt +0 -44
- data/doc/release_notes/4.27.0.txt +0 -78
- data/doc/release_notes/4.28.0.txt +0 -57
- data/doc/release_notes/4.29.0.txt +0 -41
- data/doc/release_notes/4.3.0.txt +0 -40
- data/doc/release_notes/4.30.0.txt +0 -37
- data/doc/release_notes/4.31.0.txt +0 -57
- data/doc/release_notes/4.32.0.txt +0 -132
- data/doc/release_notes/4.33.0.txt +0 -88
- data/doc/release_notes/4.34.0.txt +0 -86
- data/doc/release_notes/4.35.0.txt +0 -130
- data/doc/release_notes/4.36.0.txt +0 -116
- data/doc/release_notes/4.37.0.txt +0 -50
- data/doc/release_notes/4.38.0.txt +0 -67
- data/doc/release_notes/4.39.0.txt +0 -127
- data/doc/release_notes/4.4.0.txt +0 -92
- data/doc/release_notes/4.40.0.txt +0 -179
- data/doc/release_notes/4.41.0.txt +0 -77
- data/doc/release_notes/4.42.0.txt +0 -221
- data/doc/release_notes/4.43.0.txt +0 -87
- data/doc/release_notes/4.44.0.txt +0 -125
- data/doc/release_notes/4.45.0.txt +0 -370
- data/doc/release_notes/4.46.0.txt +0 -404
- data/doc/release_notes/4.47.0.txt +0 -56
- data/doc/release_notes/4.48.0.txt +0 -293
- data/doc/release_notes/4.49.0.txt +0 -222
- data/doc/release_notes/4.5.0.txt +0 -34
- data/doc/release_notes/4.6.0.txt +0 -30
- data/doc/release_notes/4.7.0.txt +0 -103
- data/doc/release_notes/4.8.0.txt +0 -175
- data/doc/release_notes/4.9.0.txt +0 -190
- data/spec/adapter_spec.rb +0 -4
- data/spec/adapters/db2_spec.rb +0 -170
- data/spec/adapters/mssql_spec.rb +0 -828
- data/spec/adapters/mysql_spec.rb +0 -1060
- data/spec/adapters/oracle_spec.rb +0 -371
- data/spec/adapters/postgres_spec.rb +0 -4476
- data/spec/adapters/spec_helper.rb +0 -44
- data/spec/adapters/sqlanywhere_spec.rb +0 -97
- data/spec/adapters/sqlite_spec.rb +0 -652
- data/spec/bin_spec.rb +0 -278
- data/spec/core/connection_pool_spec.rb +0 -1250
- data/spec/core/database_spec.rb +0 -2915
- data/spec/core/dataset_spec.rb +0 -5544
- data/spec/core/deprecated_spec.rb +0 -70
- data/spec/core/expression_filters_spec.rb +0 -1498
- data/spec/core/mock_adapter_spec.rb +0 -722
- data/spec/core/object_graph_spec.rb +0 -336
- data/spec/core/placeholder_literalizer_spec.rb +0 -166
- data/spec/core/schema_generator_spec.rb +0 -214
- data/spec/core/schema_spec.rb +0 -1844
- data/spec/core/spec_helper.rb +0 -24
- data/spec/core/version_spec.rb +0 -14
- data/spec/core_extensions_spec.rb +0 -763
- data/spec/core_model_spec.rb +0 -2
- data/spec/core_spec.rb +0 -1
- data/spec/deprecation_helper.rb +0 -30
- data/spec/extensions/accessed_columns_spec.rb +0 -51
- data/spec/extensions/active_model_spec.rb +0 -99
- data/spec/extensions/after_initialize_spec.rb +0 -28
- data/spec/extensions/any_not_empty_spec.rb +0 -23
- data/spec/extensions/arbitrary_servers_spec.rb +0 -109
- data/spec/extensions/association_dependencies_spec.rb +0 -125
- data/spec/extensions/association_multi_add_remove_spec.rb +0 -1041
- data/spec/extensions/association_pks_spec.rb +0 -423
- data/spec/extensions/association_proxies_spec.rb +0 -100
- data/spec/extensions/auto_literal_strings_spec.rb +0 -205
- data/spec/extensions/auto_validations_spec.rb +0 -229
- data/spec/extensions/blacklist_security_spec.rb +0 -95
- data/spec/extensions/blank_spec.rb +0 -69
- data/spec/extensions/boolean_readers_spec.rb +0 -93
- data/spec/extensions/boolean_subsets_spec.rb +0 -47
- data/spec/extensions/caching_spec.rb +0 -273
- data/spec/extensions/caller_logging_spec.rb +0 -52
- data/spec/extensions/class_table_inheritance_spec.rb +0 -750
- data/spec/extensions/column_conflicts_spec.rb +0 -75
- data/spec/extensions/column_select_spec.rb +0 -129
- data/spec/extensions/columns_introspection_spec.rb +0 -90
- data/spec/extensions/columns_updated_spec.rb +0 -35
- data/spec/extensions/composition_spec.rb +0 -248
- data/spec/extensions/connection_expiration_spec.rb +0 -151
- data/spec/extensions/connection_validator_spec.rb +0 -144
- data/spec/extensions/constant_sql_override_spec.rb +0 -24
- data/spec/extensions/constraint_validations_plugin_spec.rb +0 -300
- data/spec/extensions/constraint_validations_spec.rb +0 -439
- data/spec/extensions/core_refinements_spec.rb +0 -528
- data/spec/extensions/csv_serializer_spec.rb +0 -183
- data/spec/extensions/current_datetime_timestamp_spec.rb +0 -27
- data/spec/extensions/dataset_associations_spec.rb +0 -365
- data/spec/extensions/dataset_source_alias_spec.rb +0 -51
- data/spec/extensions/date_arithmetic_spec.rb +0 -181
- data/spec/extensions/datetime_parse_to_time_spec.rb +0 -169
- data/spec/extensions/def_dataset_method_spec.rb +0 -100
- data/spec/extensions/defaults_setter_spec.rb +0 -150
- data/spec/extensions/delay_add_association_spec.rb +0 -73
- data/spec/extensions/dirty_spec.rb +0 -222
- data/spec/extensions/duplicate_columns_handler_spec.rb +0 -104
- data/spec/extensions/eager_each_spec.rb +0 -62
- data/spec/extensions/eager_graph_eager_spec.rb +0 -100
- data/spec/extensions/empty_array_consider_nulls_spec.rb +0 -24
- data/spec/extensions/empty_failure_backtraces_spec.rb +0 -60
- data/spec/extensions/error_splitter_spec.rb +0 -18
- data/spec/extensions/error_sql_spec.rb +0 -20
- data/spec/extensions/escaped_like_spec.rb +0 -40
- data/spec/extensions/eval_inspect_spec.rb +0 -81
- data/spec/extensions/exclude_or_null_spec.rb +0 -15
- data/spec/extensions/finder_spec.rb +0 -260
- data/spec/extensions/force_encoding_spec.rb +0 -126
- data/spec/extensions/freeze_datasets_spec.rb +0 -31
- data/spec/extensions/graph_each_spec.rb +0 -113
- data/spec/extensions/hook_class_methods_spec.rb +0 -402
- data/spec/extensions/identifier_mangling_spec.rb +0 -201
- data/spec/extensions/implicit_subquery_spec.rb +0 -58
- data/spec/extensions/index_caching_spec.rb +0 -66
- data/spec/extensions/inflector_spec.rb +0 -183
- data/spec/extensions/input_transformer_spec.rb +0 -69
- data/spec/extensions/insert_conflict_spec.rb +0 -103
- data/spec/extensions/insert_returning_select_spec.rb +0 -72
- data/spec/extensions/instance_filters_spec.rb +0 -79
- data/spec/extensions/instance_hooks_spec.rb +0 -246
- data/spec/extensions/integer64_spec.rb +0 -22
- data/spec/extensions/inverted_subsets_spec.rb +0 -33
- data/spec/extensions/json_serializer_spec.rb +0 -346
- data/spec/extensions/lazy_attributes_spec.rb +0 -183
- data/spec/extensions/list_spec.rb +0 -291
- data/spec/extensions/looser_typecasting_spec.rb +0 -43
- data/spec/extensions/many_through_many_spec.rb +0 -2177
- data/spec/extensions/migration_spec.rb +0 -864
- data/spec/extensions/modification_detection_spec.rb +0 -93
- data/spec/extensions/mssql_optimistic_locking_spec.rb +0 -92
- data/spec/extensions/named_timezones_spec.rb +0 -218
- data/spec/extensions/nested_attributes_spec.rb +0 -815
- data/spec/extensions/null_dataset_spec.rb +0 -85
- data/spec/extensions/optimistic_locking_spec.rb +0 -127
- data/spec/extensions/pagination_spec.rb +0 -116
- data/spec/extensions/pg_array_associations_spec.rb +0 -802
- data/spec/extensions/pg_array_ops_spec.rb +0 -144
- data/spec/extensions/pg_array_spec.rb +0 -398
- data/spec/extensions/pg_auto_constraint_validations_spec.rb +0 -209
- data/spec/extensions/pg_enum_spec.rb +0 -118
- data/spec/extensions/pg_extended_date_support_spec.rb +0 -126
- data/spec/extensions/pg_hstore_ops_spec.rb +0 -238
- data/spec/extensions/pg_hstore_spec.rb +0 -219
- data/spec/extensions/pg_inet_ops_spec.rb +0 -102
- data/spec/extensions/pg_inet_spec.rb +0 -72
- data/spec/extensions/pg_interval_spec.rb +0 -103
- data/spec/extensions/pg_json_ops_spec.rb +0 -356
- data/spec/extensions/pg_json_spec.rb +0 -451
- data/spec/extensions/pg_loose_count_spec.rb +0 -23
- data/spec/extensions/pg_range_ops_spec.rb +0 -60
- data/spec/extensions/pg_range_spec.rb +0 -600
- data/spec/extensions/pg_row_ops_spec.rb +0 -61
- data/spec/extensions/pg_row_plugin_spec.rb +0 -60
- data/spec/extensions/pg_row_spec.rb +0 -363
- data/spec/extensions/pg_static_cache_updater_spec.rb +0 -93
- data/spec/extensions/pg_timestamptz_spec.rb +0 -17
- data/spec/extensions/prepared_statements_safe_spec.rb +0 -66
- data/spec/extensions/prepared_statements_spec.rb +0 -177
- data/spec/extensions/pretty_table_spec.rb +0 -123
- data/spec/extensions/query_spec.rb +0 -94
- data/spec/extensions/rcte_tree_spec.rb +0 -387
- data/spec/extensions/round_timestamps_spec.rb +0 -39
- data/spec/extensions/s_spec.rb +0 -60
- data/spec/extensions/schema_caching_spec.rb +0 -64
- data/spec/extensions/schema_dumper_spec.rb +0 -870
- data/spec/extensions/select_remove_spec.rb +0 -38
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +0 -121
- data/spec/extensions/serialization_modification_detection_spec.rb +0 -98
- data/spec/extensions/serialization_spec.rb +0 -365
- data/spec/extensions/server_block_spec.rb +0 -135
- data/spec/extensions/server_logging_spec.rb +0 -45
- data/spec/extensions/sharding_spec.rb +0 -197
- data/spec/extensions/shared_caching_spec.rb +0 -151
- data/spec/extensions/single_table_inheritance_spec.rb +0 -347
- data/spec/extensions/singular_table_names_spec.rb +0 -22
- data/spec/extensions/skip_create_refresh_spec.rb +0 -18
- data/spec/extensions/spec_helper.rb +0 -70
- data/spec/extensions/split_array_nil_spec.rb +0 -24
- data/spec/extensions/split_values_spec.rb +0 -57
- data/spec/extensions/sql_comments_spec.rb +0 -33
- data/spec/extensions/sql_expr_spec.rb +0 -59
- data/spec/extensions/static_cache_cache_spec.rb +0 -35
- data/spec/extensions/static_cache_spec.rb +0 -471
- data/spec/extensions/string_agg_spec.rb +0 -90
- data/spec/extensions/string_date_time_spec.rb +0 -95
- data/spec/extensions/string_stripper_spec.rb +0 -68
- data/spec/extensions/subclasses_spec.rb +0 -79
- data/spec/extensions/subset_conditions_spec.rb +0 -38
- data/spec/extensions/symbol_aref_refinement_spec.rb +0 -28
- data/spec/extensions/symbol_as_refinement_spec.rb +0 -21
- data/spec/extensions/synchronize_sql_spec.rb +0 -124
- data/spec/extensions/table_select_spec.rb +0 -83
- data/spec/extensions/tactical_eager_loading_spec.rb +0 -402
- data/spec/extensions/thread_local_timezones_spec.rb +0 -67
- data/spec/extensions/throw_failures_spec.rb +0 -74
- data/spec/extensions/timestamps_spec.rb +0 -209
- data/spec/extensions/to_dot_spec.rb +0 -153
- data/spec/extensions/touch_spec.rb +0 -226
- data/spec/extensions/tree_spec.rb +0 -334
- data/spec/extensions/typecast_on_load_spec.rb +0 -86
- data/spec/extensions/unlimited_update_spec.rb +0 -21
- data/spec/extensions/update_or_create_spec.rb +0 -83
- data/spec/extensions/update_primary_key_spec.rb +0 -105
- data/spec/extensions/update_refresh_spec.rb +0 -59
- data/spec/extensions/uuid_spec.rb +0 -101
- data/spec/extensions/validate_associated_spec.rb +0 -52
- data/spec/extensions/validation_class_methods_spec.rb +0 -1040
- data/spec/extensions/validation_contexts_spec.rb +0 -31
- data/spec/extensions/validation_helpers_spec.rb +0 -525
- data/spec/extensions/whitelist_security_spec.rb +0 -157
- data/spec/extensions/xml_serializer_spec.rb +0 -213
- data/spec/files/bad_down_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_down_migration/002_create_alt_advanced.rb +0 -4
- data/spec/files/bad_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/bad_timestamped_migrations/1273253853_3_create_users.rb +0 -3
- data/spec/files/bad_up_migration/001_create_alt_basic.rb +0 -4
- data/spec/files/bad_up_migration/002_create_alt_advanced.rb +0 -3
- data/spec/files/convert_to_timestamp_migrations/001_create_sessions.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/002_create_nodes.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/003_3_create_users.rb +0 -4
- data/spec/files/convert_to_timestamp_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/convert_to_timestamp_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/double_migration/001_create_sessions.rb +0 -9
- data/spec/files/double_migration/002_create_nodes.rb +0 -19
- data/spec/files/double_migration/003_3_create_users.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_advanced.rb +0 -4
- data/spec/files/duplicate_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/duplicate_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_nodes.rb +0 -9
- data/spec/files/duplicate_timestamped_migrations/1273253853_create_users.rb +0 -4
- data/spec/files/empty_migration/001_create_sessions.rb +0 -9
- data/spec/files/empty_migration/002_create_nodes.rb +0 -0
- data/spec/files/empty_migration/003_3_create_users.rb +0 -4
- data/spec/files/integer_migrations/001_create_sessions.rb +0 -9
- data/spec/files/integer_migrations/002_create_nodes.rb +0 -9
- data/spec/files/integer_migrations/003_3_create_users.rb +0 -4
- data/spec/files/interleaved_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253850_create_artists.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253852_create_albums.rb +0 -9
- data/spec/files/interleaved_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/missing_integer_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/missing_integer_migrations/003_create_alt_advanced.rb +0 -4
- data/spec/files/missing_timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/missing_timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/reversible_migrations/001_reversible.rb +0 -5
- data/spec/files/reversible_migrations/002_reversible.rb +0 -5
- data/spec/files/reversible_migrations/003_reversible.rb +0 -5
- data/spec/files/reversible_migrations/004_reversible.rb +0 -5
- data/spec/files/reversible_migrations/005_reversible.rb +0 -10
- data/spec/files/reversible_migrations/006_reversible.rb +0 -10
- data/spec/files/reversible_migrations/007_reversible.rb +0 -10
- data/spec/files/timestamped_migrations/1273253849_create_sessions.rb +0 -9
- data/spec/files/timestamped_migrations/1273253851_create_nodes.rb +0 -9
- data/spec/files/timestamped_migrations/1273253853_3_create_users.rb +0 -4
- data/spec/files/transaction_specified_migrations/001_create_alt_basic.rb +0 -4
- data/spec/files/transaction_specified_migrations/002_create_basic.rb +0 -4
- data/spec/files/transaction_unspecified_migrations/001_create_alt_basic.rb +0 -3
- data/spec/files/transaction_unspecified_migrations/002_create_basic.rb +0 -3
- data/spec/files/uppercase_timestamped_migrations/1273253849_CREATE_SESSIONS.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253851_CREATE_NODES.RB +0 -9
- data/spec/files/uppercase_timestamped_migrations/1273253853_3_CREATE_USERS.RB +0 -4
- data/spec/guards_helper.rb +0 -59
- data/spec/integration/associations_test.rb +0 -2597
- data/spec/integration/database_test.rb +0 -113
- data/spec/integration/dataset_test.rb +0 -2037
- data/spec/integration/eager_loader_test.rb +0 -687
- data/spec/integration/migrator_test.rb +0 -262
- data/spec/integration/model_test.rb +0 -203
- data/spec/integration/plugin_test.rb +0 -2423
- data/spec/integration/prepared_statement_test.rb +0 -405
- data/spec/integration/schema_test.rb +0 -903
- data/spec/integration/spec_helper.rb +0 -71
- data/spec/integration/timezone_test.rb +0 -86
- data/spec/integration/transaction_test.rb +0 -603
- data/spec/integration/type_test.rb +0 -127
- data/spec/model/association_reflection_spec.rb +0 -803
- data/spec/model/associations_spec.rb +0 -4738
- data/spec/model/base_spec.rb +0 -875
- data/spec/model/class_dataset_methods_spec.rb +0 -146
- data/spec/model/dataset_methods_spec.rb +0 -198
- data/spec/model/eager_loading_spec.rb +0 -2377
- data/spec/model/hooks_spec.rb +0 -370
- data/spec/model/inflector_spec.rb +0 -26
- data/spec/model/model_spec.rb +0 -956
- data/spec/model/plugins_spec.rb +0 -429
- data/spec/model/record_spec.rb +0 -2118
- data/spec/model/spec_helper.rb +0 -46
- data/spec/model/validations_spec.rb +0 -220
- data/spec/model_no_assoc_spec.rb +0 -1
- data/spec/model_spec.rb +0 -1
- data/spec/plugin_spec.rb +0 -1
- data/spec/sequel_coverage.rb +0 -15
- data/spec/sequel_warning.rb +0 -5
- data/spec/spec_config.rb +0 -12
@@ -1,722 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Sequel Mock Adapter" do
|
4
|
-
it "should have an adapter method" do
|
5
|
-
db = Sequel.mock
|
6
|
-
db.must_be_kind_of(Sequel::Mock::Database)
|
7
|
-
db.adapter_scheme.must_equal :mock
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should support registering mock adapter type" do
|
11
|
-
begin
|
12
|
-
Module.new do
|
13
|
-
Sequel::Database.set_shared_adapter_scheme(:foo, self)
|
14
|
-
|
15
|
-
def self.mock_adapter_setup(db)
|
16
|
-
db.instance_variable_set(:@foo, :foo)
|
17
|
-
end
|
18
|
-
|
19
|
-
module self::DatabaseMethods
|
20
|
-
def foo
|
21
|
-
@foo
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module self::DatasetMethods
|
26
|
-
def foo
|
27
|
-
db.foo
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
Sequel.connect('mock://foo') do |db|
|
33
|
-
db.foo.must_equal :foo
|
34
|
-
db.dataset.foo.must_equal :foo
|
35
|
-
end
|
36
|
-
ensure
|
37
|
-
Sequel.synchronize{Sequel::SHARED_ADAPTER_MAP.delete(:foo)}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should have constructor accept no arguments" do
|
42
|
-
Sequel.require 'adapters/mock'
|
43
|
-
Sequel::Mock::Database.new.must_be_kind_of(Sequel::Mock::Database)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should each not return any rows by default" do
|
47
|
-
called = false
|
48
|
-
Sequel.mock[:t].each{|r| called = true}
|
49
|
-
called.must_equal false
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should return 0 for update/delete/with_sql_delete/execute_dui by default" do
|
53
|
-
Sequel.mock[:t].update(:a=>1).must_equal 0
|
54
|
-
Sequel.mock[:t].delete.must_equal 0
|
55
|
-
Sequel.mock[:t].with_sql_delete('DELETE FROM t').must_equal 0
|
56
|
-
Sequel.mock.execute_dui('DELETE FROM t').must_equal 0
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should return nil for insert/execute_insert by default" do
|
60
|
-
Sequel.mock[:t].insert(:a=>1).must_be_nil
|
61
|
-
Sequel.mock.execute_insert('INSERT INTO a () DEFAULT VALUES').must_be_nil
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should be able to set the rows returned by each using :fetch option with a single hash" do
|
65
|
-
rs = []
|
66
|
-
db = Sequel.mock(:fetch=>{:a=>1})
|
67
|
-
db[:t].each{|r| rs << r}
|
68
|
-
rs.must_equal [{:a=>1}]
|
69
|
-
db[:t].each{|r| rs << r}
|
70
|
-
rs.must_equal [{:a=>1}, {:a=>1}]
|
71
|
-
db[:t].each{|r| r[:a] = 2; rs << r}
|
72
|
-
rs.must_equal [{:a=>1}, {:a=>1}, {:a=>2}]
|
73
|
-
db[:t].each{|r| rs << r}
|
74
|
-
rs.must_equal [{:a=>1}, {:a=>1}, {:a=>2}, {:a=>1}]
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should be able to set the rows returned by each using :fetch option with an array of hashes" do
|
78
|
-
rs = []
|
79
|
-
db = Sequel.mock(:fetch=>[{:a=>1}, {:a=>2}])
|
80
|
-
db[:t].each{|r| rs << r}
|
81
|
-
rs.must_equal [{:a=>1}, {:a=>2}]
|
82
|
-
db[:t].each{|r| rs << r}
|
83
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>1}, {:a=>2}]
|
84
|
-
db[:t].each{|r| r[:a] += 2; rs << r}
|
85
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>1}, {:a=>2}, {:a=>3}, {:a=>4}]
|
86
|
-
db[:t].each{|r| rs << r}
|
87
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>1}, {:a=>2}, {:a=>3}, {:a=>4}, {:a=>1}, {:a=>2}]
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should be able to set the rows returned by each using :fetch option with an array or arrays of hashes" do
|
91
|
-
rs = []
|
92
|
-
db = Sequel.mock(:fetch=>[[{:a=>1}, {:a=>2}], [{:a=>3}, {:a=>4}]])
|
93
|
-
db[:t].each{|r| rs << r}
|
94
|
-
rs.must_equal [{:a=>1}, {:a=>2}]
|
95
|
-
db[:t].each{|r| rs << r}
|
96
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>3}, {:a=>4}]
|
97
|
-
db[:t].each{|r| rs << r}
|
98
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>3}, {:a=>4}]
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should be able to set the rows returned by each using :fetch option with a proc that takes sql" do
|
102
|
-
rs = []
|
103
|
-
db = Sequel.mock(:fetch=>proc{|sql| sql =~ /FROM t/ ? {:b=>1} : [{:a=>1}, {:a=>2}]})
|
104
|
-
db[:t].each{|r| rs << r}
|
105
|
-
rs.must_equal [{:b=>1}]
|
106
|
-
db[:b].each{|r| rs << r}
|
107
|
-
rs.must_equal [{:b=>1}, {:a=>1}, {:a=>2}]
|
108
|
-
db[:t].each{|r| r[:b] += 1; rs << r}
|
109
|
-
db[:b].each{|r| r[:a] += 2; rs << r}
|
110
|
-
rs.must_equal [{:b=>1}, {:a=>1}, {:a=>2}, {:b=>2}, {:a=>3}, {:a=>4}]
|
111
|
-
db[:t].each{|r| rs << r}
|
112
|
-
db[:b].each{|r| rs << r}
|
113
|
-
rs.must_equal [{:b=>1}, {:a=>1}, {:a=>2}, {:b=>2}, {:a=>3}, {:a=>4}, {:b=>1}, {:a=>1}, {:a=>2}]
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should have a fetch= method for setting rows returned by each after the fact" do
|
117
|
-
rs = []
|
118
|
-
db = Sequel.mock
|
119
|
-
db.fetch = {:a=>1}
|
120
|
-
db[:t].each{|r| rs << r}
|
121
|
-
rs.must_equal [{:a=>1}]
|
122
|
-
db[:t].each{|r| rs << r}
|
123
|
-
rs.must_equal [{:a=>1}] * 2
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should be able to set an exception to raise by setting the :fetch option to an exception class " do
|
127
|
-
db = Sequel.mock(:fetch=>ArgumentError)
|
128
|
-
proc{db[:t].all}.must_raise(Sequel::DatabaseError)
|
129
|
-
begin
|
130
|
-
db[:t].all
|
131
|
-
rescue => e
|
132
|
-
end
|
133
|
-
e.must_be_kind_of(Sequel::DatabaseError)
|
134
|
-
e.wrapped_exception.must_be_kind_of(ArgumentError)
|
135
|
-
end
|
136
|
-
|
137
|
-
it "should be able to set separate kinds of results for fetch using an array" do
|
138
|
-
rs = []
|
139
|
-
db = Sequel.mock(:fetch=>[{:a=>1}, [{:a=>2}, {:a=>3}], proc{|s| {:a=>4}}, proc{|s| }, nil, ArgumentError])
|
140
|
-
db[:t].each{|r| rs << r}
|
141
|
-
rs.must_equal [{:a=>1}]
|
142
|
-
db[:t].each{|r| rs << r}
|
143
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>3}]
|
144
|
-
db[:t].each{|r| rs << r}
|
145
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>3}, {:a=>4}]
|
146
|
-
db[:t].each{|r| rs << r}
|
147
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>3}, {:a=>4}]
|
148
|
-
db[:t].each{|r| rs << r}
|
149
|
-
rs.must_equal [{:a=>1}, {:a=>2}, {:a=>3}, {:a=>4}]
|
150
|
-
proc{db[:t].all}.must_raise(Sequel::DatabaseError)
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should be able to set the rows returned by each on a per dataset basis using with_fetch" do
|
154
|
-
rs = []
|
155
|
-
db = Sequel.mock(:fetch=>{:a=>1})
|
156
|
-
ds = db[:t]
|
157
|
-
ds.each{|r| rs << r}
|
158
|
-
rs.must_equal [{:a=>1}]
|
159
|
-
ds = ds.with_fetch(:b=>2)
|
160
|
-
ds.each{|r| rs << r}
|
161
|
-
rs.must_equal [{:a=>1}, {:b=>2}]
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should raise Error if given an invalid object to fetch" do
|
165
|
-
proc{Sequel.mock(:fetch=>Class.new).get(:a)}.must_raise(Sequel::DatabaseError)
|
166
|
-
proc{Sequel.mock(:fetch=>Object.new).get(:a)}.must_raise(Sequel::DatabaseError)
|
167
|
-
end
|
168
|
-
|
169
|
-
it "should be able to set the number of rows modified by update and delete using :numrows option as an integer" do
|
170
|
-
db = Sequel.mock(:numrows=>2)
|
171
|
-
db[:t].update(:a=>1).must_equal 2
|
172
|
-
db[:t].delete.must_equal 2
|
173
|
-
db[:t].update(:a=>1).must_equal 2
|
174
|
-
db[:t].delete.must_equal 2
|
175
|
-
end
|
176
|
-
|
177
|
-
it "should be able to set the number of rows modified by update and delete using :numrows option as an array of integers" do
|
178
|
-
db = Sequel.mock(:numrows=>[2, 1])
|
179
|
-
db[:t].update(:a=>1).must_equal 2
|
180
|
-
db[:t].delete.must_equal 1
|
181
|
-
db[:t].update(:a=>1).must_equal 0
|
182
|
-
db[:t].delete.must_equal 0
|
183
|
-
end
|
184
|
-
|
185
|
-
it "should be able to set the number of rows modified by update and delete using :numrows option as a proc" do
|
186
|
-
db = Sequel.mock(:numrows=>proc{|sql| sql =~ / t/ ? 2 : 1})
|
187
|
-
db[:t].update(:a=>1).must_equal 2
|
188
|
-
db[:t].delete.must_equal 2
|
189
|
-
db[:b].update(:a=>1).must_equal 1
|
190
|
-
db[:b].delete.must_equal 1
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should be able to set an exception to raise by setting the :numrows option to an exception class " do
|
194
|
-
db = Sequel.mock(:numrows=>ArgumentError)
|
195
|
-
proc{db[:t].update(:a=>1)}.must_raise(Sequel::DatabaseError)
|
196
|
-
begin
|
197
|
-
db[:t].delete
|
198
|
-
rescue => e
|
199
|
-
end
|
200
|
-
e.must_be_kind_of(Sequel::DatabaseError)
|
201
|
-
e.wrapped_exception.must_be_kind_of(ArgumentError)
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should be able to set separate kinds of results for numrows using an array" do
|
205
|
-
db = Sequel.mock(:numrows=>[1, proc{|s| 2}, nil, ArgumentError])
|
206
|
-
db[:t].delete.must_equal 1
|
207
|
-
db[:t].update(:a=>1).must_equal 2
|
208
|
-
db[:t].delete.must_equal 0
|
209
|
-
proc{db[:t].delete}.must_raise(Sequel::DatabaseError)
|
210
|
-
end
|
211
|
-
|
212
|
-
it "should have a numrows= method to set the number of rows modified by update and delete after the fact" do
|
213
|
-
db = Sequel.mock
|
214
|
-
db.numrows = 2
|
215
|
-
db[:t].update(:a=>1).must_equal 2
|
216
|
-
db[:t].delete.must_equal 2
|
217
|
-
db[:t].update(:a=>1).must_equal 2
|
218
|
-
db[:t].delete.must_equal 2
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should be able to set the number of rows modified by update and delete on a per dataset basis" do
|
222
|
-
db = Sequel.mock(:numrows=>2)
|
223
|
-
ds = db[:t]
|
224
|
-
ds.update(:a=>1).must_equal 2
|
225
|
-
ds.delete.must_equal 2
|
226
|
-
ds = ds.with_numrows(3)
|
227
|
-
ds.update(:a=>1).must_equal 3
|
228
|
-
ds.delete.must_equal 3
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should raise Error if given an invalid object for numrows or autoid" do
|
232
|
-
proc{Sequel.mock(:numrows=>Class.new)[:a].delete}.must_raise(Sequel::DatabaseError)
|
233
|
-
proc{Sequel.mock(:numrows=>Object.new)[:a].delete}.must_raise(Sequel::DatabaseError)
|
234
|
-
proc{Sequel.mock(:autoid=>Class.new)[:a].insert}.must_raise(Sequel::DatabaseError)
|
235
|
-
proc{Sequel.mock(:autoid=>Object.new)[:a].insert}.must_raise(Sequel::DatabaseError)
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should be able to set the autogenerated primary key returned by insert using :autoid option as an integer" do
|
239
|
-
db = Sequel.mock(:autoid=>1)
|
240
|
-
db[:t].insert(:a=>1).must_equal 1
|
241
|
-
db[:t].insert(:a=>1).must_equal 2
|
242
|
-
db[:t].insert(:a=>1).must_equal 3
|
243
|
-
end
|
244
|
-
|
245
|
-
it "should be able to set the autogenerated primary key returned by insert using :autoid option as an array of integers" do
|
246
|
-
db = Sequel.mock(:autoid=>[1, 3, 5])
|
247
|
-
db[:t].insert(:a=>1).must_equal 1
|
248
|
-
db[:t].insert(:a=>1).must_equal 3
|
249
|
-
db[:t].insert(:a=>1).must_equal 5
|
250
|
-
db[:t].insert(:a=>1).must_be_nil
|
251
|
-
end
|
252
|
-
|
253
|
-
it "should be able to set the autogenerated primary key returned by insert using :autoid option as a proc" do
|
254
|
-
db = Sequel.mock(:autoid=>proc{|sql| sql =~ /INTO t / ? 2 : 1})
|
255
|
-
db[:t].insert(:a=>1).must_equal 2
|
256
|
-
db[:t].insert(:a=>1).must_equal 2
|
257
|
-
db[:b].insert(:a=>1).must_equal 1
|
258
|
-
db[:b].insert(:a=>1).must_equal 1
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should be able to set an exception to raise by setting the :autoid option to an exception class " do
|
262
|
-
db = Sequel.mock(:autoid=>ArgumentError)
|
263
|
-
proc{db[:t].insert(:a=>1)}.must_raise(Sequel::DatabaseError)
|
264
|
-
begin
|
265
|
-
db[:t].insert
|
266
|
-
rescue => e
|
267
|
-
end
|
268
|
-
e.must_be_kind_of(Sequel::DatabaseError)
|
269
|
-
e.wrapped_exception.must_be_kind_of(ArgumentError)
|
270
|
-
end
|
271
|
-
|
272
|
-
it "should be able to set separate kinds of results for autoid using an array" do
|
273
|
-
db = Sequel.mock(:autoid=>[1, proc{|s| 2}, nil, ArgumentError])
|
274
|
-
db[:t].insert.must_equal 1
|
275
|
-
db[:t].insert.must_equal 2
|
276
|
-
db[:t].insert.must_be_nil
|
277
|
-
proc{db[:t].insert}.must_raise(Sequel::DatabaseError)
|
278
|
-
end
|
279
|
-
|
280
|
-
it "should have an autoid= method to set the autogenerated primary key returned by insert after the fact" do
|
281
|
-
db = Sequel.mock
|
282
|
-
db.autoid = 1
|
283
|
-
db[:t].insert(:a=>1).must_equal 1
|
284
|
-
db[:t].insert(:a=>1).must_equal 2
|
285
|
-
db[:t].insert(:a=>1).must_equal 3
|
286
|
-
end
|
287
|
-
|
288
|
-
it "should be able to set the autogenerated primary key returned by insert on a per dataset basis" do
|
289
|
-
db = Sequel.mock(:autoid=>1)
|
290
|
-
ds = db[:t]
|
291
|
-
ds.insert(:a=>1).must_equal 1
|
292
|
-
ds = ds.with_autoid(5)
|
293
|
-
ds.insert(:a=>1).must_equal 5
|
294
|
-
ds.insert(:a=>1).must_equal 6
|
295
|
-
db[:t].insert(:a=>1).must_equal 2
|
296
|
-
end
|
297
|
-
|
298
|
-
it "should be able to set the columns to set in the dataset as an array of symbols" do
|
299
|
-
db = Sequel.mock(:columns=>[:a, :b])
|
300
|
-
db[:t].columns.must_equal [:a, :b]
|
301
|
-
db.sqls.must_equal ["SELECT * FROM t LIMIT 1"]
|
302
|
-
ds = db[:t]
|
303
|
-
ds.all
|
304
|
-
db.sqls.must_equal ["SELECT * FROM t"]
|
305
|
-
ds.columns.must_equal [:a, :b]
|
306
|
-
db.sqls.must_equal []
|
307
|
-
db[:t].columns.must_equal [:a, :b]
|
308
|
-
end
|
309
|
-
|
310
|
-
it "should be able to set the columns to set in the dataset as an array of arrays of symbols" do
|
311
|
-
db = Sequel.mock(:columns=>[[:a, :b], [:c, :d]])
|
312
|
-
db[:t].columns.must_equal [:a, :b]
|
313
|
-
db[:x].columns.must_equal [:c, :d]
|
314
|
-
end
|
315
|
-
|
316
|
-
it "should be able to set the columns to set in the dataset as a proc" do
|
317
|
-
db = Sequel.mock(:columns=>proc{|sql| (sql =~ / t/) ? [:a, :b] : [:c, :d]})
|
318
|
-
db[:b].columns.must_equal [:c, :d]
|
319
|
-
db[:t].columns.must_equal [:a, :b]
|
320
|
-
end
|
321
|
-
|
322
|
-
it "should have a columns= method to set the columns to set after the fact" do
|
323
|
-
db = Sequel.mock
|
324
|
-
db.columns = [[:a, :b], [:c, :d]]
|
325
|
-
db[:t].columns.must_equal [:a, :b]
|
326
|
-
db[:x].columns.must_equal [:c, :d]
|
327
|
-
end
|
328
|
-
|
329
|
-
it "should raise Error if given an invalid columns" do
|
330
|
-
proc{Sequel.mock(:columns=>Object.new)[:a].columns}.must_raise(Sequel::DatabaseError)
|
331
|
-
end
|
332
|
-
|
333
|
-
it "should not quote identifiers by default" do
|
334
|
-
Sequel.mock.send(:quote_identifiers_default).must_equal false
|
335
|
-
end
|
336
|
-
|
337
|
-
it "should allow overriding of server_version" do
|
338
|
-
db = Sequel.mock
|
339
|
-
db.server_version.must_be_nil
|
340
|
-
db.server_version = 80102
|
341
|
-
db.server_version.must_equal 80102
|
342
|
-
end
|
343
|
-
|
344
|
-
it "should not fold to uppercase by default" do
|
345
|
-
Sequel.mock.send(:folds_unquoted_identifiers_to_uppercase?).must_equal false
|
346
|
-
end
|
347
|
-
|
348
|
-
it "should keep a record of all executed SQL in #sqls" do
|
349
|
-
db = Sequel.mock
|
350
|
-
db[:t].all
|
351
|
-
db[:b].delete
|
352
|
-
db[:c].insert(:a=>1)
|
353
|
-
db[:d].update(:a=>1)
|
354
|
-
db.sqls.must_equal ['SELECT * FROM t', 'DELETE FROM b', 'INSERT INTO c (a) VALUES (1)', 'UPDATE d SET a = 1']
|
355
|
-
end
|
356
|
-
|
357
|
-
it "should clear sqls on retrieval" do
|
358
|
-
db = Sequel.mock
|
359
|
-
db[:t].all
|
360
|
-
db.sqls.must_equal ['SELECT * FROM t']
|
361
|
-
db.sqls.must_equal []
|
362
|
-
end
|
363
|
-
|
364
|
-
it "should also log SQL executed to the given loggers" do
|
365
|
-
a = []
|
366
|
-
def a.method_missing(m, *x) push(*x) end
|
367
|
-
db = Sequel.mock(:loggers=>[a])
|
368
|
-
db[:t].all
|
369
|
-
db[:b].delete
|
370
|
-
db[:c].insert(:a=>1)
|
371
|
-
db[:d].update(:a=>1)
|
372
|
-
a.zip(['SELECT * FROM t', 'DELETE FROM b', 'INSERT INTO c (a) VALUES (1)', 'UPDATE d SET a = 1']).each do |is, should|
|
373
|
-
is.must_match should
|
374
|
-
end
|
375
|
-
end
|
376
|
-
|
377
|
-
it "should correctly handle transactions" do
|
378
|
-
db = Sequel.mock
|
379
|
-
db.transaction{db[:a].all}
|
380
|
-
db.sqls.must_equal ['BEGIN', 'SELECT * FROM a', 'COMMIT']
|
381
|
-
db.transaction{db[:a].all; raise Sequel::Rollback}
|
382
|
-
db.sqls.must_equal ['BEGIN', 'SELECT * FROM a', 'ROLLBACK']
|
383
|
-
proc{db.transaction{db[:a].all; raise ArgumentError}}.must_raise(ArgumentError)
|
384
|
-
db.sqls.must_equal ['BEGIN', 'SELECT * FROM a', 'ROLLBACK']
|
385
|
-
proc{db.transaction(:rollback=>:reraise){db[:a].all; raise Sequel::Rollback}}.must_raise(Sequel::Rollback)
|
386
|
-
db.sqls.must_equal ['BEGIN', 'SELECT * FROM a', 'ROLLBACK']
|
387
|
-
db.transaction(:rollback=>:always){db[:a].all}
|
388
|
-
db.sqls.must_equal ['BEGIN', 'SELECT * FROM a', 'ROLLBACK']
|
389
|
-
db.transaction{db.transaction{db[:a].all; raise Sequel::Rollback}}
|
390
|
-
db.sqls.must_equal ['BEGIN', 'SELECT * FROM a', 'ROLLBACK']
|
391
|
-
db.transaction{db.transaction(:savepoint=>true){db[:a].all; raise Sequel::Rollback}}
|
392
|
-
db.sqls.must_equal ['BEGIN', 'SAVEPOINT autopoint_1', 'SELECT * FROM a', 'ROLLBACK TO SAVEPOINT autopoint_1', 'COMMIT']
|
393
|
-
db.transaction{db.transaction(:savepoint=>true){db[:a].all}; raise Sequel::Rollback}
|
394
|
-
db.sqls.must_equal ['BEGIN', 'SAVEPOINT autopoint_1', 'SELECT * FROM a', 'RELEASE SAVEPOINT autopoint_1', 'ROLLBACK']
|
395
|
-
end
|
396
|
-
|
397
|
-
it "should correctly handle transactions when sharding" do
|
398
|
-
db = Sequel.mock(:servers=>{:test=>{}})
|
399
|
-
db.transaction{db.transaction(:server=>:test){db[:a].all; db[:t].server(:test).all}}
|
400
|
-
db.sqls.must_equal ['BEGIN', 'BEGIN -- test', 'SELECT * FROM a', 'SELECT * FROM t -- test', 'COMMIT -- test', 'COMMIT']
|
401
|
-
end
|
402
|
-
|
403
|
-
it "should yield a mock connection object from synchronize" do
|
404
|
-
c = Sequel.mock.synchronize{|conn| conn}
|
405
|
-
c.must_be_kind_of(Sequel::Mock::Connection)
|
406
|
-
end
|
407
|
-
|
408
|
-
it "should deal correctly with sharding" do
|
409
|
-
db = Sequel.mock(:servers=>{:test=>{}})
|
410
|
-
c1 = db.synchronize{|conn| conn}
|
411
|
-
c2 = db.synchronize(:test){|conn| conn}
|
412
|
-
c1.server.must_equal :default
|
413
|
-
c2.server.must_equal :test
|
414
|
-
end
|
415
|
-
|
416
|
-
it "should disconnect correctly" do
|
417
|
-
db = Sequel.mock
|
418
|
-
db.test_connection
|
419
|
-
db.disconnect
|
420
|
-
end
|
421
|
-
|
422
|
-
it "should accept :extend option for extending the object with a module" do
|
423
|
-
Sequel.mock(:extend=>Module.new{def foo(v) v * 2 end}).foo(3).must_equal 6
|
424
|
-
end
|
425
|
-
|
426
|
-
it "should accept :sqls option for where to store the SQL queries" do
|
427
|
-
a = []
|
428
|
-
Sequel.mock(:sqls=>a)[:t].all
|
429
|
-
a.must_equal ['SELECT * FROM t']
|
430
|
-
end
|
431
|
-
|
432
|
-
it "should include :append option in SQL if it is given" do
|
433
|
-
db = Sequel.mock(:append=>'a')
|
434
|
-
db[:t].all
|
435
|
-
db.sqls.must_equal ['SELECT * FROM t -- a']
|
436
|
-
end
|
437
|
-
|
438
|
-
it "should append :arguments option to execute to the SQL if present" do
|
439
|
-
db = Sequel.mock
|
440
|
-
db.execute('SELECT * FROM t', :arguments=>[1, 2])
|
441
|
-
db.sqls.must_equal ['SELECT * FROM t -- args: [1, 2]']
|
442
|
-
end
|
443
|
-
|
444
|
-
it "should have Dataset#columns take columns to set and return self" do
|
445
|
-
db = Sequel.mock
|
446
|
-
ds = db[:t].columns(:id, :a, :b)
|
447
|
-
ds.must_be_kind_of(Sequel::Mock::Dataset)
|
448
|
-
ds.columns.must_equal [:id, :a, :b]
|
449
|
-
end
|
450
|
-
|
451
|
-
it "should be able to load dialects based on the database name" do
|
452
|
-
Sequel.mock(:host=>'access').select(Date.new(2011, 12, 13)).sql.must_equal 'SELECT #2011-12-13#'
|
453
|
-
Sequel.mock(:host=>'db2').select(1).sql.must_equal 'SELECT 1 FROM "SYSIBM"."SYSDUMMY1"'
|
454
|
-
Sequel.mock(:host=>'mssql')[:A].full_text_search(:B, 'C').with_quote_identifiers(false).sql.must_equal "SELECT * FROM A WHERE (CONTAINS (B, 'C'))"
|
455
|
-
Sequel.mock(:host=>'mysql')[:a].full_text_search(:b, 'c').with_quote_identifiers(false).sql.must_equal "SELECT * FROM a WHERE (MATCH (b) AGAINST ('c'))"
|
456
|
-
Sequel.mock(:host=>'oracle')[:a].limit(1).with_quote_identifiers(false).sql.upcase.must_equal 'SELECT * FROM (SELECT * FROM A) T1 WHERE (ROWNUM <= 1)'
|
457
|
-
Sequel.mock(:host=>'postgres')[:a].full_text_search(:b, 'c').with_quote_identifiers(false).sql.must_equal "SELECT * FROM a WHERE (to_tsvector(CAST('simple' AS regconfig), (COALESCE(b, ''))) @@ to_tsquery(CAST('simple' AS regconfig), 'c'))"
|
458
|
-
Sequel.mock(:host=>'sqlanywhere').from(:A).offset(1).with_quote_identifiers(false).sql.must_equal 'SELECT TOP 2147483647 START AT (1 + 1) * FROM A'
|
459
|
-
Sequel.mock(:host=>'sqlite')[Sequel[:a].as(:b)].with_quote_identifiers(false).sql.must_equal "SELECT * FROM a AS 'b'"
|
460
|
-
end
|
461
|
-
|
462
|
-
it "should be able to mock schema calls" do
|
463
|
-
Sequel.mock(:host=>'mysql', :fetch=>{:Field=>'a'}).schema(:a).first.first.must_equal :a
|
464
|
-
end
|
465
|
-
|
466
|
-
it "should automatically set version for adapters needing versions" do
|
467
|
-
Sequel.mock(:host=>'postgres').server_version.must_be :>=, 90400
|
468
|
-
Sequel.mock(:host=>'mssql').server_version.must_be :>=, 11000000
|
469
|
-
Sequel.mock(:host=>'mysql').server_version.must_be :>=, 50617
|
470
|
-
Sequel.mock(:host=>'sqlite').sqlite_version.must_be :>=, 30804
|
471
|
-
Sequel.mock(:host=>'oracle').server_version.must_be :>=, 11000000
|
472
|
-
end
|
473
|
-
|
474
|
-
it "should stub out the primary_key method for postgres" do
|
475
|
-
Sequel.mock(:host=>'postgres').primary_key(:t).must_equal :id
|
476
|
-
end
|
477
|
-
|
478
|
-
it "should stub out the bound_variable_arg method for postgres" do
|
479
|
-
Sequel.mock(:host=>'postgres').bound_variable_arg(:t, nil).must_equal :t
|
480
|
-
end
|
481
|
-
|
482
|
-
it "should handle creating tables on oracle" do
|
483
|
-
Sequel.mock(:host=>'oracle').create_table(:a){String :b}
|
484
|
-
end
|
485
|
-
end
|
486
|
-
|
487
|
-
describe "PostgreSQL support" do
|
488
|
-
before do
|
489
|
-
@db = Sequel.mock(:host=>'postgres')
|
490
|
-
end
|
491
|
-
|
492
|
-
it "should create an unlogged table" do
|
493
|
-
@db.create_table(:unlogged_dolls, :unlogged => true){text :name}
|
494
|
-
@db.sqls.must_equal ['CREATE UNLOGGED TABLE "unlogged_dolls" ("name" text)']
|
495
|
-
end
|
496
|
-
|
497
|
-
it "should support spatial indexes" do
|
498
|
-
@db.alter_table(:posts){add_spatial_index [:geom]}
|
499
|
-
@db.sqls.must_equal ['CREATE INDEX "posts_geom_index" ON "posts" USING gist ("geom")']
|
500
|
-
end
|
501
|
-
|
502
|
-
it "should support indexes with index type" do
|
503
|
-
@db.alter_table(:posts){add_index :p, :type => 'gist'}
|
504
|
-
@db.sqls.must_equal ['CREATE INDEX "posts_p_index" ON "posts" USING gist ("p")']
|
505
|
-
end
|
506
|
-
|
507
|
-
it "should have #transaction support various types of synchronous options" do
|
508
|
-
@db.transaction(:synchronous=>:on){}
|
509
|
-
@db.transaction(:synchronous=>true){}
|
510
|
-
@db.transaction(:synchronous=>:off){}
|
511
|
-
@db.transaction(:synchronous=>false){}
|
512
|
-
@db.sqls.grep(/synchronous/).must_equal ["SET LOCAL synchronous_commit = on", "SET LOCAL synchronous_commit = on", "SET LOCAL synchronous_commit = off", "SET LOCAL synchronous_commit = off"]
|
513
|
-
|
514
|
-
@db.transaction(:synchronous=>nil){}
|
515
|
-
@db.sqls.must_equal ['BEGIN', 'COMMIT']
|
516
|
-
|
517
|
-
if @db.server_version >= 90100
|
518
|
-
@db.transaction(:synchronous=>:local){}
|
519
|
-
@db.sqls.grep(/synchronous/).must_equal ["SET LOCAL synchronous_commit = local"]
|
520
|
-
|
521
|
-
if @db.server_version >= 90200
|
522
|
-
@db.transaction(:synchronous=>:remote_write){}
|
523
|
-
@db.sqls.grep(/synchronous/).must_equal ["SET LOCAL synchronous_commit = remote_write"]
|
524
|
-
end
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
it "should have #transaction support read only transactions" do
|
529
|
-
@db.transaction(:read_only=>true){}
|
530
|
-
@db.transaction(:read_only=>false){}
|
531
|
-
@db.transaction(:isolation=>:serializable, :read_only=>true){}
|
532
|
-
@db.transaction(:isolation=>:serializable, :read_only=>false){}
|
533
|
-
@db.sqls.grep(/READ/).must_equal ["SET TRANSACTION READ ONLY", "SET TRANSACTION READ WRITE", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE"]
|
534
|
-
end
|
535
|
-
|
536
|
-
it "should have #transaction support deferrable transactions" do
|
537
|
-
@db.transaction(:deferrable=>true){}
|
538
|
-
@db.transaction(:deferrable=>false){}
|
539
|
-
@db.transaction(:deferrable=>true, :read_only=>true){}
|
540
|
-
@db.transaction(:deferrable=>false, :read_only=>false){}
|
541
|
-
@db.transaction(:isolation=>:serializable, :deferrable=>true, :read_only=>true){}
|
542
|
-
@db.transaction(:isolation=>:serializable, :deferrable=>false, :read_only=>false){}
|
543
|
-
@db.sqls.grep(/DEF/).must_equal ["SET TRANSACTION DEFERRABLE", "SET TRANSACTION NOT DEFERRABLE", "SET TRANSACTION READ ONLY DEFERRABLE", "SET TRANSACTION READ WRITE NOT DEFERRABLE", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY DEFERRABLE", "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE NOT DEFERRABLE"]
|
544
|
-
end
|
545
|
-
|
546
|
-
it "should support creating indexes concurrently" do
|
547
|
-
@db.add_index :test, [:name, :value], :concurrently=>true
|
548
|
-
@db.sqls.must_equal ['CREATE INDEX CONCURRENTLY "test_name_value_index" ON "test" ("name", "value")']
|
549
|
-
end
|
550
|
-
|
551
|
-
it "should support dropping indexes concurrently" do
|
552
|
-
@db.drop_index :test, [:name, :value], :concurrently=>true, :name=>'tnv2'
|
553
|
-
@db.sqls.must_equal ['DROP INDEX CONCURRENTLY "tnv2"']
|
554
|
-
end
|
555
|
-
|
556
|
-
it "should use INSERT RETURNING for inserts" do
|
557
|
-
@db[:test5].insert(:value=>10)
|
558
|
-
@db.sqls.must_equal ['INSERT INTO "test5" ("value") VALUES (10) RETURNING "id"']
|
559
|
-
end
|
560
|
-
|
561
|
-
it "should support opclass specification" do
|
562
|
-
@db.alter_table(:posts){add_index(:user_id, :opclass => :int4_ops, :type => :btree)}
|
563
|
-
@db.sqls.must_equal ['CREATE INDEX "posts_user_id_index" ON "posts" USING btree ("user_id" int4_ops)']
|
564
|
-
end
|
565
|
-
|
566
|
-
it 'should quote NaN' do
|
567
|
-
nan = 0.0/0.0
|
568
|
-
@db[:test5].insert_sql(:value => nan).must_equal %q{INSERT INTO "test5" ("value") VALUES ('NaN')}
|
569
|
-
end
|
570
|
-
|
571
|
-
it 'should quote +Infinity' do
|
572
|
-
inf = 1.0/0.0
|
573
|
-
@db[:test5].insert_sql(:value => inf).must_equal %q{INSERT INTO "test5" ("value") VALUES ('Infinity')}
|
574
|
-
end
|
575
|
-
|
576
|
-
it 'should quote -Infinity' do
|
577
|
-
inf = -1.0/0.0
|
578
|
-
@db[:test5].insert_sql(:value => inf).must_equal %q{INSERT INTO "test5" ("value") VALUES ('-Infinity')}
|
579
|
-
end
|
580
|
-
|
581
|
-
it "Dataset#insert_conflict should respect expressions in the target argument" do
|
582
|
-
@ds = @db[:ic_test]
|
583
|
-
@ds.insert_conflict(:target=>:a).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"a\") DO NOTHING"
|
584
|
-
@ds.insert_conflict(:target=>:c, :conflict_where=>{:c_is_unique=>true}).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"c\") WHERE (\"c_is_unique\" IS TRUE) DO NOTHING"
|
585
|
-
@ds.insert_conflict(:target=>[:b, :c]).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"b\", \"c\") DO NOTHING"
|
586
|
-
@ds.insert_conflict(:target=>[:b, Sequel.function(:round, :c)]).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"b\", round(\"c\")) DO NOTHING"
|
587
|
-
@ds.insert_conflict(:target=>[:b, Sequel.virtual_row{|o| o.round(:c)}]).insert_sql(1, 2, 3).must_equal "INSERT INTO \"ic_test\" VALUES (1, 2, 3) ON CONFLICT (\"b\", round(\"c\")) DO NOTHING"
|
588
|
-
end
|
589
|
-
|
590
|
-
it "should support creating and dropping foreign tables" do
|
591
|
-
@db.create_table(:t, :foreign=>:f, :options=>{:o=>1}){Integer :a}
|
592
|
-
@db.drop_table(:t, :foreign=>true)
|
593
|
-
@db.sqls.must_equal ['CREATE FOREIGN TABLE "t" ("a" integer) SERVER "f" OPTIONS (o \'1\')',
|
594
|
-
'DROP FOREIGN TABLE "t"']
|
595
|
-
end
|
596
|
-
|
597
|
-
it "#create_function and #drop_function should create and drop functions" do
|
598
|
-
@db.create_function('tf', 'SELECT 1', :returns=>:integer)
|
599
|
-
@db.drop_function('tf')
|
600
|
-
@db.sqls.map{|s| s.gsub(/\s+/, ' ').strip}.must_equal ["CREATE FUNCTION tf() RETURNS integer LANGUAGE SQL AS 'SELECT 1'",
|
601
|
-
'DROP FUNCTION tf()']
|
602
|
-
end
|
603
|
-
|
604
|
-
it "#create_function and #drop_function should support options" do
|
605
|
-
@db.create_function('tf', 'SELECT $1 + $2', :args=>[[:integer, :a], :integer], :replace=>true, :returns=>:integer, :language=>'SQL', :behavior=>:immutable, :strict=>true, :security_definer=>true, :cost=>2, :set=>{:search_path => 'public'})
|
606
|
-
@db.drop_function('tf', :if_exists=>true, :cascade=>true, :args=>[[:integer, :a], :integer])
|
607
|
-
@db.sqls.map{|s| s.gsub(/\s+/, ' ').strip}.must_equal ["CREATE OR REPLACE FUNCTION tf(a integer, integer) RETURNS integer LANGUAGE SQL IMMUTABLE STRICT SECURITY DEFINER COST 2 SET search_path = public AS 'SELECT $1 + $2'",
|
608
|
-
'DROP FUNCTION IF EXISTS tf(a integer, integer) CASCADE']
|
609
|
-
end
|
610
|
-
|
611
|
-
it "#create_language and #drop_language should create and drop languages" do
|
612
|
-
@db.create_language(:plpgsql)
|
613
|
-
@db.create_language(:plpgsql, :replace=>true, :trusted=>true, :handler=>:a, :validator=>:b)
|
614
|
-
@db.drop_language(:plpgsql)
|
615
|
-
@db.drop_language(:plpgsql, :if_exists=>true, :cascade=>true)
|
616
|
-
@db.sqls.map{|s| s.gsub(/\s+/, ' ').strip}.must_equal ['CREATE LANGUAGE plpgsql',
|
617
|
-
'CREATE OR REPLACE TRUSTED LANGUAGE plpgsql HANDLER a VALIDATOR b',
|
618
|
-
'DROP LANGUAGE plpgsql',
|
619
|
-
'DROP LANGUAGE IF EXISTS plpgsql CASCADE']
|
620
|
-
end
|
621
|
-
|
622
|
-
it "#create_schema and #drop_schema should create and drop schemas" do
|
623
|
-
@db.create_schema(:sequel)
|
624
|
-
@db.create_schema(:sequel, :if_not_exists=>true, :owner=>:foo)
|
625
|
-
@db.drop_schema(:sequel)
|
626
|
-
@db.drop_schema(:sequel, :if_exists=>true, :cascade=>true)
|
627
|
-
@db.sqls.must_equal ['CREATE SCHEMA "sequel"',
|
628
|
-
'CREATE SCHEMA IF NOT EXISTS "sequel" AUTHORIZATION "foo"',
|
629
|
-
'DROP SCHEMA "sequel"',
|
630
|
-
'DROP SCHEMA IF EXISTS "sequel" CASCADE']
|
631
|
-
end
|
632
|
-
|
633
|
-
it "#create_trigger and #drop_trigger should create and drop triggers" do
|
634
|
-
@db.create_trigger(:test, :identity, :tf, :each_row=>true)
|
635
|
-
@db.create_trigger(:test, :identity, :tf, :after=>true, :events=>:insert, :args=>[1, 'a'])
|
636
|
-
@db.create_trigger(:test, :identity, :tf, :each_row=>true, :when=> {Sequel[:new][:name] => 'b'})
|
637
|
-
@db.drop_trigger(:test, :identity)
|
638
|
-
@db.drop_trigger(:test, :identity, :if_exists=>true, :cascade=>true)
|
639
|
-
@db.sqls.map{|s| s.gsub(/\s+/, ' ').strip}.must_equal ['CREATE TRIGGER identity BEFORE INSERT OR UPDATE OR DELETE ON "test" FOR EACH ROW EXECUTE PROCEDURE tf()',
|
640
|
-
'CREATE TRIGGER identity AFTER INSERT ON "test" EXECUTE PROCEDURE tf(1, \'a\')',
|
641
|
-
%q{CREATE TRIGGER identity BEFORE INSERT OR UPDATE OR DELETE ON "test" FOR EACH ROW WHEN ("new"."name" = 'b') EXECUTE PROCEDURE tf()},
|
642
|
-
'DROP TRIGGER identity ON "test"',
|
643
|
-
'DROP TRIGGER IF EXISTS identity ON "test" CASCADE']
|
644
|
-
end
|
645
|
-
end
|
646
|
-
|
647
|
-
describe "MySQL support" do
|
648
|
-
before do
|
649
|
-
@db = Sequel.mock(:host=>'mysql')
|
650
|
-
end
|
651
|
-
|
652
|
-
it "should support spatial indexes" do
|
653
|
-
@db.alter_table(:posts){add_spatial_index [:geom]}
|
654
|
-
@db.sqls.must_equal ['CREATE SPATIAL INDEX `posts_geom_index` ON `posts` (`geom`)']
|
655
|
-
end
|
656
|
-
|
657
|
-
it "should support fulltext indexes and full_text_search" do
|
658
|
-
@db.alter_table(:posts){add_full_text_index :title; add_full_text_index [:title, :body]}
|
659
|
-
@db.sqls.must_equal [ "CREATE FULLTEXT INDEX `posts_title_index` ON `posts` (`title`)", "CREATE FULLTEXT INDEX `posts_title_body_index` ON `posts` (`title`, `body`)" ]
|
660
|
-
end
|
661
|
-
|
662
|
-
it "should support indexes with index type" do
|
663
|
-
@db.alter_table(:posts){add_index :id, :type => :btree}
|
664
|
-
@db.sqls.must_equal ["CREATE INDEX `posts_id_index` USING btree ON `posts` (`id`)"]
|
665
|
-
end
|
666
|
-
end
|
667
|
-
|
668
|
-
describe "SQLite support" do
|
669
|
-
before do
|
670
|
-
@db = Sequel.mock(:host=>'sqlite')
|
671
|
-
end
|
672
|
-
|
673
|
-
it "should use a string literal for Sequel[:col].as(:alias)" do
|
674
|
-
@db.literal(Sequel[:c].as(:a)).must_equal "`c` AS 'a'"
|
675
|
-
end
|
676
|
-
|
677
|
-
it "should use a string literal for Sequel[:table][:col].as(:alias)" do
|
678
|
-
@db.literal(Sequel[:t][:c].as(:a)).must_equal "`t`.`c` AS 'a'"
|
679
|
-
end
|
680
|
-
|
681
|
-
it "should use a string literal for :column.as(:alias)" do
|
682
|
-
@db.literal(Sequel.as(:c, :a)).must_equal "`c` AS 'a'"
|
683
|
-
end
|
684
|
-
|
685
|
-
it "should use a string literal in the SELECT clause" do
|
686
|
-
@db[:t].select(Sequel[:c].as(:a)).sql.must_equal "SELECT `c` AS 'a' FROM `t`"
|
687
|
-
end
|
688
|
-
|
689
|
-
it "should use a string literal in the FROM clause" do
|
690
|
-
@db[Sequel[:t].as(:a)].sql.must_equal "SELECT * FROM `t` AS 'a'"
|
691
|
-
end
|
692
|
-
|
693
|
-
it "should use a string literal in the JOIN clause" do
|
694
|
-
@db[:t].join_table(:natural, :j, nil, :table_alias=>:a).sql.must_equal "SELECT * FROM `t` NATURAL JOIN `j` AS 'a'"
|
695
|
-
end
|
696
|
-
|
697
|
-
it "should have support for various #transaction modes" do
|
698
|
-
@db.transaction{}
|
699
|
-
@db.transaction(:mode => :immediate){}
|
700
|
-
@db.transaction(:mode => :exclusive){}
|
701
|
-
@db.transaction(:mode => :deferred){}
|
702
|
-
@db.sqls.must_equal ["BEGIN", "COMMIT", "BEGIN IMMEDIATE TRANSACTION", "COMMIT", "BEGIN EXCLUSIVE TRANSACTION", "COMMIT", "BEGIN DEFERRED TRANSACTION", "COMMIT"]
|
703
|
-
|
704
|
-
@db.transaction_mode.must_be_nil
|
705
|
-
@db.transaction_mode = :immediate
|
706
|
-
@db.transaction_mode.must_equal :immediate
|
707
|
-
@db.transaction{}
|
708
|
-
@db.transaction(:mode => :exclusive){}
|
709
|
-
@db.sqls.must_equal ["BEGIN IMMEDIATE TRANSACTION", "COMMIT", "BEGIN EXCLUSIVE TRANSACTION", "COMMIT"]
|
710
|
-
end
|
711
|
-
|
712
|
-
it "should choose a temporary table name that isn't already used when dropping or renaming columns" do
|
713
|
-
exists = [true, true, false]
|
714
|
-
@db.define_singleton_method(:table_exists?){|x| exists.shift}
|
715
|
-
@db.drop_column(:test3, :i)
|
716
|
-
@db.sqls.grep(/ALTER/).must_equal ["ALTER TABLE `test3` RENAME TO `test3_backup2`"]
|
717
|
-
|
718
|
-
exists = [true, true, true, false]
|
719
|
-
@db.rename_column(:test3, :h, :i)
|
720
|
-
@db.sqls.grep(/ALTER/).must_equal ["ALTER TABLE `test3` RENAME TO `test3_backup3`"]
|
721
|
-
end
|
722
|
-
end
|