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,347 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe Sequel::Model, "single table inheritance plugin" do
|
4
|
-
before do
|
5
|
-
class ::StiTest < Sequel::Model
|
6
|
-
columns :id, :kind, :blah
|
7
|
-
plugin :single_table_inheritance, :kind
|
8
|
-
end
|
9
|
-
class ::StiTestSub1 < StiTest
|
10
|
-
end
|
11
|
-
class ::StiTestSub2 < StiTest
|
12
|
-
end
|
13
|
-
@ds = StiTest.dataset
|
14
|
-
DB.reset
|
15
|
-
end
|
16
|
-
after do
|
17
|
-
Object.send(:remove_const, :StiTestSub1)
|
18
|
-
Object.send(:remove_const, :StiTestSub2)
|
19
|
-
Object.send(:remove_const, :StiTest)
|
20
|
-
end
|
21
|
-
|
22
|
-
describe ".sti_load" do
|
23
|
-
it "should load instances of the correct type" do
|
24
|
-
StiTest.sti_load(:id => 3).must_be_instance_of StiTest
|
25
|
-
StiTest.sti_load(:id => 3, :kind => 'StiTestSub1').must_be_instance_of StiTestSub1
|
26
|
-
StiTest.sti_load(:id => 3, :kind => 'StiTestSub2').must_be_instance_of StiTestSub2
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe ".sti_class_from_sti_key" do
|
31
|
-
it "should load the correct subclass based on the key" do
|
32
|
-
StiTest.sti_class_from_sti_key('StiTest').must_equal StiTest
|
33
|
-
StiTest.sti_class_from_sti_key('StiTestSub1').must_equal StiTestSub1
|
34
|
-
StiTest.sti_class_from_sti_key('StiTestSub2').must_equal StiTestSub2
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should freeze sti metadata when freezing model class" do
|
39
|
-
StiTest.freeze
|
40
|
-
StiTest.sti_dataset.frozen?.must_equal true
|
41
|
-
|
42
|
-
StiTestSub1.freeze
|
43
|
-
StiTestSub1.sti_key_array.frozen?.must_equal true
|
44
|
-
|
45
|
-
proc{class ::StiTestSub1Sub1 < StiTestSub1; end}.must_raise RuntimeError, TypeError
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should have simple_table = nil" do
|
49
|
-
StiTest.simple_table.must_equal "sti_tests"
|
50
|
-
StiTestSub1.simple_table.must_be_nil
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should allow changing the inheritance column via a plugin :single_table_inheritance call" do
|
54
|
-
StiTest.plugin :single_table_inheritance, :blah
|
55
|
-
Object.send(:remove_const, :StiTestSub1)
|
56
|
-
Object.send(:remove_const, :StiTestSub2)
|
57
|
-
class ::StiTestSub1 < StiTest; end
|
58
|
-
class ::StiTestSub2 < StiTest; end
|
59
|
-
StiTest.dataset = StiTest.dataset.with_fetch([{:blah=>'StiTest'}, {:blah=>'StiTestSub1'}, {:blah=>'StiTestSub2'}])
|
60
|
-
StiTest.all.collect{|x| x.class}.must_equal [StiTest, StiTestSub1, StiTestSub2]
|
61
|
-
StiTest.dataset.sql.must_equal "SELECT * FROM sti_tests"
|
62
|
-
StiTestSub1.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.blah IN ('StiTestSub1'))"
|
63
|
-
StiTestSub2.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.blah IN ('StiTestSub2'))"
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should return rows with the correct class based on the polymorphic_key value" do
|
67
|
-
StiTest.dataset = StiTest.dataset.with_fetch([{:kind=>'StiTest'}, {:kind=>'StiTestSub1'}, {:kind=>'StiTestSub2'}])
|
68
|
-
StiTest.all.collect{|x| x.class}.must_equal [StiTest, StiTestSub1, StiTestSub2]
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should return rows with the correct class based on the polymorphic_key value when retreiving by primary key" do
|
72
|
-
StiTest.dataset = StiTest.dataset.with_fetch([{:kind=>'StiTestSub1'}])
|
73
|
-
StiTest[1].class.must_equal StiTestSub1
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should return rows with the correct class for subclasses based on the polymorphic_key value" do
|
77
|
-
class ::StiTestSub1Sub < StiTestSub1; end
|
78
|
-
StiTestSub1.dataset = StiTestSub1.dataset.with_fetch([{:kind=>'StiTestSub1'}, {:kind=>'StiTestSub1Sub'}])
|
79
|
-
StiTestSub1.all.collect{|x| x.class}.must_equal [StiTestSub1, StiTestSub1Sub]
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should fallback to the main class if the given class does not exist" do
|
83
|
-
StiTest.dataset = StiTest.dataset.with_fetch(:kind=>'StiTestSub3')
|
84
|
-
StiTest.all.collect{|x| x.class}.must_equal [StiTest]
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should inherit dataset_modules correctly in subclass" do
|
88
|
-
StiTest.dataset_module{def foo; 1; end}
|
89
|
-
Object.send(:remove_const, :StiTestSub1)
|
90
|
-
Object.send(:remove_const, :StiTestSub2)
|
91
|
-
class ::StiTestSub1 < StiTest; end
|
92
|
-
StiTestSub1.dataset_module{def bar; 2; end}
|
93
|
-
class ::StiTestSub2 < StiTestSub1; end
|
94
|
-
StiTestSub2.dataset_module{def baz; 3; end}
|
95
|
-
|
96
|
-
StiTest.dataset.foo.must_equal 1
|
97
|
-
proc{StiTest.dataset.bar}.must_raise NoMethodError
|
98
|
-
proc{StiTest.dataset.baz}.must_raise NoMethodError
|
99
|
-
StiTestSub1.dataset.foo.must_equal 1
|
100
|
-
StiTestSub1.dataset.bar.must_equal 2
|
101
|
-
proc{StiTestSub1.dataset.baz}.must_raise NoMethodError
|
102
|
-
StiTestSub2.dataset.foo.must_equal 1
|
103
|
-
StiTestSub2.dataset.bar.must_equal 2
|
104
|
-
StiTestSub2.dataset.baz.must_equal 3
|
105
|
-
end
|
106
|
-
|
107
|
-
it "should fallback to the main class if the sti_key field is empty or nil without calling constantize" do
|
108
|
-
called = false
|
109
|
-
StiTest.define_singleton_method(:constantize){|_| called = true}
|
110
|
-
StiTest.plugin :single_table_inheritance, :kind
|
111
|
-
StiTest.dataset = StiTest.dataset.with_fetch([{:kind=>''}, {:kind=>nil}])
|
112
|
-
StiTest.all.collect{|x| x.class}.must_equal [StiTest, StiTest]
|
113
|
-
called.must_equal false
|
114
|
-
end
|
115
|
-
|
116
|
-
it "should set the model class name when saving" do
|
117
|
-
StiTest.new.save
|
118
|
-
StiTestSub1.new.save
|
119
|
-
StiTestSub2.new.save
|
120
|
-
DB.sqls.must_equal ["INSERT INTO sti_tests (kind) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE id = 10", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub1')) AND (id = 10)) LIMIT 1", "INSERT INTO sti_tests (kind) VALUES ('StiTestSub2')", "SELECT * FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub2')) AND (id = 10)) LIMIT 1"]
|
121
|
-
end
|
122
|
-
|
123
|
-
it "should destroy the model correctly" do
|
124
|
-
StiTest.load(:id=>1).destroy
|
125
|
-
StiTestSub1.load(:id=>1).destroy
|
126
|
-
StiTestSub2.load(:id=>1).destroy
|
127
|
-
DB.sqls.must_equal ["DELETE FROM sti_tests WHERE id = 1", "DELETE FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub1')) AND (id = 1))", "DELETE FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub2')) AND (id = 1))"]
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should handle validations on the type column field" do
|
131
|
-
o = StiTestSub1.new
|
132
|
-
def o.validate
|
133
|
-
errors.add(:kind, 'not present') unless kind
|
134
|
-
end
|
135
|
-
o.valid?.must_equal true
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should set type column field even if validations are skipped" do
|
139
|
-
StiTestSub1.new.save(:validate=>false)
|
140
|
-
DB.sqls.must_equal ["INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE ((sti_tests.kind IN ('StiTestSub1')) AND (id = 10)) LIMIT 1"]
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should override an existing value in the class name field" do
|
144
|
-
StiTest.create(:kind=>'StiTestSub1')
|
145
|
-
DB.sqls.must_equal ["INSERT INTO sti_tests (kind) VALUES ('StiTestSub1')", "SELECT * FROM sti_tests WHERE id = 10"]
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should handle type column with the same name as existing method names" do
|
149
|
-
StiTest.plugin :single_table_inheritance, :type
|
150
|
-
StiTest.columns :id, :type
|
151
|
-
StiTest.create
|
152
|
-
DB.sqls.must_equal ["INSERT INTO sti_tests (type) VALUES ('StiTest')", "SELECT * FROM sti_tests WHERE id = 10"]
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should add a filter to model datasets inside subclasses hook to only retreive objects with the matching key" do
|
156
|
-
StiTest.dataset.sql.must_equal "SELECT * FROM sti_tests"
|
157
|
-
StiTestSub1.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub1'))"
|
158
|
-
StiTestSub2.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub2'))"
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should add a correct filter for multiple levels of subclasses" do
|
162
|
-
class ::StiTestSub1A < StiTestSub1; end
|
163
|
-
StiTestSub1.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub1', 'StiTestSub1A'))"
|
164
|
-
StiTestSub1A.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub1A'))"
|
165
|
-
class ::StiTestSub2A < StiTestSub2; end
|
166
|
-
StiTestSub2.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub2', 'StiTestSub2A'))"
|
167
|
-
StiTestSub2A.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub2A'))"
|
168
|
-
class ::StiTestSub1B < StiTestSub1A; end
|
169
|
-
StiTestSub1.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub1', 'StiTestSub1A', 'StiTestSub1B'))"
|
170
|
-
StiTestSub1A.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub1A', 'StiTestSub1B'))"
|
171
|
-
StiTestSub1B.dataset.sql.must_equal "SELECT * FROM sti_tests WHERE (sti_tests.kind IN ('StiTestSub1B'))"
|
172
|
-
end
|
173
|
-
|
174
|
-
it "should work correctly with the :caching plugin" do
|
175
|
-
cache_class = Class.new(Hash) do
|
176
|
-
attr_accessor :ttl
|
177
|
-
def set(k, v, ttl); self[k] = v; @ttl = ttl; end
|
178
|
-
def get(k); self[k]; end
|
179
|
-
end
|
180
|
-
cache = cache_class.new
|
181
|
-
|
182
|
-
StiTest.plugin :caching, cache
|
183
|
-
def StiTest.cache_key_prefix; "stitest" end
|
184
|
-
c2 = Class.new StiTest
|
185
|
-
c2.cache_key(:id).must_equal StiTest.cache_key(:id)
|
186
|
-
|
187
|
-
obj2 = c2.new
|
188
|
-
obj2.values[:x] = 2
|
189
|
-
obj2.save
|
190
|
-
c2[obj2.id]
|
191
|
-
c2.cache_get_pk(obj2.id).values.must_equal StiTest.cache_get_pk(obj2.id).values
|
192
|
-
obj2.save
|
193
|
-
c2.cache_get_pk(obj2.id).must_be_nil
|
194
|
-
StiTest.cache_get_pk(obj2.id).must_be_nil
|
195
|
-
end
|
196
|
-
|
197
|
-
describe "with custom options" do
|
198
|
-
before do
|
199
|
-
class ::StiTest2 < Sequel::Model
|
200
|
-
columns :id, :kind
|
201
|
-
def _save_refresh; end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
after do
|
205
|
-
Object.send(:remove_const, :StiTest2)
|
206
|
-
Object.send(:remove_const, :StiTest3) if defined?(StiTest3)
|
207
|
-
Object.send(:remove_const, :StiTest4) if defined?(StiTest4)
|
208
|
-
end
|
209
|
-
|
210
|
-
it "should freeze sti key and model map if given as hashes when freezing model class" do
|
211
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>{0=>StiTest2, 1=>:StiTest3, 2=>'StiTest4'}, :key_map=>{StiTest2=>4, 'StiTest3'=>5, 'StiTest4'=>6}
|
212
|
-
StiTest2.freeze
|
213
|
-
StiTest2.sti_key_map.frozen?.must_equal true
|
214
|
-
StiTest2.sti_model_map.frozen?.must_equal true
|
215
|
-
end
|
216
|
-
|
217
|
-
it "should have working row_proc if using set_dataset in subclass to remove columns" do
|
218
|
-
StiTest2.plugin :single_table_inheritance, :kind
|
219
|
-
class ::StiTest3 < ::StiTest2
|
220
|
-
set_dataset(dataset.select(*(columns - [:blah])))
|
221
|
-
end
|
222
|
-
class ::StiTest4 < ::StiTest3; end
|
223
|
-
StiTest3.dataset = StiTest3.dataset.with_fetch(:id=>1, :kind=>'StiTest4')
|
224
|
-
StiTest3[1].must_equal StiTest4.load(:id=>1, :kind=>'StiTest4')
|
225
|
-
end
|
226
|
-
|
227
|
-
it "should work with custom procs with strings" do
|
228
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>proc{|v| v == 1 ? 'StiTest3' : 'StiTest4'}, :key_map=>proc{|klass| klass.name == 'StiTest3' ? 1 : 2}
|
229
|
-
class ::StiTest3 < ::StiTest2; end
|
230
|
-
class ::StiTest4 < ::StiTest2; end
|
231
|
-
StiTest2.dataset.row_proc.call(:kind=>0).must_be_instance_of(StiTest4)
|
232
|
-
StiTest2.dataset.row_proc.call(:kind=>1).must_be_instance_of(StiTest3)
|
233
|
-
StiTest2.dataset.row_proc.call(:kind=>2).must_be_instance_of(StiTest4)
|
234
|
-
|
235
|
-
StiTest2.create.kind.must_equal 2
|
236
|
-
StiTest3.create.kind.must_equal 1
|
237
|
-
StiTest4.create.kind.must_equal 2
|
238
|
-
end
|
239
|
-
|
240
|
-
it "should work with custom procs with symbols" do
|
241
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>proc{|v| v == 1 ? :StiTest3 : :StiTest4}, :key_map=>proc{|klass| klass.name == 'StiTest3' ? 1 : 2}
|
242
|
-
class ::StiTest3 < ::StiTest2; end
|
243
|
-
class ::StiTest4 < ::StiTest2; end
|
244
|
-
StiTest2.dataset.row_proc.call(:kind=>0).must_be_instance_of(StiTest4)
|
245
|
-
StiTest2.dataset.row_proc.call(:kind=>1).must_be_instance_of(StiTest3)
|
246
|
-
StiTest2.dataset.row_proc.call(:kind=>2).must_be_instance_of(StiTest4)
|
247
|
-
|
248
|
-
StiTest2.create.kind.must_equal 2
|
249
|
-
StiTest3.create.kind.must_equal 1
|
250
|
-
StiTest4.create.kind.must_equal 2
|
251
|
-
end
|
252
|
-
|
253
|
-
it "should work with custom hashes" do
|
254
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>{0=>StiTest2, 1=>:StiTest3, 2=>'StiTest4'}, :key_map=>{StiTest2=>4, 'StiTest3'=>5, 'StiTest4'=>6}
|
255
|
-
class ::StiTest3 < ::StiTest2; end
|
256
|
-
class ::StiTest4 < ::StiTest2; end
|
257
|
-
StiTest2.dataset.row_proc.call(:kind=>0).must_be_instance_of(StiTest2)
|
258
|
-
StiTest2.dataset.row_proc.call(:kind=>1).must_be_instance_of(StiTest3)
|
259
|
-
StiTest2.dataset.row_proc.call(:kind=>2).must_be_instance_of(StiTest4)
|
260
|
-
StiTest3.sti_model_map.must_equal StiTest2.sti_model_map
|
261
|
-
|
262
|
-
StiTest2.create.kind.must_equal 4
|
263
|
-
StiTest3.create.kind.must_equal 5
|
264
|
-
StiTest4.create.kind.must_equal 6
|
265
|
-
|
266
|
-
class ::StiTest5 < ::StiTest4; end
|
267
|
-
StiTest5.create.kind.must_be_nil
|
268
|
-
end
|
269
|
-
|
270
|
-
it "should infer key_map from model_map if provided as a hash" do
|
271
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>{0=>StiTest2, 1=>'StiTest3', 2=>:StiTest4}
|
272
|
-
class ::StiTest3 < ::StiTest2; end
|
273
|
-
class ::StiTest4 < ::StiTest2; end
|
274
|
-
StiTest2.dataset.row_proc.call(:kind=>0).must_be_instance_of(StiTest2)
|
275
|
-
StiTest2.dataset.row_proc.call(:kind=>1).must_be_instance_of(StiTest3)
|
276
|
-
StiTest2.dataset.row_proc.call(:kind=>2).must_be_instance_of(StiTest4)
|
277
|
-
|
278
|
-
StiTest2.create.kind.must_equal 0
|
279
|
-
StiTest3.create.kind.must_equal 1
|
280
|
-
StiTest4.create.kind.must_equal 2
|
281
|
-
end
|
282
|
-
|
283
|
-
it "should raise exceptions if a bad model value is used" do
|
284
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>{0=>1,1=>1.5, 2=>Date.today}
|
285
|
-
class ::StiTest3 < ::StiTest2; end
|
286
|
-
class ::StiTest4 < ::StiTest2; end
|
287
|
-
proc{StiTest2.dataset.row_proc.call(:kind=>0)}.must_raise(Sequel::Error)
|
288
|
-
proc{StiTest2.dataset.row_proc.call(:kind=>1)}.must_raise(Sequel::Error)
|
289
|
-
proc{StiTest2.dataset.row_proc.call(:kind=>2)}.must_raise(Sequel::Error)
|
290
|
-
end
|
291
|
-
|
292
|
-
it "should work with non-bijective mappings" do
|
293
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>{0=>'StiTest3', 1=>'StiTest3', 2=>'StiTest4'}
|
294
|
-
class ::StiTest3 < ::StiTest2; end
|
295
|
-
class ::StiTest4 < ::StiTest2; end
|
296
|
-
StiTest2.dataset.row_proc.call(:kind=>0).must_be_instance_of(StiTest3)
|
297
|
-
StiTest2.dataset.row_proc.call(:kind=>1).must_be_instance_of(StiTest3)
|
298
|
-
StiTest2.dataset.row_proc.call(:kind=>2).must_be_instance_of(StiTest4)
|
299
|
-
|
300
|
-
[0,1].must_include(StiTest3.create.kind)
|
301
|
-
StiTest4.create.kind.must_equal 2
|
302
|
-
end
|
303
|
-
|
304
|
-
it "should work with non-bijective mappings and key map procs" do
|
305
|
-
StiTest2.plugin :single_table_inheritance, :kind,
|
306
|
-
:key_map=>proc{|model| model.to_s == 'StiTest4' ? 2 : [0,1] }
|
307
|
-
class ::StiTest3 < ::StiTest2; end
|
308
|
-
class ::StiTest4 < ::StiTest2; end
|
309
|
-
|
310
|
-
StiTest2.dataset.sql.must_equal "SELECT * FROM sti_test2s"
|
311
|
-
StiTest3.dataset.sql.must_equal "SELECT * FROM sti_test2s WHERE (sti_test2s.kind IN (0, 1))"
|
312
|
-
StiTest4.dataset.sql.must_equal "SELECT * FROM sti_test2s WHERE (sti_test2s.kind IN (2))"
|
313
|
-
end
|
314
|
-
|
315
|
-
it "should create correct sql with non-bijective mappings" do
|
316
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>{0=>'StiTest3', 1=>'StiTest3', 2=>'StiTest4'}
|
317
|
-
class ::StiTest3 < ::StiTest2; end
|
318
|
-
class ::StiTest4 < ::StiTest2; end
|
319
|
-
|
320
|
-
StiTest2.dataset.sql.must_equal "SELECT * FROM sti_test2s"
|
321
|
-
["SELECT * FROM sti_test2s WHERE (sti_test2s.kind IN (0, 1))",
|
322
|
-
"SELECT * FROM sti_test2s WHERE (sti_test2s.kind IN (1, 0))"].must_include(StiTest3.dataset.sql)
|
323
|
-
end
|
324
|
-
|
325
|
-
it "should destroy the model correctly" do
|
326
|
-
StiTest2.plugin :single_table_inheritance, :kind, :model_map=>{'sti3'=>'StiTest3', 'sti3b'=>'StiTest3', 'sti4'=>'StiTest4'}
|
327
|
-
class ::StiTest3 < ::StiTest2; end
|
328
|
-
class ::StiTest4 < ::StiTest2; end
|
329
|
-
StiTest2.load(:id=>1).destroy
|
330
|
-
StiTest3.load(:id=>1).destroy
|
331
|
-
sqls = DB.sqls
|
332
|
-
sqls.shift.must_equal "DELETE FROM sti_test2s WHERE id = 1"
|
333
|
-
["DELETE FROM sti_test2s WHERE ((sti_test2s.kind IN ('sti3', 'sti3b')) AND (id = 1))",
|
334
|
-
"DELETE FROM sti_test2s WHERE ((sti_test2s.kind IN ('sti3b', 'sti3')) AND (id = 1))"].must_include(sqls.pop)
|
335
|
-
sqls.must_equal []
|
336
|
-
end
|
337
|
-
|
338
|
-
it "should honor a :key_chooser" do
|
339
|
-
StiTest2.plugin :single_table_inheritance, :kind, :key_chooser => proc{|inst| inst.model.to_s.downcase }
|
340
|
-
class ::StiTest3 < ::StiTest2; end
|
341
|
-
class ::StiTest4 < ::StiTest2; end
|
342
|
-
|
343
|
-
StiTest3.create.kind.must_equal 'stitest3'
|
344
|
-
StiTest4.create.kind.must_equal 'stitest4'
|
345
|
-
end
|
346
|
-
end
|
347
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Sequel::Plugins::SingularTableNames" do
|
4
|
-
before do
|
5
|
-
@c = Class.new(Sequel::Model)
|
6
|
-
@c.plugin :singular_table_names
|
7
|
-
end
|
8
|
-
after do
|
9
|
-
Object.send(:remove_const, :Foo)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should not used the pluralized table name" do
|
13
|
-
class ::Foo < @c; end
|
14
|
-
Foo.table_name.must_equal :foo
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should handle nested moedls name" do
|
18
|
-
module ::Foo; end
|
19
|
-
class Foo::Bar < @c; end
|
20
|
-
Foo::Bar.table_name.must_equal :bar
|
21
|
-
end
|
22
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Sequel::Plugins::SkipCreateRefresh" do
|
4
|
-
it "should skip the refresh after saving a new object" do
|
5
|
-
c = Class.new(Sequel::Model(:a))
|
6
|
-
c.columns :id, :x
|
7
|
-
c.dataset = c.dataset.with_autoid(2)
|
8
|
-
c.db.reset
|
9
|
-
c.create(:x=>1)
|
10
|
-
c.db.sqls.must_equal ['INSERT INTO a (x) VALUES (1)', 'SELECT * FROM a WHERE id = 2']
|
11
|
-
|
12
|
-
c.dataset = c.dataset.with_autoid(2)
|
13
|
-
c.plugin :skip_create_refresh
|
14
|
-
c.db.reset
|
15
|
-
c.create(:x=>3).values.must_equal(:id=>2, :x=>3)
|
16
|
-
c.db.sqls.must_equal ['INSERT INTO a (x) VALUES (3)']
|
17
|
-
end
|
18
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require_relative "../sequel_warning"
|
2
|
-
|
3
|
-
if ENV['COVERAGE']
|
4
|
-
require_relative "../sequel_coverage"
|
5
|
-
SimpleCov.sequel_coverage(:filter=>%r{lib/sequel/(extensions|plugins)/\w+\.rb\z})
|
6
|
-
end
|
7
|
-
|
8
|
-
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
9
|
-
gem 'minitest'
|
10
|
-
require 'minitest/global_expectations/autorun'
|
11
|
-
require 'minitest/hooks/default'
|
12
|
-
require 'minitest/shared_description'
|
13
|
-
|
14
|
-
$:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "../../lib/"))
|
15
|
-
require_relative "../../lib/sequel"
|
16
|
-
|
17
|
-
require_relative '../deprecation_helper'
|
18
|
-
|
19
|
-
if ENV['SEQUEL_TZINFO_VERSION']
|
20
|
-
# Allow forcing specific TZInfo versions, useful when testing
|
21
|
-
gem 'tzinfo', ENV['SEQUEL_TZINFO_VERSION']
|
22
|
-
end
|
23
|
-
|
24
|
-
begin
|
25
|
-
# Attempt to load ActiveSupport blank extension and inflector first, so Sequel
|
26
|
-
# can override them.
|
27
|
-
require 'active_support/core_ext/object/blank'
|
28
|
-
require 'active_support/inflector'
|
29
|
-
require 'active_support/core_ext/string/inflections'
|
30
|
-
rescue LoadError
|
31
|
-
nil
|
32
|
-
end
|
33
|
-
|
34
|
-
if (RUBY_VERSION >= '2.0.0' && RUBY_ENGINE == 'ruby') || (RUBY_ENGINE == 'jruby' && (JRUBY_VERSION >= '9.3' || (JRUBY_VERSION.match(/\A9\.2\.(\d+)/) && $1.to_i >= 7)))
|
35
|
-
Sequel.extension :core_refinements
|
36
|
-
end
|
37
|
-
|
38
|
-
class << Sequel::Model
|
39
|
-
attr_writer :db_schema
|
40
|
-
alias orig_columns columns
|
41
|
-
def columns(*cols)
|
42
|
-
return super if cols.empty?
|
43
|
-
define_method(:columns){cols}
|
44
|
-
@dataset.send(:columns=, cols) if @dataset
|
45
|
-
def_column_accessor(*cols)
|
46
|
-
@columns = cols
|
47
|
-
@db_schema = {}
|
48
|
-
cols.each{|c| @db_schema[c] = {}}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
Sequel::DB = nil
|
53
|
-
Sequel::Model.use_transactions = false
|
54
|
-
Sequel::Model.cache_anonymous_models = false
|
55
|
-
|
56
|
-
db = Sequel.mock(:fetch=>{:id => 1, :x => 1}, :numrows=>1, :autoid=>proc{|sql| 10})
|
57
|
-
def db.schema(*) [[:id, {:primary_key=>true}]] end
|
58
|
-
def db.reset() sqls end
|
59
|
-
def db.supports_schema_parsing?() true end
|
60
|
-
Sequel::Model.db = DB = db
|
61
|
-
|
62
|
-
if ENV['SEQUEL_COLUMNS_INTROSPECTION']
|
63
|
-
Sequel.extension :columns_introspection
|
64
|
-
Sequel::Database.extension :columns_introspection
|
65
|
-
Sequel::Mock::Dataset.send(:include, Sequel::ColumnsIntrospection)
|
66
|
-
end
|
67
|
-
if ENV['SEQUEL_NO_CACHE_ASSOCIATIONS']
|
68
|
-
Sequel::Model.cache_associations = false
|
69
|
-
end
|
70
|
-
Sequel::Model.plugin :throw_failures if ENV['SEQUEL_MODEL_THROW_FAILURES']
|