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,19 +0,0 @@
|
|
1
|
-
Class.new(Sequel::Migration) do
|
2
|
-
def up
|
3
|
-
create_table(:sm2222){Integer :smc2}
|
4
|
-
end
|
5
|
-
|
6
|
-
def down
|
7
|
-
drop_table(:sm2222)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
Class.new(Sequel::Migration) do
|
12
|
-
def up
|
13
|
-
create_table(:sm2443){Integer :smc2}
|
14
|
-
end
|
15
|
-
|
16
|
-
def down
|
17
|
-
drop_table(:sm2443)
|
18
|
-
end
|
19
|
-
end
|
File without changes
|
data/spec/guards_helper.rb
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
|
2
|
-
gem 'minitest'
|
3
|
-
require 'minitest/global_expectations/autorun'
|
4
|
-
require 'minitest/hooks/default'
|
5
|
-
require 'minitest/shared_description'
|
6
|
-
|
7
|
-
require_relative "deprecation_helper"
|
8
|
-
|
9
|
-
def Sequel.guarded?(*checked)
|
10
|
-
unless ENV['SEQUEL_NO_PENDING']
|
11
|
-
checked.each do |c|
|
12
|
-
case c
|
13
|
-
when DB.database_type
|
14
|
-
return c
|
15
|
-
when Array
|
16
|
-
case c.length
|
17
|
-
when 1
|
18
|
-
return c if c.first == DB.adapter_scheme
|
19
|
-
when 2
|
20
|
-
if c.first.is_a?(Proc)
|
21
|
-
return c if c.last == DB.database_type && c.first.call(DB)
|
22
|
-
elsif c.last.is_a?(Proc)
|
23
|
-
return c if c.first == DB.adapter_scheme && c.last.call(DB)
|
24
|
-
else
|
25
|
-
return c if c.first == DB.adapter_scheme && c.last == DB.database_type
|
26
|
-
end
|
27
|
-
when 3
|
28
|
-
return c if c[0] == DB.adapter_scheme && c[1] == DB.database_type && c[2].call(DB)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
false
|
34
|
-
end
|
35
|
-
|
36
|
-
module Minitest::Spec::DSL
|
37
|
-
def cspecify(message, *checked, &block)
|
38
|
-
if pending = Sequel.guarded?(*checked)
|
39
|
-
it(message) do
|
40
|
-
proc{instance_exec(&block)}.must_raise(Exception) if ENV['SEQUEL_CHECK_PENDING']
|
41
|
-
skip "Not yet working on #{Array(pending).map{|x| x.is_a?(Proc) ? :proc : x}.join(', ')}"
|
42
|
-
end
|
43
|
-
else
|
44
|
-
it(message, &block)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class Minitest::HooksSpec
|
50
|
-
def log
|
51
|
-
begin
|
52
|
-
DB.loggers << Logger.new(STDOUT)
|
53
|
-
yield
|
54
|
-
ensure
|
55
|
-
DB.loggers.pop
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
@@ -1,2597 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
OneToOneEagerLimitStrategies = shared_description do
|
4
|
-
it "eager loading one_to_one associations should work correctly" do
|
5
|
-
Artist.one_to_one :first_album, {:clone=>:first_album}.merge(@els) if @els
|
6
|
-
Artist.one_to_one :last_album, {:clone=>:last_album}.merge(@els) if @els
|
7
|
-
Artist.one_to_one :second_album, {:clone=>:second_album}.merge(@els) if @els && @els[:eager_limit_strategy] != :distinct_on
|
8
|
-
@album.update(:artist => @artist)
|
9
|
-
diff_album = @diff_album.call
|
10
|
-
ar = @pr.call[1]
|
11
|
-
|
12
|
-
a = Artist.eager(:first_album, :last_album, :second_album).order(:name).all
|
13
|
-
a.must_equal [@artist, ar]
|
14
|
-
a.first.first_album.must_equal @album
|
15
|
-
a.first.last_album.must_equal diff_album
|
16
|
-
a.first.second_album.must_equal diff_album
|
17
|
-
a.last.first_album.must_be_nil
|
18
|
-
a.last.last_album.must_be_nil
|
19
|
-
a.last.second_album.must_be_nil
|
20
|
-
|
21
|
-
# Check that no extra columns got added by the eager loading
|
22
|
-
a.first.first_album.values.must_equal @album.values
|
23
|
-
a.first.last_album.values.must_equal diff_album.values
|
24
|
-
a.first.second_album.values.must_equal diff_album.values
|
25
|
-
|
26
|
-
same_album = @same_album.call
|
27
|
-
a = Artist.eager(:first_album).order(:name).all
|
28
|
-
a.must_equal [@artist, ar]
|
29
|
-
[@album, same_album].must_include(a.first.first_album)
|
30
|
-
a.last.first_album.must_be_nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
OneToOneEagerGraphLimitStrategies = shared_description do
|
35
|
-
it "eager graphing one_to_one associations should work correctly" do
|
36
|
-
@album.update(:artist => @artist)
|
37
|
-
diff_album = @diff_album.call
|
38
|
-
ar = @pr.call[1]
|
39
|
-
ds = Artist.order(Sequel[:artists][:name])
|
40
|
-
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
41
|
-
|
42
|
-
a = ds.eager_graph_with_options(:first_album, limit_strategy).all
|
43
|
-
a.must_equal [@artist, ar]
|
44
|
-
a.first.first_album.must_equal @album
|
45
|
-
a.last.first_album.must_be_nil
|
46
|
-
a.first.first_album.values.must_equal @album.values
|
47
|
-
|
48
|
-
a = ds.eager_graph_with_options(:last_album, limit_strategy).all
|
49
|
-
a = ds.eager_graph(:last_album).all
|
50
|
-
a.must_equal [@artist, ar]
|
51
|
-
a.first.last_album.must_equal diff_album
|
52
|
-
a.last.last_album.must_be_nil
|
53
|
-
a.first.last_album.values.must_equal diff_album.values
|
54
|
-
|
55
|
-
if @els[:eager_limit_strategy] != :distinct_on && (@els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?)
|
56
|
-
a = ds.eager_graph_with_options(:second_album, limit_strategy).all
|
57
|
-
a = ds.eager_graph(:second_album).all
|
58
|
-
a.must_equal [@artist, ar]
|
59
|
-
a.first.second_album.must_equal diff_album
|
60
|
-
a.last.second_album.must_be_nil
|
61
|
-
a.first.second_album.values.must_equal diff_album.values
|
62
|
-
end
|
63
|
-
|
64
|
-
same_album = @same_album.call
|
65
|
-
a = ds.eager_graph_with_options(:first_album, limit_strategy).all
|
66
|
-
a.must_equal [@artist, ar]
|
67
|
-
[@album, same_album].must_include(a.first.first_album)
|
68
|
-
a.last.first_album.must_be_nil
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
OneToManyEagerLimitStrategies = shared_description do
|
73
|
-
it "should correctly handle limits and offsets when eager loading one_to_many associations" do
|
74
|
-
Artist.one_to_many :first_two_albums, {:clone=>:first_two_albums}.merge(@els) if @els
|
75
|
-
Artist.one_to_many :second_two_albums, {:clone=>:second_two_albums}.merge(@els) if @els
|
76
|
-
Artist.one_to_many :not_first_albums, {:clone=>:not_first_albums}.merge(@els) if @els
|
77
|
-
Artist.one_to_many :last_two_albums, {:clone=>:last_two_albums}.merge(@els) if @els
|
78
|
-
@album.update(:artist => @artist)
|
79
|
-
middle_album = @middle_album.call
|
80
|
-
diff_album = @diff_album.call
|
81
|
-
ar = @pr.call[1]
|
82
|
-
|
83
|
-
ars = Artist.eager(:first_two_albums, :second_two_albums, :not_first_albums, :last_two_albums).order(:name).all
|
84
|
-
ars.must_equal [@artist, ar]
|
85
|
-
ars.first.first_two_albums.must_equal [@album, middle_album]
|
86
|
-
ars.first.second_two_albums.must_equal [middle_album, diff_album]
|
87
|
-
ars.first.not_first_albums.must_equal [middle_album, diff_album]
|
88
|
-
ars.first.last_two_albums.must_equal [diff_album, middle_album]
|
89
|
-
ars.last.first_two_albums.must_equal []
|
90
|
-
ars.last.second_two_albums.must_equal []
|
91
|
-
ars.last.not_first_albums.must_equal []
|
92
|
-
ars.last.last_two_albums.must_equal []
|
93
|
-
|
94
|
-
# Check that no extra columns got added by the eager loading
|
95
|
-
ars.first.first_two_albums.map{|x| x.values}.must_equal [@album, middle_album].map{|x| x.values}
|
96
|
-
ars.first.second_two_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
|
97
|
-
ars.first.not_first_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
|
98
|
-
ars.first.last_two_albums.map{|x| x.values}.must_equal [diff_album, middle_album].map{|x| x.values}
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
OneToManyEagerGraphLimitStrategies = shared_description do
|
103
|
-
it "should correctly handle limits and offsets when eager graphing one_to_many associations" do
|
104
|
-
@album.update(:artist => @artist)
|
105
|
-
middle_album = @middle_album.call
|
106
|
-
diff_album = @diff_album.call
|
107
|
-
ar = @pr.call[1]
|
108
|
-
ds = Artist.order(Sequel[:artists][:name])
|
109
|
-
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
110
|
-
|
111
|
-
ars = ds.eager_graph_with_options(:first_two_albums, limit_strategy).all
|
112
|
-
ars.must_equal [@artist, ar]
|
113
|
-
ars.first.first_two_albums.must_equal [@album, middle_album]
|
114
|
-
ars.last.first_two_albums.must_equal []
|
115
|
-
ars.first.first_two_albums.map{|x| x.values}.must_equal [@album, middle_album].map{|x| x.values}
|
116
|
-
|
117
|
-
if @els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?
|
118
|
-
ars = ds.eager_graph_with_options(:second_two_albums, limit_strategy).all
|
119
|
-
ars.must_equal [@artist, ar]
|
120
|
-
ars.first.second_two_albums.must_equal [middle_album, diff_album]
|
121
|
-
ars.last.second_two_albums.must_equal []
|
122
|
-
ars.first.second_two_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
|
123
|
-
|
124
|
-
ars = ds.eager_graph_with_options(:not_first_albums, limit_strategy).all
|
125
|
-
ars.must_equal [@artist, ar]
|
126
|
-
ars.first.not_first_albums.must_equal [middle_album, diff_album]
|
127
|
-
ars.last.not_first_albums.must_equal []
|
128
|
-
ars.first.not_first_albums.map{|x| x.values}.must_equal [middle_album, diff_album].map{|x| x.values}
|
129
|
-
end
|
130
|
-
|
131
|
-
ars = ds.eager_graph_with_options(:last_two_albums, limit_strategy).all
|
132
|
-
ars.must_equal [@artist, ar]
|
133
|
-
ars.first.last_two_albums.must_equal [diff_album, middle_album]
|
134
|
-
ars.last.last_two_albums.must_equal []
|
135
|
-
ars.first.last_two_albums.map{|x| x.values}.must_equal [diff_album, middle_album].map{|x| x.values}
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
OneThroughOneEagerLimitStrategies = shared_description do
|
140
|
-
it "should correctly handle offsets when eager loading one_through_one associations" do
|
141
|
-
Album.one_through_one :first_tag, {:clone=>:first_tag}.merge(@els) if @els
|
142
|
-
Album.one_through_one :second_tag, {:clone=>:second_tag}.merge(@els) if @els && @els[:eager_limit_strategy] != :distinct_on
|
143
|
-
Album.one_through_one :last_tag, {:clone=>:last_tag}.merge(@els) if @els
|
144
|
-
tu, tv = @other_tags.call
|
145
|
-
al = @pr.call.first
|
146
|
-
|
147
|
-
als = Album.eager(:first_tag, :second_tag, :last_tag).order(:name).all
|
148
|
-
als.must_equal [@album, al]
|
149
|
-
als.first.first_tag.must_equal @tag
|
150
|
-
als.first.second_tag.must_equal tu
|
151
|
-
als.first.last_tag.must_equal tv
|
152
|
-
als.last.first_tag.must_be_nil
|
153
|
-
als.last.second_tag.must_be_nil
|
154
|
-
als.last.last_tag.must_be_nil
|
155
|
-
|
156
|
-
# Check that no extra columns got added by the eager loading
|
157
|
-
als.first.first_tag.values.must_equal @tag.values
|
158
|
-
als.first.second_tag.values.must_equal tu.values
|
159
|
-
als.first.last_tag.values.must_equal tv.values
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
OneThroughOneEagerGraphLimitStrategies = shared_description do
|
164
|
-
it "should correctly handle offsets when eager graphing one_through_one associations" do
|
165
|
-
tu, tv = @other_tags.call
|
166
|
-
al = @pr.call.first
|
167
|
-
ds = Album.order(Sequel[:albums][:name])
|
168
|
-
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
169
|
-
|
170
|
-
als = ds.eager_graph_with_options(:first_tag, limit_strategy).all
|
171
|
-
als.must_equal [@album, al]
|
172
|
-
als.first.first_tag.must_equal @tag
|
173
|
-
als.last.first_tag.must_be_nil
|
174
|
-
als.first.first_tag.values.must_equal @tag.values
|
175
|
-
|
176
|
-
als = ds.eager_graph_with_options(:second_tag, @els[:eager_limit_strategy] != :distinct_on ? limit_strategy : {}).all
|
177
|
-
als.must_equal [@album, al]
|
178
|
-
als.first.second_tag.must_equal tu
|
179
|
-
als.last.second_tag.must_be_nil
|
180
|
-
als.first.second_tag.values.must_equal tu.values
|
181
|
-
|
182
|
-
als = ds.eager_graph_with_options(:last_tag, limit_strategy).all
|
183
|
-
als.must_equal [@album, al]
|
184
|
-
als.first.last_tag.must_equal tv
|
185
|
-
als.last.last_tag.must_be_nil
|
186
|
-
als.first.last_tag.values.must_equal tv.values
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
ManyToManyEagerLimitStrategies = shared_description do
|
191
|
-
it "should correctly handle limits and offsets when eager loading many_to_many associations" do
|
192
|
-
Album.send @many_to_many_method||:many_to_many, :first_two_tags, {:clone=>:first_two_tags}.merge(@els) if @els
|
193
|
-
Album.send @many_to_many_method||:many_to_many, :second_two_tags, {:clone=>:second_two_tags}.merge(@els) if @els
|
194
|
-
Album.send @many_to_many_method||:many_to_many, :not_first_tags, {:clone=>:not_first_tags}.merge(@els) if @els
|
195
|
-
Album.send @many_to_many_method||:many_to_many, :last_two_tags, {:clone=>:last_two_tags}.merge(@els) if @els
|
196
|
-
tu, tv = @other_tags.call
|
197
|
-
al = @pr.call.first
|
198
|
-
al.add_tag(tu)
|
199
|
-
|
200
|
-
als = Album.eager(:first_two_tags, :second_two_tags, :not_first_tags, :last_two_tags).order(:name).all
|
201
|
-
als.must_equal [@album, al]
|
202
|
-
als.first.first_two_tags.must_equal [@tag, tu]
|
203
|
-
als.first.second_two_tags.must_equal [tu, tv]
|
204
|
-
als.first.not_first_tags.must_equal [tu, tv]
|
205
|
-
als.first.last_two_tags.must_equal [tv, tu]
|
206
|
-
als.last.first_two_tags.must_equal [tu]
|
207
|
-
als.last.second_two_tags.must_equal []
|
208
|
-
als.last.last_two_tags.must_equal [tu]
|
209
|
-
|
210
|
-
# Check that no extra columns got added by the eager loading
|
211
|
-
als.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
|
212
|
-
als.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
213
|
-
als.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
214
|
-
als.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
ManyToManyEagerGraphLimitStrategies = shared_description do
|
219
|
-
it "should correctly handle limits and offsets when eager loading many_to_many associations" do
|
220
|
-
tu, tv = @other_tags.call
|
221
|
-
al = @pr.call.first
|
222
|
-
al.add_tag(tu)
|
223
|
-
ds = Album.order(Sequel[:albums][:name])
|
224
|
-
limit_strategy = {:limit_strategy=>(@els||{})[:eager_limit_strategy]}
|
225
|
-
|
226
|
-
als = ds.eager_graph_with_options(:first_two_tags, limit_strategy).all
|
227
|
-
als.must_equal [@album, al]
|
228
|
-
als.first.first_two_tags.must_equal [@tag, tu]
|
229
|
-
als.last.first_two_tags.must_equal [tu]
|
230
|
-
als.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
|
231
|
-
|
232
|
-
als = ds.eager_graph_with_options(:second_two_tags, limit_strategy).all
|
233
|
-
als.must_equal [@album, al]
|
234
|
-
als.first.second_two_tags.must_equal [tu, tv]
|
235
|
-
als.last.second_two_tags.must_equal []
|
236
|
-
als.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
237
|
-
|
238
|
-
als = ds.eager_graph_with_options(:not_first_tags, limit_strategy).all
|
239
|
-
als.must_equal [@album, al]
|
240
|
-
als.first.not_first_tags.must_equal [tu, tv]
|
241
|
-
als.last.not_first_tags.must_equal []
|
242
|
-
als.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
243
|
-
|
244
|
-
als = ds.eager_graph_with_options(:last_two_tags, limit_strategy).all
|
245
|
-
als.must_equal [@album, al]
|
246
|
-
als.first.last_two_tags.must_equal [tv, tu]
|
247
|
-
als.last.last_two_tags.must_equal [tu]
|
248
|
-
als.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
ManyThroughManyEagerLimitStrategies = shared_description do
|
253
|
-
it "should correctly handle limits and offsets when eager loading many_through_many associations" do
|
254
|
-
Artist.many_through_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els) if @els
|
255
|
-
Artist.many_through_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els) if @els
|
256
|
-
Artist.many_through_many :not_first_tags, {:clone=>:not_first_tags}.merge(@els) if @els
|
257
|
-
Artist.many_through_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els) if @els
|
258
|
-
@album.update(:artist => @artist)
|
259
|
-
tu, tv = @other_tags.call
|
260
|
-
al, ar, _ = @pr.call
|
261
|
-
al.update(:artist=>ar)
|
262
|
-
al.add_tag(tu)
|
263
|
-
|
264
|
-
ars = Artist.eager(:first_two_tags, :second_two_tags, :not_first_tags, :last_two_tags).order(:name).all
|
265
|
-
ars.must_equal [@artist, ar]
|
266
|
-
ars.first.first_two_tags.must_equal [@tag, tu]
|
267
|
-
ars.first.second_two_tags.must_equal [tu, tv]
|
268
|
-
ars.first.not_first_tags.must_equal [tu, tv]
|
269
|
-
ars.first.last_two_tags.must_equal [tv, tu]
|
270
|
-
ars.last.first_two_tags.must_equal [tu]
|
271
|
-
ars.last.second_two_tags.must_equal []
|
272
|
-
ars.last.not_first_tags.must_equal []
|
273
|
-
ars.last.last_two_tags.must_equal [tu]
|
274
|
-
|
275
|
-
# Check that no extra columns got added by the eager loading
|
276
|
-
ars.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
|
277
|
-
ars.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
278
|
-
ars.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
279
|
-
ars.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
ManyThroughManyEagerGraphLimitStrategies = shared_description do
|
284
|
-
it "should correctly handle limits and offsets when eager loading many_through_many associations" do
|
285
|
-
@album.update(:artist => @artist)
|
286
|
-
tu, tv = @other_tags.call
|
287
|
-
al, ar, _ = @pr.call
|
288
|
-
al.update(:artist=>ar)
|
289
|
-
al.add_tag(tu)
|
290
|
-
ds = Artist.order(Sequel[:artists][:name])
|
291
|
-
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
292
|
-
|
293
|
-
ars = ds.eager_graph_with_options(:first_two_tags, limit_strategy).all
|
294
|
-
ars.must_equal [@artist, ar]
|
295
|
-
ars.first.first_two_tags.must_equal [@tag, tu]
|
296
|
-
ars.last.first_two_tags.must_equal [tu]
|
297
|
-
ars.first.first_two_tags.map{|x| x.values}.must_equal [@tag, tu].map{|x| x.values}
|
298
|
-
|
299
|
-
ars = ds.eager_graph_with_options(:second_two_tags, limit_strategy).all
|
300
|
-
ars.must_equal [@artist, ar]
|
301
|
-
ars.first.second_two_tags.must_equal [tu, tv]
|
302
|
-
ars.last.second_two_tags.must_equal []
|
303
|
-
ars.first.second_two_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
304
|
-
|
305
|
-
ars = ds.eager_graph_with_options(:not_first_tags, limit_strategy).all
|
306
|
-
ars.must_equal [@artist, ar]
|
307
|
-
ars.first.not_first_tags.must_equal [tu, tv]
|
308
|
-
ars.last.not_first_tags.must_equal []
|
309
|
-
ars.first.not_first_tags.map{|x| x.values}.must_equal [tu, tv].map{|x| x.values}
|
310
|
-
|
311
|
-
ars = ds.eager_graph_with_options(:last_two_tags, limit_strategy).all
|
312
|
-
ars.must_equal [@artist, ar]
|
313
|
-
ars.first.last_two_tags.must_equal [tv, tu]
|
314
|
-
ars.last.last_two_tags.must_equal [tu]
|
315
|
-
ars.first.last_two_tags.map{|x| x.values}.must_equal [tv, tu].map{|x| x.values}
|
316
|
-
end
|
317
|
-
end
|
318
|
-
|
319
|
-
OneThroughManyEagerLimitStrategies = shared_description do
|
320
|
-
it "should correctly handle offsets when eager loading one_through_many associations" do
|
321
|
-
Artist.one_through_many :first_tag, {:clone=>:first_tag}.merge(@els) if @els
|
322
|
-
Artist.one_through_many :second_tag, {:clone=>:second_tag}.merge(@els) if @els && @els[:eager_limit_strategy] != :distinct_on
|
323
|
-
Artist.one_through_many :last_tag, {:clone=>:last_tag}.merge(@els) if @els
|
324
|
-
@album.update(:artist => @artist)
|
325
|
-
tu, tv = @other_tags.call
|
326
|
-
al, ar, _ = @pr.call
|
327
|
-
al.update(:artist=>ar)
|
328
|
-
al.add_tag(tu)
|
329
|
-
|
330
|
-
ars = Artist.eager(:first_tag, :second_tag, :last_tag).order(:name).all
|
331
|
-
ars.must_equal [@artist, ar]
|
332
|
-
ars.first.first_tag.must_equal @tag
|
333
|
-
ars.first.second_tag.must_equal tu
|
334
|
-
ars.first.last_tag.must_equal tv
|
335
|
-
ars.last.first_tag.must_equal tu
|
336
|
-
ars.last.second_tag.must_be_nil
|
337
|
-
ars.last.last_tag.must_equal tu
|
338
|
-
|
339
|
-
# Check that no extra columns got added by the eager loading
|
340
|
-
ars.first.first_tag.values.must_equal @tag.values
|
341
|
-
ars.first.second_tag.values.must_equal tu.values
|
342
|
-
ars.first.last_tag.values.must_equal tv.values
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
OneThroughManyEagerGraphLimitStrategies = shared_description do
|
347
|
-
it "should correctly handle offsets when eager graphing one_through_many associations" do
|
348
|
-
@album.update(:artist => @artist)
|
349
|
-
tu, tv = @other_tags.call
|
350
|
-
al, ar, _ = @pr.call
|
351
|
-
al.update(:artist=>ar)
|
352
|
-
al.add_tag(tu)
|
353
|
-
ds = Artist.order(Sequel[:artists][:name])
|
354
|
-
limit_strategy = {:limit_strategy=>@els[:eager_limit_strategy]}
|
355
|
-
|
356
|
-
ars = ds.eager_graph_with_options(:first_tag, limit_strategy).all
|
357
|
-
ars.must_equal [@artist, ar]
|
358
|
-
ars.first.first_tag.must_equal @tag
|
359
|
-
ars.last.first_tag.must_equal tu
|
360
|
-
ars.first.first_tag.values.must_equal @tag.values
|
361
|
-
|
362
|
-
ars = ds.eager_graph_with_options(:second_tag, @els[:eager_limit_strategy] != :distinct_on ? limit_strategy : {}).all
|
363
|
-
ars.must_equal [@artist, ar]
|
364
|
-
ars.first.second_tag.must_equal tu
|
365
|
-
ars.last.second_tag.must_be_nil
|
366
|
-
ars.first.second_tag.values.must_equal tu.values
|
367
|
-
|
368
|
-
ars = ds.eager_graph_with_options(:last_tag, limit_strategy).all
|
369
|
-
ars.must_equal [@artist, ar]
|
370
|
-
ars.first.last_tag.must_equal tv
|
371
|
-
ars.last.last_tag.must_equal tu
|
372
|
-
ars.first.last_tag.values.must_equal tv.values
|
373
|
-
end
|
374
|
-
end
|
375
|
-
|
376
|
-
EagerLimitStrategies = shared_description do
|
377
|
-
include OneToOneEagerLimitStrategies
|
378
|
-
include OneToManyEagerLimitStrategies
|
379
|
-
include ManyToManyEagerLimitStrategies
|
380
|
-
include OneThroughOneEagerLimitStrategies
|
381
|
-
include ManyThroughManyEagerLimitStrategies
|
382
|
-
include OneThroughManyEagerLimitStrategies
|
383
|
-
end
|
384
|
-
|
385
|
-
EagerGraphLimitStrategies = shared_description do
|
386
|
-
include OneToOneEagerGraphLimitStrategies
|
387
|
-
include OneToManyEagerGraphLimitStrategies
|
388
|
-
include ManyToManyEagerGraphLimitStrategies
|
389
|
-
include OneThroughOneEagerGraphLimitStrategies
|
390
|
-
include ManyThroughManyEagerGraphLimitStrategies
|
391
|
-
include OneThroughManyEagerGraphLimitStrategies
|
392
|
-
end
|
393
|
-
|
394
|
-
FilterByAssociations = shared_description do
|
395
|
-
it "should handle association inner joins" do
|
396
|
-
@Artist.association_join(:albums).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).all.must_equal []
|
397
|
-
@Artist.association_join(:first_album).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).all.must_equal []
|
398
|
-
@Album.association_join(:artist).select(Sequel.qualify(@Album.first_source, @Album.columns.first)).all.must_equal []
|
399
|
-
@Album.association_join(:tags).select(Sequel.qualify(@Album.first_source, @Album.columns.first)).all.must_equal []
|
400
|
-
@Album.association_join(:alias_tags).select(Sequel.qualify(@Album.first_source, @Album.columns.first)).all.must_equal []
|
401
|
-
@Tag.association_join(:albums).select(Sequel.qualify(@Tag.first_source, @Tag.columns.first)).all.must_equal []
|
402
|
-
unless @no_many_through_many
|
403
|
-
@Artist.association_join(:tags).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).all.must_equal []
|
404
|
-
@Artist.association_join(:first_tag).select(Sequel.qualify(@Artist.first_source, @Artist.columns.first)).all.must_equal []
|
405
|
-
end
|
406
|
-
|
407
|
-
@album.update(:artist => @artist)
|
408
|
-
@album.add_tag(@tag)
|
409
|
-
|
410
|
-
@Artist.association_join(:albums).select_all(:artists).all.must_equal [@artist]
|
411
|
-
@Artist.association_join(:first_album).select_all(:artists).all.must_equal [@artist]
|
412
|
-
@Album.association_join(:artist).select_all(:albums).all.must_equal [@album]
|
413
|
-
@Album.association_join(:tags).select_all(:albums).all.must_equal [@album]
|
414
|
-
@Album.association_join(:alias_tags).select_all(:albums).all.must_equal [@album]
|
415
|
-
@Tag.association_join(:albums).select_all(:tags).all.must_equal [@tag]
|
416
|
-
unless @no_many_through_many
|
417
|
-
@Artist.association_join(:tags).select_all(:artists).all.must_equal [@artist]
|
418
|
-
@Artist.association_join(:first_tag).select_all(:artists).all.must_equal [@artist]
|
419
|
-
end
|
420
|
-
|
421
|
-
@Artist.association_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
|
422
|
-
@Artist.association_join(:first_album).select_all(:first_album).naked.all.must_equal [@album.values]
|
423
|
-
@Album.association_join(:artist).select_all(:artist).naked.all.must_equal [@artist.values]
|
424
|
-
@Album.association_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
|
425
|
-
@Album.association_join(:alias_tags).select_all(:alias_tags).naked.all.must_equal [@tag.values]
|
426
|
-
@Tag.association_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
|
427
|
-
unless @no_many_through_many
|
428
|
-
@Artist.association_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
|
429
|
-
@Artist.association_join(:first_tag).select_all(:first_tag).naked.all.must_equal [@tag.values]
|
430
|
-
end
|
431
|
-
end
|
432
|
-
|
433
|
-
it "should handle association left joins" do
|
434
|
-
@Artist.association_left_join(:albums).select_all(:artists).all.must_equal [@artist]
|
435
|
-
@Artist.association_left_join(:first_album).select_all(:artists).all.must_equal [@artist]
|
436
|
-
@Album.association_left_join(:artist).select_all(:albums).all.must_equal [@album]
|
437
|
-
@Album.association_left_join(:tags).select_all(:albums).all.must_equal [@album]
|
438
|
-
@Album.association_left_join(:alias_tags).select_all(:albums).all.must_equal [@album]
|
439
|
-
@Tag.association_left_join(:albums).select_all(:tags).all.must_equal [@tag]
|
440
|
-
unless @no_many_through_many
|
441
|
-
@Artist.association_left_join(:tags).select_all(:artists).all.must_equal [@artist]
|
442
|
-
@Artist.association_left_join(:first_tag).select_all(:artists).all.must_equal [@artist]
|
443
|
-
end
|
444
|
-
|
445
|
-
nil_hash = lambda{|obj| [obj.values.keys.inject({}){|h,k| h[k] = nil; h}]}
|
446
|
-
@Artist.association_left_join(:albums).select_all(:albums).naked.all.must_equal nil_hash[@album]
|
447
|
-
@Artist.association_left_join(:first_album).select_all(:first_album).naked.all.must_equal nil_hash[@album]
|
448
|
-
@Album.association_left_join(:artist).select_all(:artist).naked.all.must_equal nil_hash[@artist]
|
449
|
-
@Album.association_left_join(:tags).select_all(:tags).naked.all.must_equal nil_hash[@tag]
|
450
|
-
@Album.association_left_join(:alias_tags).select_all(:alias_tags).naked.all.must_equal nil_hash[@tag]
|
451
|
-
@Tag.association_left_join(:albums).select_all(:albums).naked.all.must_equal nil_hash[@album]
|
452
|
-
unless @no_many_through_many
|
453
|
-
@Artist.association_left_join(:tags).select_all(:tags).naked.all.must_equal nil_hash[@tag]
|
454
|
-
@Artist.association_left_join(:first_tag).select_all(:first_tag).naked.all.must_equal nil_hash[@tag]
|
455
|
-
end
|
456
|
-
|
457
|
-
@album.update(:artist => @artist)
|
458
|
-
@album.add_tag(@tag)
|
459
|
-
|
460
|
-
|
461
|
-
@Artist.association_left_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
|
462
|
-
@Artist.association_left_join(:first_album).select_all(:first_album).naked.all.must_equal [@album.values]
|
463
|
-
@Album.association_left_join(:artist).select_all(:artist).naked.all.must_equal [@artist.values]
|
464
|
-
@Album.association_left_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
|
465
|
-
@Album.association_left_join(:alias_tags).select_all(:alias_tags).naked.all.must_equal [@tag.values]
|
466
|
-
@Tag.association_left_join(:albums).select_all(:albums).naked.all.must_equal [@album.values]
|
467
|
-
unless @no_many_through_many
|
468
|
-
@Artist.association_left_join(:tags).select_all(:tags).naked.all.must_equal [@tag.values]
|
469
|
-
@Artist.association_left_join(:first_tag).select_all(:first_tag).naked.all.must_equal [@tag.values]
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
it "should work correctly when filtering by associations" do
|
474
|
-
@album.update(:artist => @artist)
|
475
|
-
@album.add_tag(@tag)
|
476
|
-
|
477
|
-
@Artist.filter(:albums=>@album).all.must_equal [@artist]
|
478
|
-
@Artist.filter(:first_album=>@album).all.must_equal [@artist]
|
479
|
-
unless @no_many_through_many
|
480
|
-
@Artist.filter(:tags=>@tag).all.must_equal [@artist]
|
481
|
-
@Artist.filter(:first_tag=>@tag).all.must_equal [@artist]
|
482
|
-
end
|
483
|
-
@Album.filter(:artist=>@artist).all.must_equal [@album]
|
484
|
-
@Album.filter(:tags=>@tag).all.must_equal [@album]
|
485
|
-
@Album.filter(:alias_tags=>@tag).all.must_equal [@album]
|
486
|
-
@Tag.filter(:albums=>@album).all.must_equal [@tag]
|
487
|
-
@Album.filter(:artist=>@artist, :tags=>@tag).all.must_equal [@album]
|
488
|
-
@artist.albums_dataset.filter(:tags=>@tag).all.must_equal [@album]
|
489
|
-
end
|
490
|
-
|
491
|
-
it "should work correctly when excluding by associations" do
|
492
|
-
@album.update(:artist => @artist)
|
493
|
-
@album.add_tag(@tag)
|
494
|
-
album, artist, tag = @pr.call
|
495
|
-
|
496
|
-
@Artist.exclude(:albums=>@album).all.must_equal [artist]
|
497
|
-
@Artist.exclude(:first_album=>@album).all.must_equal [artist]
|
498
|
-
unless @no_many_through_many
|
499
|
-
@Artist.exclude(:tags=>@tag).all.must_equal [artist]
|
500
|
-
@Artist.exclude(:first_tag=>@tag).all.must_equal [artist]
|
501
|
-
end
|
502
|
-
@Album.exclude(:artist=>@artist).all.must_equal [album]
|
503
|
-
@Album.exclude(:tags=>@tag).all.must_equal [album]
|
504
|
-
@Album.exclude(:alias_tags=>@tag).all.must_equal [album]
|
505
|
-
@Tag.exclude(:albums=>@album).all.must_equal [tag]
|
506
|
-
@Album.exclude(:artist=>@artist, :tags=>@tag).all.must_equal [album]
|
507
|
-
end
|
508
|
-
|
509
|
-
it "should work correctly when filtering by associations with conditions" do
|
510
|
-
@album.update(:artist => @artist)
|
511
|
-
@album.add_tag(@tag)
|
512
|
-
|
513
|
-
@Artist.filter(:a_albums=>@album).all.must_equal [@artist]
|
514
|
-
@Artist.filter(:first_a_album=>@album).all.must_equal [@artist]
|
515
|
-
@album.update(:name=>'Foo')
|
516
|
-
@Artist.filter(:a_albums=>@album).all.must_equal []
|
517
|
-
@Artist.filter(:first_a_album=>@album).all.must_equal []
|
518
|
-
|
519
|
-
@Album.filter(:a_artist=>@artist).all.must_equal [@album]
|
520
|
-
@artist.update(:name=>'Foo')
|
521
|
-
@Album.filter(:a_artist=>@artist).all.must_equal []
|
522
|
-
|
523
|
-
@Album.filter(:t_tags=>@tag).all.must_equal [@album]
|
524
|
-
@Album.filter(:alias_t_tags=>@tag).all.must_equal [@album]
|
525
|
-
unless @no_many_through_many
|
526
|
-
@Album.filter(:t_tag=>@tag).all.must_equal [@album]
|
527
|
-
@Album.filter(:alias_t_tag=>@tag).all.must_equal [@album]
|
528
|
-
@Artist.filter(:t_tags=>@tag).all.must_equal [@artist]
|
529
|
-
@Artist.filter(:t_tag=>@tag).all.must_equal [@artist]
|
530
|
-
end
|
531
|
-
@tag.update(:name=>'Foo')
|
532
|
-
@Album.filter(:t_tags=>@tag).all.must_equal []
|
533
|
-
@Album.filter(:alias_t_tags=>@tag).all.must_equal []
|
534
|
-
unless @no_many_through_many
|
535
|
-
@Album.filter(:t_tag=>@tag).all.must_equal []
|
536
|
-
@Album.filter(:alias_t_tag=>@tag).all.must_equal []
|
537
|
-
@Artist.filter(:t_tags=>@tag).all.must_equal []
|
538
|
-
@Artist.filter(:t_tag=>@tag).all.must_equal []
|
539
|
-
end
|
540
|
-
end
|
541
|
-
|
542
|
-
it "should work correctly when excluding by associations with conditions" do
|
543
|
-
@album.update(:artist => @artist)
|
544
|
-
@album.add_tag(@tag)
|
545
|
-
|
546
|
-
@Artist.exclude(:a_albums=>@album).all.must_equal []
|
547
|
-
@Artist.exclude(:first_a_album=>@album).all.must_equal []
|
548
|
-
@album.update(:name=>'Foo')
|
549
|
-
@Artist.exclude(:a_albums=>@album).all.must_equal [@artist]
|
550
|
-
@Artist.exclude(:first_a_album=>@album).all.must_equal [@artist]
|
551
|
-
|
552
|
-
@Album.exclude(:a_artist=>@artist).all.must_equal []
|
553
|
-
@artist.update(:name=>'Foo')
|
554
|
-
@Album.exclude(:a_artist=>@artist).all.must_equal [@album]
|
555
|
-
|
556
|
-
@Album.exclude(:t_tags=>@tag).all.must_equal []
|
557
|
-
@Album.exclude(:alias_t_tags=>@tag).all.must_equal []
|
558
|
-
unless @no_many_through_many
|
559
|
-
@Album.exclude(:t_tag=>@tag).all.must_equal []
|
560
|
-
@Album.exclude(:alias_t_tag=>@tag).all.must_equal []
|
561
|
-
@Artist.exclude(:t_tags=>@tag).all.must_equal []
|
562
|
-
@Artist.exclude(:t_tag=>@tag).all.must_equal []
|
563
|
-
end
|
564
|
-
@tag.update(:name=>'Foo')
|
565
|
-
@Album.exclude(:t_tags=>@tag).all.must_equal [@album]
|
566
|
-
@Album.exclude(:alias_t_tags=>@tag).all.must_equal [@album]
|
567
|
-
unless @no_many_through_many
|
568
|
-
@Album.exclude(:t_tag=>@tag).all.must_equal [@album]
|
569
|
-
@Album.exclude(:alias_t_tag=>@tag).all.must_equal [@album]
|
570
|
-
@Artist.exclude(:t_tags=>@tag).all.must_equal [@artist]
|
571
|
-
@Artist.exclude(:t_tag=>@tag).all.must_equal [@artist]
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
it "should work correctly when filtering by multiple associations" do
|
576
|
-
album, artist, tag = @pr.call
|
577
|
-
@album.update(:artist => @artist)
|
578
|
-
@album.add_tag(@tag)
|
579
|
-
|
580
|
-
@Artist.filter(:albums=>[@album, album]).all.must_equal [@artist]
|
581
|
-
@Artist.filter(:first_album=>[@album, album]).all.must_equal [@artist]
|
582
|
-
@Album.filter(:artist=>[@artist, artist]).all.must_equal [@album]
|
583
|
-
@Album.filter(:tags=>[@tag, tag]).all.must_equal [@album]
|
584
|
-
@Album.filter(:alias_tags=>[@tag, tag]).all.must_equal [@album]
|
585
|
-
@Tag.filter(:albums=>[@album, album]).all.must_equal [@tag]
|
586
|
-
@Album.filter(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal [@album]
|
587
|
-
@artist.albums_dataset.filter(:tags=>[@tag, tag]).all.must_equal [@album]
|
588
|
-
unless @no_many_through_many
|
589
|
-
@Artist.filter(:tags=>[@tag, tag]).all.must_equal [@artist]
|
590
|
-
@Artist.filter(:first_tag=>[@tag, tag]).all.must_equal [@artist]
|
591
|
-
end
|
592
|
-
|
593
|
-
album.add_tag(tag)
|
594
|
-
|
595
|
-
@Artist.filter(:albums=>[@album, album]).all.must_equal [@artist]
|
596
|
-
@Artist.filter(:first_album=>[@album, album]).all.must_equal [@artist]
|
597
|
-
@Album.filter(:artist=>[@artist, artist]).all.must_equal [@album]
|
598
|
-
@Album.filter(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
599
|
-
@Album.filter(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
600
|
-
@Tag.filter(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
|
601
|
-
@Album.filter(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal [@album]
|
602
|
-
unless @no_many_through_many
|
603
|
-
@Artist.filter(:tags=>[@tag, tag]).all.must_equal [@artist]
|
604
|
-
@Artist.filter(:first_tag=>[@tag, tag]).all.must_equal [@artist]
|
605
|
-
end
|
606
|
-
|
607
|
-
album.update(:artist => artist)
|
608
|
-
|
609
|
-
@Artist.filter(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
610
|
-
@Artist.filter(:first_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
611
|
-
@Album.filter(:artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
612
|
-
@Album.filter(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
613
|
-
@Album.filter(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
614
|
-
@Tag.filter(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
|
615
|
-
@Album.filter(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
616
|
-
unless @no_many_through_many
|
617
|
-
@Artist.filter(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
618
|
-
@Artist.filter(:first_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
619
|
-
end
|
620
|
-
end
|
621
|
-
|
622
|
-
it "should work correctly when excluding by multiple associations" do
|
623
|
-
album, artist, tag = @pr.call
|
624
|
-
|
625
|
-
@Artist.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
626
|
-
@Artist.exclude(:first_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
627
|
-
@Album.exclude(:artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
628
|
-
@Album.exclude(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
629
|
-
@Album.exclude(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
630
|
-
@Tag.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
|
631
|
-
@Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
632
|
-
unless @no_many_through_many
|
633
|
-
@Artist.exclude(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
634
|
-
@Artist.exclude(:first_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
635
|
-
end
|
636
|
-
|
637
|
-
@album.update(:artist => @artist)
|
638
|
-
@album.add_tag(@tag)
|
639
|
-
|
640
|
-
@Artist.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [artist]
|
641
|
-
@Artist.exclude(:first_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [artist]
|
642
|
-
@Album.exclude(:artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [album]
|
643
|
-
@Album.exclude(:tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [album]
|
644
|
-
@Album.exclude(:alias_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [album]
|
645
|
-
@Tag.exclude(:albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [tag]
|
646
|
-
@Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [album]
|
647
|
-
unless @no_many_through_many
|
648
|
-
@Artist.exclude(:tags=>[@tag, tag]).all.must_equal [artist]
|
649
|
-
@Artist.exclude(:first_tag=>[@tag, tag]).all.must_equal [artist]
|
650
|
-
end
|
651
|
-
|
652
|
-
album.add_tag(tag)
|
653
|
-
|
654
|
-
@Artist.exclude(:albums=>[@album, album]).all.must_equal [artist]
|
655
|
-
@Artist.exclude(:first_album=>[@album, album]).all.must_equal [artist]
|
656
|
-
@Album.exclude(:artist=>[@artist, artist]).all.must_equal [album]
|
657
|
-
@Album.exclude(:tags=>[@tag, tag]).all.must_equal []
|
658
|
-
@Album.exclude(:alias_tags=>[@tag, tag]).all.must_equal []
|
659
|
-
@Tag.exclude(:albums=>[@album, album]).all.must_equal []
|
660
|
-
@Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal [album]
|
661
|
-
unless @no_many_through_many
|
662
|
-
@Artist.exclude(:tags=>[@tag, tag]).all.must_equal [artist]
|
663
|
-
@Artist.exclude(:first_tag=>[@tag, tag]).all.must_equal [artist]
|
664
|
-
end
|
665
|
-
|
666
|
-
album.update(:artist => artist)
|
667
|
-
|
668
|
-
@Artist.exclude(:albums=>[@album, album]).all.must_equal []
|
669
|
-
@Artist.exclude(:first_album=>[@album, album]).all.must_equal []
|
670
|
-
@Album.exclude(:artist=>[@artist, artist]).all.must_equal []
|
671
|
-
@Album.exclude(:tags=>[@tag, tag]).all.must_equal []
|
672
|
-
@Album.exclude(:alias_tags=>[@tag, tag]).all.must_equal []
|
673
|
-
@Tag.exclude(:albums=>[@album, album]).all.must_equal []
|
674
|
-
@Album.exclude(:artist=>[@artist, artist], :tags=>[@tag, tag]).all.must_equal []
|
675
|
-
unless @no_many_through_many
|
676
|
-
@Artist.exclude(:tags=>[@tag, tag]).all.must_equal []
|
677
|
-
@Artist.exclude(:first_tag=>[@tag, tag]).all.must_equal []
|
678
|
-
end
|
679
|
-
end
|
680
|
-
|
681
|
-
it "should work correctly when filtering associations with conditions with multiple objects" do
|
682
|
-
album, artist, tag = @pr.call
|
683
|
-
album.update(:name=>@album.name)
|
684
|
-
artist.update(:name=>@artist.name)
|
685
|
-
tag.update(:name=>@tag.name)
|
686
|
-
|
687
|
-
@album.update(:artist => @artist)
|
688
|
-
@album.add_tag(@tag)
|
689
|
-
album.update(:artist => @artist)
|
690
|
-
tag.add_album(@album)
|
691
|
-
|
692
|
-
@Artist.filter(:a_albums=>[@album, album]).all.must_equal [@artist]
|
693
|
-
@Artist.filter(:first_a_album=>[@album, album]).all.must_equal [@artist]
|
694
|
-
@album.update(:name=>'Foo')
|
695
|
-
@Artist.filter(:a_albums=>[@album, album]).all.must_equal [@artist]
|
696
|
-
@Artist.filter(:first_a_album=>[@album, album]).all.must_equal [@artist]
|
697
|
-
album.update(:name=>'Foo')
|
698
|
-
@Artist.filter(:a_albums=>[@album, album]).all.must_equal []
|
699
|
-
@Artist.filter(:first_a_album=>[@album, album]).all.must_equal []
|
700
|
-
|
701
|
-
album.update(:artist => nil)
|
702
|
-
artist.add_album(@album)
|
703
|
-
@Album.filter(:a_artist=>[@artist, artist]).all.must_equal [@album]
|
704
|
-
@artist.update(:name=>'Foo')
|
705
|
-
@Album.filter(:a_artist=>[@artist, artist]).all.must_equal [@album]
|
706
|
-
artist.update(:name=>'Foo')
|
707
|
-
@Album.filter(:a_artist=>[@artist, artist]).all.must_equal []
|
708
|
-
|
709
|
-
@Album.filter(:t_tags=>[@tag, tag]).all.must_equal [@album]
|
710
|
-
@Album.filter(:alias_t_tags=>[@tag, tag]).all.must_equal [@album]
|
711
|
-
unless @no_many_through_many
|
712
|
-
@Album.filter(:t_tag=>[@tag, tag]).all.must_equal [@album]
|
713
|
-
@Album.filter(:alias_t_tag=>[@tag, tag]).all.must_equal [@album]
|
714
|
-
@Artist.filter(:t_tags=>[@tag, tag]).all.must_equal [artist]
|
715
|
-
@Artist.filter(:t_tag=>[@tag, tag]).all.must_equal [artist]
|
716
|
-
end
|
717
|
-
@tag.update(:name=>'Foo')
|
718
|
-
@Album.filter(:t_tags=>[@tag, tag]).all.must_equal [@album]
|
719
|
-
@Album.filter(:alias_t_tags=>[@tag, tag]).all.must_equal [@album]
|
720
|
-
unless @no_many_through_many
|
721
|
-
@Album.filter(:t_tag=>[@tag, tag]).all.must_equal [@album]
|
722
|
-
@Album.filter(:alias_t_tag=>[@tag, tag]).all.must_equal [@album]
|
723
|
-
@Artist.filter(:t_tags=>[@tag, tag]).all.must_equal [artist]
|
724
|
-
@Artist.filter(:t_tag=>[@tag, tag]).all.must_equal [artist]
|
725
|
-
end
|
726
|
-
tag.update(:name=>'Foo')
|
727
|
-
@Album.filter(:t_tags=>[@tag, tag]).all.must_equal []
|
728
|
-
@Album.filter(:alias_t_tags=>[@tag, tag]).all.must_equal []
|
729
|
-
unless @no_many_through_many
|
730
|
-
@Album.filter(:t_tag=>[@tag, tag]).all.must_equal []
|
731
|
-
@Album.filter(:alias_t_tag=>[@tag, tag]).all.must_equal []
|
732
|
-
@Artist.filter(:t_tags=>[@tag, tag]).all.must_equal []
|
733
|
-
@Artist.filter(:t_tag=>[@tag, tag]).all.must_equal []
|
734
|
-
end
|
735
|
-
end
|
736
|
-
|
737
|
-
it "should work correctly when excluding associations with conditions with multiple objects" do
|
738
|
-
album, artist, tag = @pr.call
|
739
|
-
album.update(:name=>@album.name)
|
740
|
-
artist.update(:name=>@artist.name)
|
741
|
-
tag.update(:name=>@tag.name)
|
742
|
-
|
743
|
-
@album.update(:artist => @artist)
|
744
|
-
@album.add_tag(@tag)
|
745
|
-
album.update(:artist => @artist)
|
746
|
-
tag.add_album(@album)
|
747
|
-
|
748
|
-
artist.add_album(@album)
|
749
|
-
@Artist.exclude(:a_albums=>[@album, album]).all.must_equal []
|
750
|
-
@Artist.exclude(:first_a_album=>[@album, album]).all.must_equal []
|
751
|
-
@album.update(:name=>'Foo')
|
752
|
-
@Artist.exclude(:a_albums=>[@album, album]).all.must_equal [artist]
|
753
|
-
@Artist.exclude(:first_a_album=>[@album, album]).all.must_equal [artist]
|
754
|
-
album.update(:name=>'Foo')
|
755
|
-
@Artist.exclude(:a_albums=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
756
|
-
@Artist.exclude(:first_a_album=>[@album, album]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
757
|
-
|
758
|
-
@Album.exclude(:a_artist=>[@artist, artist]).all.must_equal []
|
759
|
-
album.update(:artist => nil)
|
760
|
-
@artist.update(:name=>'Foo')
|
761
|
-
@Album.exclude(:a_artist=>[@artist, artist]).all.must_equal [album]
|
762
|
-
artist.update(:name=>'Foo')
|
763
|
-
@Album.exclude(:a_artist=>[@artist, artist]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
764
|
-
|
765
|
-
@tag.add_album(album)
|
766
|
-
@Album.exclude(:t_tags=>[@tag, tag]).all.must_equal []
|
767
|
-
@Album.exclude(:alias_t_tags=>[@tag, tag]).all.must_equal []
|
768
|
-
unless @no_many_through_many
|
769
|
-
@Album.exclude(:t_tag=>[@tag, tag]).all.must_equal []
|
770
|
-
@Album.exclude(:alias_t_tag=>[@tag, tag]).all.must_equal []
|
771
|
-
@Artist.exclude(:t_tags=>[@tag, tag]).all.must_equal [@artist]
|
772
|
-
@Artist.exclude(:t_tag=>[@tag, tag]).all.must_equal [@artist]
|
773
|
-
end
|
774
|
-
@tag.update(:name=>'Foo')
|
775
|
-
@Album.exclude(:t_tags=>[@tag, tag]).all.must_equal [album]
|
776
|
-
@Album.exclude(:alias_t_tags=>[@tag, tag]).all.must_equal [album]
|
777
|
-
unless @no_many_through_many
|
778
|
-
@Album.exclude(:t_tag=>[@tag, tag]).all.must_equal [album]
|
779
|
-
@Album.exclude(:alias_t_tag=>[@tag, tag]).all.must_equal [album]
|
780
|
-
@Artist.exclude(:t_tags=>[@tag, tag]).all.must_equal [@artist]
|
781
|
-
@Artist.exclude(:t_tag=>[@tag, tag]).all.must_equal [@artist]
|
782
|
-
end
|
783
|
-
tag.update(:name=>'Foo')
|
784
|
-
@Album.exclude(:t_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
785
|
-
@Album.exclude(:alias_t_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
786
|
-
unless @no_many_through_many
|
787
|
-
@Album.exclude(:t_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
788
|
-
@Album.exclude(:alias_t_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
789
|
-
@Artist.exclude(:t_tags=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
790
|
-
@Artist.exclude(:t_tag=>[@tag, tag]).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
791
|
-
end
|
792
|
-
end
|
793
|
-
|
794
|
-
it "should work correctly when excluding by associations in regards to NULL values" do
|
795
|
-
@Artist.exclude(:albums=>@album).all.must_equal [@artist]
|
796
|
-
@Artist.exclude(:first_album=>@album).all.must_equal [@artist]
|
797
|
-
@Album.exclude(:artist=>@artist).all.must_equal [@album]
|
798
|
-
@Album.exclude(:tags=>@tag).all.must_equal [@album]
|
799
|
-
@Album.exclude(:alias_tags=>@tag).all.must_equal [@album]
|
800
|
-
@Tag.exclude(:albums=>@album).all.must_equal [@tag]
|
801
|
-
@Album.exclude(:artist=>@artist, :tags=>@tag).all.must_equal [@album]
|
802
|
-
|
803
|
-
@Artist.exclude(:a_albums=>@album).all.must_equal [@artist]
|
804
|
-
@Artist.exclude(:first_a_album=>@album).all.must_equal [@artist]
|
805
|
-
@Album.exclude(:a_artist=>@artist).all.must_equal [@album]
|
806
|
-
@Album.exclude(:t_tags=>@tag).all.must_equal [@album]
|
807
|
-
@Album.exclude(:alias_t_tags=>@tag).all.must_equal [@album]
|
808
|
-
unless @no_many_through_many
|
809
|
-
@Album.exclude(:t_tag=>@tag).all.must_equal [@album]
|
810
|
-
@Album.exclude(:alias_t_tag=>@tag).all.must_equal [@album]
|
811
|
-
@Artist.exclude(:t_tags=>@tag).all.must_equal [@artist]
|
812
|
-
@Artist.exclude(:t_tag=>@tag).all.must_equal [@artist]
|
813
|
-
end
|
814
|
-
|
815
|
-
@album.update(:artist => @artist)
|
816
|
-
@artist.albums_dataset.exclude(:tags=>@tag).all.must_equal [@album]
|
817
|
-
end
|
818
|
-
|
819
|
-
it "should handle NULL values in join table correctly when filtering/excluding many_to_many associations" do
|
820
|
-
@ins.call
|
821
|
-
@Album.exclude(:tags=>@tag).all.must_equal [@album]
|
822
|
-
@Album.exclude(:alias_tags=>@tag).all.must_equal [@album]
|
823
|
-
@Album.exclude(:t_tags=>@tag).all.must_equal [@album]
|
824
|
-
@Album.exclude(:alias_t_tags=>@tag).all.must_equal [@album]
|
825
|
-
@album.add_tag(@tag)
|
826
|
-
@Album.filter(:tags=>@tag).all.must_equal [@album]
|
827
|
-
@Album.filter(:alias_tags=>@tag).all.must_equal [@album]
|
828
|
-
@Album.filter(:t_tags=>@tag).all.must_equal [@album]
|
829
|
-
@Album.filter(:alias_t_tags=>@tag).all.must_equal [@album]
|
830
|
-
album, tag = @pr.call.values_at(0, 2)
|
831
|
-
@Album.exclude(:tags=>@tag).all.must_equal [album]
|
832
|
-
@Album.exclude(:alias_tags=>@tag).all.must_equal [album]
|
833
|
-
@Album.exclude(:t_tags=>@tag).all.must_equal [album]
|
834
|
-
@Album.exclude(:alias_t_tags=>@tag).all.must_equal [album]
|
835
|
-
@Album.exclude(:tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
836
|
-
@Album.exclude(:alias_tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
837
|
-
@Album.exclude(:t_tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
838
|
-
@Album.exclude(:alias_t_tags=>tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
839
|
-
end
|
840
|
-
|
841
|
-
it "should work correctly when filtering by association datasets" do
|
842
|
-
album, artist, tag = @pr.call
|
843
|
-
@album.update(:artist => @artist)
|
844
|
-
@album.add_tag(@tag)
|
845
|
-
album.add_tag(tag)
|
846
|
-
album.update(:artist => artist)
|
847
|
-
|
848
|
-
@Artist.filter(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
849
|
-
@Artist.filter(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
850
|
-
@Artist.filter(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
851
|
-
@Artist.filter(:first_album=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
852
|
-
@Artist.filter(:first_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
853
|
-
@Artist.filter(:first_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
854
|
-
@Album.filter(:artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
855
|
-
@Album.filter(:artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
856
|
-
@Album.filter(:artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
857
|
-
@Album.filter(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
858
|
-
@Album.filter(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
859
|
-
@Album.filter(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
860
|
-
@Album.filter(:alias_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
861
|
-
@Album.filter(:alias_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
862
|
-
@Album.filter(:alias_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
863
|
-
@Tag.filter(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
|
864
|
-
@Tag.filter(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [tag]
|
865
|
-
@Tag.filter(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
866
|
-
|
867
|
-
unless @no_many_through_many
|
868
|
-
@Artist.filter(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
869
|
-
@Artist.filter(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
870
|
-
@Artist.filter(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
871
|
-
@Artist.filter(:first_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
872
|
-
@Artist.filter(:first_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
873
|
-
@Artist.filter(:first_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
874
|
-
end
|
875
|
-
end
|
876
|
-
|
877
|
-
it "should work correctly when excluding by association datasets" do
|
878
|
-
album, artist, tag = @pr.call
|
879
|
-
@album.update(:artist => @artist)
|
880
|
-
@album.add_tag(@tag)
|
881
|
-
album.add_tag(tag)
|
882
|
-
album.update(:artist => artist)
|
883
|
-
|
884
|
-
@Artist.exclude(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal []
|
885
|
-
@Artist.exclude(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
886
|
-
@Artist.exclude(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
887
|
-
@Artist.exclude(:first_album=>@Album).all.sort_by{|x| x.pk}.must_equal []
|
888
|
-
@Artist.exclude(:first_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
889
|
-
@Artist.exclude(:first_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
890
|
-
@Album.exclude(:artist=>@Artist).all.sort_by{|x| x.pk}.must_equal []
|
891
|
-
@Album.exclude(:artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
892
|
-
@Album.exclude(:artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
893
|
-
@Album.exclude(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
894
|
-
@Album.exclude(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
895
|
-
@Album.exclude(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
896
|
-
@Album.exclude(:alias_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
897
|
-
@Album.exclude(:alias_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
898
|
-
@Album.exclude(:alias_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
899
|
-
@Tag.exclude(:albums=>@Album).all.sort_by{|x| x.pk}.must_equal []
|
900
|
-
@Tag.exclude(:albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@tag]
|
901
|
-
@Tag.exclude(:albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@tag, tag]
|
902
|
-
|
903
|
-
unless @no_many_through_many
|
904
|
-
@Artist.exclude(:tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
905
|
-
@Artist.exclude(:tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
906
|
-
@Artist.exclude(:tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
907
|
-
@Artist.exclude(:first_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
908
|
-
@Artist.exclude(:first_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
909
|
-
@Artist.exclude(:first_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
910
|
-
end
|
911
|
-
end
|
912
|
-
|
913
|
-
it "should work correctly when filtering by association datasets with conditions" do
|
914
|
-
album, artist, tag = @pr.call
|
915
|
-
@album.update(:artist => @artist)
|
916
|
-
@album.add_tag(@tag)
|
917
|
-
album.add_tag(tag)
|
918
|
-
album.update(:artist => artist)
|
919
|
-
|
920
|
-
@Artist.filter(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist]
|
921
|
-
@Artist.filter(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist]
|
922
|
-
@Album.filter(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [@album]
|
923
|
-
@Album.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
|
924
|
-
@Album.filter(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
|
925
|
-
unless @no_many_through_many
|
926
|
-
@Album.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
|
927
|
-
@Album.filter(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album]
|
928
|
-
@Artist.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist]
|
929
|
-
@Artist.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist]
|
930
|
-
end
|
931
|
-
|
932
|
-
artist.update(:name=>@artist.name)
|
933
|
-
album.update(:name=>@album.name)
|
934
|
-
tag.update(:name=>@tag.name)
|
935
|
-
|
936
|
-
@Artist.filter(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
937
|
-
@Artist.filter(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
938
|
-
@Album.filter(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
939
|
-
@Album.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
940
|
-
@Album.filter(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
941
|
-
unless @no_many_through_many
|
942
|
-
@Album.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
943
|
-
@Album.filter(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
944
|
-
@Artist.filter(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
945
|
-
@Artist.filter(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
946
|
-
end
|
947
|
-
|
948
|
-
@Artist.filter(:a_albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
949
|
-
@Artist.filter(:first_a_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
950
|
-
@Album.filter(:a_artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
951
|
-
@Album.filter(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
952
|
-
@Album.filter(:alias_t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
953
|
-
unless @no_many_through_many
|
954
|
-
@Album.filter(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
955
|
-
@Album.filter(:alias_t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
956
|
-
@Artist.filter(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
957
|
-
@Artist.filter(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [artist]
|
958
|
-
end
|
959
|
-
|
960
|
-
@Artist.filter(:a_albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
961
|
-
@Artist.filter(:first_a_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
962
|
-
@Album.filter(:a_artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
963
|
-
@Album.filter(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
964
|
-
@Album.filter(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
965
|
-
@Album.filter(:alias_t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
966
|
-
unless @no_many_through_many
|
967
|
-
@Album.filter(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [album]
|
968
|
-
@Album.filter(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
969
|
-
@Album.filter(:alias_t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
970
|
-
@Artist.filter(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
971
|
-
@Artist.filter(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal []
|
972
|
-
end
|
973
|
-
end
|
974
|
-
|
975
|
-
it "should work correctly when excluding by association datasets with conditions" do
|
976
|
-
album, artist, tag = @pr.call
|
977
|
-
@album.update(:artist => @artist)
|
978
|
-
@album.add_tag(@tag)
|
979
|
-
album.add_tag(tag)
|
980
|
-
album.update(:artist => artist)
|
981
|
-
|
982
|
-
@Artist.exclude(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal [artist]
|
983
|
-
@Artist.exclude(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal [artist]
|
984
|
-
@Album.exclude(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal [album]
|
985
|
-
@Album.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
|
986
|
-
@Album.exclude(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
|
987
|
-
unless @no_many_through_many
|
988
|
-
@Album.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
|
989
|
-
@Album.exclude(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [album]
|
990
|
-
@Artist.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal [artist]
|
991
|
-
@Artist.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal [artist]
|
992
|
-
end
|
993
|
-
|
994
|
-
artist.update(:name=>@artist.name)
|
995
|
-
album.update(:name=>@album.name)
|
996
|
-
tag.update(:name=>@tag.name)
|
997
|
-
|
998
|
-
@Artist.exclude(:a_albums=>@Album).all.sort_by{|x| x.pk}.must_equal []
|
999
|
-
@Artist.exclude(:first_a_album=>@Album).all.sort_by{|x| x.pk}.must_equal []
|
1000
|
-
@Album.exclude(:a_artist=>@Artist).all.sort_by{|x| x.pk}.must_equal []
|
1001
|
-
@Album.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
1002
|
-
@Album.exclude(:alias_t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
1003
|
-
unless @no_many_through_many
|
1004
|
-
@Album.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
1005
|
-
@Album.exclude(:alias_t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
1006
|
-
@Artist.exclude(:t_tags=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
1007
|
-
@Artist.exclude(:t_tag=>@Tag).all.sort_by{|x| x.pk}.must_equal []
|
1008
|
-
end
|
1009
|
-
|
1010
|
-
@Artist.exclude(:a_albums=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
1011
|
-
@Artist.exclude(:first_a_album=>@Album.filter(Array(Album.primary_key).map{|k| Sequel.qualify(Album.table_name, k)}.zip(Array(album.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
1012
|
-
@Album.exclude(:a_artist=>@Artist.filter(Array(Artist.primary_key).map{|k| Sequel.qualify(Artist.table_name, k)}.zip(Array(artist.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
1013
|
-
@Album.exclude(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
1014
|
-
@Album.exclude(:alias_t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
1015
|
-
unless @no_many_through_many
|
1016
|
-
@Album.exclude(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
1017
|
-
@Album.exclude(:alias_t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@album]
|
1018
|
-
@Artist.exclude(:t_tags=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
1019
|
-
@Artist.exclude(:t_tag=>@Tag.filter(Array(Tag.primary_key).map{|k| Sequel.qualify(Tag.table_name, k)}.zip(Array(tag.pk)))).all.sort_by{|x| x.pk}.must_equal [@artist]
|
1020
|
-
end
|
1021
|
-
|
1022
|
-
@Artist.exclude(:a_albums=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
1023
|
-
@Artist.exclude(:first_a_album=>@Album.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
1024
|
-
@Album.exclude(:a_artist=>@Artist.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
1025
|
-
@Album.exclude(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
1026
|
-
@Album.exclude(:alias_t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
1027
|
-
unless @no_many_through_many
|
1028
|
-
@Album.exclude(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
1029
|
-
@Album.exclude(:alias_t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@album, album]
|
1030
|
-
@Artist.exclude(:t_tags=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
1031
|
-
@Artist.exclude(:t_tag=>@Tag.filter(1=>0)).all.sort_by{|x| x.pk}.must_equal [@artist, artist]
|
1032
|
-
end
|
1033
|
-
end
|
1034
|
-
end
|
1035
|
-
|
1036
|
-
FilterByAssociationsOneToOneLimitStrategies = shared_description do
|
1037
|
-
it "filter by associations with limited one_to_one associations should work correctly" do
|
1038
|
-
Artist.one_to_one :first_album, {:clone=>:first_album}.merge(@els)
|
1039
|
-
Artist.one_to_one :last_album, {:clone=>:last_album}.merge(@els)
|
1040
|
-
Artist.one_to_one :second_album, {:clone=>:second_album}.merge(@els)
|
1041
|
-
@album.update(:artist => @artist)
|
1042
|
-
diff_album = @diff_album.call
|
1043
|
-
ar = @pr.call[1]
|
1044
|
-
ds = Artist.order(:name)
|
1045
|
-
|
1046
|
-
ds.where(:first_album=>@album).all.must_equal [@artist]
|
1047
|
-
ds.where(:first_album=>diff_album).all.must_equal []
|
1048
|
-
ds.exclude(:first_album=>@album).all.must_equal [ar]
|
1049
|
-
ds.exclude(:first_album=>diff_album).all.must_equal [@artist, ar]
|
1050
|
-
|
1051
|
-
if @els[:eager_limit_strategy] != :distinct_on && (@els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?)
|
1052
|
-
ds.where(:second_album=>@album).all.must_equal []
|
1053
|
-
ds.where(:second_album=>diff_album).all.must_equal [@artist]
|
1054
|
-
ds.exclude(:second_album=>@album).all.must_equal [@artist, ar]
|
1055
|
-
ds.exclude(:second_album=>diff_album).all.must_equal [ar]
|
1056
|
-
end
|
1057
|
-
|
1058
|
-
ds.where(:last_album=>@album).all.must_equal []
|
1059
|
-
ds.where(:last_album=>diff_album).all.must_equal [@artist]
|
1060
|
-
ds.exclude(:last_album=>@album).all.must_equal [@artist, ar]
|
1061
|
-
ds.exclude(:last_album=>diff_album).all.must_equal [ar]
|
1062
|
-
|
1063
|
-
Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(Sequel[:albums][:name]=>diff_album.name) end
|
1064
|
-
ar.add_album(diff_album)
|
1065
|
-
ds.where(:first_album=>[@album, diff_album]).all.must_equal [ar]
|
1066
|
-
ds.exclude(:first_album=>[@album, diff_album]).all.must_equal [@artist]
|
1067
|
-
end
|
1068
|
-
end
|
1069
|
-
|
1070
|
-
FilterByAssociationsSingularLimitStrategies = shared_description do
|
1071
|
-
include FilterByAssociationsOneToOneLimitStrategies
|
1072
|
-
|
1073
|
-
it "dataset associations with limited one_to_one associations should work correctly" do
|
1074
|
-
Artist.one_to_one :first_album, {:clone=>:first_album}.merge(@els)
|
1075
|
-
Artist.one_to_one :last_album, {:clone=>:last_album}.merge(@els)
|
1076
|
-
Artist.one_to_one :second_album, {:clone=>:second_album}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
|
1077
|
-
@album.update(:artist => @artist)
|
1078
|
-
diff_album = @diff_album.call
|
1079
|
-
ar = @pr.call[1]
|
1080
|
-
ds = Artist
|
1081
|
-
|
1082
|
-
ds.where(@artist.pk_hash).first_albums.all.must_equal [@album]
|
1083
|
-
ds.where(@artist.pk_hash).second_albums.all.must_equal [diff_album]
|
1084
|
-
ds.where(@artist.pk_hash).last_albums.all.must_equal [diff_album]
|
1085
|
-
ds.where(ar.pk_hash).first_albums.all.must_equal []
|
1086
|
-
ds.where(ar.pk_hash).second_albums.all.must_equal []
|
1087
|
-
ds.where(ar.pk_hash).last_albums.all.must_equal []
|
1088
|
-
|
1089
|
-
Artist.one_to_one :first_album, :clone=>:first_album do |ads| ads.where(Sequel[:albums][:name]=>diff_album.name) end
|
1090
|
-
ar.add_album(diff_album)
|
1091
|
-
ds.where(@artist.pk_hash).first_albums.all.must_equal []
|
1092
|
-
ds.where(ar.pk_hash).first_albums.all.must_equal [diff_album]
|
1093
|
-
end
|
1094
|
-
|
1095
|
-
it "filter by associations with limited one_through_one associations should work correctly" do
|
1096
|
-
Album.one_through_one :first_tag, {:clone=>:first_tag}.merge(@els)
|
1097
|
-
Album.one_through_one :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
|
1098
|
-
Album.one_through_one :last_tag, {:clone=>:last_tag}.merge(@els)
|
1099
|
-
tu, tv = @other_tags.call
|
1100
|
-
al = @pr.call.first
|
1101
|
-
ds = Album.order(:name)
|
1102
|
-
al.add_tag(tu)
|
1103
|
-
|
1104
|
-
ds.where(:first_tag=>@tag).all.must_equal [@album]
|
1105
|
-
ds.where(:first_tag=>tu).all.must_equal [al]
|
1106
|
-
ds.where(:first_tag=>tv).all.must_equal []
|
1107
|
-
ds.exclude(:first_tag=>@tag).all.must_equal [al]
|
1108
|
-
ds.exclude(:first_tag=>tu).all.must_equal [@album]
|
1109
|
-
ds.exclude(:first_tag=>tv).all.must_equal [@album, al]
|
1110
|
-
|
1111
|
-
ds.where(:second_tag=>@tag).all.must_equal []
|
1112
|
-
ds.where(:second_tag=>tu).all.must_equal [@album]
|
1113
|
-
ds.where(:second_tag=>tv).all.must_equal []
|
1114
|
-
ds.exclude(:second_tag=>@tag).all.must_equal [@album, al]
|
1115
|
-
ds.exclude(:second_tag=>tu).all.must_equal [al]
|
1116
|
-
ds.exclude(:second_tag=>tv).all.must_equal [@album, al]
|
1117
|
-
|
1118
|
-
ds.where(:last_tag=>@tag).all.must_equal []
|
1119
|
-
ds.where(:last_tag=>tu).all.must_equal [al]
|
1120
|
-
ds.where(:last_tag=>tv).all.must_equal [@album]
|
1121
|
-
ds.exclude(:last_tag=>@tag).all.must_equal [@album, al]
|
1122
|
-
ds.exclude(:last_tag=>tu).all.must_equal [@album]
|
1123
|
-
ds.exclude(:last_tag=>tv).all.must_equal [al]
|
1124
|
-
|
1125
|
-
Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1126
|
-
Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1127
|
-
|
1128
|
-
ds.where(:first_tag=>[@tag, tu]).all.must_equal [@album, al]
|
1129
|
-
ds.exclude(:first_tag=>[@tag, tu]).all.must_equal []
|
1130
|
-
|
1131
|
-
al.add_tag(tv)
|
1132
|
-
ds.where(:second_tag=>[tv, tu]).all.must_equal [@album, al]
|
1133
|
-
ds.exclude(:second_tag=>[tv, tu]).all.must_equal []
|
1134
|
-
end
|
1135
|
-
|
1136
|
-
it "dataset associations with limited one_through_one associations should work correctly" do
|
1137
|
-
Album.one_through_one :first_tag, {:clone=>:first_tag}.merge(@els)
|
1138
|
-
Album.one_through_one :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
|
1139
|
-
Album.one_through_one :last_tag, {:clone=>:last_tag}.merge(@els)
|
1140
|
-
tu, tv = @other_tags.call
|
1141
|
-
al = @pr.call.first
|
1142
|
-
ds = Album
|
1143
|
-
al.add_tag(tu)
|
1144
|
-
|
1145
|
-
ds.where(@album.pk_hash).first_tags.all.must_equal [@tag]
|
1146
|
-
ds.where(@album.pk_hash).second_tags.all.must_equal [tu]
|
1147
|
-
ds.where(@album.pk_hash).last_tags.all.must_equal [tv]
|
1148
|
-
ds.where(al.pk_hash).first_tags.all.must_equal [tu]
|
1149
|
-
ds.where(al.pk_hash).second_tags.all.must_equal []
|
1150
|
-
ds.where(al.pk_hash).last_tags.all.must_equal [tu]
|
1151
|
-
|
1152
|
-
Album.one_through_one :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1153
|
-
Album.one_through_one :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1154
|
-
|
1155
|
-
ds.where(@album.pk_hash).first_tags.all.must_equal [tu]
|
1156
|
-
ds.where(@album.pk_hash).second_tags.all.must_equal [tv]
|
1157
|
-
ds.where(al.pk_hash).first_tags.all.must_equal [tu]
|
1158
|
-
ds.where(al.pk_hash).second_tags.all.must_equal []
|
1159
|
-
|
1160
|
-
al.add_tag(tv)
|
1161
|
-
ds.where(@album.pk_hash).first_tags.all.must_equal [tu]
|
1162
|
-
ds.where(@album.pk_hash).second_tags.all.must_equal [tv]
|
1163
|
-
ds.where(al.pk_hash).first_tags.all.must_equal [tu]
|
1164
|
-
ds.where(al.pk_hash).second_tags.all.must_equal [tv]
|
1165
|
-
end
|
1166
|
-
|
1167
|
-
it "filter by associations with limited one_through_many associations should work correctly" do
|
1168
|
-
Artist.one_through_many :first_tag, {:clone=>:first_tag}.merge(@els)
|
1169
|
-
Artist.one_through_many :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
|
1170
|
-
Artist.one_through_many :last_tag, {:clone=>:last_tag}.merge(@els)
|
1171
|
-
@album.update(:artist => @artist)
|
1172
|
-
tu, tv = @other_tags.call
|
1173
|
-
al, ar, _ = @pr.call
|
1174
|
-
al.update(:artist=>ar)
|
1175
|
-
al.add_tag(tu)
|
1176
|
-
ds = Artist.order(:name)
|
1177
|
-
|
1178
|
-
ds.where(:first_tag=>@tag).all.must_equal [@artist]
|
1179
|
-
ds.where(:first_tag=>tu).all.must_equal [ar]
|
1180
|
-
ds.where(:first_tag=>tv).all.must_equal []
|
1181
|
-
ds.exclude(:first_tag=>@tag).all.must_equal [ar]
|
1182
|
-
ds.exclude(:first_tag=>tu).all.must_equal [@artist]
|
1183
|
-
ds.exclude(:first_tag=>tv).all.must_equal [@artist, ar]
|
1184
|
-
|
1185
|
-
ds.where(:second_tag=>@tag).all.must_equal []
|
1186
|
-
ds.where(:second_tag=>tu).all.must_equal [@artist]
|
1187
|
-
ds.where(:second_tag=>tv).all.must_equal []
|
1188
|
-
ds.exclude(:second_tag=>@tag).all.must_equal [@artist, ar]
|
1189
|
-
ds.exclude(:second_tag=>tu).all.must_equal [ar]
|
1190
|
-
ds.exclude(:second_tag=>tv).all.must_equal [@artist, ar]
|
1191
|
-
|
1192
|
-
ds.where(:last_tag=>@tag).all.must_equal []
|
1193
|
-
ds.where(:last_tag=>tu).all.must_equal [ar]
|
1194
|
-
ds.where(:last_tag=>tv).all.must_equal [@artist]
|
1195
|
-
ds.exclude(:last_tag=>@tag).all.must_equal [@artist, ar]
|
1196
|
-
ds.exclude(:last_tag=>tu).all.must_equal [@artist]
|
1197
|
-
ds.exclude(:last_tag=>tv).all.must_equal [ar]
|
1198
|
-
|
1199
|
-
Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1200
|
-
Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1201
|
-
|
1202
|
-
ds.where(:first_tag=>[@tag, tu]).all.must_equal [@artist, ar]
|
1203
|
-
ds.exclude(:first_tag=>[@tag, tu]).all.must_equal []
|
1204
|
-
|
1205
|
-
al.add_tag(tv)
|
1206
|
-
ds.where(:second_tag=>[tv, tu]).all.must_equal [@artist, ar]
|
1207
|
-
ds.exclude(:second_tag=>[tv, tu]).all.must_equal []
|
1208
|
-
end
|
1209
|
-
|
1210
|
-
it "dataset associations with limited one_through_many associations should work correctly" do
|
1211
|
-
Artist.one_through_many :first_tag, {:clone=>:first_tag}.merge(@els)
|
1212
|
-
Artist.one_through_many :second_tag, {:clone=>:second_tag}.merge(@els) if @els[:eager_limit_strategy] != :distinct_on
|
1213
|
-
Artist.one_through_many :last_tag, {:clone=>:last_tag}.merge(@els)
|
1214
|
-
@album.update(:artist => @artist)
|
1215
|
-
tu, tv = @other_tags.call
|
1216
|
-
al, ar, _ = @pr.call
|
1217
|
-
al.update(:artist=>ar)
|
1218
|
-
al.add_tag(tu)
|
1219
|
-
ds = Artist.order(:name)
|
1220
|
-
|
1221
|
-
ds.where(@artist.pk_hash).first_tags.all.must_equal [@tag]
|
1222
|
-
ds.where(@artist.pk_hash).second_tags.all.must_equal [tu]
|
1223
|
-
ds.where(@artist.pk_hash).last_tags.all.must_equal [tv]
|
1224
|
-
ds.where(ar.pk_hash).first_tags.all.must_equal [tu]
|
1225
|
-
ds.where(ar.pk_hash).second_tags.all.must_equal []
|
1226
|
-
ds.where(ar.pk_hash).last_tags.all.must_equal [tu]
|
1227
|
-
|
1228
|
-
Artist.one_through_many :first_tag, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1229
|
-
Artist.one_through_many :second_tag, :clone=>:second_tag do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1230
|
-
|
1231
|
-
ds.where(@artist.pk_hash).first_tags.all.must_equal [tu]
|
1232
|
-
ds.where(@artist.pk_hash).second_tags.all.must_equal [tv]
|
1233
|
-
ds.where(ar.pk_hash).first_tags.all.must_equal [tu]
|
1234
|
-
ds.where(ar.pk_hash).second_tags.all.must_equal []
|
1235
|
-
|
1236
|
-
al.add_tag(tv)
|
1237
|
-
ds.where(@artist.pk_hash).first_tags.all.must_equal [tu]
|
1238
|
-
ds.where(@artist.pk_hash).second_tags.all.must_equal [tv]
|
1239
|
-
ds.where(ar.pk_hash).first_tags.all.must_equal [tu]
|
1240
|
-
ds.where(ar.pk_hash).second_tags.all.must_equal [tv]
|
1241
|
-
end
|
1242
|
-
end
|
1243
|
-
|
1244
|
-
FilterByAssociationsOneToManyLimitStrategies = shared_description do
|
1245
|
-
it "filter by associations with limited one_to_many associations should work correctly" do
|
1246
|
-
Artist.one_to_many :first_two_albums, {:clone=>:first_two_albums}.merge(@els)
|
1247
|
-
Artist.one_to_many :second_two_albums, {:clone=>:second_two_albums}.merge(@els)
|
1248
|
-
Artist.one_to_many :not_first_albums, {:clone=>:not_first_albums}.merge(@els)
|
1249
|
-
Artist.one_to_many :last_two_albums, {:clone=>:last_two_albums}.merge(@els)
|
1250
|
-
@album.update(:artist => @artist)
|
1251
|
-
middle_album = @middle_album.call
|
1252
|
-
diff_album = @diff_album.call
|
1253
|
-
ar = @pr.call[1]
|
1254
|
-
ds = Artist.order(:name)
|
1255
|
-
|
1256
|
-
ds.where(:first_two_albums=>@album).all.must_equal [@artist]
|
1257
|
-
ds.where(:first_two_albums=>middle_album).all.must_equal [@artist]
|
1258
|
-
ds.where(:first_two_albums=>diff_album).all.must_equal []
|
1259
|
-
ds.exclude(:first_two_albums=>@album).all.must_equal [ar]
|
1260
|
-
ds.exclude(:first_two_albums=>middle_album).all.must_equal [ar]
|
1261
|
-
ds.exclude(:first_two_albums=>diff_album).all.must_equal [@artist, ar]
|
1262
|
-
|
1263
|
-
assocs = if @els[:eager_limit_strategy] != :correlated_subquery || Album.dataset.supports_offsets_in_correlated_subqueries?
|
1264
|
-
[:second_two_albums, :not_first_albums, :last_two_albums]
|
1265
|
-
else
|
1266
|
-
[:last_two_albums]
|
1267
|
-
end
|
1268
|
-
|
1269
|
-
assocs.each do |a|
|
1270
|
-
ds.where(a=>@album).all.must_equal []
|
1271
|
-
ds.where(a=>middle_album).all.must_equal [@artist]
|
1272
|
-
ds.where(a=>diff_album).all.must_equal [@artist]
|
1273
|
-
ds.exclude(a=>@album).all.must_equal [@artist, ar]
|
1274
|
-
ds.exclude(a=>middle_album).all.must_equal [ar]
|
1275
|
-
ds.exclude(a=>diff_album).all.must_equal [ar]
|
1276
|
-
end
|
1277
|
-
|
1278
|
-
Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(Sequel[:albums][:name]=>diff_album.name) end
|
1279
|
-
ar.add_album(diff_album)
|
1280
|
-
ds.where(:first_two_albums=>[@album, diff_album]).all.must_equal [ar]
|
1281
|
-
ds.exclude(:first_two_albums=>[@album, diff_album]).all.must_equal [@artist]
|
1282
|
-
end
|
1283
|
-
end
|
1284
|
-
|
1285
|
-
FilterByAssociationsLimitStrategies = shared_description do
|
1286
|
-
include FilterByAssociationsSingularLimitStrategies
|
1287
|
-
include FilterByAssociationsOneToManyLimitStrategies
|
1288
|
-
|
1289
|
-
it "dataset associations with limited one_to_many associations should work correctly" do
|
1290
|
-
Artist.one_to_many :first_two_albums, {:clone=>:first_two_albums}.merge(@els)
|
1291
|
-
Artist.one_to_many :second_two_albums, {:clone=>:second_two_albums}.merge(@els)
|
1292
|
-
Artist.one_to_many :not_first_albums, {:clone=>:not_first_albums}.merge(@els)
|
1293
|
-
Artist.one_to_many :last_two_albums, {:clone=>:last_two_albums}.merge(@els)
|
1294
|
-
@album.update(:artist => @artist)
|
1295
|
-
middle_album = @middle_album.call
|
1296
|
-
diff_album = @diff_album.call
|
1297
|
-
ar = @pr.call[1]
|
1298
|
-
ds = Artist.order(:name)
|
1299
|
-
|
1300
|
-
ds.where(@artist.pk_hash).first_two_albums.all.must_equal [@album, middle_album]
|
1301
|
-
ds.where(@artist.pk_hash).second_two_albums.all.must_equal [middle_album, diff_album]
|
1302
|
-
ds.where(@artist.pk_hash).not_first_albums.all.must_equal [middle_album, diff_album]
|
1303
|
-
ds.where(@artist.pk_hash).last_two_albums.all.must_equal [diff_album, middle_album]
|
1304
|
-
ds.where(ar.pk_hash).first_two_albums.all.must_equal []
|
1305
|
-
ds.where(ar.pk_hash).second_two_albums.all.must_equal []
|
1306
|
-
ds.where(ar.pk_hash).not_first_albums.all.must_equal []
|
1307
|
-
ds.where(ar.pk_hash).last_two_albums.all.must_equal []
|
1308
|
-
|
1309
|
-
Artist.one_to_one :first_two_albums, :clone=>:first_two_albums do |ads| ads.where(Sequel[:albums][:name]=>[diff_album.name, middle_album.name]) end
|
1310
|
-
ar.add_album(diff_album)
|
1311
|
-
ds.where(@artist.pk_hash).first_two_albums.all.must_equal [middle_album]
|
1312
|
-
ds.where(ar.pk_hash).first_two_albums.all.must_equal [diff_album]
|
1313
|
-
end
|
1314
|
-
|
1315
|
-
it "filter by associations with limited many_to_many associations should work correctly" do
|
1316
|
-
Album.send :many_to_many, :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
|
1317
|
-
Album.send :many_to_many, :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
|
1318
|
-
Album.send :many_to_many, :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
|
1319
|
-
Album.send :many_to_many, :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
|
1320
|
-
tu, tv = @other_tags.call
|
1321
|
-
al = @pr.call.first
|
1322
|
-
al.add_tag(tu)
|
1323
|
-
ds = Album.order(:name)
|
1324
|
-
|
1325
|
-
ds.where(:first_two_tags=>@tag).all.must_equal [@album]
|
1326
|
-
ds.where(:first_two_tags=>tu).all.must_equal [@album, al]
|
1327
|
-
ds.where(:first_two_tags=>tv).all.must_equal []
|
1328
|
-
ds.exclude(:first_two_tags=>@tag).all.must_equal [al]
|
1329
|
-
ds.exclude(:first_two_tags=>tu).all.must_equal []
|
1330
|
-
ds.exclude(:first_two_tags=>tv).all.must_equal [@album, al]
|
1331
|
-
|
1332
|
-
ds.where(:second_two_tags=>@tag).all.must_equal []
|
1333
|
-
ds.where(:second_two_tags=>tu).all.must_equal [@album]
|
1334
|
-
ds.where(:second_two_tags=>tv).all.must_equal [@album]
|
1335
|
-
ds.exclude(:second_two_tags=>@tag).all.must_equal [@album, al]
|
1336
|
-
ds.exclude(:second_two_tags=>tu).all.must_equal [al]
|
1337
|
-
ds.exclude(:second_two_tags=>tv).all.must_equal [al]
|
1338
|
-
|
1339
|
-
ds.where(:not_first_tags=>@tag).all.must_equal []
|
1340
|
-
ds.where(:not_first_tags=>tu).all.must_equal [@album]
|
1341
|
-
ds.where(:not_first_tags=>tv).all.must_equal [@album]
|
1342
|
-
ds.exclude(:not_first_tags=>@tag).all.must_equal [@album, al]
|
1343
|
-
ds.exclude(:not_first_tags=>tu).all.must_equal [al]
|
1344
|
-
ds.exclude(:not_first_tags=>tv).all.must_equal [al]
|
1345
|
-
|
1346
|
-
ds.where(:last_two_tags=>@tag).all.must_equal []
|
1347
|
-
ds.where(:last_two_tags=>tu).all.must_equal [@album, al]
|
1348
|
-
ds.where(:last_two_tags=>tv).all.must_equal [@album]
|
1349
|
-
ds.exclude(:last_two_tags=>@tag).all.must_equal [@album, al]
|
1350
|
-
ds.exclude(:last_two_tags=>tu).all.must_equal []
|
1351
|
-
ds.exclude(:last_two_tags=>tv).all.must_equal [al]
|
1352
|
-
|
1353
|
-
Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1354
|
-
Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1355
|
-
|
1356
|
-
ds.where(:first_two_tags=>[@tag, tu]).all.must_equal [@album, al]
|
1357
|
-
ds.exclude(:first_two_tags=>[@tag, tu]).all.must_equal []
|
1358
|
-
|
1359
|
-
al.add_tag(tv)
|
1360
|
-
ds.where(:second_two_tags=>[tv, tu]).all.must_equal [@album, al]
|
1361
|
-
ds.exclude(:second_two_tags=>[tv, tu]).all.must_equal []
|
1362
|
-
end
|
1363
|
-
|
1364
|
-
it "dataset associations with limited many_to_many associations should work correctly" do
|
1365
|
-
Album.send :many_to_many, :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
|
1366
|
-
Album.send :many_to_many, :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
|
1367
|
-
Album.send :many_to_many, :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
|
1368
|
-
Album.send :many_to_many, :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
|
1369
|
-
tu, tv = @other_tags.call
|
1370
|
-
al = @pr.call.first
|
1371
|
-
al.add_tag(tu)
|
1372
|
-
ds = Album.order(:name)
|
1373
|
-
|
1374
|
-
ds.where(@album.pk_hash).first_two_tags.all.must_equal [@tag, tu]
|
1375
|
-
ds.where(@album.pk_hash).second_two_tags.all.must_equal [tu, tv]
|
1376
|
-
ds.where(@album.pk_hash).not_first_tags.all.must_equal [tu, tv]
|
1377
|
-
ds.where(@album.pk_hash).last_two_tags.all.must_equal [tv, tu]
|
1378
|
-
ds.where(al.pk_hash).first_two_tags.all.must_equal [tu]
|
1379
|
-
ds.where(al.pk_hash).second_two_tags.all.must_equal []
|
1380
|
-
ds.where(al.pk_hash).not_first_tags.all.must_equal []
|
1381
|
-
ds.where(al.pk_hash).last_two_tags.all.must_equal [tu]
|
1382
|
-
|
1383
|
-
Album.many_to_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1384
|
-
Album.many_to_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1385
|
-
|
1386
|
-
ds.where(@album.pk_hash).first_two_tags.all.must_equal [tu]
|
1387
|
-
ds.where(@album.pk_hash).second_two_tags.all.must_equal [tv]
|
1388
|
-
ds.where(al.pk_hash).first_two_tags.all.must_equal [tu]
|
1389
|
-
ds.where(al.pk_hash).second_two_tags.all.must_equal []
|
1390
|
-
|
1391
|
-
al.add_tag(tv)
|
1392
|
-
ds.where(@album.pk_hash).first_two_tags.all.must_equal [tu]
|
1393
|
-
ds.where(@album.pk_hash).second_two_tags.all.must_equal [tv]
|
1394
|
-
ds.where(al.pk_hash).first_two_tags.all.must_equal [tu]
|
1395
|
-
ds.where(al.pk_hash).second_two_tags.all.must_equal [tv]
|
1396
|
-
end
|
1397
|
-
|
1398
|
-
it "filter by associations with limited many_through_many associations should work correctly" do
|
1399
|
-
Artist.many_through_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
|
1400
|
-
Artist.many_through_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
|
1401
|
-
Artist.many_through_many :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
|
1402
|
-
Artist.many_through_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
|
1403
|
-
@album.update(:artist => @artist)
|
1404
|
-
tu, tv = @other_tags.call
|
1405
|
-
al, ar, _ = @pr.call
|
1406
|
-
al.update(:artist=>ar)
|
1407
|
-
al.add_tag(tu)
|
1408
|
-
ds = Artist.order(:name)
|
1409
|
-
|
1410
|
-
ds.where(:first_two_tags=>@tag).all.must_equal [@artist]
|
1411
|
-
ds.where(:first_two_tags=>tu).all.must_equal [@artist, ar]
|
1412
|
-
ds.where(:first_two_tags=>tv).all.must_equal []
|
1413
|
-
ds.exclude(:first_two_tags=>@tag).all.must_equal [ar]
|
1414
|
-
ds.exclude(:first_two_tags=>tu).all.must_equal []
|
1415
|
-
ds.exclude(:first_two_tags=>tv).all.must_equal [@artist, ar]
|
1416
|
-
|
1417
|
-
ds.where(:second_two_tags=>@tag).all.must_equal []
|
1418
|
-
ds.where(:second_two_tags=>tu).all.must_equal [@artist]
|
1419
|
-
ds.where(:second_two_tags=>tv).all.must_equal [@artist]
|
1420
|
-
ds.exclude(:second_two_tags=>@tag).all.must_equal [@artist, ar]
|
1421
|
-
ds.exclude(:second_two_tags=>tu).all.must_equal [ar]
|
1422
|
-
ds.exclude(:second_two_tags=>tv).all.must_equal [ar]
|
1423
|
-
|
1424
|
-
ds.where(:not_first_tags=>@tag).all.must_equal []
|
1425
|
-
ds.where(:not_first_tags=>tu).all.must_equal [@artist]
|
1426
|
-
ds.where(:not_first_tags=>tv).all.must_equal [@artist]
|
1427
|
-
ds.exclude(:not_first_tags=>@tag).all.must_equal [@artist, ar]
|
1428
|
-
ds.exclude(:not_first_tags=>tu).all.must_equal [ar]
|
1429
|
-
ds.exclude(:not_first_tags=>tv).all.must_equal [ar]
|
1430
|
-
|
1431
|
-
ds.where(:last_two_tags=>@tag).all.must_equal []
|
1432
|
-
ds.where(:last_two_tags=>tu).all.must_equal [@artist, ar]
|
1433
|
-
ds.where(:last_two_tags=>tv).all.must_equal [@artist]
|
1434
|
-
ds.exclude(:last_two_tags=>@tag).all.must_equal [@artist, ar]
|
1435
|
-
ds.exclude(:last_two_tags=>tu).all.must_equal []
|
1436
|
-
ds.exclude(:last_two_tags=>tv).all.must_equal [ar]
|
1437
|
-
|
1438
|
-
Artist.many_through_many :first_two_tags, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1439
|
-
Artist.many_through_many :second_two_tags, :clone=>:first_tag do |ads| ads.where(Sequel[:tags][:name]=>[tv.name, tu.name]) end
|
1440
|
-
|
1441
|
-
ds.where(:first_two_tags=>[@tag, tu]).all.must_equal [@artist, ar]
|
1442
|
-
ds.exclude(:first_two_tags=>[@tag, tu]).all.must_equal []
|
1443
|
-
|
1444
|
-
al.add_tag(tv)
|
1445
|
-
ds.where(:second_two_tags=>[tv, tu]).all.must_equal [@artist, ar]
|
1446
|
-
ds.exclude(:second_two_tags=>[tv, tu]).all.must_equal []
|
1447
|
-
end
|
1448
|
-
|
1449
|
-
it "dataset associations with limited many_through_many associations should work correctly" do
|
1450
|
-
Artist.many_through_many :first_two_tags, {:clone=>:first_two_tags}.merge(@els)
|
1451
|
-
Artist.many_through_many :second_two_tags, {:clone=>:second_two_tags}.merge(@els)
|
1452
|
-
Artist.many_through_many :not_first_tags, {:clone=>:not_first_tags}.merge(@els)
|
1453
|
-
Artist.many_through_many :last_two_tags, {:clone=>:last_two_tags}.merge(@els)
|
1454
|
-
@album.update(:artist => @artist)
|
1455
|
-
tu, tv = @other_tags.call
|
1456
|
-
al, ar, _ = @pr.call
|
1457
|
-
al.update(:artist=>ar)
|
1458
|
-
al.add_tag(tu)
|
1459
|
-
ds = Artist.order(:name)
|
1460
|
-
|
1461
|
-
ds.where(@artist.pk_hash).first_two_tags.all.must_equal [@tag, tu]
|
1462
|
-
ds.where(@artist.pk_hash).second_two_tags.all.must_equal [tu, tv]
|
1463
|
-
ds.where(@artist.pk_hash).not_first_tags.all.must_equal [tu, tv]
|
1464
|
-
ds.where(@artist.pk_hash).last_two_tags.all.must_equal [tv, tu]
|
1465
|
-
ds.where(ar.pk_hash).first_two_tags.all.must_equal [tu]
|
1466
|
-
ds.where(ar.pk_hash).second_two_tags.all.must_equal []
|
1467
|
-
ds.where(ar.pk_hash).not_first_tags.all.must_equal []
|
1468
|
-
ds.where(ar.pk_hash).last_two_tags.all.must_equal [tu]
|
1469
|
-
|
1470
|
-
Artist.many_through_many :first_two_tags, :clone=>:first_two_tags do |ads| ads.where(Sequel[:tags][:name]=>tu.name) end
|
1471
|
-
Artist.many_through_many :second_two_tags, :clone=>:second_two_tags do |ads| ads.where(Sequel[:tags][:name]=>[tu.name, tv.name]) end
|
1472
|
-
|
1473
|
-
ds.where(@artist.pk_hash).first_two_tags.all.must_equal [tu]
|
1474
|
-
ds.where(@artist.pk_hash).second_two_tags.all.must_equal [tv]
|
1475
|
-
ds.where(ar.pk_hash).first_two_tags.all.must_equal [tu]
|
1476
|
-
ds.where(ar.pk_hash).second_two_tags.all.must_equal []
|
1477
|
-
|
1478
|
-
al.add_tag(tv)
|
1479
|
-
ds.where(@artist.pk_hash).first_two_tags.all.must_equal [tu]
|
1480
|
-
ds.where(@artist.pk_hash).second_two_tags.all.must_equal [tv]
|
1481
|
-
ds.where(ar.pk_hash).first_two_tags.all.must_equal [tu]
|
1482
|
-
ds.where(ar.pk_hash).second_two_tags.all.must_equal [tv]
|
1483
|
-
end
|
1484
|
-
end
|
1485
|
-
|
1486
|
-
BasicRegularAndCompositeKeyAssociations = shared_description do
|
1487
|
-
describe "when filtering/excluding by associations" do
|
1488
|
-
before do
|
1489
|
-
@Artist = Artist.dataset
|
1490
|
-
@Album = Album.dataset
|
1491
|
-
@Tag = Tag.dataset
|
1492
|
-
end
|
1493
|
-
|
1494
|
-
include FilterByAssociations
|
1495
|
-
end
|
1496
|
-
|
1497
|
-
it "should return no objects if none are associated" do
|
1498
|
-
@album.artist.must_be_nil
|
1499
|
-
@album.artist_dataset.first.must_be_nil
|
1500
|
-
@artist.first_album.must_be_nil
|
1501
|
-
@artist.first_album_dataset.first.must_be_nil
|
1502
|
-
@artist.albums.must_equal []
|
1503
|
-
@artist.albums_dataset.all.must_equal []
|
1504
|
-
@album.tags.must_equal []
|
1505
|
-
@album.tags_dataset.all.must_equal []
|
1506
|
-
@album.alias_tags.must_equal []
|
1507
|
-
@album.alias_tags_dataset.all.must_equal []
|
1508
|
-
@tag.albums.must_equal []
|
1509
|
-
@tag.albums_dataset.all.must_equal []
|
1510
|
-
unless @no_many_through_many
|
1511
|
-
@album.first_tag.must_be_nil
|
1512
|
-
@album.first_tag_dataset.first.must_be_nil
|
1513
|
-
end
|
1514
|
-
end
|
1515
|
-
|
1516
|
-
it "should have set methods work" do
|
1517
|
-
# many to one
|
1518
|
-
@album.update(:artist => @artist)
|
1519
|
-
@album.reload.artist.must_equal @artist
|
1520
|
-
@album.update(:artist => nil)
|
1521
|
-
@album.reload.artist.must_be_nil
|
1522
|
-
|
1523
|
-
# one to one
|
1524
|
-
@artist.update(:first_album => @album)
|
1525
|
-
@artist.reload.first_album.must_equal @album
|
1526
|
-
@artist.update(:first_album => nil)
|
1527
|
-
@artist.reload.first_album.must_be_nil
|
1528
|
-
|
1529
|
-
unless @no_many_through_many
|
1530
|
-
tag = @pr.call.last
|
1531
|
-
# one through one
|
1532
|
-
@album.update(:first_tag => @tag)
|
1533
|
-
@album.reload.first_tag.must_equal @tag
|
1534
|
-
@album.update(:first_tag => @tag)
|
1535
|
-
@album.reload.first_tag.must_equal @tag
|
1536
|
-
@album.update(:first_tag => tag)
|
1537
|
-
@album.reload.first_tag.must_equal tag
|
1538
|
-
@album.update(:first_tag => nil)
|
1539
|
-
@album.reload.first_tag.must_be_nil
|
1540
|
-
@album.update(:first_tag => nil)
|
1541
|
-
@album.reload.first_tag.must_be_nil
|
1542
|
-
|
1543
|
-
# one through one with alias
|
1544
|
-
@album.update(:alias_t_tag => @tag)
|
1545
|
-
@album.reload.alias_t_tag.must_equal @tag
|
1546
|
-
@album.update(:alias_t_tag => nil)
|
1547
|
-
@album.reload.alias_t_tag.must_be_nil
|
1548
|
-
end
|
1549
|
-
end
|
1550
|
-
|
1551
|
-
it "should have add and remove methods work" do
|
1552
|
-
# one to many
|
1553
|
-
@artist.add_album(@album)
|
1554
|
-
@artist.reload.albums.must_equal [@album]
|
1555
|
-
@artist.remove_album(@album)
|
1556
|
-
@artist.reload.albums.must_equal []
|
1557
|
-
|
1558
|
-
# many to many
|
1559
|
-
@album.add_tag(@tag)
|
1560
|
-
@album.reload.tags.must_equal [@tag]
|
1561
|
-
@tag.reload.albums.must_equal [@album]
|
1562
|
-
@album.alias_tags.must_equal [@tag]
|
1563
|
-
@album.remove_tag(@tag)
|
1564
|
-
@album.reload.tags.must_equal []
|
1565
|
-
|
1566
|
-
# many to many with alias
|
1567
|
-
@album.add_alias_tag(@tag)
|
1568
|
-
@album.reload.alias_tags.must_equal [@tag]
|
1569
|
-
@album.remove_alias_tag(@tag)
|
1570
|
-
@album.reload.alias_tags.must_equal []
|
1571
|
-
end
|
1572
|
-
|
1573
|
-
it "should have remove_all methods work" do
|
1574
|
-
# one to many
|
1575
|
-
@artist.add_album(@album)
|
1576
|
-
@artist.remove_all_albums
|
1577
|
-
@artist.reload.albums.must_equal []
|
1578
|
-
|
1579
|
-
# many to many
|
1580
|
-
@album.add_tag(@tag)
|
1581
|
-
@album.remove_all_tags
|
1582
|
-
@album.reload.tags.must_equal []
|
1583
|
-
|
1584
|
-
# many to many with alias
|
1585
|
-
@album.add_alias_tag(@tag)
|
1586
|
-
@album.remove_all_alias_tags
|
1587
|
-
@album.reload.alias_tags.must_equal []
|
1588
|
-
end
|
1589
|
-
|
1590
|
-
it "should have working dataset associations" do
|
1591
|
-
album, artist, tag = @pr.call
|
1592
|
-
|
1593
|
-
Tag.albums.all.must_equal []
|
1594
|
-
Album.artists.all.must_equal []
|
1595
|
-
Album.tags.all.must_equal []
|
1596
|
-
Album.alias_tags.all.must_equal []
|
1597
|
-
Artist.albums.all.must_equal []
|
1598
|
-
unless @no_many_through_many
|
1599
|
-
Album.first_tags.all.must_equal []
|
1600
|
-
Artist.tags.all.must_equal []
|
1601
|
-
Artist.first_tags.all.must_equal []
|
1602
|
-
Tag.tags.all.must_equal []
|
1603
|
-
end
|
1604
|
-
Artist.albums.tags.all.must_equal []
|
1605
|
-
|
1606
|
-
@album.update(:artist => @artist)
|
1607
|
-
@album.add_tag(@tag)
|
1608
|
-
|
1609
|
-
Tag.albums.all.must_equal [@album]
|
1610
|
-
Album.artists.all.must_equal [@artist]
|
1611
|
-
Album.tags.all.must_equal [@tag]
|
1612
|
-
Album.alias_tags.all.must_equal [@tag]
|
1613
|
-
Artist.albums.all.must_equal [@album]
|
1614
|
-
unless @no_many_through_many
|
1615
|
-
Album.mthm_tags.all.must_equal [@tag]
|
1616
|
-
Album.first_tags.all.must_equal [@tag]
|
1617
|
-
Artist.tags.all.must_equal [@tag]
|
1618
|
-
Artist.first_tags.all.must_equal [@tag]
|
1619
|
-
Tag.tags.all.must_equal [@tag]
|
1620
|
-
end
|
1621
|
-
Artist.albums.tags.all.must_equal [@tag]
|
1622
|
-
|
1623
|
-
album.add_tag(tag)
|
1624
|
-
album.update(:artist => artist)
|
1625
|
-
|
1626
|
-
Tag.albums.order(:name).all.must_equal [@album, album]
|
1627
|
-
Album.artists.order(:name).all.must_equal [@artist, artist]
|
1628
|
-
Album.tags.order(:name).all.must_equal [@tag, tag]
|
1629
|
-
Album.alias_tags.order(:name).all.must_equal [@tag, tag]
|
1630
|
-
Artist.albums.order(:name).all.must_equal [@album, album]
|
1631
|
-
unless @no_many_through_many
|
1632
|
-
Album.first_tags.order(:name).all.must_equal [@tag, tag]
|
1633
|
-
Artist.tags.order(:name).all.must_equal [@tag, tag]
|
1634
|
-
Artist.first_tags.order(:name).all.must_equal [@tag, tag]
|
1635
|
-
Tag.tags.order(:name).all.must_equal [@tag, tag]
|
1636
|
-
end
|
1637
|
-
Artist.albums.tags.order(:name).all.must_equal [@tag, tag]
|
1638
|
-
|
1639
|
-
Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).albums.all.must_equal [album]
|
1640
|
-
Album.filter(Album.qualified_primary_key_hash(album.pk)).artists.all.must_equal [artist]
|
1641
|
-
Album.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal [tag]
|
1642
|
-
Album.filter(Album.qualified_primary_key_hash(album.pk)).alias_tags.all.must_equal [tag]
|
1643
|
-
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.all.must_equal [album]
|
1644
|
-
unless @no_many_through_many
|
1645
|
-
Album.filter(Album.qualified_primary_key_hash(album.pk)).first_tags.all.must_equal [tag]
|
1646
|
-
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).tags.all.must_equal [tag]
|
1647
|
-
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).first_tags.all.must_equal [tag]
|
1648
|
-
Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).tags.all.must_equal [tag]
|
1649
|
-
end
|
1650
|
-
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.tags.all.must_equal [tag]
|
1651
|
-
|
1652
|
-
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal [tag]
|
1653
|
-
Artist.filter(Artist.qualified_primary_key_hash(@artist.pk)).albums.filter(Album.qualified_primary_key_hash(@album.pk)).tags.all.must_equal [@tag]
|
1654
|
-
Artist.filter(Artist.qualified_primary_key_hash(@artist.pk)).albums.filter(Album.qualified_primary_key_hash(album.pk)).tags.all.must_equal []
|
1655
|
-
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.filter(Album.qualified_primary_key_hash(@album.pk)).tags.all.must_equal []
|
1656
|
-
end
|
1657
|
-
|
1658
|
-
it "should eager load via eager correctly" do
|
1659
|
-
@album.update(:artist => @artist)
|
1660
|
-
@album.add_tag(@tag)
|
1661
|
-
|
1662
|
-
a = Artist.eager(:albums=>[:tags, :alias_tags]).eager(:first_album).all
|
1663
|
-
a.must_equal [@artist]
|
1664
|
-
a.first.albums.must_equal [@album]
|
1665
|
-
a.first.first_album.must_equal @album
|
1666
|
-
a.first.albums.first.tags.must_equal [@tag]
|
1667
|
-
a.first.albums.first.alias_tags.must_equal [@tag]
|
1668
|
-
|
1669
|
-
a = Tag.eager(:albums=>:artist).all
|
1670
|
-
a.must_equal [@tag]
|
1671
|
-
a.first.albums.must_equal [@album]
|
1672
|
-
a.first.albums.first.artist.must_equal @artist
|
1673
|
-
end
|
1674
|
-
|
1675
|
-
it "should eager load via eager_graph correctly" do
|
1676
|
-
@album.update(:artist => @artist)
|
1677
|
-
@album.add_tag(@tag)
|
1678
|
-
|
1679
|
-
a = Artist.eager_graph(:albums=>[:tags, :alias_tags]).eager_graph(:first_album).all
|
1680
|
-
a.must_equal [@artist]
|
1681
|
-
a.first.albums.must_equal [@album]
|
1682
|
-
a.first.first_album.must_equal @album
|
1683
|
-
a.first.albums.first.tags.must_equal [@tag]
|
1684
|
-
a.first.albums.first.alias_tags.must_equal [@tag]
|
1685
|
-
|
1686
|
-
a = Tag.eager_graph(:albums=>:artist).all
|
1687
|
-
a.must_equal [@tag]
|
1688
|
-
a.first.albums.must_equal [@album]
|
1689
|
-
a.first.albums.first.artist.must_equal @artist
|
1690
|
-
end
|
1691
|
-
|
1692
|
-
it "should be able to eager_graph dependent eager associations using eager callback" do
|
1693
|
-
@album.update(:artist => @artist)
|
1694
|
-
@album.add_tag(@tag)
|
1695
|
-
|
1696
|
-
a = Artist.eager(:albums=>proc{|ds| ds.eager_graph(:tags, :alias_tags).unordered}).eager(:first_album).all
|
1697
|
-
a.must_equal [@artist]
|
1698
|
-
a.first.albums.must_equal [@album]
|
1699
|
-
a.first.first_album.must_equal @album
|
1700
|
-
a.first.albums.first.tags.must_equal [@tag]
|
1701
|
-
a.first.albums.first.alias_tags.must_equal [@tag]
|
1702
|
-
|
1703
|
-
a = Tag.eager(:albums=>proc{|ds| ds.eager_graph(:artist).unordered}).all
|
1704
|
-
a.must_equal [@tag]
|
1705
|
-
a.first.albums.must_equal [@album]
|
1706
|
-
a.first.albums.first.artist.must_equal @artist
|
1707
|
-
end
|
1708
|
-
|
1709
|
-
it "should be able to eager dependent eager_graph associations using eager_graph_eager" do
|
1710
|
-
@album.update(:artist => @artist)
|
1711
|
-
@album.add_tag(@tag)
|
1712
|
-
|
1713
|
-
a = Artist.eager_graph(:albums, :first_album).eager_graph_eager([:albums], :tags, :alias_tags).all
|
1714
|
-
a.must_equal [@artist]
|
1715
|
-
a.first.albums.must_equal [@album]
|
1716
|
-
a.first.first_album.must_equal @album
|
1717
|
-
a.first.albums.first.tags.must_equal [@tag]
|
1718
|
-
a.first.albums.first.alias_tags.must_equal [@tag]
|
1719
|
-
|
1720
|
-
a = Tag.eager_graph(:albums).eager_graph_eager([:albums], :artist).all
|
1721
|
-
a.must_equal [@tag]
|
1722
|
-
a.first.albums.must_equal [@album]
|
1723
|
-
a.first.albums.first.artist.must_equal @artist
|
1724
|
-
end
|
1725
|
-
end
|
1726
|
-
|
1727
|
-
RegularAndCompositeKeyAssociations = shared_description do
|
1728
|
-
describe "when filtering/excluding by associations when joining" do
|
1729
|
-
def self_join(c)
|
1730
|
-
c.join(Sequel.as(c.table_name, :b), Array(c.primary_key).zip(Array(c.primary_key))).select_all(c.table_name)
|
1731
|
-
end
|
1732
|
-
|
1733
|
-
before do
|
1734
|
-
@Artist = self_join(Artist)
|
1735
|
-
@Album = self_join(Album)
|
1736
|
-
@Tag = self_join(Tag)
|
1737
|
-
end
|
1738
|
-
|
1739
|
-
include FilterByAssociations
|
1740
|
-
end
|
1741
|
-
|
1742
|
-
describe "with default/union :eager_limit_strategy" do
|
1743
|
-
before do
|
1744
|
-
@els = {}
|
1745
|
-
end
|
1746
|
-
include EagerLimitStrategies
|
1747
|
-
end
|
1748
|
-
|
1749
|
-
describe "with :eager_limit_strategy=>:ruby" do
|
1750
|
-
before do
|
1751
|
-
@els = {:eager_limit_strategy=>:ruby}
|
1752
|
-
end
|
1753
|
-
include EagerLimitStrategies
|
1754
|
-
include EagerGraphLimitStrategies
|
1755
|
-
end
|
1756
|
-
|
1757
|
-
describe "with :eager_limit_strategy=>:distinct_on" do
|
1758
|
-
before do
|
1759
|
-
@els = {:eager_limit_strategy=>:distinct_on}
|
1760
|
-
end
|
1761
|
-
|
1762
|
-
include OneToOneEagerLimitStrategies
|
1763
|
-
include OneThroughOneEagerLimitStrategies
|
1764
|
-
include OneThroughManyEagerLimitStrategies
|
1765
|
-
include OneToOneEagerGraphLimitStrategies
|
1766
|
-
include OneThroughOneEagerGraphLimitStrategies
|
1767
|
-
include OneThroughManyEagerGraphLimitStrategies
|
1768
|
-
include FilterByAssociationsSingularLimitStrategies
|
1769
|
-
end if DB.dataset.supports_ordered_distinct_on?
|
1770
|
-
|
1771
|
-
describe "with :eager_limit_strategy=>:window_function" do
|
1772
|
-
before do
|
1773
|
-
@els = {:eager_limit_strategy=>:window_function}
|
1774
|
-
end
|
1775
|
-
include EagerLimitStrategies
|
1776
|
-
include EagerGraphLimitStrategies
|
1777
|
-
include FilterByAssociationsLimitStrategies
|
1778
|
-
end if DB.dataset.supports_window_functions?
|
1779
|
-
|
1780
|
-
it "should work with a many_through_many association" do
|
1781
|
-
@album.update(:artist => @artist)
|
1782
|
-
@album.add_tag(@tag)
|
1783
|
-
|
1784
|
-
@album.reload
|
1785
|
-
@artist.reload
|
1786
|
-
@tag.reload
|
1787
|
-
|
1788
|
-
@album.tags.must_equal [@tag]
|
1789
|
-
|
1790
|
-
a = Artist.eager(:tags).all
|
1791
|
-
a.must_equal [@artist]
|
1792
|
-
a.first.tags.must_equal [@tag]
|
1793
|
-
|
1794
|
-
a = Artist.eager_graph(:tags).all
|
1795
|
-
a.must_equal [@artist]
|
1796
|
-
a.first.tags.must_equal [@tag]
|
1797
|
-
|
1798
|
-
a = Album.eager(:artist=>:tags).all
|
1799
|
-
a.must_equal [@album]
|
1800
|
-
a.first.artist.must_equal @artist
|
1801
|
-
a.first.artist.tags.must_equal [@tag]
|
1802
|
-
|
1803
|
-
a = Album.eager(:artist=>proc{|ds| ds.eager_graph(:tags)}).all
|
1804
|
-
a.must_equal [@album]
|
1805
|
-
a.first.artist.must_equal @artist
|
1806
|
-
a.first.artist.tags.must_equal [@tag]
|
1807
|
-
|
1808
|
-
a = Album.eager_graph(:artist=>:tags).all
|
1809
|
-
a.must_equal [@album]
|
1810
|
-
a.first.artist.must_equal @artist
|
1811
|
-
a.first.artist.tags.must_equal [@tag]
|
1812
|
-
|
1813
|
-
a = Album.eager_graph(:artist).eager_graph_eager([:artist], :tags).all
|
1814
|
-
a.must_equal [@album]
|
1815
|
-
a.first.artist.must_equal @artist
|
1816
|
-
a.first.artist.tags.must_equal [@tag]
|
1817
|
-
end
|
1818
|
-
|
1819
|
-
it "should work with a one_through_many association" do
|
1820
|
-
@album.update(:artist => @artist)
|
1821
|
-
@album.add_tag(@tag)
|
1822
|
-
|
1823
|
-
@album.reload
|
1824
|
-
@artist.reload
|
1825
|
-
@tag.reload
|
1826
|
-
|
1827
|
-
@album.tags.must_equal [@tag]
|
1828
|
-
|
1829
|
-
a = Artist.eager(:first_tag).all
|
1830
|
-
a.must_equal [@artist]
|
1831
|
-
a.first.first_tag.must_equal @tag
|
1832
|
-
|
1833
|
-
a = Artist.eager_graph(:first_tag).all
|
1834
|
-
a.must_equal [@artist]
|
1835
|
-
a.first.first_tag.must_equal @tag
|
1836
|
-
|
1837
|
-
a = Album.eager(:artist=>:first_tag).all
|
1838
|
-
a.must_equal [@album]
|
1839
|
-
a.first.artist.must_equal @artist
|
1840
|
-
a.first.artist.first_tag.must_equal @tag
|
1841
|
-
|
1842
|
-
a = Album.eager(:artist=>proc{|ds| ds.eager_graph(:first_tag)}).all
|
1843
|
-
a.must_equal [@album]
|
1844
|
-
a.first.artist.must_equal @artist
|
1845
|
-
a.first.artist.first_tag.must_equal @tag
|
1846
|
-
|
1847
|
-
a = Album.eager_graph(:artist=>:first_tag).all
|
1848
|
-
a.must_equal [@album]
|
1849
|
-
a.first.artist.must_equal @artist
|
1850
|
-
a.first.artist.first_tag.must_equal @tag
|
1851
|
-
|
1852
|
-
a = Album.eager_graph(:artist).eager_graph_eager([:artist], :first_tag).all
|
1853
|
-
a.must_equal [@album]
|
1854
|
-
a.first.artist.must_equal @artist
|
1855
|
-
a.first.artist.first_tag.must_equal @tag
|
1856
|
-
end
|
1857
|
-
end
|
1858
|
-
|
1859
|
-
describe "Sequel::Model Simple Associations" do
|
1860
|
-
before(:all) do
|
1861
|
-
@db = DB
|
1862
|
-
@db.drop_table?(:albums_tags, :tags, :albums, :artists)
|
1863
|
-
@db.create_table(:artists) do
|
1864
|
-
primary_key :id
|
1865
|
-
String :name
|
1866
|
-
end
|
1867
|
-
@db.create_table(:albums) do
|
1868
|
-
primary_key :id
|
1869
|
-
String :name
|
1870
|
-
foreign_key :artist_id, :artists
|
1871
|
-
end
|
1872
|
-
@db.create_table(:tags) do
|
1873
|
-
primary_key :id
|
1874
|
-
String :name
|
1875
|
-
end
|
1876
|
-
@db.create_table(:albums_tags) do
|
1877
|
-
foreign_key :album_id, :albums
|
1878
|
-
foreign_key :tag_id, :tags
|
1879
|
-
end
|
1880
|
-
end
|
1881
|
-
before do
|
1882
|
-
[:albums_tags, :tags, :albums, :artists].each{|t| @db[t].delete}
|
1883
|
-
class ::Artist < Sequel::Model(@db)
|
1884
|
-
plugin :dataset_associations
|
1885
|
-
plugin :eager_graph_eager
|
1886
|
-
one_to_many :albums, :order=>:name
|
1887
|
-
one_to_one :first_album, :clone=>:albums
|
1888
|
-
one_to_one :second_album, :clone=>:albums, :limit=>[nil, 1]
|
1889
|
-
one_to_one :last_album, :class=>:Album, :order=>Sequel.desc(:name)
|
1890
|
-
one_to_many :first_two_albums, :clone=>:albums, :limit=>2
|
1891
|
-
one_to_many :second_two_albums, :clone=>:albums, :limit=>[2, 1]
|
1892
|
-
one_to_many :not_first_albums, :clone=>:albums, :limit=>[nil, 1]
|
1893
|
-
one_to_many :last_two_albums, :class=>:Album, :order=>Sequel.desc(:name), :limit=>2
|
1894
|
-
one_to_many :a_albums, :clone=>:albums, :conditions=>{:name=>'Al'}
|
1895
|
-
one_to_one :first_a_album, :clone=>:a_albums
|
1896
|
-
plugin :many_through_many
|
1897
|
-
many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]]
|
1898
|
-
many_through_many :first_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>2, :graph_order=>:name
|
1899
|
-
many_through_many :second_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[2, 1], :graph_order=>:name
|
1900
|
-
many_through_many :not_first_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[nil, 1], :graph_order=>:name
|
1901
|
-
many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(Sequel[:tags][:name]), :limit=>2, :graph_order=>Sequel.desc(:name)
|
1902
|
-
many_through_many :t_tags, :clone=>:tags, :conditions=>{Sequel[:tags][:name]=>'T'}
|
1903
|
-
one_through_many :first_tag, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :order=>Sequel[:tags][:name], :graph_order=>:name, :class=>:Tag
|
1904
|
-
one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
1905
|
-
one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(Sequel[:tags][:name]), :graph_order=>Sequel.desc(:name)
|
1906
|
-
one_through_many :t_tag, :clone=>:first_tag, :conditions=>{Sequel[:tags][:name]=>'T'}
|
1907
|
-
end
|
1908
|
-
class ::Album < Sequel::Model(@db)
|
1909
|
-
plugin :dataset_associations
|
1910
|
-
plugin :eager_graph_eager
|
1911
|
-
many_to_one :artist, :reciprocal=>nil
|
1912
|
-
many_to_one :a_artist, :clone=>:artist, :conditions=>{:name=>'Ar'}, :key=>:artist_id
|
1913
|
-
many_to_many :tags, :right_key=>:tag_id
|
1914
|
-
plugin :many_through_many
|
1915
|
-
many_through_many :mthm_tags, [[:albums_tags, :album_id, :tag_id]], :class=>:Tag
|
1916
|
-
many_to_many :alias_tags, :clone=>:tags, :join_table=>Sequel[:albums_tags].as(:at)
|
1917
|
-
many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
|
1918
|
-
many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
1919
|
-
many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
1920
|
-
many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
1921
|
-
many_to_many :t_tags, :clone=>:tags, :conditions=>{:name=>'T'}
|
1922
|
-
many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>Sequel[:albums_tags].as(:at)
|
1923
|
-
one_through_one :first_tag, :clone=>:tags, :order=>:name
|
1924
|
-
one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
1925
|
-
one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
|
1926
|
-
one_through_one :t_tag, :clone=>:t_tags
|
1927
|
-
one_through_one :alias_t_tag, :clone=>:alias_t_tags
|
1928
|
-
end
|
1929
|
-
class ::Tag < Sequel::Model(@db)
|
1930
|
-
plugin :dataset_associations
|
1931
|
-
plugin :eager_graph_eager
|
1932
|
-
many_to_many :albums
|
1933
|
-
plugin :many_through_many
|
1934
|
-
many_through_many :tags, [[:albums_tags, :tag_id, :album_id], [:albums, :id, :artist_id], [:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :class=>:Tag
|
1935
|
-
end
|
1936
|
-
@album = Album.create(:name=>'Al')
|
1937
|
-
@artist = Artist.create(:name=>'Ar')
|
1938
|
-
@tag = Tag.create(:name=>'T')
|
1939
|
-
@same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
|
1940
|
-
@diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
|
1941
|
-
@middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
|
1942
|
-
@other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; @db[:albums_tags].insert([:album_id, :tag_id], Tag.select(@album.id, :id)); t}
|
1943
|
-
@pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
|
1944
|
-
@ins = lambda{@db[:albums_tags].insert(:tag_id=>@tag.id)}
|
1945
|
-
end
|
1946
|
-
after do
|
1947
|
-
[:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
|
1948
|
-
end
|
1949
|
-
after(:all) do
|
1950
|
-
@db.drop_table?(:albums_tags, :tags, :albums, :artists)
|
1951
|
-
end
|
1952
|
-
|
1953
|
-
include BasicRegularAndCompositeKeyAssociations
|
1954
|
-
include RegularAndCompositeKeyAssociations
|
1955
|
-
|
1956
|
-
describe "with :correlated_subquery limit strategy" do
|
1957
|
-
before do
|
1958
|
-
@els = {:eager_limit_strategy=>:correlated_subquery}
|
1959
|
-
end
|
1960
|
-
|
1961
|
-
include OneToOneEagerGraphLimitStrategies
|
1962
|
-
include OneToManyEagerGraphLimitStrategies
|
1963
|
-
include FilterByAssociationsOneToOneLimitStrategies
|
1964
|
-
include FilterByAssociationsOneToManyLimitStrategies
|
1965
|
-
end if DB.dataset.supports_limits_in_correlated_subqueries?
|
1966
|
-
|
1967
|
-
it "should handle eager loading limited associations for many objects" do
|
1968
|
-
@db[:artists].import([:name], (1..99).map{|i| [i.to_s]})
|
1969
|
-
artists = Artist.eager(:albums).all
|
1970
|
-
artists.length.must_equal 100
|
1971
|
-
artists.each{|a| a.albums.must_equal []}
|
1972
|
-
artists = Artist.eager(:first_two_albums).all
|
1973
|
-
artists.length.must_equal 100
|
1974
|
-
artists.each{|a| a.first_two_albums.must_equal []}
|
1975
|
-
@db[:albums].insert([:artist_id], @db[:artists].select(:id))
|
1976
|
-
artists = Artist.eager(:albums).all
|
1977
|
-
artists.length.must_equal 100
|
1978
|
-
artists.each{|a| a.albums.length.must_equal 1}
|
1979
|
-
artists = Artist.eager(:first_two_albums).all
|
1980
|
-
artists.length.must_equal 100
|
1981
|
-
artists.each{|a| a.first_two_albums.length.must_equal 1}
|
1982
|
-
end
|
1983
|
-
|
1984
|
-
it "should handle the :eager_limit option in eager-loading callbacks" do
|
1985
|
-
@db[:artists].import([:name], (1..4).map{|i| ['test']})
|
1986
|
-
artist_ids = @db[:artists].where(:name => 'test').select_map([:id])
|
1987
|
-
@db[:albums].import([:artist_id], artist_ids * 3)
|
1988
|
-
ads = Artist.where(:id => artist_ids)
|
1989
|
-
|
1990
|
-
artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 1)}).all
|
1991
|
-
artists.length.must_equal 4
|
1992
|
-
artists.each{|a| a.albums.length.must_equal 1}
|
1993
|
-
|
1994
|
-
artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 2)}).all
|
1995
|
-
artists.length.must_equal 4
|
1996
|
-
artists.each{|a| a.albums.length.must_equal 2}
|
1997
|
-
|
1998
|
-
artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 3)}).all
|
1999
|
-
artists.length.must_equal 4
|
2000
|
-
artists.each{|a| a.albums.length.must_equal 3}
|
2001
|
-
|
2002
|
-
artists = ads.eager(:albums => proc{|ds| ds.clone(:eager_limit => 4)}).all
|
2003
|
-
artists.length.must_equal 4
|
2004
|
-
artists.each{|a| a.albums.length.must_equal 3}
|
2005
|
-
end
|
2006
|
-
|
2007
|
-
it "should handle many_to_one associations with same name as :key" do
|
2008
|
-
Album.def_column_alias(:artist_id_id, :artist_id)
|
2009
|
-
Album.many_to_one :artist_id, :key_column =>:artist_id, :class=>Artist
|
2010
|
-
@album.update(:artist_id_id => @artist.id)
|
2011
|
-
@album.artist_id.must_equal @artist
|
2012
|
-
|
2013
|
-
as = Album.eager(:artist_id).all
|
2014
|
-
as.must_equal [@album]
|
2015
|
-
as.map{|a| a.artist_id}.must_equal [@artist]
|
2016
|
-
|
2017
|
-
as = Album.eager_graph(:artist_id).all
|
2018
|
-
as.must_equal [@album]
|
2019
|
-
as.map{|a| a.artist_id}.must_equal [@artist]
|
2020
|
-
end
|
2021
|
-
|
2022
|
-
it "should handle aliased tables when eager_graphing" do
|
2023
|
-
@album.update(:artist => @artist)
|
2024
|
-
@album.add_tag(@tag)
|
2025
|
-
|
2026
|
-
Artist.set_dataset(Sequel[:artists].as(:ar))
|
2027
|
-
Album.set_dataset(Sequel[:albums].as(:a))
|
2028
|
-
Tag.set_dataset(Sequel[:tags].as(:t))
|
2029
|
-
Artist.one_to_many :balbums, :class=>Album, :key=>:artist_id, :reciprocal=>nil
|
2030
|
-
Album.many_to_many :btags, :class=>Tag, :join_table=>:albums_tags, :right_key=>:tag_id
|
2031
|
-
Album.many_to_one :bartist, :class=>Artist, :key=>:artist_id
|
2032
|
-
Tag.many_to_many :balbums, :class=>Album, :join_table=>:albums_tags, :right_key=>:album_id
|
2033
|
-
|
2034
|
-
a = Artist.eager_graph(:balbums=>:btags).all
|
2035
|
-
a.must_equal [@artist]
|
2036
|
-
a.first.balbums.must_equal [@album]
|
2037
|
-
a.first.balbums.first.btags.must_equal [@tag]
|
2038
|
-
|
2039
|
-
a = Tag.eager_graph(:balbums=>:bartist).all
|
2040
|
-
a.must_equal [@tag]
|
2041
|
-
a.first.balbums.must_equal [@album]
|
2042
|
-
a.first.balbums.first.bartist.must_equal @artist
|
2043
|
-
end
|
2044
|
-
|
2045
|
-
it "should have add method accept hashes and create new records" do
|
2046
|
-
@artist.remove_all_albums
|
2047
|
-
Album.dataset.delete
|
2048
|
-
@album = @artist.add_album(:name=>'Al2')
|
2049
|
-
Album.first[:name].must_equal 'Al2'
|
2050
|
-
@artist.albums_dataset.first[:name].must_equal 'Al2'
|
2051
|
-
|
2052
|
-
@album.remove_all_tags
|
2053
|
-
Tag.dataset.delete
|
2054
|
-
@album.add_tag(:name=>'T2')
|
2055
|
-
Tag.first[:name].must_equal 'T2'
|
2056
|
-
@album.tags_dataset.first[:name].must_equal 'T2'
|
2057
|
-
end
|
2058
|
-
|
2059
|
-
it "should have add method accept primary key and add related records" do
|
2060
|
-
@artist.remove_all_albums
|
2061
|
-
@artist.add_album(@album.id)
|
2062
|
-
@artist.albums_dataset.first[:id].must_equal @album.id
|
2063
|
-
|
2064
|
-
@album.remove_all_tags
|
2065
|
-
@album.add_tag(@tag.id)
|
2066
|
-
@album.tags_dataset.first[:id].must_equal @tag.id
|
2067
|
-
end
|
2068
|
-
|
2069
|
-
it "should have remove method accept primary key and remove related album" do
|
2070
|
-
@artist.add_album(@album)
|
2071
|
-
@artist.reload.remove_album(@album.id)
|
2072
|
-
@artist.reload.albums.must_equal []
|
2073
|
-
|
2074
|
-
@album.add_tag(@tag)
|
2075
|
-
@album.reload.remove_tag(@tag.id)
|
2076
|
-
@tag.reload.albums.must_equal []
|
2077
|
-
end
|
2078
|
-
|
2079
|
-
it "should handle dynamic callbacks for regular loading" do
|
2080
|
-
@artist.add_album(@album)
|
2081
|
-
|
2082
|
-
@artist.albums.must_equal [@album]
|
2083
|
-
@artist.albums{|ds| ds.exclude(:id=>@album.id)}.must_equal []
|
2084
|
-
@artist.albums{|ds| ds.filter(:id=>@album.id)}.must_equal [@album]
|
2085
|
-
|
2086
|
-
@album.artist.must_equal @artist
|
2087
|
-
@album.artist{|ds| ds.exclude(:id=>@artist.id)}.must_be_nil
|
2088
|
-
@album.artist{|ds| ds.filter(:id=>@artist.id)}.must_equal @artist
|
2089
|
-
|
2090
|
-
@artist.albums{|ds| ds.exclude(:id=>@album.id)}.must_equal []
|
2091
|
-
@artist.albums{|ds| ds.filter(:id=>@album.id)}.must_equal [@album]
|
2092
|
-
@album.artist{|ds| ds.exclude(:id=>@artist.id)}.must_be_nil
|
2093
|
-
@album.artist{|ds| ds.filter(:id=>@artist.id)}.must_equal @artist
|
2094
|
-
end
|
2095
|
-
|
2096
|
-
it "should handle dynamic callbacks for eager loading via eager and eager_graph" do
|
2097
|
-
@artist.add_album(@album)
|
2098
|
-
@album.add_tag(@tag)
|
2099
|
-
album2 = @artist.add_album(:name=>'Foo')
|
2100
|
-
tag2 = album2.add_tag(:name=>'T2')
|
2101
|
-
|
2102
|
-
artist = Artist.eager(:albums=>:tags).all.first
|
2103
|
-
artist.albums.must_equal [@album, album2]
|
2104
|
-
artist.albums.map{|x| x.tags}.must_equal [[@tag], [tag2]]
|
2105
|
-
|
2106
|
-
artist = Artist.eager_graph(:albums=>:tags).all.first
|
2107
|
-
artist.albums.must_equal [@album, album2]
|
2108
|
-
artist.albums.map{|x| x.tags}.must_equal [[@tag], [tag2]]
|
2109
|
-
|
2110
|
-
artist = Artist.eager(:albums=>{proc{|ds| ds.where(:id=>album2.id)}=>:tags}).all.first
|
2111
|
-
artist.albums.must_equal [album2]
|
2112
|
-
artist.albums.first.tags.must_equal [tag2]
|
2113
|
-
|
2114
|
-
artist = Artist.eager_graph(:albums=>{proc{|ds| ds.where(:id=>album2.id)}=>:tags}).all.first
|
2115
|
-
artist.albums.must_equal [album2]
|
2116
|
-
artist.albums.first.tags.must_equal [tag2]
|
2117
|
-
end
|
2118
|
-
|
2119
|
-
it "should not produce duplicates when eager graphing many_to_one=>one_to_many association" do
|
2120
|
-
@pr.call
|
2121
|
-
@album.update(:artist => @artist)
|
2122
|
-
album2 = Album.last
|
2123
|
-
album2.update(:artist => @artist)
|
2124
|
-
|
2125
|
-
a = Album.eager_graph(:artist=>:albums).order{[albums[:id], albums_0[:id]]}.all
|
2126
|
-
a.must_equal [@album, album2]
|
2127
|
-
a.map(&:artist).must_equal [@artist, @artist]
|
2128
|
-
a.map(&:artist).map(&:albums).must_equal [[@album, album2], [@album, album2]]
|
2129
|
-
|
2130
|
-
a = Album.eager_graph(:artist=>:albums).eager_graph_eager([:artist], :tags).order{[albums[:id], albums_0[:id]]}.all
|
2131
|
-
a.must_equal [@album, album2]
|
2132
|
-
a.map(&:artist).must_equal [@artist, @artist]
|
2133
|
-
a.map(&:artist).map(&:albums).must_equal [[@album, album2], [@album, album2]]
|
2134
|
-
a.map(&:artist).map{|artist| artist.associations[:tags]}.must_equal [[], []]
|
2135
|
-
end
|
2136
|
-
|
2137
|
-
it "should have remove method raise an error for one_to_many records if the object isn't already associated" do
|
2138
|
-
proc{@artist.remove_album(@album.id)}.must_raise(Sequel::Error)
|
2139
|
-
proc{@artist.remove_album(@album)}.must_raise(Sequel::Error)
|
2140
|
-
end
|
2141
|
-
|
2142
|
-
it "should handle dataset associations with :dataset_associations_join options" do
|
2143
|
-
Album.many_to_many :tags, :right_key=>:tag_id, :select=>[Sequel.expr(:tags).*, Sequel[:albums_tags][:tag_id].as(:atid)], :dataset_associations_join=>true
|
2144
|
-
Artist.many_through_many :tags, [[:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :select=>[Sequel.expr(:tags).*, Sequel[:albums_tags][:tag_id].as(:atid), Sequel[:albums][:artist_id].as(:aid)], :dataset_associations_join=>true
|
2145
|
-
|
2146
|
-
Album.tags.order(Sequel[:tags][:name]).first.must_be_nil
|
2147
|
-
Artist.tags.order(Sequel[:tags][:name]).first.must_be_nil
|
2148
|
-
|
2149
|
-
@album.add_tag(@tag)
|
2150
|
-
@artist.add_album(@album)
|
2151
|
-
|
2152
|
-
Album.tags.order(Sequel[:tags][:name]).first.must_equal Tag.load(:id=>@tag.id, :name=>"T", :atid=>@tag.id)
|
2153
|
-
Artist.tags.order(Sequel[:tags][:name]).first.must_equal Tag.load(:id=>@tag.id, :name=>"T", :atid=>@tag.id, :aid=>@artist.id)
|
2154
|
-
end
|
2155
|
-
end
|
2156
|
-
|
2157
|
-
describe "Sequel::Model Composite Key Associations" do
|
2158
|
-
before(:all) do
|
2159
|
-
@db = DB
|
2160
|
-
@db.drop_table?(:albums_tags, :tags, :albums, :artists)
|
2161
|
-
@db.create_table(:artists) do
|
2162
|
-
Integer :id1
|
2163
|
-
Integer :id2
|
2164
|
-
String :name
|
2165
|
-
primary_key [:id1, :id2]
|
2166
|
-
end
|
2167
|
-
@db.create_table(:albums) do
|
2168
|
-
Integer :id1
|
2169
|
-
Integer :id2
|
2170
|
-
String :name
|
2171
|
-
Integer :artist_id1
|
2172
|
-
Integer :artist_id2
|
2173
|
-
foreign_key [:artist_id1, :artist_id2], :artists
|
2174
|
-
primary_key [:id1, :id2]
|
2175
|
-
end
|
2176
|
-
@db.create_table(:tags) do
|
2177
|
-
Integer :id1
|
2178
|
-
Integer :id2
|
2179
|
-
String :name
|
2180
|
-
primary_key [:id1, :id2]
|
2181
|
-
end
|
2182
|
-
@db.create_table(:albums_tags) do
|
2183
|
-
Integer :album_id1
|
2184
|
-
Integer :album_id2
|
2185
|
-
Integer :tag_id1
|
2186
|
-
Integer :tag_id2
|
2187
|
-
foreign_key [:album_id1, :album_id2], :albums
|
2188
|
-
foreign_key [:tag_id1, :tag_id2], :tags
|
2189
|
-
end
|
2190
|
-
end
|
2191
|
-
before do
|
2192
|
-
[:albums_tags, :tags, :albums, :artists].each{|t| @db[t].delete}
|
2193
|
-
class ::Artist < Sequel::Model(@db)
|
2194
|
-
plugin :dataset_associations
|
2195
|
-
plugin :eager_graph_eager
|
2196
|
-
set_primary_key [:id1, :id2]
|
2197
|
-
unrestrict_primary_key
|
2198
|
-
one_to_many :albums, :key=>[:artist_id1, :artist_id2], :order=>:name
|
2199
|
-
one_to_one :first_album, :clone=>:albums
|
2200
|
-
one_to_one :last_album, :clone=>:albums, :order=>Sequel.desc(:name)
|
2201
|
-
one_to_one :second_album, :clone=>:albums, :limit=>[nil, 1]
|
2202
|
-
one_to_many :first_two_albums, :clone=>:albums, :order=>:name, :limit=>2
|
2203
|
-
one_to_many :second_two_albums, :clone=>:albums, :order=>:name, :limit=>[2, 1]
|
2204
|
-
one_to_many :not_first_albums, :clone=>:albums, :order=>:name, :limit=>[nil, 1]
|
2205
|
-
one_to_many :last_two_albums, :clone=>:albums, :order=>Sequel.desc(:name), :limit=>2
|
2206
|
-
one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
|
2207
|
-
one_to_one :first_a_album, :clone=>:a_albums
|
2208
|
-
plugin :many_through_many
|
2209
|
-
many_through_many :tags, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]]
|
2210
|
-
many_through_many :first_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>2, :graph_order=>:name
|
2211
|
-
many_through_many :second_two_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[2, 1], :graph_order=>:name
|
2212
|
-
many_through_many :not_first_tags, :clone=>:tags, :order=>Sequel[:tags][:name], :limit=>[nil, 1], :graph_order=>:name
|
2213
|
-
many_through_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(Sequel[:tags][:name]), :limit=>2, :graph_order=>Sequel.desc(:name)
|
2214
|
-
many_through_many :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2215
|
-
one_through_many :first_tag, [[:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :order=>Sequel[:tags][:name], :graph_order=>:name, :class=>:Tag
|
2216
|
-
one_through_many :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
2217
|
-
one_through_many :last_tag, :clone=>:first_tag, :order=>Sequel.desc(Sequel[:tags][:name]), :graph_order=>Sequel.desc(:name)
|
2218
|
-
one_through_many :t_tag, :clone=>:first_tag do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2219
|
-
end
|
2220
|
-
class ::Album < Sequel::Model(@db)
|
2221
|
-
plugin :dataset_associations
|
2222
|
-
plugin :eager_graph_eager
|
2223
|
-
set_primary_key [:id1, :id2]
|
2224
|
-
unrestrict_primary_key
|
2225
|
-
many_to_one :artist, :key=>[:artist_id1, :artist_id2], :reciprocal=>nil
|
2226
|
-
many_to_one(:a_artist, :clone=>:artist){|ds| ds.where(:name=>'Ar')}
|
2227
|
-
many_to_many :tags, :left_key=>[:album_id1, :album_id2], :right_key=>[:tag_id1, :tag_id2]
|
2228
|
-
plugin :many_through_many
|
2229
|
-
many_through_many :mthm_tags, [[:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :class=>:Tag
|
2230
|
-
many_to_many :alias_tags, :clone=>:tags, :join_table=>Sequel[:albums_tags].as(:at)
|
2231
|
-
many_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
|
2232
|
-
many_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
2233
|
-
many_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
2234
|
-
many_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
2235
|
-
many_to_many :t_tags, :clone=>:tags do |ds| ds.where(:name=>'T') end
|
2236
|
-
many_to_many :alias_t_tags, :clone=>:t_tags, :join_table=>Sequel[:albums_tags].as(:at)
|
2237
|
-
one_through_one :first_tag, :clone=>:tags, :order=>:name
|
2238
|
-
one_through_one :second_tag, :clone=>:first_tag, :limit=>[nil, 1]
|
2239
|
-
one_through_one :last_tag, :clone=>:tags, :order=>Sequel.desc(:name)
|
2240
|
-
one_through_one :t_tag, :clone=>:t_tags
|
2241
|
-
one_through_one :alias_t_tag, :clone=>:alias_t_tags
|
2242
|
-
end
|
2243
|
-
class ::Tag < Sequel::Model(@db)
|
2244
|
-
plugin :dataset_associations
|
2245
|
-
plugin :eager_graph_eager
|
2246
|
-
set_primary_key [:id1, :id2]
|
2247
|
-
unrestrict_primary_key
|
2248
|
-
many_to_many :albums, :right_key=>[:album_id1, :album_id2], :left_key=>[:tag_id1, :tag_id2]
|
2249
|
-
plugin :many_through_many
|
2250
|
-
many_through_many :tags, [[:albums_tags, [:tag_id1, :tag_id2], [:album_id1, :album_id2]], [:albums, [:id1, :id2], [:artist_id1, :artist_id2]], [:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :class=>:Tag
|
2251
|
-
end
|
2252
|
-
@album = Album.create(:name=>'Al', :id1=>1, :id2=>2)
|
2253
|
-
@artist = Artist.create(:name=>'Ar', :id1=>3, :id2=>4)
|
2254
|
-
@tag = Tag.create(:name=>'T', :id1=>5, :id2=>6)
|
2255
|
-
@same_album = lambda{Album.create(:name=>'Al', :id1=>7, :id2=>8, :artist_id1=>3, :artist_id2=>4)}
|
2256
|
-
@diff_album = lambda{Album.create(:name=>'lA', :id1=>9, :id2=>10, :artist_id1=>3, :artist_id2=>4)}
|
2257
|
-
@middle_album = lambda{Album.create(:name=>'Bl', :id1=>13, :id2=>14, :artist_id1=>3, :artist_id2=>4)}
|
2258
|
-
@other_tags = lambda{t = [Tag.create(:name=>'U', :id1=>17, :id2=>18), Tag.create(:name=>'V', :id1=>19, :id2=>20)]; @db[:albums_tags].insert([:album_id1, :album_id2, :tag_id1, :tag_id2], Tag.select(1, 2, :id1, :id2)); t}
|
2259
|
-
@pr = lambda{[Album.create(:name=>'Al2', :id1=>11, :id2=>12),Artist.create(:name=>'Ar2', :id1=>13, :id2=>14),Tag.create(:name=>'T2', :id1=>15, :id2=>16)]}
|
2260
|
-
@ins = lambda{@db[:albums_tags].insert(:tag_id1=>@tag.id1, :tag_id2=>@tag.id2)}
|
2261
|
-
end
|
2262
|
-
after do
|
2263
|
-
[:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
|
2264
|
-
end
|
2265
|
-
after(:all) do
|
2266
|
-
@db.drop_table?(:albums_tags, :tags, :albums, :artists)
|
2267
|
-
end
|
2268
|
-
|
2269
|
-
include BasicRegularAndCompositeKeyAssociations
|
2270
|
-
include RegularAndCompositeKeyAssociations
|
2271
|
-
|
2272
|
-
describe "with :correlated_subquery limit strategy" do
|
2273
|
-
before do
|
2274
|
-
@els = {:eager_limit_strategy=>:correlated_subquery}
|
2275
|
-
end
|
2276
|
-
|
2277
|
-
include OneToOneEagerGraphLimitStrategies
|
2278
|
-
include OneToManyEagerGraphLimitStrategies
|
2279
|
-
include FilterByAssociationsOneToOneLimitStrategies
|
2280
|
-
include FilterByAssociationsOneToManyLimitStrategies
|
2281
|
-
end if DB.dataset.supports_limits_in_correlated_subqueries? && DB.dataset.supports_multiple_column_in?
|
2282
|
-
|
2283
|
-
it "should have add method accept hashes and create new records" do
|
2284
|
-
@artist.remove_all_albums
|
2285
|
-
Album.dataset.delete
|
2286
|
-
@artist.add_album(:id1=>1, :id2=>2, :name=>'Al2')
|
2287
|
-
Album.first[:name].must_equal 'Al2'
|
2288
|
-
@artist.albums_dataset.first[:name].must_equal 'Al2'
|
2289
|
-
|
2290
|
-
@album.remove_all_tags
|
2291
|
-
Tag.dataset.delete
|
2292
|
-
@album.add_tag(:id1=>1, :id2=>2, :name=>'T2')
|
2293
|
-
Tag.first[:name].must_equal 'T2'
|
2294
|
-
@album.tags_dataset.first[:name].must_equal 'T2'
|
2295
|
-
end
|
2296
|
-
|
2297
|
-
it "should have add method accept primary key and add related records" do
|
2298
|
-
@artist.remove_all_albums
|
2299
|
-
@artist.add_album([@album.id1, @album.id2])
|
2300
|
-
@artist.albums_dataset.first.pk.must_equal [@album.id1, @album.id2]
|
2301
|
-
|
2302
|
-
@album.remove_all_tags
|
2303
|
-
@album.add_tag([@tag.id1, @tag.id2])
|
2304
|
-
@album.tags_dataset.first.pk.must_equal [@tag.id1, @tag.id2]
|
2305
|
-
end
|
2306
|
-
|
2307
|
-
it "should have remove method accept primary key and remove related album" do
|
2308
|
-
@artist.add_album(@album)
|
2309
|
-
@artist.reload.remove_album([@album.id1, @album.id2])
|
2310
|
-
@artist.reload.albums.must_equal []
|
2311
|
-
|
2312
|
-
@album.add_tag(@tag)
|
2313
|
-
@album.reload.remove_tag([@tag.id1, @tag.id2])
|
2314
|
-
@tag.reload.albums.must_equal []
|
2315
|
-
end
|
2316
|
-
|
2317
|
-
it "should have remove method raise an error for one_to_many records if the object isn't already associated" do
|
2318
|
-
proc{@artist.remove_album([@album.id1, @album.id2])}.must_raise(Sequel::Error)
|
2319
|
-
proc{@artist.remove_album(@album)}.must_raise(Sequel::Error)
|
2320
|
-
end
|
2321
|
-
|
2322
|
-
it "should not have association method or dataset method return rows with NULL keys" do
|
2323
|
-
Album.one_to_many :other_albums, :class=>Album, :key=>[:artist_id1, :artist_id2], :primary_key=>[:artist_id1, :artist_id2]
|
2324
|
-
@album.update(:artist_id1=>1)
|
2325
|
-
@album.other_albums.must_equal []
|
2326
|
-
@album.other_albums_dataset.all.must_equal []
|
2327
|
-
end
|
2328
|
-
end
|
2329
|
-
|
2330
|
-
describe "Sequel::Model pg_array_to_many" do
|
2331
|
-
before(:all) do
|
2332
|
-
db = @db = DB
|
2333
|
-
@db.extension :pg_array unless @db.frozen?
|
2334
|
-
Sequel.extension :pg_array_ops
|
2335
|
-
@db.drop_table?(:tags, :albums, :artists)
|
2336
|
-
@db.create_table(:artists) do
|
2337
|
-
primary_key :id
|
2338
|
-
String :name
|
2339
|
-
end
|
2340
|
-
@db.create_table(:albums) do
|
2341
|
-
primary_key :id
|
2342
|
-
String :name
|
2343
|
-
foreign_key :artist_id, :artists
|
2344
|
-
column :tag_ids, "#{db.send(:type_literal, :type=>Integer)}[]"
|
2345
|
-
end
|
2346
|
-
@db.create_table(:tags) do
|
2347
|
-
primary_key :id
|
2348
|
-
String :name
|
2349
|
-
end
|
2350
|
-
end
|
2351
|
-
before do
|
2352
|
-
[:tags, :albums, :artists].each{|t| @db[t].delete}
|
2353
|
-
class ::Artist < Sequel::Model(@db)
|
2354
|
-
plugin :dataset_associations
|
2355
|
-
plugin :eager_graph_eager
|
2356
|
-
one_to_many :albums, :order=>:name
|
2357
|
-
one_to_one :first_album, :clone=>:albums
|
2358
|
-
one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
|
2359
|
-
one_to_one :first_a_album, :clone=>:a_albums
|
2360
|
-
end
|
2361
|
-
class ::Album < Sequel::Model(@db)
|
2362
|
-
plugin :dataset_associations
|
2363
|
-
plugin :pg_array_associations
|
2364
|
-
plugin :eager_graph_eager
|
2365
|
-
many_to_one :artist, :reciprocal=>nil
|
2366
|
-
many_to_one :a_artist, :clone=>:artist, :key=>:artist_id do |ds| ds.where(:name=>'Ar') end
|
2367
|
-
pg_array_to_many :tags, :key=>:tag_ids, :save_after_modify=>true
|
2368
|
-
pg_array_to_many :alias_tags, :clone=>:tags
|
2369
|
-
pg_array_to_many :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
|
2370
|
-
pg_array_to_many :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
2371
|
-
pg_array_to_many :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
2372
|
-
pg_array_to_many :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
2373
|
-
pg_array_to_many :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2374
|
-
pg_array_to_many :alias_t_tags, :clone=>:t_tags
|
2375
|
-
end
|
2376
|
-
class ::Tag < Sequel::Model(@db)
|
2377
|
-
plugin :dataset_associations
|
2378
|
-
plugin :pg_array_associations
|
2379
|
-
plugin :eager_graph_eager
|
2380
|
-
many_to_pg_array :albums
|
2381
|
-
end
|
2382
|
-
@album = Album.create(:name=>'Al')
|
2383
|
-
@artist = Artist.create(:name=>'Ar')
|
2384
|
-
@tag = Tag.create(:name=>'T')
|
2385
|
-
@many_to_many_method = :pg_array_to_many
|
2386
|
-
@no_many_through_many = true
|
2387
|
-
@same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
|
2388
|
-
@diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
|
2389
|
-
@middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
|
2390
|
-
@other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; Tag.all{|x| @album.add_tag(x)}; t}
|
2391
|
-
@pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
|
2392
|
-
@ins = lambda{}
|
2393
|
-
end
|
2394
|
-
after do
|
2395
|
-
[:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
|
2396
|
-
end
|
2397
|
-
after(:all) do
|
2398
|
-
@db.drop_table?(:tags, :albums, :artists)
|
2399
|
-
end
|
2400
|
-
|
2401
|
-
include BasicRegularAndCompositeKeyAssociations
|
2402
|
-
include ManyToManyEagerLimitStrategies
|
2403
|
-
include ManyToManyEagerGraphLimitStrategies
|
2404
|
-
|
2405
|
-
it "should handle adding and removing entries in array" do
|
2406
|
-
a = Album.create
|
2407
|
-
a.typecast_on_assignment = false
|
2408
|
-
a.add_tag(@tag)
|
2409
|
-
a.remove_tag(@tag)
|
2410
|
-
a.save
|
2411
|
-
end
|
2412
|
-
end if DB.database_type == :postgres && [:postgres, :jdbc].include?(DB.adapter_scheme) && DB.server_version >= 90300
|
2413
|
-
|
2414
|
-
describe "Sequel::Model many_to_pg_array" do
|
2415
|
-
before(:all) do
|
2416
|
-
db = @db = DB
|
2417
|
-
@db.extension :pg_array unless @db.frozen?
|
2418
|
-
Sequel.extension :pg_array_ops
|
2419
|
-
@db.drop_table?(:tags, :albums, :artists)
|
2420
|
-
@db.create_table(:artists) do
|
2421
|
-
primary_key :id
|
2422
|
-
String :name
|
2423
|
-
end
|
2424
|
-
@db.create_table(:albums) do
|
2425
|
-
primary_key :id
|
2426
|
-
String :name
|
2427
|
-
foreign_key :artist_id, :artists
|
2428
|
-
end
|
2429
|
-
@db.create_table(:tags) do
|
2430
|
-
primary_key :id
|
2431
|
-
String :name
|
2432
|
-
column :album_ids, "#{db.send(:type_literal, :type=>Integer)}[]"
|
2433
|
-
end
|
2434
|
-
end
|
2435
|
-
before do
|
2436
|
-
[:tags, :albums, :artists].each{|t| @db[t].delete}
|
2437
|
-
class ::Artist < Sequel::Model(@db)
|
2438
|
-
plugin :dataset_associations
|
2439
|
-
plugin :eager_graph_eager
|
2440
|
-
one_to_many :albums, :order=>:name
|
2441
|
-
one_to_one :first_album, :class=>:Album, :order=>:name
|
2442
|
-
one_to_many :a_albums, :clone=>:albums do |ds| ds.where(:name=>'Al') end
|
2443
|
-
one_to_one :first_a_album, :clone=>:a_albums
|
2444
|
-
end
|
2445
|
-
class ::Album < Sequel::Model(@db)
|
2446
|
-
plugin :dataset_associations
|
2447
|
-
plugin :pg_array_associations
|
2448
|
-
plugin :eager_graph_eager
|
2449
|
-
many_to_one :artist, :reciprocal=>nil
|
2450
|
-
many_to_one :a_artist, :clone=>:artist, :key=>:artist_id do |ds| ds.where(:name=>'Ar') end
|
2451
|
-
many_to_pg_array :tags
|
2452
|
-
many_to_pg_array :alias_tags, :clone=>:tags
|
2453
|
-
many_to_pg_array :first_two_tags, :clone=>:tags, :order=>:name, :limit=>2
|
2454
|
-
many_to_pg_array :second_two_tags, :clone=>:tags, :order=>:name, :limit=>[2, 1]
|
2455
|
-
many_to_pg_array :not_first_tags, :clone=>:tags, :order=>:name, :limit=>[nil, 1]
|
2456
|
-
many_to_pg_array :last_two_tags, :clone=>:tags, :order=>Sequel.desc(:name), :limit=>2
|
2457
|
-
many_to_pg_array :t_tags, :clone=>:tags do |ds| ds.where(Sequel[:tags][:name]=>'T') end
|
2458
|
-
many_to_pg_array :alias_t_tags, :clone=>:t_tags
|
2459
|
-
end
|
2460
|
-
class ::Tag < Sequel::Model(@db)
|
2461
|
-
plugin :dataset_associations
|
2462
|
-
plugin :pg_array_associations
|
2463
|
-
plugin :eager_graph_eager
|
2464
|
-
pg_array_to_many :albums, :save_after_modify=>true
|
2465
|
-
end
|
2466
|
-
@album = Album.create(:name=>'Al')
|
2467
|
-
@artist = Artist.create(:name=>'Ar')
|
2468
|
-
@tag = Tag.create(:name=>'T')
|
2469
|
-
@many_to_many_method = :pg_array_to_many
|
2470
|
-
@no_many_through_many = true
|
2471
|
-
@same_album = lambda{Album.create(:name=>'Al', :artist_id=>@artist.id)}
|
2472
|
-
@diff_album = lambda{Album.create(:name=>'lA', :artist_id=>@artist.id)}
|
2473
|
-
@middle_album = lambda{Album.create(:name=>'Bl', :artist_id=>@artist.id)}
|
2474
|
-
@other_tags = lambda{t = [Tag.create(:name=>'U'), Tag.create(:name=>'V')]; Tag.all{|x| @album.add_tag(x)}; @tag.refresh; t.each{|x| x.refresh}; t}
|
2475
|
-
@pr = lambda{[Album.create(:name=>'Al2'),Artist.create(:name=>'Ar2'),Tag.create(:name=>'T2')]}
|
2476
|
-
@ins = lambda{}
|
2477
|
-
end
|
2478
|
-
after do
|
2479
|
-
[:Tag, :Album, :Artist].each{|x| Object.send(:remove_const, x)}
|
2480
|
-
end
|
2481
|
-
after(:all) do
|
2482
|
-
@db.drop_table?(:tags, :albums, :artists)
|
2483
|
-
end
|
2484
|
-
|
2485
|
-
include BasicRegularAndCompositeKeyAssociations
|
2486
|
-
include ManyToManyEagerLimitStrategies
|
2487
|
-
include ManyToManyEagerGraphLimitStrategies
|
2488
|
-
|
2489
|
-
it "should handle adding and removing entries in array" do
|
2490
|
-
a = Album.create
|
2491
|
-
@tag.typecast_on_assignment = false
|
2492
|
-
a.add_tag(@tag)
|
2493
|
-
a.remove_tag(@tag)
|
2494
|
-
end
|
2495
|
-
end if DB.database_type == :postgres && [:postgres, :jdbc].include?(DB.adapter_scheme) && DB.server_version >= 90300
|
2496
|
-
|
2497
|
-
describe "Sequel::Model Associations with clashing column names" do
|
2498
|
-
before(:all) do
|
2499
|
-
@db = DB
|
2500
|
-
@db.drop_table?(:bars_foos, :bars, :foos)
|
2501
|
-
@db.create_table(:foos) do
|
2502
|
-
primary_key :id
|
2503
|
-
Integer :object_id
|
2504
|
-
end
|
2505
|
-
@db.create_table(:bars) do
|
2506
|
-
primary_key :id
|
2507
|
-
Integer :object_id
|
2508
|
-
end
|
2509
|
-
@db.create_table(:bars_foos) do
|
2510
|
-
Integer :foo_id
|
2511
|
-
Integer :object_id
|
2512
|
-
primary_key [:foo_id, :object_id]
|
2513
|
-
end
|
2514
|
-
end
|
2515
|
-
before do
|
2516
|
-
[:bars_foos, :bars, :foos].each{|t| @db[t].delete}
|
2517
|
-
@Foo = Class.new(Sequel::Model(:foos))
|
2518
|
-
@Bar = Class.new(Sequel::Model(:bars))
|
2519
|
-
@Foo.def_column_alias(:obj_id, :object_id)
|
2520
|
-
@Bar.def_column_alias(:obj_id, :object_id)
|
2521
|
-
@Foo.one_to_many :bars, :primary_key=>:obj_id, :primary_key_column=>:object_id, :key=>:object_id, :key_method=>:obj_id, :class=>@Bar
|
2522
|
-
@Foo.one_to_one :bar, :primary_key=>:obj_id, :primary_key_column=>:object_id, :key=>:object_id, :key_method=>:obj_id, :class=>@Bar
|
2523
|
-
@Bar.many_to_one :foo, :key=>:obj_id, :key_column=>:object_id, :primary_key=>:object_id, :primary_key_method=>:obj_id, :class=>@Foo
|
2524
|
-
@Foo.many_to_many :mtmbars, :join_table=>:bars_foos, :left_primary_key=>:obj_id, :left_primary_key_column=>:object_id, :right_primary_key=>:object_id, :right_primary_key_method=>:obj_id, :left_key=>:foo_id, :right_key=>:object_id, :class=>@Bar
|
2525
|
-
@Foo.one_through_one :mtmbar, :join_table=>:bars_foos, :left_primary_key=>:obj_id, :left_primary_key_column=>:object_id, :right_primary_key=>:object_id, :right_primary_key_method=>:obj_id, :left_key=>:foo_id, :right_key=>:object_id, :class=>@Bar
|
2526
|
-
@Bar.many_to_many :mtmfoos, :join_table=>:bars_foos, :left_primary_key=>:obj_id, :left_primary_key_column=>:object_id, :right_primary_key=>:object_id, :right_primary_key_method=>:obj_id, :left_key=>:object_id, :right_key=>:foo_id, :class=>@Foo
|
2527
|
-
@foo = @Foo.create(:obj_id=>2)
|
2528
|
-
@bar = @Bar.create(:obj_id=>2)
|
2529
|
-
@Foo.db[:bars_foos].insert(2, 2)
|
2530
|
-
end
|
2531
|
-
after(:all) do
|
2532
|
-
@db.drop_table?(:bars_foos, :bars, :foos)
|
2533
|
-
end
|
2534
|
-
|
2535
|
-
it "should have working regular association methods" do
|
2536
|
-
@Bar.first.foo.must_equal @foo
|
2537
|
-
@Foo.first.bars.must_equal [@bar]
|
2538
|
-
@Foo.first.bar.must_equal @bar
|
2539
|
-
@Foo.first.mtmbars.must_equal [@bar]
|
2540
|
-
@Foo.first.mtmbar.must_equal @bar
|
2541
|
-
@Bar.first.mtmfoos.must_equal [@foo]
|
2542
|
-
end
|
2543
|
-
|
2544
|
-
it "should have working eager loading methods" do
|
2545
|
-
@Bar.eager(:foo).all.map{|o| [o, o.foo]}.must_equal [[@bar, @foo]]
|
2546
|
-
@Foo.eager(:bars).all.map{|o| [o, o.bars]}.must_equal [[@foo, [@bar]]]
|
2547
|
-
@Foo.eager(:bar).all.map{|o| [o, o.bar]}.must_equal [[@foo, @bar]]
|
2548
|
-
@Foo.eager(:mtmbars).all.map{|o| [o, o.mtmbars]}.must_equal [[@foo, [@bar]]]
|
2549
|
-
@Foo.eager(:mtmbar).all.map{|o| [o, o.mtmbar]}.must_equal [[@foo, @bar]]
|
2550
|
-
@Bar.eager(:mtmfoos).all.map{|o| [o, o.mtmfoos]}.must_equal [[@bar, [@foo]]]
|
2551
|
-
end
|
2552
|
-
|
2553
|
-
it "should have working eager graphing methods" do
|
2554
|
-
@Bar.eager_graph(:foo).all.map{|o| [o, o.foo]}.must_equal [[@bar, @foo]]
|
2555
|
-
@Foo.eager_graph(:bars).all.map{|o| [o, o.bars]}.must_equal [[@foo, [@bar]]]
|
2556
|
-
@Foo.eager_graph(:bar).all.map{|o| [o, o.bar]}.must_equal [[@foo, @bar]]
|
2557
|
-
@Foo.eager_graph(:mtmbars).all.map{|o| [o, o.mtmbars]}.must_equal [[@foo, [@bar]]]
|
2558
|
-
@Foo.eager_graph(:mtmbar).all.map{|o| [o, o.mtmbar]}.must_equal [[@foo, @bar]]
|
2559
|
-
@Bar.eager_graph(:mtmfoos).all.map{|o| [o, o.mtmfoos]}.must_equal [[@bar, [@foo]]]
|
2560
|
-
end
|
2561
|
-
|
2562
|
-
it "should have working modification methods" do
|
2563
|
-
b = @Bar.create(:obj_id=>3)
|
2564
|
-
f = @Foo.create(:obj_id=>3)
|
2565
|
-
|
2566
|
-
@bar.foo = f
|
2567
|
-
@bar.obj_id.must_equal 3
|
2568
|
-
@foo.bar = @bar
|
2569
|
-
@bar.obj_id.must_equal 2
|
2570
|
-
|
2571
|
-
@foo.add_bar(b)
|
2572
|
-
@foo.bars.sort_by{|x| x.id}.must_equal [@bar, b]
|
2573
|
-
@foo.remove_bar(b)
|
2574
|
-
@foo.bars.must_equal [@bar]
|
2575
|
-
@foo.remove_all_bars
|
2576
|
-
@foo.bars.must_equal []
|
2577
|
-
|
2578
|
-
@bar.refresh.update(:obj_id=>2)
|
2579
|
-
b.refresh.update(:obj_id=>3)
|
2580
|
-
@foo.mtmbars.must_equal [@bar]
|
2581
|
-
@foo.remove_all_mtmbars
|
2582
|
-
@foo.mtmbars.must_equal []
|
2583
|
-
@foo.add_mtmbar(b)
|
2584
|
-
@foo.mtmbars.must_equal [b]
|
2585
|
-
@foo.remove_mtmbar(b)
|
2586
|
-
@foo.mtmbars.must_equal []
|
2587
|
-
|
2588
|
-
@bar.add_mtmfoo(f)
|
2589
|
-
@bar.mtmfoos.must_equal [f]
|
2590
|
-
@bar.remove_all_mtmfoos
|
2591
|
-
@bar.mtmfoos.must_equal []
|
2592
|
-
@bar.add_mtmfoo(f)
|
2593
|
-
@bar.mtmfoos.must_equal [f]
|
2594
|
-
@bar.remove_mtmfoo(f)
|
2595
|
-
@bar.mtmfoos.must_equal []
|
2596
|
-
end
|
2597
|
-
end
|