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,75 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "column_conflicts plugin" do
|
4
|
-
before do
|
5
|
-
@db = Sequel.mock
|
6
|
-
@c = Class.new(Sequel::Model(@db[:test]))
|
7
|
-
@c.columns :model, :use_transactions, :foo
|
8
|
-
@c.plugin :column_conflicts
|
9
|
-
@o = @c.load(:model=>1, :use_transactions=>2, :foo=>4)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should have mass assignment work correctly" do
|
13
|
-
@o.set_fields({:use_transactions=>3}, [:use_transactions])
|
14
|
-
@o.get_column_value(:use_transactions).must_equal 3
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should handle both symbols and strings" do
|
18
|
-
@o.get_column_value(:model).must_equal 1
|
19
|
-
@o.get_column_value("model").must_equal 1
|
20
|
-
@o.set_column_value(:use_transactions=, 3)
|
21
|
-
@o.get_column_value(:use_transactions).must_equal 3
|
22
|
-
@o.set_column_value(:use_transactions=, 4)
|
23
|
-
@o.get_column_value(:use_transactions).must_equal 4
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should work correctly if there are no conflicts" do
|
27
|
-
@o.get_column_value(:foo).must_equal 4
|
28
|
-
@o.set_column_value(:model=, 2).must_equal 2
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should allow manual setting of conflicted columns" do
|
32
|
-
@c.send(:define_method, :foo){raise}
|
33
|
-
@c.get_column_conflict!(:foo)
|
34
|
-
@o.get_column_value(:foo).must_equal 4
|
35
|
-
|
36
|
-
@c.send(:define_method, :model=){raise}
|
37
|
-
@c.set_column_conflict!(:model)
|
38
|
-
@o.set_column_value(:model=, 2).must_equal 2
|
39
|
-
@o.get_column_value(:model).must_equal 2
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should not erase existing column conflicts when loading the plugin" do
|
43
|
-
@c.send(:define_method, :foo){raise}
|
44
|
-
@c.send(:define_method, :model=){raise}
|
45
|
-
@c.get_column_conflict!(:foo)
|
46
|
-
@c.set_column_conflict!(:model)
|
47
|
-
@c.plugin :column_conflicts
|
48
|
-
@o.get_column_value(:foo).must_equal 4
|
49
|
-
@o.set_column_value(:model=, 2).must_equal 2
|
50
|
-
@o.get_column_value(:model).must_equal 2
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should work correctly in subclasses" do
|
54
|
-
@o = Class.new(@c).load(:model=>1, :use_transactions=>2)
|
55
|
-
@o.get_column_value(:model).must_equal 1
|
56
|
-
@o.get_column_value("model").must_equal 1
|
57
|
-
@o.set_column_value(:use_transactions=, 3)
|
58
|
-
@o.get_column_value(:use_transactions).must_equal 3
|
59
|
-
@o.set_column_value(:use_transactions=, 4)
|
60
|
-
@o.get_column_value(:use_transactions).must_equal 4
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should work correctly for dataset changes" do
|
64
|
-
@c.dataset = @db[:test].with_extend{def columns; [:object_id] end}
|
65
|
-
o = @c.load(:object_id=>3)
|
66
|
-
o.get_column_value(:object_id).must_equal 3
|
67
|
-
o.object_id.wont_equal 3
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should freeze column conflict information when freezing model class" do
|
71
|
-
@c.freeze
|
72
|
-
@c.get_column_conflicts.frozen?.must_equal true
|
73
|
-
@c.set_column_conflicts.frozen?.must_equal true
|
74
|
-
end
|
75
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Sequel::Plugins::ColumnSelect" do
|
4
|
-
def set_cols(*cols)
|
5
|
-
@cols.replace(cols)
|
6
|
-
end
|
7
|
-
|
8
|
-
before do
|
9
|
-
cols = @cols = []
|
10
|
-
@db = Sequel.mock
|
11
|
-
@db.extend_datasets(Module.new{define_method(:columns){cols}})
|
12
|
-
set_cols :id, :a, :b, :c
|
13
|
-
@Album = Class.new(Sequel::Model(@db[:albums]))
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should add a explicit column selections to existing dataset without explicit selection" do
|
17
|
-
@Album.plugin :column_select
|
18
|
-
@Album.dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
|
19
|
-
|
20
|
-
@Album.dataset = :albs
|
21
|
-
@Album.dataset.sql.must_equal 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
|
22
|
-
|
23
|
-
@Album.dataset = Sequel.identifier(:albs)
|
24
|
-
@Album.dataset.sql.must_equal 'SELECT albs.id, albs.a, albs.b, albs.c FROM albs'
|
25
|
-
end
|
26
|
-
|
27
|
-
with_symbol_splitting "should handle splittable symbols" do
|
28
|
-
@Album.dataset = :s__albums
|
29
|
-
@Album.plugin :column_select
|
30
|
-
@Album.dataset.sql.must_equal 'SELECT s.albums.id, s.albums.a, s.albums.b, s.albums.c FROM s.albums'
|
31
|
-
|
32
|
-
@Album.dataset = :albums___a
|
33
|
-
@Album.dataset.sql.must_equal 'SELECT a.id, a.a, a.b, a.c FROM albums AS a'
|
34
|
-
|
35
|
-
@Album.dataset = :s__albums___a
|
36
|
-
@Album.dataset.sql.must_equal 'SELECT a.id, a.a, a.b, a.c FROM s.albums AS a'
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should handle qualified tables" do
|
40
|
-
@Album.dataset = Sequel.qualify(:s2, :albums)
|
41
|
-
@Album.plugin :column_select
|
42
|
-
@Album.dataset.sql.must_equal 'SELECT s2.albums.id, s2.albums.a, s2.albums.b, s2.albums.c FROM s2.albums'
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should handle aliases" do
|
46
|
-
@Album.plugin :column_select
|
47
|
-
@Album.dataset = Sequel.as(:albums, :b)
|
48
|
-
@Album.dataset.sql.must_equal 'SELECT b.id, b.a, b.b, b.c FROM albums AS b'
|
49
|
-
|
50
|
-
@Album.dataset = @Album.db[:albums].from_self
|
51
|
-
@Album.dataset.sql.must_equal 'SELECT t1.id, t1.a, t1.b, t1.c FROM (SELECT * FROM albums) AS t1'
|
52
|
-
|
53
|
-
@Album.dataset = Sequel.as(@Album.db[:albums], :b)
|
54
|
-
@Album.dataset.sql.must_equal 'SELECT b.id, b.a, b.b, b.c FROM (SELECT * FROM albums) AS b'
|
55
|
-
end
|
56
|
-
|
57
|
-
it "should not add a explicit column selection selection on existing dataset with explicit selection" do
|
58
|
-
@Album.dataset = @Album.dataset.select(:name)
|
59
|
-
@Album.plugin :column_select
|
60
|
-
@Album.dataset.sql.must_equal 'SELECT name FROM albums'
|
61
|
-
|
62
|
-
@Album.dataset = @Album.dataset.select(:name, :artist)
|
63
|
-
@Album.dataset.sql.must_equal 'SELECT name, artist FROM albums'
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should work with implicit subqueries used for joined datasets" do
|
67
|
-
@Album.dataset = @Album.db.from(:a1, :a2)
|
68
|
-
@Album.plugin :column_select
|
69
|
-
@Album.dataset.sql.must_equal "SELECT a1.id, a1.a, a1.b, a1.c FROM (SELECT * FROM a1, a2) AS a1"
|
70
|
-
|
71
|
-
@Album.dataset = @Album.db.from(:a1).cross_join(:a2)
|
72
|
-
@Album.dataset.sql.must_equal "SELECT a1.id, a1.a, a1.b, a1.c FROM (SELECT * FROM a1 CROSS JOIN a2) AS a1"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should add a explicit column selection on existing dataset with a subquery" do
|
76
|
-
@Album.dataset = @Album.db.from(:a1, :a2).from_self(:alias=>:foo)
|
77
|
-
@Album.plugin :column_select
|
78
|
-
@Album.dataset.sql.must_equal 'SELECT foo.id, foo.a, foo.b, foo.c FROM (SELECT * FROM a1, a2) AS foo'
|
79
|
-
|
80
|
-
@Album.dataset = @Album.db.from(:a1).cross_join(:a2).from_self(:alias=>:foo)
|
81
|
-
@Album.dataset.sql.must_equal 'SELECT foo.id, foo.a, foo.b, foo.c FROM (SELECT * FROM a1 CROSS JOIN a2) AS foo'
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should use explicit column selection for many_to_many associations" do
|
85
|
-
@Album.plugin :column_select
|
86
|
-
@Album.many_to_many :albums, :class=>@Album, :left_key=>:l, :right_key=>:r, :join_table=>:j
|
87
|
-
@Album.load(:id=>1).albums_dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
|
88
|
-
end
|
89
|
-
|
90
|
-
it "should set not explicit column selection for many_to_many associations when overriding select" do
|
91
|
-
@Album.plugin :column_select
|
92
|
-
@Album.dataset = @Album.dataset.select(:a)
|
93
|
-
@Album.many_to_many :albums, :class=>@Album, :left_key=>:l, :right_key=>:r, :join_table=>:j
|
94
|
-
@Album.load(:id=>1).albums_dataset.sql.must_equal 'SELECT albums.* FROM albums INNER JOIN j ON (j.r = albums.id) WHERE (j.l = 1)'
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should use the schema to get columns if available" do
|
98
|
-
def @db.supports_schema_parsing?() true end
|
99
|
-
def @db.schema(t, *)
|
100
|
-
[[:t, {}], [:d, {}]]
|
101
|
-
end
|
102
|
-
@Album.plugin :column_select
|
103
|
-
@Album.dataset.sql.must_equal 'SELECT albums.t, albums.d FROM albums'
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should handle case where schema parsing does not produce results" do
|
107
|
-
def @db.supports_schema_parsing?() true end
|
108
|
-
def @db.schema_parse_table(t, *) [] end
|
109
|
-
@Album.plugin :column_select
|
110
|
-
@Album.dataset.sql.must_equal 'SELECT albums.id, albums.a, albums.b, albums.c FROM albums'
|
111
|
-
end
|
112
|
-
|
113
|
-
it "should handle case where schema parsing and columns does not produce results" do
|
114
|
-
def @db.supports_schema_parsing?() true end
|
115
|
-
def @db.schema_parse_table(t, *) [] end
|
116
|
-
@db.extend_datasets{def columns; raise Sequel::DatabaseError; end}
|
117
|
-
@Album.require_valid_table = false
|
118
|
-
@Album.plugin :column_select
|
119
|
-
@Album.dataset.sql.must_equal 'SELECT * FROM albums'
|
120
|
-
end
|
121
|
-
|
122
|
-
it "works correctly when loaded on model without a dataset" do
|
123
|
-
c = Class.new(Sequel::Model)
|
124
|
-
c.plugin :column_select
|
125
|
-
sc = Class.new(c)
|
126
|
-
sc.dataset = @db[:a]
|
127
|
-
sc.dataset.sql.must_equal "SELECT a.id, a.a, a.b, a.c FROM a"
|
128
|
-
end
|
129
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
Sequel.extension :columns_introspection
|
4
|
-
|
5
|
-
describe "columns_introspection extension" do
|
6
|
-
before do
|
7
|
-
@db = Sequel.mock.extension(:columns_introspection)
|
8
|
-
@ds = @db[:a]
|
9
|
-
@db.sqls
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should not issue a database query if the columns are already loaded" do
|
13
|
-
@ds.send(:columns=, [:x])
|
14
|
-
@ds.columns.must_equal [:x]
|
15
|
-
@db.sqls.length.must_equal 0
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should handle plain symbols without a database query" do
|
19
|
-
@ds.select(:x).columns.must_equal [:x]
|
20
|
-
@db.sqls.length.must_equal 0
|
21
|
-
end
|
22
|
-
|
23
|
-
with_symbol_splitting "should handle qualified symbols without a database query" do
|
24
|
-
@ds.select(:t__x).columns.must_equal [:x]
|
25
|
-
@db.sqls.length.must_equal 0
|
26
|
-
end
|
27
|
-
|
28
|
-
with_symbol_splitting "should handle aliased symbols without a database query" do
|
29
|
-
@ds.select(:x___a).columns.must_equal [:a]
|
30
|
-
@db.sqls.length.must_equal 0
|
31
|
-
end
|
32
|
-
|
33
|
-
with_symbol_splitting "should handle qualified and aliased symbols without a database query" do
|
34
|
-
@ds.select(:t__x___a).columns.must_equal [:a]
|
35
|
-
@db.sqls.length.must_equal 0
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should handle SQL::Identifiers " do
|
39
|
-
@ds.select(Sequel.identifier(:x)).columns.must_equal [:x]
|
40
|
-
@db.sqls.length.must_equal 0
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should handle SQL::QualifiedIdentifiers" do
|
44
|
-
@ds.select(Sequel.qualify(:t, :x)).columns.must_equal [:x]
|
45
|
-
@ds.select(Sequel.identifier(:x).qualify(:t)).columns.must_equal [:x]
|
46
|
-
@db.sqls.length.must_equal 0
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should handle SQL::AliasedExpressions" do
|
50
|
-
@ds.select(Sequel.as(:x, :a)).columns.must_equal [:a]
|
51
|
-
@ds.select(Sequel.as(:x, Sequel.identifier(:a))).columns.must_equal [:a]
|
52
|
-
@db.sqls.length.must_equal 0
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should handle selecting * from a single subselect with no joins without a database query if the subselect's columns can be handled" do
|
56
|
-
@ds.select(:x).from_self.columns.must_equal [:x]
|
57
|
-
@db.sqls.length.must_equal 0
|
58
|
-
@ds.select(:x).from_self.from_self.columns.must_equal [:x]
|
59
|
-
@db.sqls.length.must_equal 0
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should handle selecting * from a single table with no joins without a database query if the database has cached schema columns for the table" do
|
63
|
-
@db.instance_variable_set(:@schemas, "a"=>[[:x, {}]])
|
64
|
-
@ds.columns.must_equal [:x]
|
65
|
-
@db.sqls.length.must_equal 0
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should issue a database query for multiple subselects or joins" do
|
69
|
-
@ds.from(@ds.select(:x), @ds.select(:y)).columns
|
70
|
-
@db.sqls.length.must_equal 1
|
71
|
-
@ds.select(:x).from_self.natural_join(:a).columns
|
72
|
-
@db.sqls.length.must_equal 1
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should issue a database query when common table expressions are used" do
|
76
|
-
@db.instance_variable_set(:@schemas, "a"=>[[:x, {}]])
|
77
|
-
@ds.with_extend{def supports_cte?(*) true end}.with(:a, @ds).columns
|
78
|
-
@db.sqls.length.must_equal 1
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should issue a database query if the wildcard is selected" do
|
82
|
-
@ds.columns
|
83
|
-
@db.sqls.length.must_equal 1
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should issue a database query if an unsupported type is used" do
|
87
|
-
@ds.select(1).columns
|
88
|
-
@db.sqls.length.must_equal 1
|
89
|
-
end
|
90
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Sequel::Plugins::ColumnsUpdated" do
|
4
|
-
before do
|
5
|
-
@c = Class.new(Sequel::Model(DB[:items].with_autoid(13)))
|
6
|
-
@c.columns :id, :x, :y
|
7
|
-
@c.plugin :columns_updated
|
8
|
-
end
|
9
|
-
|
10
|
-
it "should make hash used for updating available in columns_updated until after hooks finish running" do
|
11
|
-
res = nil
|
12
|
-
@c.send(:define_method, :after_save){res = columns_updated}
|
13
|
-
o = @c.new(:x => 1, :y => nil)
|
14
|
-
o[:x] = 2
|
15
|
-
o.save
|
16
|
-
res.must_be_nil
|
17
|
-
o.after_save
|
18
|
-
res.must_be_nil
|
19
|
-
|
20
|
-
o = @c.load(:id => 23,:x => 1, :y => nil)
|
21
|
-
o[:x] = 2
|
22
|
-
o.save
|
23
|
-
res.must_equal(:x=>2, :y=>nil)
|
24
|
-
o.after_save
|
25
|
-
res.must_be_nil
|
26
|
-
|
27
|
-
o = @c.load(:id => 23,:x => 2, :y => nil)
|
28
|
-
o[:x] = 2
|
29
|
-
o[:y] = 22
|
30
|
-
o.save(:columns=>:x)
|
31
|
-
res.must_equal(:x=>2)
|
32
|
-
o.after_save
|
33
|
-
res.must_be_nil
|
34
|
-
end
|
35
|
-
end
|
@@ -1,248 +0,0 @@
|
|
1
|
-
require_relative "spec_helper"
|
2
|
-
|
3
|
-
describe "Composition plugin" do
|
4
|
-
before do
|
5
|
-
@c = Class.new(Sequel::Model(:items))
|
6
|
-
@c.plugin :composition
|
7
|
-
@c.columns :id, :year, :month, :day
|
8
|
-
@o = @c.load(:id=>1, :year=>1, :month=>2, :day=>3)
|
9
|
-
DB.reset
|
10
|
-
end
|
11
|
-
|
12
|
-
it ".composition should add compositions" do
|
13
|
-
@o.wont_respond_to(:date)
|
14
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
15
|
-
@o.date.must_equal Date.new(1, 2, 3)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "loading the plugin twice should not remove existing compositions" do
|
19
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
20
|
-
@c.plugin :composition
|
21
|
-
@c.compositions.keys.must_equal [:date]
|
22
|
-
end
|
23
|
-
|
24
|
-
it ".composition should raise an error if :composer and :decomposer options are not present and :mapping option is not provided" do
|
25
|
-
proc{@c.composition :date}.must_raise(Sequel::Error)
|
26
|
-
@c.composition :date, :composer=>proc{}, :decomposer=>proc{}
|
27
|
-
@c.composition :date, :mapping=>[]
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should handle validations of underlying columns" do
|
31
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
32
|
-
o = @c.new
|
33
|
-
def o.validate
|
34
|
-
[:year, :month, :day].each{|c| errors.add(c, "not present") unless send(c)}
|
35
|
-
end
|
36
|
-
o.valid?.must_equal false
|
37
|
-
o.date = Date.new(1, 2, 3)
|
38
|
-
o.valid?.must_equal true
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should have decomposer work with column_conflicts plugin" do
|
42
|
-
@c.plugin :column_conflicts
|
43
|
-
@c.set_column_conflict! :year
|
44
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
45
|
-
o = @c.new
|
46
|
-
def o.validate
|
47
|
-
[:year, :month, :day].each{|c| errors.add(c, "not present") unless send(c)}
|
48
|
-
end
|
49
|
-
o.valid?.must_equal false
|
50
|
-
o.date = Date.new(1, 2, 3)
|
51
|
-
o.valid?.must_equal true
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should set column values even when not validating" do
|
55
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
56
|
-
@c.load(id: 1).set(:date=>Date.new(4, 8, 12)).save(:validate=>false)
|
57
|
-
DB.sqls.must_equal ['UPDATE items SET year = 4, month = 8, day = 12 WHERE (id = 1)']
|
58
|
-
end
|
59
|
-
|
60
|
-
it ".compositions should return the reflection hash of compositions" do
|
61
|
-
@c.compositions.must_equal({})
|
62
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
63
|
-
@c.compositions.keys.must_equal [:date]
|
64
|
-
r = @c.compositions.values.first
|
65
|
-
r[:mapping].must_equal [:year, :month, :day]
|
66
|
-
r[:composer].must_be_kind_of Proc
|
67
|
-
r[:decomposer].must_be_kind_of Proc
|
68
|
-
end
|
69
|
-
|
70
|
-
it "#compositions should be a hash of cached values of compositions" do
|
71
|
-
@o.compositions.must_equal({})
|
72
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
73
|
-
@o.date
|
74
|
-
@o.compositions.must_equal(:date=>Date.new(1, 2, 3))
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should work with custom :composer and :decomposer options" do
|
78
|
-
@c.composition :date, :composer=>proc{Date.new(year+1, month+2, day+3)}, :decomposer=>proc{[:year, :month, :day].each{|s| self.send("#{s}=", date.send(s) * 2)}}
|
79
|
-
@o.date.must_equal Date.new(2, 4, 6)
|
80
|
-
@o.save
|
81
|
-
DB.sqls.must_equal ['UPDATE items SET year = 4, month = 8, day = 12 WHERE (id = 1)']
|
82
|
-
end
|
83
|
-
|
84
|
-
it "should allow call super in composition getter and setter method definition in class" do
|
85
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
86
|
-
@c.class_eval do
|
87
|
-
def date
|
88
|
-
super + 1
|
89
|
-
end
|
90
|
-
def date=(v)
|
91
|
-
super(v - 3)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
@o.date.must_equal Date.new(1, 2, 4)
|
95
|
-
@o.compositions[:date].must_equal Date.new(1, 2, 3)
|
96
|
-
@o.date = Date.new(1, 3, 5)
|
97
|
-
@o.compositions[:date].must_equal Date.new(1, 3, 2)
|
98
|
-
@o.date.must_equal Date.new(1, 3, 3)
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should mark the object as modified whenever the composition is set" do
|
102
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
103
|
-
@o.modified?.must_equal false
|
104
|
-
@o.date = Date.new(3, 4, 5)
|
105
|
-
@o.modified?.must_equal true
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should only decompose existing compositions" do
|
109
|
-
called = false
|
110
|
-
@c.composition :date, :composer=>proc{}, :decomposer=>proc{called = true}
|
111
|
-
called.must_equal false
|
112
|
-
@o.save
|
113
|
-
called.must_equal false
|
114
|
-
@o.date = Date.new(1,2,3)
|
115
|
-
called.must_equal false
|
116
|
-
@o.save_changes
|
117
|
-
called.must_equal true
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should clear compositions cache when refreshing" do
|
121
|
-
@c.composition :date, :composer=>proc{}, :decomposer=>proc{}
|
122
|
-
@o.date = Date.new(3, 4, 5)
|
123
|
-
@o.refresh
|
124
|
-
@o.compositions.must_equal({})
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should not clear compositions cache when refreshing after save" do
|
128
|
-
@c.composition :date, :composer=>proc{}, :decomposer=>proc{}
|
129
|
-
@c.create(:date=>Date.new(3, 4, 5)).compositions.must_equal(:date=>Date.new(3, 4, 5))
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should not clear compositions cache when saving with insert_select" do
|
133
|
-
@c.dataset = @c.dataset.with_extend do
|
134
|
-
def supports_insert_select?; true end
|
135
|
-
def insert_select(*) {:id=>1} end
|
136
|
-
end
|
137
|
-
@c.composition :date, :composer=>proc{}, :decomposer=>proc{}
|
138
|
-
@c.create(:date=>Date.new(3, 4, 5)).compositions.must_equal(:date=>Date.new(3, 4, 5))
|
139
|
-
end
|
140
|
-
|
141
|
-
it "should instantiate compositions lazily" do
|
142
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
143
|
-
@o.compositions.must_equal({})
|
144
|
-
@o.date
|
145
|
-
@o.compositions.must_equal(:date=>Date.new(1,2,3))
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should cache value of composition" do
|
149
|
-
times = 0
|
150
|
-
@c.composition :date, :composer=>proc{times+=1}, :decomposer=>proc{}
|
151
|
-
times.must_equal 0
|
152
|
-
@o.date
|
153
|
-
times.must_equal 1
|
154
|
-
@o.date
|
155
|
-
times.must_equal 1
|
156
|
-
end
|
157
|
-
|
158
|
-
it ":class option should take an string, symbol, or class" do
|
159
|
-
@c.composition :date1, :class=>'Date', :mapping=>[:year, :month, :day]
|
160
|
-
@c.composition :date2, :class=>:Date, :mapping=>[:year, :month, :day]
|
161
|
-
@c.composition :date3, :class=>Date, :mapping=>[:year, :month, :day]
|
162
|
-
@o.date1.must_equal Date.new(1, 2, 3)
|
163
|
-
@o.date2.must_equal Date.new(1, 2, 3)
|
164
|
-
@o.date3.must_equal Date.new(1, 2, 3)
|
165
|
-
end
|
166
|
-
|
167
|
-
it ":mapping option should work with a single array of symbols" do
|
168
|
-
c = Class.new do
|
169
|
-
def initialize(y, m)
|
170
|
-
@y, @m = y, m
|
171
|
-
end
|
172
|
-
def year
|
173
|
-
@y * 2
|
174
|
-
end
|
175
|
-
def month
|
176
|
-
@m * 3
|
177
|
-
end
|
178
|
-
end
|
179
|
-
@c.composition :date, :class=>c, :mapping=>[:year, :month]
|
180
|
-
@o.date.year.must_equal 2
|
181
|
-
@o.date.month.must_equal 6
|
182
|
-
@o.date = c.new(3, 4)
|
183
|
-
@o.save
|
184
|
-
DB.sqls.must_equal ['UPDATE items SET year = 6, month = 12, day = 3 WHERE (id = 1)']
|
185
|
-
end
|
186
|
-
|
187
|
-
it ":mapping option should work with an array of two pairs of symbols" do
|
188
|
-
c = Class.new do
|
189
|
-
def initialize(y, m)
|
190
|
-
@y, @m = y, m
|
191
|
-
end
|
192
|
-
def y
|
193
|
-
@y * 2
|
194
|
-
end
|
195
|
-
def m
|
196
|
-
@m * 3
|
197
|
-
end
|
198
|
-
end
|
199
|
-
@c.composition :date, :class=>c, :mapping=>[[:year, :y], [:month, :m]]
|
200
|
-
@o.date.y.must_equal 2
|
201
|
-
@o.date.m.must_equal 6
|
202
|
-
@o.date = c.new(3, 4)
|
203
|
-
@o.save
|
204
|
-
DB.sqls.must_equal ['UPDATE items SET year = 6, month = 12, day = 3 WHERE (id = 1)']
|
205
|
-
end
|
206
|
-
|
207
|
-
it ":mapping option :composer should return nil if all values are nil" do
|
208
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
209
|
-
@c.new.date.must_be_nil
|
210
|
-
end
|
211
|
-
|
212
|
-
it ":mapping option :decomposer should set all related fields to nil if nil" do
|
213
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
214
|
-
@o.date = nil
|
215
|
-
@o.save
|
216
|
-
DB.sqls.must_equal ['UPDATE items SET year = NULL, month = NULL, day = NULL WHERE (id = 1)']
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should work with frozen instances" do
|
220
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
221
|
-
@o.freeze
|
222
|
-
@o.date.must_equal Date.new(1, 2, 3)
|
223
|
-
proc{@o.date = Date.today}.must_raise
|
224
|
-
end
|
225
|
-
|
226
|
-
it "should have #dup duplicate compositions" do
|
227
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
228
|
-
@o.date.must_equal Date.new(1, 2, 3)
|
229
|
-
@o.dup.compositions.must_equal @o.compositions
|
230
|
-
@o.dup.compositions.wont_be_same_as(@o.compositions)
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should work correctly with subclasses" do
|
234
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
235
|
-
c = Class.new(@c)
|
236
|
-
o = c.load(:id=>1, :year=>1, :month=>2, :day=>3)
|
237
|
-
o.date.must_equal Date.new(1, 2, 3)
|
238
|
-
o.save
|
239
|
-
DB.sqls.must_equal ['UPDATE items SET year = 1, month = 2, day = 3 WHERE (id = 1)']
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should freeze composition metadata when freezing model class" do
|
243
|
-
@c.composition :date, :mapping=>[:year, :month, :day]
|
244
|
-
@c.freeze
|
245
|
-
@c.compositions.frozen?.must_equal true
|
246
|
-
@c.compositions[:date].frozen?.must_equal true
|
247
|
-
end
|
248
|
-
end
|