sequel 4.41.0 → 4.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +98 -0
- data/README.rdoc +23 -10
- data/doc/active_record.rdoc +4 -4
- data/doc/advanced_associations.rdoc +2 -2
- data/doc/association_basics.rdoc +5 -2
- data/doc/cheat_sheet.rdoc +3 -3
- data/doc/core_extensions.rdoc +2 -2
- data/doc/dataset_basics.rdoc +4 -4
- data/doc/dataset_filtering.rdoc +1 -1
- data/doc/migration.rdoc +19 -1
- data/doc/prepared_statements.rdoc +2 -2
- data/doc/release_notes/4.42.0.txt +221 -0
- data/doc/testing.rdoc +3 -1
- data/lib/sequel/adapters/ado/access.rb +0 -1
- data/lib/sequel/adapters/ado/mssql.rb +0 -1
- data/lib/sequel/adapters/do/mysql.rb +0 -1
- data/lib/sequel/adapters/do/postgres.rb +0 -1
- data/lib/sequel/adapters/do/sqlite3.rb +0 -1
- data/lib/sequel/adapters/ibmdb.rb +21 -25
- data/lib/sequel/adapters/jdbc.rb +8 -16
- data/lib/sequel/adapters/jdbc/as400.rb +0 -1
- data/lib/sequel/adapters/jdbc/cubrid.rb +0 -1
- data/lib/sequel/adapters/jdbc/db2.rb +0 -1
- data/lib/sequel/adapters/jdbc/derby.rb +0 -1
- data/lib/sequel/adapters/jdbc/firebirdsql.rb +0 -1
- data/lib/sequel/adapters/jdbc/h2.rb +0 -1
- data/lib/sequel/adapters/jdbc/hsqldb.rb +0 -1
- data/lib/sequel/adapters/jdbc/informix-sqli.rb +0 -1
- data/lib/sequel/adapters/jdbc/jdbcprogress.rb +0 -1
- data/lib/sequel/adapters/jdbc/jtds.rb +0 -1
- data/lib/sequel/adapters/jdbc/mssql.rb +0 -1
- data/lib/sequel/adapters/jdbc/mysql.rb +0 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +0 -1
- data/lib/sequel/adapters/jdbc/postgresql.rb +0 -13
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +0 -1
- data/lib/sequel/adapters/jdbc/sqlite.rb +0 -1
- data/lib/sequel/adapters/jdbc/sqlserver.rb +3 -4
- data/lib/sequel/adapters/mock.rb +54 -12
- data/lib/sequel/adapters/mysql.rb +1 -1
- data/lib/sequel/adapters/mysql2.rb +11 -17
- data/lib/sequel/adapters/odbc/mssql.rb +0 -1
- data/lib/sequel/adapters/oracle.rb +8 -20
- data/lib/sequel/adapters/postgres.rb +11 -29
- data/lib/sequel/adapters/shared/access.rb +5 -12
- data/lib/sequel/adapters/shared/cubrid.rb +4 -13
- data/lib/sequel/adapters/shared/db2.rb +4 -2
- data/lib/sequel/adapters/shared/firebird.rb +2 -4
- data/lib/sequel/adapters/shared/informix.rb +4 -2
- data/lib/sequel/adapters/shared/mssql.rb +3 -5
- data/lib/sequel/adapters/shared/mysql.rb +4 -14
- data/lib/sequel/adapters/shared/oracle.rb +1 -3
- data/lib/sequel/adapters/shared/postgres.rb +16 -38
- data/lib/sequel/adapters/shared/progress.rb +0 -2
- data/lib/sequel/adapters/shared/sqlanywhere.rb +0 -2
- data/lib/sequel/adapters/shared/sqlite.rb +20 -16
- data/lib/sequel/adapters/sqlite.rb +8 -20
- data/lib/sequel/adapters/swift/mysql.rb +0 -1
- data/lib/sequel/adapters/swift/postgres.rb +0 -1
- data/lib/sequel/adapters/swift/sqlite.rb +0 -1
- data/lib/sequel/adapters/tinytds.rb +4 -12
- data/lib/sequel/adapters/utils/emulate_offset_with_reverse_and_count.rb +1 -1
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +2 -2
- data/lib/sequel/adapters/utils/mysql_prepared_statements.rb +11 -34
- data/lib/sequel/adapters/utils/stored_procedures.rb +9 -22
- data/lib/sequel/adapters/utils/unmodified_identifiers.rb +26 -0
- data/lib/sequel/ast_transformer.rb +2 -2
- data/lib/sequel/database/dataset.rb +1 -1
- data/lib/sequel/database/dataset_defaults.rb +0 -66
- data/lib/sequel/database/features.rb +6 -0
- data/lib/sequel/database/misc.rb +31 -17
- data/lib/sequel/database/query.rb +7 -4
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset.rb +8 -8
- data/lib/sequel/dataset/actions.rb +140 -46
- data/lib/sequel/dataset/features.rb +1 -5
- data/lib/sequel/dataset/graph.rb +7 -8
- data/lib/sequel/dataset/misc.rb +127 -56
- data/lib/sequel/dataset/mutation.rb +9 -20
- data/lib/sequel/dataset/placeholder_literalizer.rb +10 -1
- data/lib/sequel/dataset/prepared_statements.rb +102 -46
- data/lib/sequel/dataset/query.rb +155 -72
- data/lib/sequel/dataset/sql.rb +26 -9
- data/lib/sequel/extensions/columns_introspection.rb +3 -1
- data/lib/sequel/extensions/core_extensions.rb +5 -5
- data/lib/sequel/extensions/core_refinements.rb +5 -5
- data/lib/sequel/extensions/duplicate_columns_handler.rb +4 -2
- data/lib/sequel/extensions/freeze_datasets.rb +69 -0
- data/lib/sequel/extensions/identifier_mangling.rb +196 -0
- data/lib/sequel/extensions/looser_typecasting.rb +11 -7
- data/lib/sequel/extensions/migration.rb +1 -1
- data/lib/sequel/extensions/null_dataset.rb +5 -2
- data/lib/sequel/extensions/pagination.rb +42 -23
- data/lib/sequel/extensions/pg_enum.rb +3 -3
- data/lib/sequel/extensions/query.rb +3 -3
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +15 -8
- data/lib/sequel/model/associations.rb +25 -8
- data/lib/sequel/model/base.rb +88 -29
- data/lib/sequel/model/dataset_module.rb +37 -0
- data/lib/sequel/plugins/association_pks.rb +4 -4
- data/lib/sequel/plugins/class_table_inheritance.rb +2 -2
- data/lib/sequel/plugins/constraint_validations.rb +1 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -2
- data/lib/sequel/plugins/dataset_associations.rb +8 -8
- data/lib/sequel/plugins/eager_each.rb +2 -2
- data/lib/sequel/plugins/instance_filters.rb +1 -1
- data/lib/sequel/plugins/json_serializer.rb +2 -2
- data/lib/sequel/plugins/lazy_attributes.rb +1 -1
- data/lib/sequel/plugins/list.rb +4 -4
- data/lib/sequel/plugins/prepared_statements.rb +2 -4
- data/lib/sequel/plugins/prepared_statements_associations.rb +1 -3
- data/lib/sequel/plugins/prepared_statements_with_pk.rb +1 -1
- data/lib/sequel/plugins/rcte_tree.rb +13 -13
- data/lib/sequel/plugins/sharding.rb +1 -1
- data/lib/sequel/plugins/single_table_inheritance.rb +9 -4
- data/lib/sequel/plugins/tactical_eager_loading.rb +4 -4
- data/lib/sequel/plugins/validation_class_methods.rb +1 -1
- data/lib/sequel/plugins/validation_helpers.rb +1 -1
- data/lib/sequel/plugins/xml_serializer.rb +2 -2
- data/lib/sequel/sql.rb +69 -36
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +10 -0
- data/spec/adapters/firebird_spec.rb +1 -1
- data/spec/adapters/mssql_spec.rb +4 -5
- data/spec/adapters/mysql_spec.rb +9 -9
- data/spec/adapters/postgres_spec.rb +67 -68
- data/spec/adapters/spec_helper.rb +6 -1
- data/spec/adapters/sqlite_spec.rb +29 -15
- data/spec/core/connection_pool_spec.rb +14 -14
- data/spec/core/database_spec.rb +38 -180
- data/spec/core/dataset_mutation_spec.rb +253 -0
- data/spec/core/dataset_spec.rb +394 -537
- data/spec/core/expression_filters_spec.rb +34 -32
- data/spec/core/mock_adapter_spec.rb +27 -35
- data/spec/core/placeholder_literalizer_spec.rb +2 -4
- data/spec/core/schema_generator_spec.rb +4 -4
- data/spec/core/schema_spec.rb +1 -2
- data/spec/core_extensions_spec.rb +22 -29
- data/spec/extensions/active_model_spec.rb +6 -6
- data/spec/extensions/association_dependencies_spec.rb +2 -2
- data/spec/extensions/blacklist_security_spec.rb +3 -3
- data/spec/extensions/boolean_readers_spec.rb +12 -12
- data/spec/extensions/caching_spec.rb +13 -10
- data/spec/extensions/class_table_inheritance_spec.rb +38 -43
- data/spec/extensions/column_conflicts_spec.rb +1 -3
- data/spec/extensions/columns_introspection_spec.rb +2 -3
- data/spec/extensions/composition_spec.rb +5 -3
- data/spec/extensions/constraint_validations_plugin_spec.rb +5 -5
- data/spec/extensions/constraint_validations_spec.rb +14 -8
- data/spec/extensions/core_refinements_spec.rb +22 -29
- data/spec/extensions/csv_serializer_spec.rb +7 -6
- data/spec/extensions/date_arithmetic_spec.rb +15 -15
- data/spec/extensions/defaults_setter_spec.rb +2 -2
- data/spec/extensions/delay_add_association_spec.rb +1 -1
- data/spec/extensions/dirty_spec.rb +19 -10
- data/spec/extensions/duplicate_columns_handler_spec.rb +12 -18
- data/spec/extensions/eager_each_spec.rb +12 -16
- data/spec/extensions/empty_array_consider_nulls_spec.rb +1 -1
- data/spec/extensions/eval_inspect_spec.rb +4 -3
- data/spec/extensions/force_encoding_spec.rb +12 -12
- data/spec/extensions/freeze_datasets_spec.rb +31 -0
- data/spec/extensions/graph_each_spec.rb +6 -18
- data/spec/extensions/hook_class_methods_spec.rb +7 -7
- data/spec/extensions/identifier_mangling_spec.rb +307 -0
- data/spec/extensions/instance_filters_spec.rb +5 -6
- data/spec/extensions/instance_hooks_spec.rb +12 -12
- data/spec/extensions/json_serializer_spec.rb +12 -15
- data/spec/extensions/lazy_attributes_spec.rb +4 -4
- data/spec/extensions/list_spec.rb +19 -21
- data/spec/extensions/many_through_many_spec.rb +108 -163
- data/spec/extensions/meta_def_spec.rb +7 -2
- data/spec/extensions/migration_spec.rb +10 -12
- data/spec/extensions/mssql_optimistic_locking_spec.rb +4 -3
- data/spec/extensions/named_timezones_spec.rb +4 -3
- data/spec/extensions/nested_attributes_spec.rb +2 -2
- data/spec/extensions/null_dataset_spec.rb +17 -12
- data/spec/extensions/optimistic_locking_spec.rb +4 -5
- data/spec/extensions/pagination_spec.rb +8 -10
- data/spec/extensions/pg_array_associations_spec.rb +28 -27
- data/spec/extensions/pg_array_ops_spec.rb +2 -1
- data/spec/extensions/pg_array_spec.rb +6 -2
- data/spec/extensions/pg_enum_spec.rb +5 -3
- data/spec/extensions/pg_hstore_ops_spec.rb +3 -1
- data/spec/extensions/pg_hstore_spec.rb +7 -6
- data/spec/extensions/pg_inet_ops_spec.rb +2 -1
- data/spec/extensions/pg_inet_spec.rb +2 -1
- data/spec/extensions/pg_interval_spec.rb +2 -1
- data/spec/extensions/pg_json_ops_spec.rb +2 -1
- data/spec/extensions/pg_json_spec.rb +6 -3
- data/spec/extensions/pg_loose_count_spec.rb +1 -0
- data/spec/extensions/pg_range_ops_spec.rb +3 -1
- data/spec/extensions/pg_range_spec.rb +9 -5
- data/spec/extensions/pg_row_ops_spec.rb +2 -1
- data/spec/extensions/pg_row_plugin_spec.rb +4 -6
- data/spec/extensions/pg_row_spec.rb +5 -3
- data/spec/extensions/pg_static_cache_updater_spec.rb +2 -1
- data/spec/extensions/pg_typecast_on_load_spec.rb +1 -1
- data/spec/extensions/prepared_statements_associations_spec.rb +1 -1
- data/spec/extensions/prepared_statements_spec.rb +12 -11
- data/spec/extensions/pretty_table_spec.rb +1 -1
- data/spec/extensions/query_spec.rb +8 -5
- data/spec/extensions/rcte_tree_spec.rb +39 -39
- data/spec/extensions/round_timestamps_spec.rb +2 -2
- data/spec/extensions/schema_dumper_spec.rb +3 -2
- data/spec/extensions/schema_spec.rb +2 -2
- data/spec/extensions/scissors_spec.rb +1 -2
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +30 -17
- data/spec/extensions/serialization_modification_detection_spec.rb +2 -2
- data/spec/extensions/serialization_spec.rb +15 -13
- data/spec/extensions/set_overrides_spec.rb +14 -8
- data/spec/extensions/sharding_spec.rb +9 -18
- data/spec/extensions/shared_caching_spec.rb +3 -4
- data/spec/extensions/single_table_inheritance_spec.rb +11 -11
- data/spec/extensions/skip_create_refresh_spec.rb +2 -1
- data/spec/extensions/spec_helper.rb +1 -1
- data/spec/extensions/split_values_spec.rb +2 -2
- data/spec/extensions/sql_comments_spec.rb +6 -0
- data/spec/extensions/static_cache_spec.rb +7 -9
- data/spec/extensions/string_agg_spec.rb +30 -29
- data/spec/extensions/tactical_eager_loading_spec.rb +4 -5
- data/spec/extensions/thread_local_timezones_spec.rb +2 -2
- data/spec/extensions/timestamps_spec.rb +28 -3
- data/spec/extensions/to_dot_spec.rb +1 -2
- data/spec/extensions/tree_spec.rb +33 -29
- data/spec/extensions/typecast_on_load_spec.rb +1 -1
- data/spec/extensions/unlimited_update_spec.rb +1 -0
- data/spec/extensions/update_primary_key_spec.rb +11 -7
- data/spec/extensions/update_refresh_spec.rb +1 -1
- data/spec/extensions/uuid_spec.rb +0 -1
- data/spec/extensions/validate_associated_spec.rb +1 -1
- data/spec/extensions/validation_class_methods_spec.rb +10 -10
- data/spec/extensions/validation_helpers_spec.rb +10 -10
- data/spec/extensions/xml_serializer_spec.rb +7 -3
- data/spec/integration/associations_test.rb +31 -31
- data/spec/integration/dataset_test.rb +17 -19
- data/spec/integration/eager_loader_test.rb +24 -24
- data/spec/integration/model_test.rb +6 -6
- data/spec/integration/plugin_test.rb +43 -43
- data/spec/integration/prepared_statement_test.rb +6 -6
- data/spec/integration/schema_test.rb +63 -52
- data/spec/integration/spec_helper.rb +6 -1
- data/spec/integration/transaction_test.rb +13 -13
- data/spec/model/association_reflection_spec.rb +17 -17
- data/spec/model/associations_spec.rb +101 -96
- data/spec/model/base_spec.rb +175 -49
- data/spec/model/class_dataset_methods_spec.rb +5 -9
- data/spec/model/dataset_methods_spec.rb +5 -5
- data/spec/model/eager_loading_spec.rb +209 -235
- data/spec/model/hooks_spec.rb +15 -15
- data/spec/model/model_spec.rb +28 -21
- data/spec/model/plugins_spec.rb +4 -5
- data/spec/model/record_spec.rb +59 -57
- data/spec/model/spec_helper.rb +1 -1
- data/spec/model/validations_spec.rb +6 -6
- data/spec/spec_config.rb +1 -1
- metadata +10 -2
|
@@ -371,7 +371,7 @@ describe "Bound Argument Types" do
|
|
|
371
371
|
cspecify "should handle blob type with nil values", [:oracle], [:tinytds], [:jdbc, :mssql] do
|
|
372
372
|
@ds.delete
|
|
373
373
|
@ds.prepare(:insert, :ps_blob, {:file=>:$x}).call(:x=>nil)
|
|
374
|
-
@ds.get(:file).
|
|
374
|
+
@ds.get(:file).must_be_nil
|
|
375
375
|
end
|
|
376
376
|
|
|
377
377
|
cspecify "should handle blob type with embedded zeros", [:odbc] do
|
|
@@ -412,10 +412,10 @@ describe "Dataset#unbind" do
|
|
|
412
412
|
it "should unbind values assigned to equality and inequality statements" do
|
|
413
413
|
@ct[Integer, 10]
|
|
414
414
|
@u[@ds.filter(:c=>10)].must_equal(:c=>10)
|
|
415
|
-
@u[@ds.exclude(:c=>10)].
|
|
416
|
-
@u[@ds.filter{c < 10}].
|
|
415
|
+
@u[@ds.exclude(:c=>10)].must_be_nil
|
|
416
|
+
@u[@ds.filter{c < 10}].must_be_nil
|
|
417
417
|
@u[@ds.filter{c <= 10}].must_equal(:c=>10)
|
|
418
|
-
@u[@ds.filter{c > 10}].
|
|
418
|
+
@u[@ds.filter{c > 10}].must_be_nil
|
|
419
419
|
@u[@ds.filter{c >= 10}].must_equal(:c=>10)
|
|
420
420
|
end
|
|
421
421
|
|
|
@@ -456,12 +456,12 @@ describe "Dataset#unbind" do
|
|
|
456
456
|
end
|
|
457
457
|
@ds.insert(:a=>2, :b=>0, :c=>3, :d=>5)
|
|
458
458
|
@u[@ds.filter{a > 1}.and{b < 2}.or(:c=>3).and(Sequel.case({~Sequel.expr(:d=>4)=>1}, 0) => 1)].must_equal(:a=>2, :b=>0, :c=>3, :d=>5)
|
|
459
|
-
@u[@ds.filter{a > 1}.and{b < 2}.or(:c=>3).and(Sequel.case({~Sequel.expr(:d=>5)=>1}, 0) => 1)].
|
|
459
|
+
@u[@ds.filter{a > 1}.and{b < 2}.or(:c=>3).and(Sequel.case({~Sequel.expr(:d=>5)=>1}, 0) => 1)].must_be_nil
|
|
460
460
|
end
|
|
461
461
|
|
|
462
462
|
it "should handle case where the same variable has the same value in multiple places " do
|
|
463
463
|
@ct[Integer, 1]
|
|
464
464
|
@u[@ds.filter{c > 1}.or{c < 1}.invert].must_equal(:c=>1)
|
|
465
|
-
@u[@ds.filter{c > 1}.or{c < 1}].
|
|
465
|
+
@u[@ds.filter{c > 1}.or{c < 1}].must_be_nil
|
|
466
466
|
end
|
|
467
467
|
end
|
|
@@ -1,50 +1,54 @@
|
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
2
2
|
|
|
3
3
|
describe "Database schema parser" do
|
|
4
|
-
before do
|
|
5
|
-
@iom = DB.identifier_output_method
|
|
6
|
-
@iim = DB.identifier_input_method
|
|
7
|
-
@qi = DB.quote_identifiers?
|
|
8
|
-
end
|
|
9
4
|
after do
|
|
10
|
-
DB.identifier_output_method = @iom
|
|
11
|
-
DB.identifier_input_method = @iim
|
|
12
|
-
DB.quote_identifiers = @qi
|
|
13
5
|
DB.drop_table?(:items)
|
|
14
6
|
end
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
DB.
|
|
24
|
-
|
|
25
|
-
DB.
|
|
8
|
+
describe "with identifier mangling" do
|
|
9
|
+
before do
|
|
10
|
+
@iom = DB.identifier_output_method
|
|
11
|
+
@iim = DB.identifier_input_method
|
|
12
|
+
@qi = DB.quote_identifiers?
|
|
13
|
+
end
|
|
14
|
+
after do
|
|
15
|
+
DB.identifier_output_method = @iom
|
|
16
|
+
DB.identifier_input_method = @iim
|
|
17
|
+
DB.quote_identifiers = @qi
|
|
26
18
|
end
|
|
27
|
-
end
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
DB.identifier_output_method = :reverse
|
|
31
|
-
DB.identifier_input_method = :reverse
|
|
32
|
-
DB.quote_identifiers = true
|
|
33
|
-
DB.create_table!(:items){Integer :number}
|
|
34
|
-
DB.identifier_output_method = @iom
|
|
35
|
-
DB.identifier_input_method = @iim
|
|
36
|
-
ds = DB[:items].
|
|
37
|
-
with_identifier_output_method(:reverse).
|
|
38
|
-
with_identifier_input_method(:reverse)
|
|
39
|
-
begin
|
|
40
|
-
DB.schema(ds, :reload=>true).must_be_kind_of(Array)
|
|
41
|
-
DB.schema(ds, :reload=>true).first.first.must_equal :number
|
|
42
|
-
ensure
|
|
20
|
+
it "should handle a database with a identifier methods" do
|
|
43
21
|
DB.identifier_output_method = :reverse
|
|
44
22
|
DB.identifier_input_method = :reverse
|
|
45
|
-
DB.
|
|
23
|
+
DB.quote_identifiers = true
|
|
24
|
+
DB.create_table!(:items){Integer :number}
|
|
25
|
+
begin
|
|
26
|
+
DB.schema(:items, :reload=>true).must_be_kind_of(Array)
|
|
27
|
+
DB.schema(:items, :reload=>true).first.first.must_equal :number
|
|
28
|
+
ensure
|
|
29
|
+
end
|
|
46
30
|
end
|
|
47
|
-
|
|
31
|
+
|
|
32
|
+
it "should handle a dataset with identifier methods different than the database's" do
|
|
33
|
+
DB.identifier_output_method = :reverse
|
|
34
|
+
DB.identifier_input_method = :reverse
|
|
35
|
+
DB.quote_identifiers = true
|
|
36
|
+
DB.create_table!(:items){Integer :number}
|
|
37
|
+
DB.identifier_output_method = @iom
|
|
38
|
+
DB.identifier_input_method = @iim
|
|
39
|
+
ds = DB[:items].
|
|
40
|
+
with_identifier_output_method(:reverse).
|
|
41
|
+
with_identifier_input_method(:reverse)
|
|
42
|
+
begin
|
|
43
|
+
DB.schema(ds, :reload=>true).must_be_kind_of(Array)
|
|
44
|
+
DB.schema(ds, :reload=>true).first.first.must_equal :number
|
|
45
|
+
ensure
|
|
46
|
+
DB.identifier_output_method = :reverse
|
|
47
|
+
DB.identifier_input_method = :reverse
|
|
48
|
+
DB.drop_table(:items)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end if IDENTIFIER_MANGLING
|
|
48
52
|
|
|
49
53
|
it "should not issue an sql query if the schema has been loaded unless :reload is true" do
|
|
50
54
|
DB.create_table!(:items){Integer :number}
|
|
@@ -106,7 +110,7 @@ describe "Database schema parser" do
|
|
|
106
110
|
|
|
107
111
|
it "should parse defaults from the schema properly" do
|
|
108
112
|
DB.create_table!(:items){Integer :number}
|
|
109
|
-
DB.schema(:items).first.last[:ruby_default].
|
|
113
|
+
DB.schema(:items).first.last[:ruby_default].must_be_nil
|
|
110
114
|
DB.create_table!(:items){Integer :number, :default=>0}
|
|
111
115
|
DB.schema(:items).first.last[:ruby_default].must_equal 0
|
|
112
116
|
DB.create_table!(:items){String :a, :default=>"blah"}
|
|
@@ -115,7 +119,7 @@ describe "Database schema parser" do
|
|
|
115
119
|
|
|
116
120
|
it "should make :default nil for a NULL default" do
|
|
117
121
|
DB.create_table!(:items){Integer :number}
|
|
118
|
-
DB.schema(:items).first.last[:default].
|
|
122
|
+
DB.schema(:items).first.last[:default].must_be_nil
|
|
119
123
|
DB.create_table!(:items){Integer :number, :default=>0}
|
|
120
124
|
DB.schema(:items).first.last[:default].wont_equal nil
|
|
121
125
|
end
|
|
@@ -796,12 +800,8 @@ describe "Database#tables and #views" do
|
|
|
796
800
|
@db.drop_table?(:sequel_test_table)
|
|
797
801
|
@db.create_table(:sequel_test_table){Integer :a}
|
|
798
802
|
@db.create_view :sequel_test_view, @db[:sequel_test_table]
|
|
799
|
-
@iom = @db.identifier_output_method
|
|
800
|
-
@iim = @db.identifier_input_method
|
|
801
803
|
end
|
|
802
804
|
after do
|
|
803
|
-
@db.identifier_output_method = @iom
|
|
804
|
-
@db.identifier_input_method = @iim
|
|
805
805
|
@db.drop_view :sequel_test_view
|
|
806
806
|
@db.drop_table :sequel_test_table
|
|
807
807
|
end
|
|
@@ -814,12 +814,6 @@ describe "Database#tables and #views" do
|
|
|
814
814
|
ts.wont_include(:sequel_test_view)
|
|
815
815
|
end if DB.supports_table_listing?
|
|
816
816
|
|
|
817
|
-
it "#tables should respect the database's identifier_output_method" do
|
|
818
|
-
@db.identifier_output_method = :xxxxx
|
|
819
|
-
@db.identifier_input_method = :xxxxx
|
|
820
|
-
@db.tables.each{|t| t.to_s.must_match(/\Ax{5}\d+\z/)}
|
|
821
|
-
end if DB.supports_table_listing?
|
|
822
|
-
|
|
823
817
|
it "#views should return an array of symbols" do
|
|
824
818
|
ts = @db.views
|
|
825
819
|
ts.must_be_kind_of(Array)
|
|
@@ -828,9 +822,26 @@ describe "Database#tables and #views" do
|
|
|
828
822
|
ts.must_include(:sequel_test_view)
|
|
829
823
|
end if DB.supports_view_listing?
|
|
830
824
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
825
|
+
describe "with identifier mangling" do
|
|
826
|
+
before do
|
|
827
|
+
@iom = @db.identifier_output_method
|
|
828
|
+
@iim = @db.identifier_input_method
|
|
829
|
+
end
|
|
830
|
+
after do
|
|
831
|
+
@db.identifier_output_method = @iom
|
|
832
|
+
@db.identifier_input_method = @iim
|
|
833
|
+
end
|
|
834
|
+
|
|
835
|
+
it "#tables should respect the database's identifier_output_method" do
|
|
836
|
+
@db.identifier_output_method = :xxxxx
|
|
837
|
+
@db.identifier_input_method = :xxxxx
|
|
838
|
+
@db.tables.each{|t| t.to_s.must_match(/\Ax{5}\d+\z/)}
|
|
839
|
+
end if DB.supports_table_listing?
|
|
840
|
+
|
|
841
|
+
it "#views should respect the database's identifier_output_method" do
|
|
842
|
+
@db.identifier_output_method = :xxxxx
|
|
843
|
+
@db.identifier_input_method = :xxxxx
|
|
844
|
+
@db.views.each{|t| t.to_s.must_match(/\Ax{5}\d+\z/)}
|
|
845
|
+
end if DB.supports_view_listing?
|
|
846
|
+
end if IDENTIFIER_MANGLING
|
|
836
847
|
end
|
|
@@ -25,8 +25,13 @@ Sequel.cache_anonymous_models = false
|
|
|
25
25
|
|
|
26
26
|
require './spec/guards_helper'
|
|
27
27
|
|
|
28
|
+
IDENTIFIER_MANGLING = !ENV['SEQUEL_NO_MANGLE'] unless defined?(IDENTIFIER_MANGLING)
|
|
29
|
+
|
|
28
30
|
unless defined?(DB)
|
|
29
|
-
|
|
31
|
+
opts = {}
|
|
32
|
+
opts[:identifier_mangling] = false unless IDENTIFIER_MANGLING
|
|
33
|
+
DB = Sequel.connect(ENV['SEQUEL_INTEGRATION_URL'], opts)
|
|
34
|
+
DB.extension(:freeze_datasets) if ENV['SEQUEL_FREEZE_DATASETS']
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
if DB.adapter_scheme == :ibmdb || (DB.adapter_scheme == :ado && DB.database_type == :access)
|
|
@@ -40,7 +40,7 @@ describe "Database transactions" do
|
|
|
40
40
|
@db.transaction do
|
|
41
41
|
@d << {:name => 'abc', :value => 1}
|
|
42
42
|
raise Sequel::Rollback
|
|
43
|
-
end.
|
|
43
|
+
end.must_be_nil
|
|
44
44
|
|
|
45
45
|
proc do
|
|
46
46
|
@db.transaction(:rollback=>:reraise) do
|
|
@@ -235,30 +235,30 @@ describe "Database transactions" do
|
|
|
235
235
|
it "should support after_rollback outside transactions" do
|
|
236
236
|
c = nil
|
|
237
237
|
@db.after_rollback{c = 1}
|
|
238
|
-
c.
|
|
238
|
+
c.must_be_nil
|
|
239
239
|
end
|
|
240
240
|
|
|
241
241
|
it "should support after_commit inside transactions" do
|
|
242
242
|
c = nil
|
|
243
|
-
@db.transaction{@db.after_commit{c = 1}; c.
|
|
243
|
+
@db.transaction{@db.after_commit{c = 1}; c.must_be_nil}
|
|
244
244
|
c.must_equal 1
|
|
245
245
|
end
|
|
246
246
|
|
|
247
247
|
it "should support after_rollback inside transactions" do
|
|
248
248
|
c = nil
|
|
249
|
-
@db.transaction{@db.after_rollback{c = 1}; c.
|
|
250
|
-
c.
|
|
249
|
+
@db.transaction{@db.after_rollback{c = 1}; c.must_be_nil}
|
|
250
|
+
c.must_be_nil
|
|
251
251
|
end
|
|
252
252
|
|
|
253
253
|
it "should not call after_commit if the transaction rolls back" do
|
|
254
254
|
c = nil
|
|
255
|
-
@db.transaction{@db.after_commit{c = 1}; c.
|
|
256
|
-
c.
|
|
255
|
+
@db.transaction{@db.after_commit{c = 1}; c.must_be_nil; raise Sequel::Rollback}
|
|
256
|
+
c.must_be_nil
|
|
257
257
|
end
|
|
258
258
|
|
|
259
259
|
it "should call after_rollback if the transaction rolls back" do
|
|
260
260
|
c = nil
|
|
261
|
-
@db.transaction{@db.after_rollback{c = 1}; c.
|
|
261
|
+
@db.transaction{@db.after_rollback{c = 1}; c.must_be_nil; raise Sequel::Rollback}
|
|
262
262
|
c.must_equal 1
|
|
263
263
|
end
|
|
264
264
|
|
|
@@ -276,26 +276,26 @@ describe "Database transactions" do
|
|
|
276
276
|
|
|
277
277
|
it "should support after_commit inside nested transactions" do
|
|
278
278
|
c = nil
|
|
279
|
-
@db.transaction{@db.transaction{@db.after_commit{c = 1}}; c.
|
|
279
|
+
@db.transaction{@db.transaction{@db.after_commit{c = 1}}; c.must_be_nil}
|
|
280
280
|
c.must_equal 1
|
|
281
281
|
end
|
|
282
282
|
|
|
283
283
|
it "should support after_rollback inside nested transactions" do
|
|
284
284
|
c = nil
|
|
285
|
-
@db.transaction{@db.transaction{@db.after_rollback{c = 1}}; c.
|
|
285
|
+
@db.transaction{@db.transaction{@db.after_rollback{c = 1}}; c.must_be_nil; raise Sequel::Rollback}
|
|
286
286
|
c.must_equal 1
|
|
287
287
|
end
|
|
288
288
|
|
|
289
289
|
if DB.supports_savepoints?
|
|
290
290
|
it "should support after_commit inside savepoints" do
|
|
291
291
|
c = nil
|
|
292
|
-
@db.transaction{@db.transaction(:savepoint=>true){@db.after_commit{c = 1}}; c.
|
|
292
|
+
@db.transaction{@db.transaction(:savepoint=>true){@db.after_commit{c = 1}}; c.must_be_nil}
|
|
293
293
|
c.must_equal 1
|
|
294
294
|
end
|
|
295
295
|
|
|
296
296
|
it "should support after_rollback inside savepoints" do
|
|
297
297
|
c = nil
|
|
298
|
-
@db.transaction{@db.transaction(:savepoint=>true){@db.after_rollback{c = 1}}; c.
|
|
298
|
+
@db.transaction{@db.transaction(:savepoint=>true){@db.after_rollback{c = 1}}; c.must_be_nil; raise Sequel::Rollback}
|
|
299
299
|
c.must_equal 1
|
|
300
300
|
end
|
|
301
301
|
end
|
|
@@ -315,7 +315,7 @@ describe "Database transactions" do
|
|
|
315
315
|
end
|
|
316
316
|
end
|
|
317
317
|
|
|
318
|
-
if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby'
|
|
318
|
+
if (! defined?(RUBY_ENGINE) or RUBY_ENGINE == 'ruby') and RUBY_VERSION < '1.9'
|
|
319
319
|
describe "Database transactions and Thread#kill" do
|
|
320
320
|
before do
|
|
321
321
|
@db = DB
|
|
@@ -208,10 +208,10 @@ describe Sequel::Model::Associations::AssociationReflection, "#select" do
|
|
|
208
208
|
it "should be blank if :select is not present for a many_to_one and one_to_many associaiton" do
|
|
209
209
|
@c.one_to_many :cs, :class=>'ParParent'
|
|
210
210
|
@c.association_reflection(:cs).keys.wont_include(:select)
|
|
211
|
-
@c.association_reflection(:cs).select.
|
|
211
|
+
@c.association_reflection(:cs).select.must_be_nil
|
|
212
212
|
@c.many_to_one :c, :class=>'ParParent'
|
|
213
213
|
@c.association_reflection(:c).keys.wont_include(:select)
|
|
214
|
-
@c.association_reflection(:c).select.
|
|
214
|
+
@c.association_reflection(:c).select.must_be_nil
|
|
215
215
|
end
|
|
216
216
|
end
|
|
217
217
|
|
|
@@ -319,11 +319,11 @@ describe Sequel::Model::Associations::AssociationReflection, "#filter_by_associa
|
|
|
319
319
|
|
|
320
320
|
it "should be nil by default for *_one associations" do
|
|
321
321
|
@c.many_to_one :c, :class=>@c
|
|
322
|
-
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).
|
|
322
|
+
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_be_nil
|
|
323
323
|
@c.one_to_one :c, :class=>@c
|
|
324
|
-
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).
|
|
324
|
+
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_be_nil
|
|
325
325
|
@c.one_through_one :c, :class=>@c
|
|
326
|
-
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).
|
|
326
|
+
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_be_nil
|
|
327
327
|
end
|
|
328
328
|
|
|
329
329
|
it "should be :correlated_subquery by default for one_to_many and one_to_one with :order associations" do
|
|
@@ -342,11 +342,11 @@ describe Sequel::Model::Associations::AssociationReflection, "#filter_by_associa
|
|
|
342
342
|
|
|
343
343
|
it "should be nil for many_to_one associations even if :eager_limit_strategy or :filter_limit_strategy is used" do
|
|
344
344
|
@c.many_to_one :c, :class=>@c, :eager_limit_strategy=>true
|
|
345
|
-
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).
|
|
345
|
+
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_be_nil
|
|
346
346
|
@c.many_to_one :c, :class=>@c, :eager_limit_strategy=>:distinct_on
|
|
347
|
-
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).
|
|
347
|
+
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_be_nil
|
|
348
348
|
@c.many_to_one :c, :class=>@c, :filter_limit_strategy=>true
|
|
349
|
-
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).
|
|
349
|
+
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_be_nil
|
|
350
350
|
end
|
|
351
351
|
|
|
352
352
|
it "should be a symbol for other associations if given a symbol" do
|
|
@@ -357,13 +357,13 @@ describe Sequel::Model::Associations::AssociationReflection, "#filter_by_associa
|
|
|
357
357
|
end
|
|
358
358
|
|
|
359
359
|
it "should use :distinct_on for one_to_one associations if picking and the association dataset supports ordered distinct on" do
|
|
360
|
-
|
|
360
|
+
@c.dataset = @c.dataset.with_extend{def supports_ordered_distinct_on?; true end}
|
|
361
361
|
@c.one_to_one :c, :class=>@c, :eager_limit_strategy=>true
|
|
362
362
|
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal :distinct_on
|
|
363
363
|
end
|
|
364
364
|
|
|
365
365
|
it "should use :window_function for associations if picking and the association dataset supports window functions" do
|
|
366
|
-
|
|
366
|
+
@c.dataset = @c.dataset.with_extend{def supports_window_functions?; true end}
|
|
367
367
|
@c.one_to_one :c, :class=>@c, :eager_limit_strategy=>true
|
|
368
368
|
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_equal :window_function
|
|
369
369
|
@c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
|
|
@@ -373,21 +373,21 @@ describe Sequel::Model::Associations::AssociationReflection, "#filter_by_associa
|
|
|
373
373
|
end
|
|
374
374
|
|
|
375
375
|
it "should use :ruby for one_to_many associations if the database doesn't support limits in subqueries" do
|
|
376
|
-
|
|
376
|
+
@c.dataset = @c.dataset.with_extend{def supports_limits_in_correlated_subqueries?; false end}
|
|
377
377
|
@c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
|
|
378
378
|
@c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
|
|
379
379
|
end
|
|
380
380
|
|
|
381
381
|
it "should use :ruby for one_to_many associations if offset doesn't work in correlated subqueries and an offset is used" do
|
|
382
|
-
|
|
382
|
+
@c.dataset = @c.dataset.with_extend{def supports_offsets_in_correlated_subqueries?; false end}
|
|
383
383
|
@c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1
|
|
384
384
|
@c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :correlated_subquery
|
|
385
385
|
@c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>[1, 1]
|
|
386
386
|
@c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
|
|
387
387
|
end
|
|
388
388
|
|
|
389
|
-
it "should use :ruby for one_to_many associations if composite primary key is used and database does not multiple columns in IN" do
|
|
390
|
-
|
|
389
|
+
it "should use :ruby for one_to_many associations if composite primary key is used and database does not support multiple columns in IN" do
|
|
390
|
+
@c.dataset = @c.dataset.with_extend{def supports_multiple_column_in?; false end}
|
|
391
391
|
@c.set_primary_key [:id, :id2]
|
|
392
392
|
@c.one_to_many :cs, :class=>@c, :eager_limit_strategy=>true, :limit=>1, :key=>[:id, :id2]
|
|
393
393
|
@c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :ruby
|
|
@@ -414,7 +414,7 @@ describe Sequel::Model::Associations::AssociationReflection, "#filter_by_associa
|
|
|
414
414
|
c.dataset = :a
|
|
415
415
|
c.one_to_many :cs, :class=>c, :limit=>1
|
|
416
416
|
c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :correlated_subquery
|
|
417
|
-
|
|
417
|
+
c.dataset = c.dataset.with_extend{def supports_window_functions?; true end}
|
|
418
418
|
c.many_to_many :cs, :class=>c, :limit=>1
|
|
419
419
|
c.association_reflection(:cs).send(:filter_by_associations_limit_strategy).must_equal :window_function
|
|
420
420
|
end
|
|
@@ -422,7 +422,7 @@ describe Sequel::Model::Associations::AssociationReflection, "#filter_by_associa
|
|
|
422
422
|
it "should ignore Model.default_eager_limit_strategy for one_to_one associations" do
|
|
423
423
|
@c.default_eager_limit_strategy = :window_function
|
|
424
424
|
@c.one_to_one :c, :class=>@c
|
|
425
|
-
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).
|
|
425
|
+
@c.association_reflection(:c).send(:filter_by_associations_limit_strategy).must_be_nil
|
|
426
426
|
end
|
|
427
427
|
end
|
|
428
428
|
|
|
@@ -459,7 +459,7 @@ describe Sequel::Model, " association reflection methods" do
|
|
|
459
459
|
end
|
|
460
460
|
|
|
461
461
|
it "#association_reflection should return nil for nonexistent association" do
|
|
462
|
-
@c1.association_reflection(:blah).
|
|
462
|
+
@c1.association_reflection(:blah).must_be_nil
|
|
463
463
|
end
|
|
464
464
|
|
|
465
465
|
it "#association_reflection should return association reflection hash if association exists" do
|
|
@@ -118,7 +118,7 @@ describe Sequel::Model, "associate" do
|
|
|
118
118
|
klass.association_reflection(:par)[:eager_block].call.must_equal 1
|
|
119
119
|
klass.association_reflection(:par1s)[:limit].must_equal 10
|
|
120
120
|
klass.association_reflection(:par1s)[:order].must_equal :b
|
|
121
|
-
klass.association_reflection(:par1s)[:block].
|
|
121
|
+
klass.association_reflection(:par1s)[:block].must_be_nil
|
|
122
122
|
klass.association_reflection(:par2s)[:after_load].length.must_equal 1
|
|
123
123
|
klass.association_reflection(:par2s)[:order].must_equal :c
|
|
124
124
|
klass.association_reflection(:par2s)[:block].call.must_equal 3
|
|
@@ -177,9 +177,10 @@ describe Sequel::Model, "associate" do
|
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
it "should not clear associations cache when saving with insert_select" do
|
|
180
|
-
ds = Sequel::Model.db[:c]
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
ds = Sequel::Model.db[:c].with_extend do
|
|
181
|
+
def supports_insert_select?; true end
|
|
182
|
+
def insert_select(*) {:id=>1} end
|
|
183
|
+
end
|
|
183
184
|
c = Class.new(Sequel::Model(ds))
|
|
184
185
|
c.many_to_one :c
|
|
185
186
|
o = c.new
|
|
@@ -297,7 +298,7 @@ describe Sequel::Model, "many_to_one" do
|
|
|
297
298
|
|
|
298
299
|
it "should not issue query if not all keys have values" do
|
|
299
300
|
@c2.many_to_one :parent, :class => @c2, :key=>[:id, :parent_id], :primary_key=>[:parent_id, :id]
|
|
300
|
-
@c2.new(:id => 1, :parent_id => nil).parent.
|
|
301
|
+
@c2.new(:id => 1, :parent_id => nil).parent.must_be_nil
|
|
301
302
|
DB.sqls.must_equal []
|
|
302
303
|
end
|
|
303
304
|
|
|
@@ -334,18 +335,18 @@ describe Sequel::Model, "many_to_one" do
|
|
|
334
335
|
|
|
335
336
|
it "should return nil if key value is nil" do
|
|
336
337
|
@c2.many_to_one :parent, :class => @c2
|
|
337
|
-
@c2.new(:id => 1).parent.
|
|
338
|
+
@c2.new(:id => 1).parent.must_be_nil
|
|
338
339
|
DB.sqls.must_equal []
|
|
339
340
|
end
|
|
340
341
|
|
|
341
342
|
it "should cache negative lookup" do
|
|
342
343
|
@c2.many_to_one :parent, :class => @c2
|
|
343
|
-
@c2.dataset
|
|
344
|
+
@c2.dataset = @c2.dataset.with_fetch([])
|
|
344
345
|
d = @c2.new(:id => 1, :parent_id=>555)
|
|
345
346
|
DB.sqls.must_equal []
|
|
346
|
-
d.parent.
|
|
347
|
+
d.parent.must_be_nil
|
|
347
348
|
DB.sqls.must_equal ['SELECT * FROM nodes WHERE id = 555']
|
|
348
|
-
d.parent.
|
|
349
|
+
d.parent.must_be_nil
|
|
349
350
|
DB.sqls.must_equal []
|
|
350
351
|
end
|
|
351
352
|
|
|
@@ -410,8 +411,8 @@ describe Sequel::Model, "many_to_one" do
|
|
|
410
411
|
|
|
411
412
|
d = @c2.load(:id => 1)
|
|
412
413
|
d.parent_id = 234
|
|
413
|
-
d.associations[:parent].
|
|
414
|
-
@c2.dataset
|
|
414
|
+
d.associations[:parent].must_be_nil
|
|
415
|
+
@c2.dataset = @c2.dataset.with_fetch(:id=>234)
|
|
415
416
|
e = d.parent
|
|
416
417
|
DB.sqls.must_equal ["SELECT * FROM nodes WHERE id = 234"]
|
|
417
418
|
d.associations[:parent].must_equal e
|
|
@@ -422,7 +423,7 @@ describe Sequel::Model, "many_to_one" do
|
|
|
422
423
|
|
|
423
424
|
d = @c2.create(:id => 1)
|
|
424
425
|
DB.reset
|
|
425
|
-
d.associations[:parent].
|
|
426
|
+
d.associations[:parent].must_be_nil
|
|
426
427
|
d.parent = @c2.new(:id => 234)
|
|
427
428
|
e = d.parent
|
|
428
429
|
d.associations[:parent].must_equal e
|
|
@@ -479,7 +480,7 @@ describe Sequel::Model, "many_to_one" do
|
|
|
479
480
|
it "should have the setter add to the reciprocal one_to_many cached association array if it exists" do
|
|
480
481
|
@c2.many_to_one :parent, :class => @c2
|
|
481
482
|
@c2.one_to_many :children, :class => @c2, :key=>:parent_id
|
|
482
|
-
@c2.dataset
|
|
483
|
+
@c2.dataset = @c2.dataset.with_fetch([])
|
|
483
484
|
|
|
484
485
|
d = @c2.new(:id => 1)
|
|
485
486
|
e = @c2.new(:id => 2)
|
|
@@ -507,13 +508,13 @@ describe Sequel::Model, "many_to_one" do
|
|
|
507
508
|
d.parent = e
|
|
508
509
|
e.child.must_equal d
|
|
509
510
|
d.parent = nil
|
|
510
|
-
e.child.
|
|
511
|
+
e.child.must_be_nil
|
|
511
512
|
d.parent = e
|
|
512
513
|
e.child.must_equal d
|
|
513
514
|
|
|
514
515
|
f = @c2.new(:id => 3)
|
|
515
516
|
d.parent = nil
|
|
516
|
-
e.child.
|
|
517
|
+
e.child.must_be_nil
|
|
517
518
|
e.associations[:child] = f
|
|
518
519
|
d.parent = e
|
|
519
520
|
e.child.must_equal d
|
|
@@ -522,7 +523,7 @@ describe Sequel::Model, "many_to_one" do
|
|
|
522
523
|
it "should have the setter remove the object from the previous associated object's reciprocal one_to_many cached association array if it exists" do
|
|
523
524
|
@c2.many_to_one :parent, :class => @c2
|
|
524
525
|
@c2.one_to_many :children, :class => @c2, :key=>:parent_id
|
|
525
|
-
@c2.dataset
|
|
526
|
+
@c2.dataset = @c2.dataset.with_fetch([])
|
|
526
527
|
|
|
527
528
|
d = @c2.new(:id => 1)
|
|
528
529
|
e = @c2.new(:id => 2)
|
|
@@ -555,9 +556,10 @@ describe Sequel::Model, "many_to_one" do
|
|
|
555
556
|
end
|
|
556
557
|
|
|
557
558
|
it "should get all matching records and only return the first if :key option is set to nil" do
|
|
559
|
+
@c2.dataset = @c2.dataset.with_fetch([{:id=>1, :parent_id=>0, :par_parent_id=>3, :blah=>4, :children_id=>2, :children_parent_id=>1, :children_par_parent_id=>5, :children_blah=>6}, {}])
|
|
560
|
+
@c2.dataset.columns(:id, :parent_id, :par_parent_id, :blah)
|
|
558
561
|
@c2.one_to_many :children, :class => @c2, :key=>:parent_id
|
|
559
562
|
@c2.many_to_one :first_grand_parent, :class => @c2, :key=>nil, :eager_graph=>:children, :dataset=>proc{model.filter(:children_id=>parent_id)}
|
|
560
|
-
@c2.dataset.columns(:id, :parent_id, :par_parent_id, :blah)._fetch = [{:id=>1, :parent_id=>0, :par_parent_id=>3, :blah=>4, :children_id=>2, :children_parent_id=>1, :children_par_parent_id=>5, :children_blah=>6}, {}]
|
|
561
563
|
p = @c2.new(:parent_id=>2)
|
|
562
564
|
fgp = p.first_grand_parent
|
|
563
565
|
DB.sqls.must_equal ["SELECT nodes.id, nodes.parent_id, nodes.par_parent_id, nodes.blah, children.id AS children_id, children.parent_id AS children_parent_id, children.par_parent_id AS children_par_parent_id, children.blah AS children_blah FROM nodes LEFT OUTER JOIN nodes AS children ON (children.parent_id = nodes.id) WHERE (children_id = 2)"]
|
|
@@ -655,7 +657,7 @@ describe Sequel::Model, "many_to_one" do
|
|
|
655
657
|
def al(v)
|
|
656
658
|
model::Foo << v.pk
|
|
657
659
|
end
|
|
658
|
-
dataset.
|
|
660
|
+
set_dataset dataset.with_fetch(:id=>20)
|
|
659
661
|
end
|
|
660
662
|
p = @c2.load(:id=>10, :parent_id=>20)
|
|
661
663
|
parent = p.parent
|
|
@@ -684,7 +686,7 @@ describe Sequel::Model, "many_to_one" do
|
|
|
684
686
|
def p._parent=; raise; end
|
|
685
687
|
proc{p.parent = c}.must_raise(Sequel::HookFailed)
|
|
686
688
|
|
|
687
|
-
p.parent.
|
|
689
|
+
p.parent.must_be_nil
|
|
688
690
|
p.associations[:parent] = c
|
|
689
691
|
p.parent.must_equal c
|
|
690
692
|
proc{p.parent = nil}.must_raise(Sequel::HookFailed)
|
|
@@ -699,7 +701,7 @@ describe Sequel::Model, "many_to_one" do
|
|
|
699
701
|
def p._parent=; raise; end
|
|
700
702
|
proc{p.parent = c}.must_raise(Sequel::HookFailed)
|
|
701
703
|
|
|
702
|
-
p.parent.
|
|
704
|
+
p.parent.must_be_nil
|
|
703
705
|
p.associations[:parent] = c
|
|
704
706
|
p.parent.must_equal c
|
|
705
707
|
proc{p.parent = nil}.must_raise(Sequel::HookFailed)
|
|
@@ -732,8 +734,8 @@ describe Sequel::Model, "one_to_one" do
|
|
|
732
734
|
columns :id, :x, :parent_id, :par_parent_id, :blah, :node_id
|
|
733
735
|
end
|
|
734
736
|
@dataset = @c2.dataset
|
|
735
|
-
@dataset
|
|
736
|
-
@c1.dataset
|
|
737
|
+
@dataset = @dataset.with_fetch({})
|
|
738
|
+
@c1.dataset = @c1.dataset.with_fetch({})
|
|
737
739
|
DB.reset
|
|
738
740
|
end
|
|
739
741
|
|
|
@@ -755,7 +757,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
755
757
|
it "should add a setter method" do
|
|
756
758
|
@c2.one_to_one :attribute, :class => @c1
|
|
757
759
|
attrib = @c1.new(:id=>3)
|
|
758
|
-
@c1.dataset
|
|
760
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>3)
|
|
759
761
|
@c2.new(:id => 1234).attribute = attrib
|
|
760
762
|
sqls = DB.sqls
|
|
761
763
|
['INSERT INTO attributes (node_id, id) VALUES (1234, 3)',
|
|
@@ -794,7 +796,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
794
796
|
it "should have the setter method respect the :primary_key option" do
|
|
795
797
|
@c2.one_to_one :attribute, :class => @c1, :primary_key=>:xxx
|
|
796
798
|
attrib = @c1.new(:id=>3)
|
|
797
|
-
@c1.dataset
|
|
799
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>3)
|
|
798
800
|
@c2.new(:id => 1234, :xxx=>5).attribute = attrib
|
|
799
801
|
sqls = DB.sqls
|
|
800
802
|
['INSERT INTO attributes (node_id, id) VALUES (5, 3)',
|
|
@@ -812,7 +814,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
812
814
|
it "should have the setter method respect composite keys" do
|
|
813
815
|
@c2.one_to_one :attribute, :class => @c1, :key=>[:node_id, :y], :primary_key=>[:id, :x]
|
|
814
816
|
attrib = @c1.load(:id=>3, :y=>6)
|
|
815
|
-
@c1.dataset
|
|
817
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>3, :y=>6)
|
|
816
818
|
@c2.load(:id => 1234, :x=>5).attribute = attrib
|
|
817
819
|
sqls = DB.sqls
|
|
818
820
|
sqls.last.must_match(/UPDATE attributes SET (node_id = 1234|y = 5), (node_id = 1234|y = 5) WHERE \(id = 3\)/)
|
|
@@ -821,6 +823,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
821
823
|
end
|
|
822
824
|
|
|
823
825
|
it "should use implicit key if omitted" do
|
|
826
|
+
@c2.dataset = @c2.dataset.with_fetch({})
|
|
824
827
|
@c2.one_to_one :parent, :class => @c2
|
|
825
828
|
|
|
826
829
|
d = @c2.new(:id => 234)
|
|
@@ -856,6 +859,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
856
859
|
end
|
|
857
860
|
|
|
858
861
|
it "should use explicit key if given" do
|
|
862
|
+
@c2.dataset = @c2.dataset.with_fetch({})
|
|
859
863
|
@c2.one_to_one :parent, :class => @c2, :key => :blah
|
|
860
864
|
|
|
861
865
|
d = @c2.new(:id => 234)
|
|
@@ -880,7 +884,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
880
884
|
|
|
881
885
|
it "should not issue query if not all keys have values" do
|
|
882
886
|
@c2.one_to_one :parent, :class => @c2, :key=>[:id, :parent_id], :primary_key=>[:parent_id, :id]
|
|
883
|
-
@c2.new(:id => 1, :parent_id => nil).parent.
|
|
887
|
+
@c2.new(:id => 1, :parent_id => nil).parent.must_be_nil
|
|
884
888
|
DB.sqls.must_equal []
|
|
885
889
|
end
|
|
886
890
|
|
|
@@ -918,18 +922,18 @@ describe Sequel::Model, "one_to_one" do
|
|
|
918
922
|
it "should return nil if primary_key value is nil" do
|
|
919
923
|
@c2.one_to_one :parent, :class => @c2, :primary_key=>:node_id
|
|
920
924
|
|
|
921
|
-
@c2.new(:id => 1).parent.
|
|
925
|
+
@c2.new(:id => 1).parent.must_be_nil
|
|
922
926
|
DB.sqls.must_equal []
|
|
923
927
|
end
|
|
924
928
|
|
|
925
929
|
it "should cache negative lookup" do
|
|
926
930
|
@c2.one_to_one :parent, :class => @c2
|
|
927
|
-
@c2.dataset
|
|
931
|
+
@c2.dataset = @c2.dataset.with_fetch([])
|
|
928
932
|
d = @c2.new(:id => 555)
|
|
929
933
|
DB.sqls.must_equal []
|
|
930
|
-
d.parent.
|
|
934
|
+
d.parent.must_be_nil
|
|
931
935
|
DB.sqls.must_equal ['SELECT * FROM nodes WHERE (nodes.node_id = 555) LIMIT 1']
|
|
932
|
-
d.parent.
|
|
936
|
+
d.parent.must_be_nil
|
|
933
937
|
DB.sqls.must_equal []
|
|
934
938
|
end
|
|
935
939
|
|
|
@@ -937,7 +941,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
937
941
|
@c2.one_to_one :parent, :class => @c2, :key=>:blah
|
|
938
942
|
d = @c2.new(:id => 3)
|
|
939
943
|
e = @c2.new(:id => 4321, :blah=>444)
|
|
940
|
-
@c2.dataset
|
|
944
|
+
@c2.dataset = @c2.dataset.with_fetch(:id => 4321, :blah => 3)
|
|
941
945
|
d.parent = e
|
|
942
946
|
e.values.must_equal(:id => 4321, :blah => 3)
|
|
943
947
|
sqls = DB.sqls
|
|
@@ -958,8 +962,8 @@ describe Sequel::Model, "one_to_one" do
|
|
|
958
962
|
@c2.one_to_one :parent, :class => @c2
|
|
959
963
|
|
|
960
964
|
d = @c2.load(:id => 1)
|
|
961
|
-
d.associations[:parent].
|
|
962
|
-
@c2.dataset
|
|
965
|
+
d.associations[:parent].must_be_nil
|
|
966
|
+
@c2.dataset = @c2.dataset.with_fetch(:id=>234)
|
|
963
967
|
e = d.parent
|
|
964
968
|
DB.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.node_id = 1) LIMIT 1"]
|
|
965
969
|
d.parent
|
|
@@ -971,7 +975,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
971
975
|
@c2.one_to_one :parent, :class => @c2
|
|
972
976
|
|
|
973
977
|
d = @c2.load(:id => 1)
|
|
974
|
-
d.associations[:parent].
|
|
978
|
+
d.associations[:parent].must_be_nil
|
|
975
979
|
e = @c2.load(:id => 234)
|
|
976
980
|
d.parent = e
|
|
977
981
|
f = d.parent
|
|
@@ -1006,27 +1010,27 @@ describe Sequel::Model, "one_to_one" do
|
|
|
1006
1010
|
DB.sqls.must_equal ["UPDATE nodes SET parent_id = NULL WHERE ((parent_id = 1) AND (id != 2))",
|
|
1007
1011
|
"UPDATE nodes SET parent_id = 1 WHERE (id = 2)"]
|
|
1008
1012
|
d.parent = nil
|
|
1009
|
-
e.child.
|
|
1013
|
+
e.child.must_be_nil
|
|
1010
1014
|
DB.sqls.must_equal ["UPDATE nodes SET parent_id = NULL WHERE (parent_id = 1)"]
|
|
1011
1015
|
end
|
|
1012
1016
|
|
|
1013
1017
|
it "should have the setter remove the object from the previous associated object's reciprocal many_to_one cached association array if it exists" do
|
|
1014
1018
|
@c2.one_to_one :parent, :class => @c2, :key=>:parent_id
|
|
1015
1019
|
@c2.many_to_one :child, :class => @c2, :key=>:parent_id
|
|
1016
|
-
@c2.dataset
|
|
1020
|
+
@c2.dataset = @c2.dataset.with_fetch([])
|
|
1017
1021
|
|
|
1018
1022
|
d = @c2.load(:id => 1)
|
|
1019
1023
|
e = @c2.load(:id => 2)
|
|
1020
1024
|
f = @c2.load(:id => 3)
|
|
1021
|
-
e.child.
|
|
1022
|
-
f.child.
|
|
1025
|
+
e.child.must_be_nil
|
|
1026
|
+
f.child.must_be_nil
|
|
1023
1027
|
d.parent = e
|
|
1024
1028
|
e.child.must_equal d
|
|
1025
1029
|
d.parent = f
|
|
1026
1030
|
f.child.must_equal d
|
|
1027
|
-
e.child.
|
|
1031
|
+
e.child.must_be_nil
|
|
1028
1032
|
d.parent = nil
|
|
1029
|
-
f.child.
|
|
1033
|
+
f.child.must_be_nil
|
|
1030
1034
|
end
|
|
1031
1035
|
|
|
1032
1036
|
it "should have the setter not modify the reciprocal if set to same value as current" do
|
|
@@ -1108,7 +1112,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
1108
1112
|
def al(v)
|
|
1109
1113
|
model::Foo << v.pk
|
|
1110
1114
|
end
|
|
1111
|
-
@dataset
|
|
1115
|
+
@dataset = @dataset.with_fetch(:id=>20)
|
|
1112
1116
|
end
|
|
1113
1117
|
p = @c2.load(:id=>10)
|
|
1114
1118
|
parent = p.parent
|
|
@@ -1125,7 +1129,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
1125
1129
|
def p._parent=; raise; end
|
|
1126
1130
|
proc{p.parent = c}.must_raise(Sequel::HookFailed)
|
|
1127
1131
|
|
|
1128
|
-
p.associations[:parent].
|
|
1132
|
+
p.associations[:parent].must_be_nil
|
|
1129
1133
|
p.associations[:parent] = c
|
|
1130
1134
|
p.parent.must_equal c
|
|
1131
1135
|
proc{p.parent = nil}.must_raise(Sequel::HookFailed)
|
|
@@ -1145,6 +1149,7 @@ describe Sequel::Model, "one_to_one" do
|
|
|
1145
1149
|
end
|
|
1146
1150
|
|
|
1147
1151
|
it "should work_correctly when used with associate" do
|
|
1152
|
+
@c2.dataset = @c2.dataset.with_fetch({})
|
|
1148
1153
|
@c2.associate :one_to_one, :parent, :class => @c2
|
|
1149
1154
|
@c2.load(:id => 567).parent.must_equal @c2.load({})
|
|
1150
1155
|
DB.sqls.must_equal ["SELECT * FROM nodes WHERE (nodes.node_id = 567) LIMIT 1"]
|
|
@@ -1172,9 +1177,8 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1172
1177
|
def self.to_s; 'Node'; end
|
|
1173
1178
|
columns :id, :x
|
|
1174
1179
|
end
|
|
1175
|
-
@dataset = @c2.dataset
|
|
1176
|
-
@dataset
|
|
1177
|
-
@c1.dataset._fetch = proc{|sql| sql =~ /SELECT 1/ ? {:a=>1} : {}}
|
|
1180
|
+
@dataset = @c2.dataset = @c2.dataset.with_fetch({})
|
|
1181
|
+
@c1.dataset = @c1.dataset.with_fetch(proc{|sql| sql =~ /SELECT 1/ ? {:a=>1} : {}})
|
|
1178
1182
|
DB.reset
|
|
1179
1183
|
end
|
|
1180
1184
|
|
|
@@ -1267,7 +1271,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1267
1271
|
|
|
1268
1272
|
n = @c2.load(:id => 1234)
|
|
1269
1273
|
a = @c1.new(:id => 234)
|
|
1270
|
-
@c1.dataset
|
|
1274
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>234, :node_id=>1234)
|
|
1271
1275
|
a.must_equal n.add_attribute(a)
|
|
1272
1276
|
sqls = DB.sqls
|
|
1273
1277
|
sqls.shift.must_match(/INSERT INTO attributes \((node_)?id, (node_)?id\) VALUES \(1?234, 1?234\)/)
|
|
@@ -1290,7 +1294,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1290
1294
|
|
|
1291
1295
|
n = @c2.new(:id => 1234)
|
|
1292
1296
|
a = @c1.load(:id => 2345, :node_id => 1234)
|
|
1293
|
-
@c1.dataset
|
|
1297
|
+
@c1.dataset = @c1.dataset.with_fetch([])
|
|
1294
1298
|
proc{n.remove_attribute(a)}.must_raise(Sequel::Error)
|
|
1295
1299
|
DB.sqls.must_equal ["SELECT 1 AS one FROM attributes WHERE ((attributes.node_id = 1234) AND (id = 2345)) LIMIT 1"]
|
|
1296
1300
|
end
|
|
@@ -1299,7 +1303,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1299
1303
|
@c2.one_to_many :attributes, :class => @c1
|
|
1300
1304
|
n = @c2.new(:id => 1234)
|
|
1301
1305
|
DB.reset
|
|
1302
|
-
@c1.dataset
|
|
1306
|
+
@c1.dataset = @c1.dataset.with_fetch(:node_id => 1234, :id => 234)
|
|
1303
1307
|
n.add_attribute(:id => 234).must_equal @c1.load(:node_id => 1234, :id => 234)
|
|
1304
1308
|
sqls = DB.sqls
|
|
1305
1309
|
sqls.shift.must_match(/INSERT INTO attributes \((node_)?id, (node_)?id\) VALUES \(1?234, 1?234\)/)
|
|
@@ -1309,7 +1313,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1309
1313
|
it "should accept a primary key for the add_ method" do
|
|
1310
1314
|
@c2.one_to_many :attributes, :class => @c1
|
|
1311
1315
|
n = @c2.new(:id => 1234)
|
|
1312
|
-
@c1.dataset
|
|
1316
|
+
@c1.dataset = @c1.dataset.with_fetch(:node_id => nil, :id => 234)
|
|
1313
1317
|
n.add_attribute(234).must_equal @c1.load(:node_id => 1234, :id => 234)
|
|
1314
1318
|
DB.sqls.must_equal ["SELECT * FROM attributes WHERE id = 234", "UPDATE attributes SET node_id = 1234 WHERE (id = 234)"]
|
|
1315
1319
|
end
|
|
@@ -1317,7 +1321,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1317
1321
|
it "should raise an error if the primary key passed to the add_ method does not match an existing record" do
|
|
1318
1322
|
@c2.one_to_many :attributes, :class => @c1
|
|
1319
1323
|
n = @c2.new(:id => 1234)
|
|
1320
|
-
@c1.dataset
|
|
1324
|
+
@c1.dataset = @c1.dataset.with_fetch([])
|
|
1321
1325
|
proc{n.add_attribute(234)}.must_raise(Sequel::NoMatchingRow)
|
|
1322
1326
|
DB.sqls.must_equal ["SELECT * FROM attributes WHERE id = 234"]
|
|
1323
1327
|
end
|
|
@@ -1330,7 +1334,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1330
1334
|
it "should accept a primary key for the remove_ method and remove an existing record" do
|
|
1331
1335
|
@c2.one_to_many :attributes, :class => @c1
|
|
1332
1336
|
n = @c2.new(:id => 1234)
|
|
1333
|
-
@c1.dataset
|
|
1337
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>234, :node_id=>1234)
|
|
1334
1338
|
n.remove_attribute(234).must_equal @c1.load(:node_id => nil, :id => 234)
|
|
1335
1339
|
DB.sqls.must_equal ['SELECT * FROM attributes WHERE ((attributes.node_id = 1234) AND (attributes.id = 234)) LIMIT 1',
|
|
1336
1340
|
'UPDATE attributes SET node_id = NULL WHERE (id = 234)']
|
|
@@ -1375,9 +1379,9 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1375
1379
|
end
|
|
1376
1380
|
|
|
1377
1381
|
it "should have add_ method accept a composite key" do
|
|
1382
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>2345, :node_id=>1234, :z=>8, :y=>5)
|
|
1378
1383
|
@c1.set_primary_key [:id, :z]
|
|
1379
1384
|
@c2.one_to_many :attributes, :class => @c1, :key =>[:node_id, :y], :primary_key=>[:id, :x]
|
|
1380
|
-
@c1.dataset._fetch = {:id => 2345, :z => 8, :node_id => 1234, :y=>5}
|
|
1381
1385
|
|
|
1382
1386
|
n = @c2.load(:id => 1234, :x=>5)
|
|
1383
1387
|
a = @c1.load(:id => 2345, :z => 8, :node_id => 1234, :y=>5)
|
|
@@ -1400,10 +1404,10 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1400
1404
|
end
|
|
1401
1405
|
|
|
1402
1406
|
it "should accept a array of composite primary key values for the remove_ method and remove an existing record" do
|
|
1407
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>234, :node_id=>123, :y=>5)
|
|
1403
1408
|
@c1.set_primary_key [:id, :y]
|
|
1404
1409
|
@c2.one_to_many :attributes, :class => @c1, :key=>:node_id, :primary_key=>:id
|
|
1405
1410
|
n = @c2.new(:id => 123)
|
|
1406
|
-
@c1.dataset._fetch = {:id=>234, :node_id=>123, :y=>5}
|
|
1407
1411
|
n.remove_attribute([234, 5]).must_equal @c1.load(:node_id => nil, :y => 5, :id => 234)
|
|
1408
1412
|
sqls = DB.sqls
|
|
1409
1413
|
sqls.length.must_equal 2
|
|
@@ -1435,9 +1439,9 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1435
1439
|
a = @c1.new(:id => 2345)
|
|
1436
1440
|
def a.validate() errors.add(:id, 'foo') end
|
|
1437
1441
|
n.associations[:attributes] = []
|
|
1438
|
-
n.add_attribute(a).
|
|
1442
|
+
n.add_attribute(a).must_be_nil
|
|
1439
1443
|
n.associations[:attributes].must_equal []
|
|
1440
|
-
n.remove_attribute(a).
|
|
1444
|
+
n.remove_attribute(a).must_be_nil
|
|
1441
1445
|
n.associations[:attributes].must_equal []
|
|
1442
1446
|
end
|
|
1443
1447
|
|
|
@@ -1506,6 +1510,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1506
1510
|
|
|
1507
1511
|
it "should support a :dataset option that is used instead of the default" do
|
|
1508
1512
|
c1 = @c1
|
|
1513
|
+
@c1.dataset = @c1.dataset.with_fetch({})
|
|
1509
1514
|
@c2.one_to_many :all_other_attributes, :class => @c1, :dataset=>proc{c1.exclude(:nodeid=>pk)}, :order=>:a, :limit=>10 do |ds|
|
|
1510
1515
|
ds.filter(:xxx => 5)
|
|
1511
1516
|
end
|
|
@@ -1591,7 +1596,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1591
1596
|
att.associations[:node] = n
|
|
1592
1597
|
att.node.must_equal n
|
|
1593
1598
|
n.remove_attribute(att)
|
|
1594
|
-
att.node.
|
|
1599
|
+
att.node.must_be_nil
|
|
1595
1600
|
end
|
|
1596
1601
|
|
|
1597
1602
|
it "should not create the add_, remove_, or remove_all_ methods if :read_only option is used" do
|
|
@@ -1682,7 +1687,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1682
1687
|
@c2.one_to_many :attributes, :class => @c1
|
|
1683
1688
|
attrib = @c1.new(:id=>3)
|
|
1684
1689
|
node = @c2.new(:id => 1234)
|
|
1685
|
-
@c1.dataset
|
|
1690
|
+
@c1.dataset = @c1.dataset.with_fetch([[], [{:id=>3, :node_id=>1234}]])
|
|
1686
1691
|
node.attributes.must_equal []
|
|
1687
1692
|
node.add_attribute(attrib)
|
|
1688
1693
|
node.associations[:attributes].must_equal [attrib]
|
|
@@ -1691,22 +1696,22 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1691
1696
|
|
|
1692
1697
|
it "remove_all should return nil if the cache is not populated" do
|
|
1693
1698
|
@c2.one_to_many :attributes, :class => @c1
|
|
1694
|
-
@c2.new(:id => 1234).remove_all_attributes.
|
|
1699
|
+
@c2.new(:id => 1234).remove_all_attributes.must_be_nil
|
|
1695
1700
|
end
|
|
1696
1701
|
|
|
1697
1702
|
it "remove_all should remove the current item from all reciprocal association caches if they are populated" do
|
|
1698
1703
|
@c2.one_to_many :attributes, :class => @c1
|
|
1699
1704
|
@c1.many_to_one :node, :class => @c2
|
|
1700
|
-
@c2.dataset
|
|
1701
|
-
@c1.dataset
|
|
1705
|
+
@c2.dataset = @c2.dataset.with_fetch([])
|
|
1706
|
+
@c1.dataset = @c1.dataset.with_fetch([[], [{:id=>3, :node_id=>1234}]])
|
|
1702
1707
|
attrib = @c1.new(:id=>3)
|
|
1703
1708
|
node = @c2.load(:id => 1234)
|
|
1704
1709
|
node.attributes.must_equal []
|
|
1705
|
-
attrib.node.
|
|
1710
|
+
attrib.node.must_be_nil
|
|
1706
1711
|
node.add_attribute(attrib)
|
|
1707
1712
|
attrib.associations[:node].must_equal node
|
|
1708
1713
|
node.remove_all_attributes
|
|
1709
|
-
attrib.associations.fetch(:node, 2).
|
|
1714
|
+
attrib.associations.fetch(:node, 2).must_be_nil
|
|
1710
1715
|
end
|
|
1711
1716
|
|
|
1712
1717
|
it "should call an _add_ method internally to add attributes" do
|
|
@@ -1847,7 +1852,7 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1847
1852
|
v.each{|x| model::Foo << x.pk}
|
|
1848
1853
|
end
|
|
1849
1854
|
end
|
|
1850
|
-
@c1.dataset
|
|
1855
|
+
@c1.dataset = @c1.dataset.with_fetch([{:id=>20}, {:id=>30}])
|
|
1851
1856
|
p = @c2.load(:id=>10, :parent_id=>20)
|
|
1852
1857
|
attributes = p.attributes
|
|
1853
1858
|
h.must_equal [[10, [20, 30]], 20, 30]
|
|
@@ -1879,11 +1884,11 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1879
1884
|
def p._add_attribute; raise; end
|
|
1880
1885
|
def p._remove_attribute; raise; end
|
|
1881
1886
|
p.associations[:attributes] = []
|
|
1882
|
-
p.add_attribute(c).
|
|
1887
|
+
p.add_attribute(c).must_be_nil
|
|
1883
1888
|
p.attributes.must_equal []
|
|
1884
1889
|
p.associations[:attributes] = [c]
|
|
1885
1890
|
def p.br(c) false end
|
|
1886
|
-
p.remove_attribute(c).
|
|
1891
|
+
p.remove_attribute(c).must_be_nil
|
|
1887
1892
|
p.attributes.must_equal [c]
|
|
1888
1893
|
end
|
|
1889
1894
|
|
|
@@ -1912,11 +1917,11 @@ describe Sequel::Model, "one_to_many" do
|
|
|
1912
1917
|
def p._add_attribute; raise; end
|
|
1913
1918
|
def p._remove_attribute; raise; end
|
|
1914
1919
|
p.associations[:attributes] = []
|
|
1915
|
-
p.add_attribute(c).
|
|
1920
|
+
p.add_attribute(c).must_be_nil
|
|
1916
1921
|
p.attributes.must_equal []
|
|
1917
1922
|
p.associations[:attributes] = [c]
|
|
1918
1923
|
def p.br(o); cancel_action; end
|
|
1919
|
-
p.remove_attribute(c).
|
|
1924
|
+
p.remove_attribute(c).must_be_nil
|
|
1920
1925
|
p.attributes.must_equal [c]
|
|
1921
1926
|
end
|
|
1922
1927
|
|
|
@@ -1945,9 +1950,9 @@ describe Sequel::Model, "many_to_many" do
|
|
|
1945
1950
|
columns :id, :x
|
|
1946
1951
|
end
|
|
1947
1952
|
@dataset = @c2.dataset
|
|
1948
|
-
@c1.dataset
|
|
1953
|
+
@c1.dataset = @c1.dataset.with_autoid(1)
|
|
1949
1954
|
|
|
1950
|
-
[@c1, @c2].each{|c| c.dataset
|
|
1955
|
+
[@c1, @c2].each{|c| c.dataset = c.dataset.with_fetch({})}
|
|
1951
1956
|
DB.reset
|
|
1952
1957
|
end
|
|
1953
1958
|
|
|
@@ -2181,7 +2186,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2181
2186
|
|
|
2182
2187
|
n = @c2.load(:id => 1234)
|
|
2183
2188
|
a = @c1.load(:id => 2345)
|
|
2184
|
-
@c1.dataset
|
|
2189
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>2345)
|
|
2185
2190
|
n.add_attribute(2345).must_equal a
|
|
2186
2191
|
sqls = DB.sqls
|
|
2187
2192
|
['INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 2345)',
|
|
@@ -2193,7 +2198,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2193
2198
|
@c2.many_to_many :attributes, :class => @c1
|
|
2194
2199
|
|
|
2195
2200
|
n = @c2.load(:id => 1234)
|
|
2196
|
-
@c1.dataset
|
|
2201
|
+
@c1.dataset = @c1.dataset.with_fetch([])
|
|
2197
2202
|
proc{n.add_attribute(2345)}.must_raise(Sequel::NoMatchingRow)
|
|
2198
2203
|
DB.sqls.must_equal ["SELECT * FROM attributes WHERE id = 2345"]
|
|
2199
2204
|
end
|
|
@@ -2202,7 +2207,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2202
2207
|
@c2.many_to_many :attributes, :class => @c1
|
|
2203
2208
|
|
|
2204
2209
|
n = @c2.load(:id => 1234)
|
|
2205
|
-
@c1.dataset
|
|
2210
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>1)
|
|
2206
2211
|
n.add_attribute(:id => 1).must_equal @c1.load(:id => 1)
|
|
2207
2212
|
sqls = DB.sqls
|
|
2208
2213
|
['INSERT INTO attributes_nodes (node_id, attribute_id) VALUES (1234, 1)',
|
|
@@ -2228,7 +2233,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2228
2233
|
it "should accept a primary key for the remove_ method and remove an existing record" do
|
|
2229
2234
|
@c2.many_to_many :attributes, :class => @c1
|
|
2230
2235
|
n = @c2.new(:id => 1234)
|
|
2231
|
-
@c1.dataset
|
|
2236
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>234)
|
|
2232
2237
|
n.remove_attribute(234).must_equal @c1.load(:id => 234)
|
|
2233
2238
|
DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE ((attributes_nodes.node_id = 1234) AND (attributes.id = 234)) LIMIT 1",
|
|
2234
2239
|
"DELETE FROM attributes_nodes WHERE ((node_id = 1234) AND (attribute_id = 234))"]
|
|
@@ -2287,10 +2292,10 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2287
2292
|
|
|
2288
2293
|
it "should have the add_ method respect composite keys" do
|
|
2289
2294
|
@c2.many_to_many :attributes, :class => @c1, :left_key=>[:l1, :l2], :right_key=>[:r1, :r2], :left_primary_key=>[:id, :x], :right_primary_key=>[:id, :z]
|
|
2295
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>2345, :z=>8)
|
|
2290
2296
|
@c1.set_primary_key [:id, :z]
|
|
2291
2297
|
n = @c2.load(:id => 1234, :x=>5)
|
|
2292
2298
|
a = @c1.load(:id => 2345, :z=>8)
|
|
2293
|
-
@c1.dataset._fetch = {:id => 2345, :z=>8}
|
|
2294
2299
|
n.add_attribute([2345, 8]).must_equal a
|
|
2295
2300
|
sqls = DB.sqls
|
|
2296
2301
|
sqls.shift.must_match(/SELECT \* FROM attributes WHERE \(\((id|z) = (8|2345)\) AND \((id|z) = (8|2345)\)\) LIMIT 1/)
|
|
@@ -2316,10 +2321,10 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2316
2321
|
end
|
|
2317
2322
|
|
|
2318
2323
|
it "should accept a array of composite primary key values for the remove_ method and remove an existing record" do
|
|
2324
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>234, :y=>8)
|
|
2319
2325
|
@c1.set_primary_key [:id, :y]
|
|
2320
2326
|
@c2.many_to_many :attributes, :class => @c1
|
|
2321
2327
|
n = @c2.new(:id => 1234)
|
|
2322
|
-
@c1.dataset._fetch = {:id=>234, :y=>8}
|
|
2323
2328
|
@c1.load(:id => 234, :y=>8).must_equal n.remove_attribute([234, 8])
|
|
2324
2329
|
sqls = DB.sqls
|
|
2325
2330
|
["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE ((attributes_nodes.node_id = 1234) AND (attributes.id = 234) AND (attributes.y = 8)) LIMIT 1",
|
|
@@ -2342,7 +2347,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2342
2347
|
n = @c1.new
|
|
2343
2348
|
a = @c2.load(:id=>123)
|
|
2344
2349
|
n.new?.must_equal true
|
|
2345
|
-
@c1.dataset
|
|
2350
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>1)
|
|
2346
2351
|
a.add_attribute(n)
|
|
2347
2352
|
n.new?.must_equal false
|
|
2348
2353
|
end
|
|
@@ -2369,7 +2374,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2369
2374
|
n = @c1.new
|
|
2370
2375
|
a = @c2.load(:id=>123)
|
|
2371
2376
|
def n.validate() errors.add(:id, 'foo') end
|
|
2372
|
-
@c1.dataset
|
|
2377
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>1)
|
|
2373
2378
|
a.add_attribute(n)
|
|
2374
2379
|
n.new?.must_equal false
|
|
2375
2380
|
end
|
|
@@ -2514,7 +2519,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2514
2519
|
@c2.many_to_many :attributes, :class => @c1
|
|
2515
2520
|
attrib = @c1.load(:id=>3)
|
|
2516
2521
|
node = @c2.load(:id => 1234)
|
|
2517
|
-
@c1.dataset
|
|
2522
|
+
@c1.dataset = @c1.dataset.with_fetch([])
|
|
2518
2523
|
node.attributes.must_equal []
|
|
2519
2524
|
node.add_attribute(attrib)
|
|
2520
2525
|
node.associations[:attributes].must_equal [attrib]
|
|
@@ -2523,14 +2528,14 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2523
2528
|
|
|
2524
2529
|
it "remove_all should return nil if the cached instance variable does not exist" do
|
|
2525
2530
|
@c2.many_to_many :attributes, :class => @c1
|
|
2526
|
-
@c2.new(:id => 1234).remove_all_attributes.
|
|
2531
|
+
@c2.new(:id => 1234).remove_all_attributes.must_be_nil
|
|
2527
2532
|
end
|
|
2528
2533
|
|
|
2529
2534
|
it "remove_all should remove the current item from all reciprocal instance varaibles if it cached instance variable exists" do
|
|
2530
2535
|
@c2.many_to_many :attributes, :class => @c1
|
|
2531
2536
|
@c1.many_to_many :nodes, :class => @c2
|
|
2532
|
-
@c1.dataset
|
|
2533
|
-
@c2.dataset
|
|
2537
|
+
@c1.dataset = @c1.dataset.with_fetch([])
|
|
2538
|
+
@c2.dataset = @c2.dataset.with_fetch([])
|
|
2534
2539
|
attrib = @c1.load(:id=>3)
|
|
2535
2540
|
node = @c2.new(:id => 1234)
|
|
2536
2541
|
node.attributes.must_equal []
|
|
@@ -2689,7 +2694,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2689
2694
|
v.each{|x| model::Foo << x.pk}
|
|
2690
2695
|
end
|
|
2691
2696
|
end
|
|
2692
|
-
@c1.dataset
|
|
2697
|
+
@c1.dataset = @c1.dataset.with_fetch([{:id=>20}, {:id=>30}])
|
|
2693
2698
|
p = @c2.load(:id=>10, :parent_id=>20)
|
|
2694
2699
|
attributes = p.attributes
|
|
2695
2700
|
h.must_equal [[10, [20, 30]], 20, 30]
|
|
@@ -2722,11 +2727,11 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2722
2727
|
def p._add_attribute; raise; end
|
|
2723
2728
|
def p._remove_attribute; raise; end
|
|
2724
2729
|
p.associations[:attributes] = []
|
|
2725
|
-
p.add_attribute(c).
|
|
2730
|
+
p.add_attribute(c).must_be_nil
|
|
2726
2731
|
p.attributes.must_equal []
|
|
2727
2732
|
p.associations[:attributes] = [c]
|
|
2728
2733
|
def p.br(c) false end
|
|
2729
|
-
p.remove_attribute(c).
|
|
2734
|
+
p.remove_attribute(c).must_be_nil
|
|
2730
2735
|
p.attributes.must_equal [c]
|
|
2731
2736
|
end
|
|
2732
2737
|
|
|
@@ -2756,17 +2761,17 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2756
2761
|
def p._add_attribute; raise; end
|
|
2757
2762
|
def p._remove_attribute; raise; end
|
|
2758
2763
|
p.associations[:attributes] = []
|
|
2759
|
-
p.add_attribute(c).
|
|
2764
|
+
p.add_attribute(c).must_be_nil
|
|
2760
2765
|
p.attributes.must_equal []
|
|
2761
2766
|
p.associations[:attributes] = [c]
|
|
2762
2767
|
def p.br(o) cancel_action end
|
|
2763
|
-
p.remove_attribute(c).
|
|
2768
|
+
p.remove_attribute(c).must_be_nil
|
|
2764
2769
|
p.attributes.must_equal [c]
|
|
2765
2770
|
end
|
|
2766
2771
|
|
|
2767
2772
|
it "should support a :uniq option that removes duplicates from the association" do
|
|
2768
2773
|
@c2.many_to_many :attributes, :class => @c1, :uniq=>true
|
|
2769
|
-
@c1.dataset
|
|
2774
|
+
@c1.dataset = @c1.dataset.with_fetch([{:id=>20}, {:id=>30}, {:id=>20}, {:id=>30}])
|
|
2770
2775
|
@c2.load(:id=>10, :parent_id=>20).attributes.must_equal [@c1.load(:id=>20), @c1.load(:id=>30)]
|
|
2771
2776
|
end
|
|
2772
2777
|
|
|
@@ -2787,7 +2792,7 @@ describe Sequel::Model, "many_to_many" do
|
|
|
2787
2792
|
@c2.many_to_many :attributes, :class => @c1 do |ds|
|
|
2788
2793
|
ds.filter(:join_table_att=>3)
|
|
2789
2794
|
end
|
|
2790
|
-
@c1.dataset
|
|
2795
|
+
@c1.dataset = @c1.dataset.with_fetch(:id=>2)
|
|
2791
2796
|
@c2.load(:id=>1).remove_attribute(2)
|
|
2792
2797
|
DB.sqls.must_equal ["SELECT attributes.* FROM attributes INNER JOIN attributes_nodes ON (attributes_nodes.attribute_id = attributes.id) WHERE ((attributes_nodes.node_id = 1) AND (join_table_att = 3) AND (attributes.id = 2)) LIMIT 1",
|
|
2793
2798
|
"DELETE FROM attributes_nodes WHERE ((node_id = 1) AND (attribute_id = 2))"]
|
|
@@ -2818,9 +2823,9 @@ describe Sequel::Model, "one_through_one" do
|
|
|
2818
2823
|
columns :id, :x
|
|
2819
2824
|
end
|
|
2820
2825
|
@dataset = @c2.dataset
|
|
2821
|
-
@c1.dataset
|
|
2826
|
+
@c1.dataset = @c1.dataset.with_autoid(1)
|
|
2822
2827
|
|
|
2823
|
-
[@c1, @c2].each{|c| c.dataset
|
|
2828
|
+
[@c1, @c2].each{|c| c.dataset = c.dataset.with_fetch({})}
|
|
2824
2829
|
DB.reset
|
|
2825
2830
|
end
|
|
2826
2831
|
after do
|
|
@@ -2873,7 +2878,7 @@ describe Sequel::Model, "one_through_one" do
|
|
|
2873
2878
|
|
|
2874
2879
|
it "should not issue query if not all keys have values" do
|
|
2875
2880
|
@c2.one_through_one :attribute, :class => @c1, :left_key=>[:l1, :l2], :right_key=>[:r1, :r2], :left_primary_key=>[:id, :x], :right_primary_key=>[:id, :y]
|
|
2876
|
-
@c2.load(:id => 1234, :x=>nil).attribute.
|
|
2881
|
+
@c2.load(:id => 1234, :x=>nil).attribute.must_be_nil
|
|
2877
2882
|
DB.sqls.must_equal []
|
|
2878
2883
|
end
|
|
2879
2884
|
|
|
@@ -3022,7 +3027,7 @@ describe Sequel::Model, "one_through_one" do
|
|
|
3022
3027
|
model::Foo << v.pk
|
|
3023
3028
|
end
|
|
3024
3029
|
end
|
|
3025
|
-
@c1.dataset
|
|
3030
|
+
@c1.dataset = @c1.dataset.with_fetch([{:id=>20}])
|
|
3026
3031
|
p = @c2.load(:id=>10, :parent_id=>20)
|
|
3027
3032
|
attribute = p.attribute
|
|
3028
3033
|
h.must_equal [[10, 20], 20]
|
|
@@ -4493,9 +4498,9 @@ describe "Model#freeze" do
|
|
|
4493
4498
|
end
|
|
4494
4499
|
|
|
4495
4500
|
it "should not break associations getters" do
|
|
4496
|
-
Album::B.dataset
|
|
4501
|
+
Album::B.dataset = Album::B.dataset.with_fetch(:album_id=>1, :id=>2)
|
|
4497
4502
|
@o.b.must_equal Album::B.load(:id=>2, :album_id=>1)
|
|
4498
|
-
@o.associations[:b].
|
|
4503
|
+
@o.associations[:b].must_be_nil
|
|
4499
4504
|
|
|
4500
4505
|
@o = @o.dup
|
|
4501
4506
|
@o.b.must_equal Album::B.load(:id=>2, :album_id=>1)
|
|
@@ -4505,7 +4510,7 @@ describe "Model#freeze" do
|
|
|
4505
4510
|
it "should not break reciprocal associations" do
|
|
4506
4511
|
b = Album::B.load(:id=>2, :album_id=>nil)
|
|
4507
4512
|
b.album = @o
|
|
4508
|
-
@o.associations[:b].
|
|
4513
|
+
@o.associations[:b].must_be_nil
|
|
4509
4514
|
|
|
4510
4515
|
@o = @o.dup
|
|
4511
4516
|
b = Album::B.load(:id=>2, :album_id=>nil)
|
|
@@ -4518,7 +4523,7 @@ describe "association autoreloading" do
|
|
|
4518
4523
|
before do
|
|
4519
4524
|
@c = Class.new(Sequel::Model)
|
|
4520
4525
|
@Artist = Class.new(@c).set_dataset(:artists)
|
|
4521
|
-
@Artist.dataset
|
|
4526
|
+
@Artist.dataset = @Artist.dataset.with_fetch(:id=>2, :name=>'Ar')
|
|
4522
4527
|
@Album = Class.new(@c).set_dataset(:albums)
|
|
4523
4528
|
@Artist.columns :id, :name
|
|
4524
4529
|
@Album.columns :id, :name, :artist_id
|