sequel 4.22.0 → 4.23.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +22 -0
- data/README.rdoc +6 -0
- data/Rakefile +59 -81
- data/doc/migration.rdoc +2 -0
- data/doc/release_notes/4.23.0.txt +65 -0
- data/doc/sharding.rdoc +16 -14
- data/doc/testing.rdoc +61 -77
- data/lib/sequel/adapters/jdbc.rb +1 -0
- data/lib/sequel/adapters/mock.rb +0 -1
- data/lib/sequel/adapters/postgres.rb +1 -0
- data/lib/sequel/adapters/postgresql.rb +1 -0
- data/lib/sequel/adapters/shared/postgres.rb +3 -3
- data/lib/sequel/connection_pool/sharded_threaded.rb +5 -0
- data/lib/sequel/connection_pool/threaded.rb +9 -1
- data/lib/sequel/database/connecting.rb +1 -1
- data/lib/sequel/database/transactions.rb +2 -1
- data/lib/sequel/dataset/prepared_statements.rb +1 -1
- data/lib/sequel/extensions/constraint_validations.rb +12 -12
- data/lib/sequel/extensions/date_arithmetic.rb +0 -4
- data/lib/sequel/extensions/pagination.rb +14 -2
- data/lib/sequel/extensions/pg_enum.rb +2 -2
- data/lib/sequel/extensions/pg_hstore.rb +1 -1
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +2 -0
- data/lib/sequel/plugins/delay_add_association.rb +50 -0
- data/lib/sequel/plugins/list.rb +2 -2
- data/lib/sequel/plugins/nested_attributes.rb +8 -28
- data/lib/sequel/plugins/update_refresh.rb +50 -0
- data/lib/sequel/plugins/validate_associated.rb +55 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +29 -29
- data/spec/adapters/firebird_spec.rb +97 -103
- data/spec/adapters/informix_spec.rb +25 -25
- data/spec/adapters/mssql_spec.rb +156 -172
- data/spec/adapters/mysql_spec.rb +334 -359
- data/spec/adapters/oracle_spec.rb +67 -69
- data/spec/adapters/postgres_spec.rb +1298 -1249
- data/spec/adapters/spec_helper.rb +2 -35
- data/spec/adapters/sqlanywhere_spec.rb +39 -39
- data/spec/adapters/sqlite_spec.rb +203 -200
- data/spec/bin_spec.rb +57 -59
- data/spec/core/connection_pool_spec.rb +402 -401
- data/spec/core/database_spec.rb +953 -944
- data/spec/core/dataset_spec.rb +2178 -2168
- data/spec/core/deprecated_spec.rb +19 -19
- data/spec/core/expression_filters_spec.rb +415 -415
- data/spec/core/mock_adapter_spec.rb +212 -212
- data/spec/core/object_graph_spec.rb +73 -73
- data/spec/core/placeholder_literalizer_spec.rb +71 -71
- data/spec/core/schema_generator_spec.rb +44 -44
- data/spec/core/schema_spec.rb +470 -472
- data/spec/core/spec_helper.rb +5 -20
- data/spec/core/version_spec.rb +2 -2
- data/spec/core_extensions_spec.rb +320 -320
- data/spec/extensions/accessed_columns_spec.rb +12 -12
- data/spec/extensions/active_model_spec.rb +3 -3
- data/spec/extensions/after_initialize_spec.rb +2 -2
- data/spec/extensions/arbitrary_servers_spec.rb +23 -23
- data/spec/extensions/association_dependencies_spec.rb +34 -34
- data/spec/extensions/association_pks_spec.rb +98 -98
- data/spec/extensions/association_proxies_spec.rb +33 -33
- data/spec/extensions/auto_validations_spec.rb +46 -46
- data/spec/extensions/blacklist_security_spec.rb +19 -18
- data/spec/extensions/blank_spec.rb +36 -36
- data/spec/extensions/boolean_readers_spec.rb +36 -36
- data/spec/extensions/caching_spec.rb +82 -82
- data/spec/extensions/class_table_inheritance_spec.rb +72 -72
- data/spec/extensions/column_conflicts_spec.rb +19 -14
- data/spec/extensions/column_select_spec.rb +19 -19
- data/spec/extensions/columns_introspection_spec.rb +43 -43
- data/spec/extensions/composition_spec.rb +64 -64
- data/spec/extensions/connection_validator_spec.rb +92 -90
- data/spec/extensions/constraint_validations_plugin_spec.rb +92 -92
- data/spec/extensions/constraint_validations_spec.rb +80 -80
- data/spec/extensions/core_refinements_spec.rb +220 -220
- data/spec/extensions/csv_serializer_spec.rb +44 -44
- data/spec/extensions/current_datetime_timestamp_spec.rb +8 -8
- data/spec/extensions/dataset_associations_spec.rb +65 -65
- data/spec/extensions/dataset_source_alias_spec.rb +16 -16
- data/spec/extensions/date_arithmetic_spec.rb +51 -58
- data/spec/extensions/defaults_setter_spec.rb +19 -19
- data/spec/extensions/delay_add_association_spec.rb +52 -0
- data/spec/extensions/dirty_spec.rb +51 -51
- data/spec/extensions/eager_each_spec.rb +8 -8
- data/spec/extensions/empty_array_ignore_nulls_spec.rb +10 -10
- data/spec/extensions/error_splitter_spec.rb +2 -2
- data/spec/extensions/error_sql_spec.rb +4 -4
- data/spec/extensions/eval_inspect_spec.rb +3 -3
- data/spec/extensions/filter_having_spec.rb +8 -8
- data/spec/extensions/force_encoding_spec.rb +30 -30
- data/spec/extensions/from_block_spec.rb +7 -7
- data/spec/extensions/graph_each_spec.rb +19 -19
- data/spec/extensions/hash_aliases_spec.rb +5 -5
- data/spec/extensions/hook_class_methods_spec.rb +100 -100
- data/spec/extensions/inflector_spec.rb +54 -54
- data/spec/extensions/input_transformer_spec.rb +10 -10
- data/spec/extensions/insert_returning_select_spec.rb +8 -8
- data/spec/extensions/instance_filters_spec.rb +26 -26
- data/spec/extensions/instance_hooks_spec.rb +85 -85
- data/spec/extensions/json_serializer_spec.rb +68 -68
- data/spec/extensions/lazy_attributes_spec.rb +49 -49
- data/spec/extensions/list_spec.rb +77 -75
- data/spec/extensions/looser_typecasting_spec.rb +16 -16
- data/spec/extensions/many_through_many_spec.rb +627 -627
- data/spec/extensions/meta_def_spec.rb +7 -7
- data/spec/extensions/migration_spec.rb +217 -217
- data/spec/extensions/modification_detection_spec.rb +20 -20
- data/spec/extensions/mssql_optimistic_locking_spec.rb +21 -21
- data/spec/extensions/named_timezones_spec.rb +18 -18
- data/spec/extensions/nested_attributes_spec.rb +107 -107
- data/spec/extensions/null_dataset_spec.rb +24 -24
- data/spec/extensions/optimistic_locking_spec.rb +21 -21
- data/spec/extensions/pagination_spec.rb +52 -52
- data/spec/extensions/pg_array_associations_spec.rb +273 -273
- data/spec/extensions/pg_array_ops_spec.rb +52 -52
- data/spec/extensions/pg_array_spec.rb +152 -152
- data/spec/extensions/pg_enum_spec.rb +13 -13
- data/spec/extensions/pg_hstore_ops_spec.rb +63 -63
- data/spec/extensions/pg_hstore_spec.rb +84 -84
- data/spec/extensions/pg_inet_spec.rb +15 -15
- data/spec/extensions/pg_interval_spec.rb +29 -29
- data/spec/extensions/pg_json_ops_spec.rb +86 -84
- data/spec/extensions/pg_json_spec.rb +104 -104
- data/spec/extensions/pg_loose_count_spec.rb +6 -6
- data/spec/extensions/pg_range_ops_spec.rb +24 -24
- data/spec/extensions/pg_range_spec.rb +143 -143
- data/spec/extensions/pg_row_ops_spec.rb +14 -14
- data/spec/extensions/pg_row_plugin_spec.rb +12 -12
- data/spec/extensions/pg_row_spec.rb +118 -118
- data/spec/extensions/pg_static_cache_updater_spec.rb +28 -28
- data/spec/extensions/pg_typecast_on_load_spec.rb +21 -21
- data/spec/extensions/prepared_statements_associations_spec.rb +42 -42
- data/spec/extensions/prepared_statements_safe_spec.rb +18 -18
- data/spec/extensions/prepared_statements_spec.rb +28 -28
- data/spec/extensions/prepared_statements_with_pk_spec.rb +11 -11
- data/spec/extensions/pretty_table_spec.rb +16 -16
- data/spec/extensions/query_literals_spec.rb +37 -37
- data/spec/extensions/query_spec.rb +32 -32
- data/spec/extensions/rcte_tree_spec.rb +141 -141
- data/spec/extensions/round_timestamps_spec.rb +21 -21
- data/spec/extensions/schema_caching_spec.rb +8 -8
- data/spec/extensions/schema_dumper_spec.rb +78 -78
- data/spec/extensions/schema_spec.rb +31 -27
- data/spec/extensions/scissors_spec.rb +3 -3
- data/spec/extensions/select_remove_spec.rb +14 -14
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +28 -28
- data/spec/extensions/serialization_modification_detection_spec.rb +33 -33
- data/spec/extensions/serialization_spec.rb +79 -78
- data/spec/extensions/server_block_spec.rb +17 -17
- data/spec/extensions/set_overrides_spec.rb +30 -30
- data/spec/extensions/sharding_spec.rb +65 -65
- data/spec/extensions/shared_caching_spec.rb +29 -29
- data/spec/extensions/single_table_inheritance_spec.rb +79 -79
- data/spec/extensions/skip_create_refresh_spec.rb +3 -3
- data/spec/extensions/spec_helper.rb +4 -29
- data/spec/extensions/split_array_nil_spec.rb +9 -9
- data/spec/extensions/split_values_spec.rb +7 -7
- data/spec/extensions/sql_expr_spec.rb +32 -32
- data/spec/extensions/static_cache_spec.rb +123 -123
- data/spec/extensions/string_date_time_spec.rb +34 -34
- data/spec/extensions/string_stripper_spec.rb +15 -15
- data/spec/extensions/subclasses_spec.rb +31 -31
- data/spec/extensions/table_select_spec.rb +15 -15
- data/spec/extensions/tactical_eager_loading_spec.rb +23 -23
- data/spec/extensions/thread_local_timezones_spec.rb +13 -13
- data/spec/extensions/timestamps_spec.rb +40 -40
- data/spec/extensions/to_dot_spec.rb +34 -34
- data/spec/extensions/touch_spec.rb +52 -52
- data/spec/extensions/tree_spec.rb +72 -72
- data/spec/extensions/typecast_on_load_spec.rb +25 -25
- data/spec/extensions/unlimited_update_spec.rb +2 -2
- data/spec/extensions/update_or_create_spec.rb +36 -36
- data/spec/extensions/update_primary_key_spec.rb +35 -35
- data/spec/extensions/update_refresh_spec.rb +41 -0
- data/spec/extensions/validate_associated_spec.rb +52 -0
- data/spec/extensions/validation_class_methods_spec.rb +314 -317
- data/spec/extensions/validation_helpers_spec.rb +195 -195
- data/spec/extensions/xml_serializer_spec.rb +48 -48
- data/spec/guards_helper.rb +55 -0
- data/spec/integration/associations_test.rb +1089 -1088
- data/spec/integration/database_test.rb +29 -29
- data/spec/integration/dataset_test.rb +661 -661
- data/spec/integration/eager_loader_test.rb +147 -147
- data/spec/integration/migrator_test.rb +122 -122
- data/spec/integration/model_test.rb +70 -70
- data/spec/integration/plugin_test.rb +682 -640
- data/spec/integration/prepared_statement_test.rb +172 -172
- data/spec/integration/schema_test.rb +245 -245
- data/spec/integration/spec_helper.rb +1 -64
- data/spec/integration/timezone_test.rb +17 -17
- data/spec/integration/transaction_test.rb +87 -87
- data/spec/integration/type_test.rb +33 -33
- data/spec/model/association_reflection_spec.rb +130 -121
- data/spec/model/associations_spec.rb +1112 -1113
- data/spec/model/base_spec.rb +197 -196
- data/spec/model/class_dataset_methods_spec.rb +118 -118
- data/spec/model/dataset_methods_spec.rb +49 -49
- data/spec/model/eager_loading_spec.rb +705 -702
- data/spec/model/hooks_spec.rb +169 -168
- data/spec/model/inflector_spec.rb +5 -5
- data/spec/model/model_spec.rb +287 -297
- data/spec/model/plugins_spec.rb +47 -47
- data/spec/model/record_spec.rb +534 -535
- data/spec/model/spec_helper.rb +3 -21
- data/spec/model/validations_spec.rb +72 -70
- data/spec/spec_config.rb +8 -0
- metadata +41 -9
- data/lib/sequel/adapters/fdbsql.rb +0 -286
- data/lib/sequel/adapters/jdbc/fdbsql.rb +0 -66
- data/lib/sequel/adapters/openbase.rb +0 -54
- data/lib/sequel/adapters/shared/fdbsql.rb +0 -550
- data/spec/adapters/fdbsql_spec.rb +0 -429
- data/spec/rspec_helper.rb +0 -22
@@ -24,200 +24,200 @@ describe Sequel::Dataset, "graphing" do
|
|
24
24
|
o1 = @ds1.opts
|
25
25
|
o2 = o1.dup
|
26
26
|
ds1 = @ds1.graph(@ds2, :x=>:id)
|
27
|
-
@ds1.opts.
|
28
|
-
@ds1.opts.
|
29
|
-
ds1.opts.
|
27
|
+
@ds1.opts.must_equal o1
|
28
|
+
@ds1.opts.must_equal o2
|
29
|
+
ds1.opts.wont_equal o1
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should not modify the current dataset's opts if current dataset is already graphed" do
|
33
33
|
ds2 = @ds1.graph(@ds2)
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
@ds1.graph(@ds2)
|
35
|
+
ds2.graph(@ds3)
|
36
|
+
ds2.graph(@ds3)
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should accept a simple dataset and pass the table to join" do
|
40
40
|
ds = @ds1.graph(@ds2, :x=>:id)
|
41
|
-
ds.sql.
|
41
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
42
42
|
end
|
43
43
|
|
44
44
|
it "should use currently selected columns as the basis for the selected columns in a new graph" do
|
45
45
|
ds = @ds1.select(:id).graph(@ds2, :x=>:id)
|
46
|
-
ds.sql.
|
46
|
+
ds.sql.must_equal 'SELECT points.id, lines.id AS lines_id, lines.x, lines.y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
47
47
|
|
48
48
|
ds = @ds1.select(:id, :x).graph(@ds2, :x=>:id)
|
49
|
-
ds.sql.
|
49
|
+
ds.sql.must_equal 'SELECT points.id, points.x, lines.id AS lines_id, lines.x AS lines_x, lines.y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
50
50
|
|
51
51
|
ds = @ds1.select(Sequel.identifier(:id), Sequel.qualify(:points, :x)).graph(@ds2, :x=>:id)
|
52
|
-
ds.sql.
|
52
|
+
ds.sql.must_equal 'SELECT points.id, points.x, lines.id AS lines_id, lines.x AS lines_x, lines.y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
53
53
|
|
54
54
|
ds = @ds1.select(Sequel.identifier(:id).qualify(:points), Sequel.identifier(:x).as(:y)).graph(@ds2, :x=>:id)
|
55
|
-
ds.sql.
|
55
|
+
ds.sql.must_equal 'SELECT points.id, points.x AS y, lines.id AS lines_id, lines.x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
56
56
|
|
57
57
|
ds = @ds1.select(:id, Sequel.identifier(:x).qualify(Sequel.identifier(:points)).as(Sequel.identifier(:y))).graph(@ds2, :x=>:id)
|
58
|
-
ds.sql.
|
58
|
+
ds.sql.must_equal 'SELECT points.id, points.x AS y, lines.id AS lines_id, lines.x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should requalify currently selected columns in new graph if current dataset joins tables" do
|
62
62
|
ds = @ds1.cross_join(:lines).select(:points__id, :lines__id___lid, :lines__x, :lines__y).graph(@ds3, :x=>:id)
|
63
|
-
ds.sql.
|
63
|
+
ds.sql.must_equal 'SELECT points.id, points.lid, points.x, points.y, graphs.id AS graphs_id, graphs.name, graphs.x AS graphs_x, graphs.y AS graphs_y, graphs.lines_x FROM (SELECT points.id, lines.id AS lid, lines.x, lines.y FROM points CROSS JOIN lines) AS points LEFT OUTER JOIN graphs ON (graphs.x = points.id)'
|
64
64
|
end
|
65
65
|
|
66
66
|
it "should raise error if currently selected expressions cannot be handled" do
|
67
|
-
proc{@ds1.select(1).graph(@ds2, :x=>:id)}.
|
67
|
+
proc{@ds1.select(1).graph(@ds2, :x=>:id)}.must_raise(Sequel::Error)
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should accept a complex dataset and pass it directly to join" do
|
71
71
|
ds = @ds1.graph(@ds2.select_all(:lines), {:x=>:id})
|
72
|
-
ds.sql.
|
72
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should accept a complex dataset and pass it directly to join" do
|
76
76
|
ds = @ds1.graph(@ds2.filter(:x=>1), {:x=>:id})
|
77
|
-
ds.sql.
|
77
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, t1.id AS t1_id, t1.x AS t1_x, t1.y AS t1_y, t1.graph_id FROM points LEFT OUTER JOIN (SELECT * FROM lines WHERE (x = 1)) AS t1 ON (t1.x = points.id)'
|
78
78
|
ds = @ds1.graph(@ds2.select_all(:lines).filter(:x=>1), {:x=>:id})
|
79
|
-
ds.sql.
|
79
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, t1.id AS t1_id, t1.x AS t1_x, t1.y AS t1_y, t1.graph_id FROM points LEFT OUTER JOIN (SELECT lines.* FROM lines WHERE (x = 1)) AS t1 ON (t1.x = points.id)'
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should work on from_self datasets" do
|
83
83
|
ds = @ds1.from_self.graph(@ds2, :x=>:id)
|
84
|
-
ds.sql.
|
84
|
+
ds.sql.must_equal 'SELECT t1.id, t1.x, t1.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM (SELECT * FROM points) AS t1 LEFT OUTER JOIN lines ON (lines.x = t1.id)'
|
85
85
|
ds = @ds1.graph(@ds2.from_self, :x=>:id)
|
86
|
-
ds.sql.
|
86
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, t1.id AS t1_id, t1.x AS t1_x, t1.y AS t1_y, t1.graph_id FROM points LEFT OUTER JOIN (SELECT * FROM (SELECT * FROM lines) AS t1) AS t1 ON (t1.x = points.id)'
|
87
87
|
ds = @ds1.from_self.from_self.graph(@ds2.from_self.from_self, :x=>:id)
|
88
|
-
ds.sql.
|
88
|
+
ds.sql.must_equal 'SELECT t1.id, t1.x, t1.y, t2.id AS t2_id, t2.x AS t2_x, t2.y AS t2_y, t2.graph_id FROM (SELECT * FROM (SELECT * FROM points) AS t1) AS t1 LEFT OUTER JOIN (SELECT * FROM (SELECT * FROM (SELECT * FROM lines) AS t1) AS t1) AS t2 ON (t2.x = t1.id)'
|
89
89
|
ds = @ds1.from(@ds1, @ds3).graph(@ds2.from_self, :x=>:id)
|
90
|
-
ds.sql.
|
90
|
+
ds.sql.must_equal 'SELECT t1.id, t1.x, t1.y, t3.id AS t3_id, t3.x AS t3_x, t3.y AS t3_y, t3.graph_id FROM (SELECT * FROM (SELECT * FROM points) AS t1, (SELECT * FROM graphs) AS t2) AS t1 LEFT OUTER JOIN (SELECT * FROM (SELECT * FROM lines) AS t1) AS t3 ON (t3.x = t1.id)'
|
91
91
|
end
|
92
92
|
|
93
93
|
it "should accept a symbol table name as the dataset" do
|
94
94
|
ds = @ds1.graph(:lines, :x=>:id)
|
95
|
-
ds.sql.
|
95
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should accept a schema qualified symbolic table name as the dataset" do
|
99
99
|
ds = @ds1.graph(:schema__lines, :x=>:id)
|
100
|
-
ds.sql.
|
100
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN schema.lines AS lines ON (lines.x = points.id)'
|
101
101
|
end
|
102
102
|
|
103
103
|
it "allows giving table alias in symbolic argument" do
|
104
104
|
ds = @ds1.graph(:lines___sketch, :x=>:id)
|
105
|
-
ds.sql.
|
105
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, sketch.id AS sketch_id, sketch.x AS sketch_x, sketch.y AS sketch_y, sketch.graph_id FROM points LEFT OUTER JOIN lines AS sketch ON (sketch.x = points.id)'
|
106
106
|
ds = @ds1.graph(:schema__lines___sketch, :x=>:id)
|
107
|
-
ds.sql.
|
107
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, sketch.id AS sketch_id, sketch.x AS sketch_x, sketch.y AS sketch_y, sketch.graph_id FROM points LEFT OUTER JOIN schema.lines AS sketch ON (sketch.x = points.id)'
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should accept a SQL::Identifier as the dataset" do
|
111
111
|
ds = @ds1.graph(Sequel.identifier(:lines), :x=>:id)
|
112
|
-
ds.sql.
|
112
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
113
113
|
ds = @ds1.graph(Sequel.identifier('lines'), :x=>:id)
|
114
|
-
ds.sql.
|
114
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines AS lines ON (lines.x = points.id)'
|
115
115
|
end
|
116
116
|
|
117
117
|
it "should handle a SQL::Identifier with double underscores correctly" do
|
118
118
|
ds = @ds1.graph(Sequel.identifier(:lin__es), :x=>:id)
|
119
|
-
ds.sql.
|
119
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lin__es.id AS lin__es_id, lin__es.name, lin__es.x AS lin__es_x, lin__es.y AS lin__es_y, lin__es.lines_x FROM points LEFT OUTER JOIN lin__es ON (lin__es.x = points.id)'
|
120
120
|
ds = @ds1.from(Sequel.identifier(:poi__nts)).graph(Sequel.identifier(:lin__es), :x=>:id)
|
121
|
-
ds.sql.
|
121
|
+
ds.sql.must_equal 'SELECT poi__nts.id, poi__nts.name, poi__nts.x, poi__nts.y, poi__nts.lines_x, lin__es.id AS lin__es_id, lin__es.name AS lin__es_name, lin__es.x AS lin__es_x, lin__es.y AS lin__es_y, lin__es.lines_x AS lin__es_lines_x FROM poi__nts LEFT OUTER JOIN lin__es ON (lin__es.x = poi__nts.id)'
|
122
122
|
ds = @ds1.from(Sequel.identifier(:poi__nts).qualify(:foo)).graph(Sequel.identifier(:lin__es).qualify(:bar), :x=>:id)
|
123
|
-
ds.sql.
|
123
|
+
ds.sql.must_equal 'SELECT foo.poi__nts.id, foo.poi__nts.x, foo.poi__nts.y, foo.poi__nts.graph_id, lin__es.id AS lin__es_id, lin__es.name, lin__es.x AS lin__es_x, lin__es.y AS lin__es_y, lin__es.lines_x FROM foo.poi__nts LEFT OUTER JOIN bar.lin__es AS lin__es ON (lin__es.x = foo.poi__nts.id)'
|
124
124
|
end
|
125
125
|
|
126
126
|
it "should accept a SQL::QualifiedIdentifier as the dataset" do
|
127
127
|
ds = @ds1.graph(Sequel.qualify(:schema, :lines), :x=>:id)
|
128
|
-
ds.sql.
|
128
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN schema.lines AS lines ON (lines.x = points.id)'
|
129
129
|
ds = @ds1.graph(Sequel.qualify('schema', 'lines'), :x=>:id)
|
130
|
-
ds.sql.
|
130
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN schema.lines AS lines ON (lines.x = points.id)'
|
131
131
|
ds = @ds1.graph(Sequel.qualify(Sequel.identifier(:schema), Sequel.identifier(:lines)), :x=>:id)
|
132
|
-
ds.sql.
|
132
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN schema.lines AS lines ON (lines.x = points.id)'
|
133
133
|
ds = @ds1.graph(Sequel.qualify(Sequel.identifier('schema'), Sequel.identifier('lines')), :x=>:id)
|
134
|
-
ds.sql.
|
134
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN schema.lines AS lines ON (lines.x = points.id)'
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should handle a qualified identifier as the source" do
|
138
138
|
ds = @ds1.from(:schema__points).graph(:lines, :x=>:id)
|
139
|
-
ds.sql.
|
139
|
+
ds.sql.must_equal 'SELECT schema.points.id, schema.points.x, schema.points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM schema.points LEFT OUTER JOIN lines ON (lines.x = schema.points.id)'
|
140
140
|
ds = @ds1.from(Sequel.qualify(:schema, :points)).graph(:lines, :x=>:id)
|
141
|
-
ds.sql.
|
141
|
+
ds.sql.must_equal 'SELECT schema.points.id, schema.points.x, schema.points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM schema.points LEFT OUTER JOIN lines ON (lines.x = schema.points.id)'
|
142
142
|
end
|
143
143
|
|
144
144
|
it "should accept a SQL::AliasedExpression as the dataset" do
|
145
145
|
ds = @ds1.graph(Sequel.as(:lines, :foo), :x=>:id)
|
146
|
-
ds.sql.
|
146
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, foo.id AS foo_id, foo.x AS foo_x, foo.y AS foo_y, foo.graph_id FROM points LEFT OUTER JOIN lines AS foo ON (foo.x = points.id)'
|
147
147
|
ds = @ds1.graph(Sequel.as(:schema__lines, :foo), :x=>:id)
|
148
|
-
ds.sql.
|
148
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, foo.id AS foo_id, foo.x AS foo_x, foo.y AS foo_y, foo.graph_id FROM points LEFT OUTER JOIN schema.lines AS foo ON (foo.x = points.id)'
|
149
149
|
ds = @ds1.graph(Sequel.as(Sequel.identifier(:lines), :foo), :x=>:id)
|
150
|
-
ds.sql.
|
150
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, foo.id AS foo_id, foo.x AS foo_x, foo.y AS foo_y, foo.graph_id FROM points LEFT OUTER JOIN lines AS foo ON (foo.x = points.id)'
|
151
151
|
ds = @ds1.graph(Sequel.as(Sequel.qualify(:schema, :lines), :foo), :x=>:id)
|
152
|
-
ds.sql.
|
152
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, foo.id AS foo_id, foo.x AS foo_x, foo.y AS foo_y, foo.graph_id FROM points LEFT OUTER JOIN schema.lines AS foo ON (foo.x = points.id)'
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should raise an error if a symbol, dataset, or model is not used" do
|
156
|
-
proc{@ds1.graph(Object.new, :x=>:id)}.
|
156
|
+
proc{@ds1.graph(Object.new, :x=>:id)}.must_raise(Sequel::Error)
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should accept a :table_alias option" do
|
160
160
|
ds = @ds1.graph(:lines, {:x=>:id}, :table_alias=>:planes)
|
161
|
-
ds.sql.
|
161
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, planes.id AS planes_id, planes.x AS planes_x, planes.y AS planes_y, planes.graph_id FROM points LEFT OUTER JOIN lines AS planes ON (planes.x = points.id)'
|
162
162
|
end
|
163
163
|
|
164
164
|
it "should accept a :implicit_qualifier option" do
|
165
165
|
ds = @ds1.graph(:lines, {:x=>:id}, :implicit_qualifier=>:planes)
|
166
|
-
ds.sql.
|
166
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = planes.id)'
|
167
167
|
end
|
168
168
|
|
169
169
|
it "should accept a :join_type option" do
|
170
170
|
ds = @ds1.graph(:lines, {:x=>:id}, :join_type=>:inner)
|
171
|
-
ds.sql.
|
171
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points INNER JOIN lines ON (lines.x = points.id)'
|
172
172
|
end
|
173
173
|
|
174
174
|
it "should accept a :join_only option" do
|
175
175
|
ds = @ds1.graph(:lines, {:x=>:id}, :join_only=>true)
|
176
|
-
ds.sql.
|
176
|
+
ds.sql.must_equal 'SELECT * FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should not select any columns from the graphed table if :select option is false" do
|
180
180
|
ds = @ds1.graph(:lines, {:x=>:id}, :select=>false).graph(:graphs, :id=>:graph_id)
|
181
|
-
ds.sql.
|
181
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, graphs.id AS graphs_id, graphs.name, graphs.x AS graphs_x, graphs.y AS graphs_y, graphs.lines_x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN graphs ON (graphs.id = lines.graph_id)'
|
182
182
|
end
|
183
183
|
|
184
184
|
it "should use the given columns if :select option is used" do
|
185
185
|
ds = @ds1.graph(:lines, {:x=>:id}, :select=>[:x, :graph_id]).graph(:graphs, :id=>:graph_id)
|
186
|
-
ds.sql.
|
186
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.x AS lines_x, lines.graph_id, graphs.id AS graphs_id, graphs.name, graphs.x AS graphs_x, graphs.y AS graphs_y, graphs.lines_x AS graphs_lines_x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN graphs ON (graphs.id = lines.graph_id)'
|
187
187
|
end
|
188
188
|
|
189
189
|
it "should pass all join_conditions to join_table" do
|
190
190
|
ds = @ds1.graph(@ds2, [[:x, :id], [:y, :id]])
|
191
|
-
ds.sql.
|
191
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON ((lines.x = points.id) AND (lines.y = points.id))'
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should accept a block instead of conditions and pass it to join_table" do
|
195
195
|
ds = @ds1.graph(@ds2){|ja, lja, js| [[Sequel.qualify(ja, :x), Sequel.qualify(lja, :id)], [Sequel.qualify(ja, :y), Sequel.qualify(lja, :id)]]}
|
196
|
-
ds.sql.
|
196
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON ((lines.x = points.id) AND (lines.y = points.id))'
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should not add columns if graph is called after set_graph_aliases" do
|
200
200
|
ds = @ds1.set_graph_aliases([[:x,[:points, :x]], [:y,[:lines, :y]]])
|
201
|
-
ds.sql.
|
201
|
+
ds.sql.must_equal 'SELECT points.x, lines.y FROM points'
|
202
202
|
ds = ds.graph(:lines, :x=>:id)
|
203
|
-
ds.sql.
|
203
|
+
ds.sql.must_equal 'SELECT points.x, lines.y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should allow graphing of multiple datasets" do
|
207
207
|
ds = @ds1.graph(@ds2, :x=>:id).graph(@ds3, :id=>:graph_id)
|
208
|
-
ds.sql.
|
208
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id, graphs.id AS graphs_id, graphs.name, graphs.x AS graphs_x, graphs.y AS graphs_y, graphs.lines_x AS graphs_lines_x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN graphs ON (graphs.id = lines.graph_id)'
|
209
209
|
end
|
210
210
|
|
211
211
|
it "should allow graphing of the same dataset multiple times" do
|
212
212
|
ds = @ds1.graph(@ds2, :x=>:id).graph(@ds2, {:y=>:points__id}, :table_alias=>:graph)
|
213
|
-
ds.sql.
|
213
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id, graph.id AS graph_id_0, graph.x AS graph_x, graph.y AS graph_y, graph.graph_id AS graph_graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id) LEFT OUTER JOIN lines AS graph ON (graph.y = points.id)'
|
214
214
|
end
|
215
215
|
|
216
216
|
it "should raise an error if the table/table alias has already been used" do
|
217
|
-
proc{@ds1.graph(@ds1, :x=>:id)}.
|
218
|
-
|
219
|
-
proc{@ds1.graph(@ds2, :x=>:id).graph(@ds2, :x=>:id)}.
|
220
|
-
|
217
|
+
proc{@ds1.graph(@ds1, :x=>:id)}.must_raise(Sequel::Error)
|
218
|
+
@ds1.graph(@ds2, :x=>:id)
|
219
|
+
proc{@ds1.graph(@ds2, :x=>:id).graph(@ds2, :x=>:id)}.must_raise(Sequel::Error)
|
220
|
+
@ds1.graph(@ds2, :x=>:id).graph(@ds2, {:x=>:id}, :table_alias=>:blah)
|
221
221
|
end
|
222
222
|
end
|
223
223
|
|
@@ -226,51 +226,51 @@ describe Sequel::Dataset, "graphing" do
|
|
226
226
|
o1 = @ds1.opts
|
227
227
|
o2 = o1.dup
|
228
228
|
ds1 = @ds1.set_graph_aliases(:x=>[:graphs,:id])
|
229
|
-
@ds1.opts.
|
230
|
-
@ds1.opts.
|
231
|
-
ds1.opts.
|
229
|
+
@ds1.opts.must_equal o1
|
230
|
+
@ds1.opts.must_equal o2
|
231
|
+
ds1.opts.wont_equal o1
|
232
232
|
end
|
233
233
|
|
234
234
|
it "should specify the graph mapping" do
|
235
235
|
ds = @ds1.graph(:lines, :x=>:id)
|
236
|
-
ds.sql.
|
236
|
+
ds.sql.must_equal 'SELECT points.id, points.x, points.y, lines.id AS lines_id, lines.x AS lines_x, lines.y AS lines_y, lines.graph_id FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
237
237
|
ds = ds.set_graph_aliases(:x=>[:points, :x], :y=>[:lines, :y])
|
238
238
|
['SELECT points.x, lines.y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)',
|
239
239
|
'SELECT lines.y, points.x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
240
|
-
].
|
240
|
+
].must_include(ds.sql)
|
241
241
|
end
|
242
242
|
|
243
243
|
it "should allow a third entry to specify an expression to use other than the default" do
|
244
244
|
ds = @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :x, 1], :y=>[:lines, :y, Sequel.function(:random)])
|
245
245
|
['SELECT 1 AS x, random() AS y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)',
|
246
246
|
'SELECT random() AS y, 1 AS x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
247
|
-
].
|
247
|
+
].must_include(ds.sql)
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should allow a single array entry to specify a table, assuming the same column as the key" do
|
251
251
|
ds = @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points], :y=>[:lines])
|
252
252
|
['SELECT points.x, lines.y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)',
|
253
253
|
'SELECT lines.y, points.x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
254
|
-
].
|
254
|
+
].must_include(ds.sql)
|
255
255
|
end
|
256
256
|
|
257
257
|
it "should allow hash values to be symbols specifying table, assuming the same column as the key" do
|
258
258
|
ds = @ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>:points, :y=>:lines)
|
259
259
|
['SELECT points.x, lines.y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)',
|
260
260
|
'SELECT lines.y, points.x FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
261
|
-
].
|
261
|
+
].must_include(ds.sql)
|
262
262
|
end
|
263
263
|
|
264
264
|
it "should only alias columns if necessary" do
|
265
265
|
ds = @ds1.set_graph_aliases(:x=>[:points, :x], :y=>[:lines, :y])
|
266
266
|
['SELECT points.x, lines.y FROM points',
|
267
267
|
'SELECT lines.y, points.x FROM points'
|
268
|
-
].
|
268
|
+
].must_include(ds.sql)
|
269
269
|
|
270
270
|
ds = @ds1.set_graph_aliases(:x1=>[:points, :x], :y=>[:lines, :y])
|
271
271
|
['SELECT points.x AS x1, lines.y FROM points',
|
272
272
|
'SELECT lines.y, points.x AS x1 FROM points'
|
273
|
-
].
|
273
|
+
].must_include(ds.sql)
|
274
274
|
end
|
275
275
|
end
|
276
276
|
|
@@ -280,24 +280,24 @@ describe Sequel::Dataset, "graphing" do
|
|
280
280
|
o1 = ds1.opts
|
281
281
|
o2 = o1.dup
|
282
282
|
ds2 = ds1.add_graph_aliases(:y=>[:blah,:id])
|
283
|
-
ds1.opts.
|
284
|
-
ds1.opts.
|
285
|
-
ds2.opts.
|
283
|
+
ds1.opts.must_equal o1
|
284
|
+
ds1.opts.must_equal o2
|
285
|
+
ds2.opts.wont_equal o1
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should add columns to the graph mapping" do
|
289
|
-
@ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :q]).add_graph_aliases(:y=>[:lines, :r]).sql.
|
289
|
+
@ds1.graph(:lines, :x=>:id).set_graph_aliases(:x=>[:points, :q]).add_graph_aliases(:y=>[:lines, :r]).sql.must_equal 'SELECT points.q AS x, lines.r AS y FROM points LEFT OUTER JOIN lines ON (lines.x = points.id)'
|
290
290
|
end
|
291
291
|
|
292
292
|
it "should raise an error if called without existing graph aliases" do
|
293
|
-
proc{@ds1.add_graph_aliases(:y=>[:lines, :r])}.
|
293
|
+
proc{@ds1.add_graph_aliases(:y=>[:lines, :r])}.must_raise(Sequel::Error)
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
297
|
describe "#ungraphed" do
|
298
298
|
it "should remove the splitting of result sets into component tables" do
|
299
299
|
@db.fetch = {:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}
|
300
|
-
@ds1.graph(@ds2, :x=>:id).ungraphed.all.
|
300
|
+
@ds1.graph(@ds2, :x=>:id).ungraphed.all.must_equal [{:id=>1,:x=>2,:y=>3,:lines_id=>4,:lines_x=>5,:lines_y=>6,:graph_id=>7}]
|
301
301
|
end
|
302
302
|
end
|
303
303
|
end
|
@@ -9,147 +9,147 @@ describe "Dataset::PlaceholderLiteralizer" do
|
|
9
9
|
@ds.db.fetch = @h
|
10
10
|
end
|
11
11
|
|
12
|
-
|
12
|
+
it "should handle calls with no placeholders" do
|
13
13
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>1)}
|
14
|
-
loader.first.
|
15
|
-
@db.sqls.
|
14
|
+
loader.first.must_equal @h
|
15
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)"]
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
it "should handle calls with a single placeholder" do
|
19
19
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
20
|
-
loader.first(1).
|
21
|
-
loader.first(2).
|
22
|
-
@db.sqls.
|
20
|
+
loader.first(1).must_equal @h
|
21
|
+
loader.first(2).must_equal @h
|
22
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)", "SELECT * FROM items WHERE (a = 2)"]
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
it "should handle calls with multiple placeholders" do
|
26
26
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg).where(:b=>Sequel.+(pl.arg, 1)).where(pl.arg)}
|
27
|
-
loader.first(1, :c, :id=>1).
|
28
|
-
loader.first(2, :d, :id=>2).
|
29
|
-
@db.sqls.
|
27
|
+
loader.first(1, :c, :id=>1).must_equal @h
|
28
|
+
loader.first(2, :d, :id=>2).must_equal @h
|
29
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE ((a = 1) AND (b = (c + 1)) AND (id = 1))", "SELECT * FROM items WHERE ((a = 2) AND (b = (d + 1)) AND (id = 2))"]
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
it "should handle calls with placeholders and delayed arguments" do
|
33
33
|
h = :h
|
34
34
|
s = :s
|
35
35
|
d = @ds.having(Sequel.delay{h}).select(Sequel.delay{s})
|
36
36
|
loader = @c.loader(d){|pl, ds| ds.where(:a=>pl.arg).where(:b=>Sequel.+(pl.arg, 1)).where(pl.arg)}
|
37
|
-
loader.first(1, :c, :id=>1).
|
37
|
+
loader.first(1, :c, :id=>1).must_equal @h
|
38
38
|
h = :h2
|
39
39
|
s = :s2
|
40
|
-
loader.first(2, :d, :id=>2).
|
41
|
-
@db.sqls.
|
40
|
+
loader.first(2, :d, :id=>2).must_equal @h
|
41
|
+
@db.sqls.must_equal ["SELECT s FROM items WHERE ((a = 1) AND (b = (c + 1)) AND (id = 1)) HAVING h", "SELECT s2 FROM items WHERE ((a = 2) AND (b = (d + 1)) AND (id = 2)) HAVING h2"]
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
it "should handle calls with placeholders and delayed arguments that take dataset argument" do
|
45
45
|
d = @ds.select(Sequel.delay{|ds| ds.first_source})
|
46
46
|
loader = @c.loader(d){|pl, ds| ds.where(:a=>pl.arg).where(:b=>Sequel.+(pl.arg, 1)).where(pl.arg)}
|
47
|
-
loader.first(1, :c, :id=>1).
|
48
|
-
loader.first(2, :d, :id=>2).
|
49
|
-
@db.sqls.
|
47
|
+
loader.first(1, :c, :id=>1).must_equal @h
|
48
|
+
loader.first(2, :d, :id=>2).must_equal @h
|
49
|
+
@db.sqls.must_equal ["SELECT items FROM items WHERE ((a = 1) AND (b = (c + 1)) AND (id = 1))", "SELECT items FROM items WHERE ((a = 2) AND (b = (d + 1)) AND (id = 2))"]
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
it "should handle calls with a placeholders used as filter arguments" do
|
53
53
|
loader = @c.loader(@ds){|pl, ds| ds.where(pl.arg)}
|
54
|
-
loader.first(:id=>1).
|
55
|
-
loader.first(proc{a(b)}).
|
56
|
-
loader.first("a = 1").
|
57
|
-
@db.sqls.
|
54
|
+
loader.first(:id=>1).must_equal @h
|
55
|
+
loader.first(proc{a(b)}).must_equal @h
|
56
|
+
loader.first("a = 1").must_equal @h
|
57
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (id = 1)", "SELECT * FROM items WHERE a(b)", "SELECT * FROM items WHERE (a = 1)"]
|
58
58
|
end
|
59
59
|
|
60
|
-
|
60
|
+
it "should handle calls with a placeholders used as right hand side of condition specifiers" do
|
61
61
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
62
|
-
loader.first(1).
|
63
|
-
loader.first([1, 2]).
|
64
|
-
loader.first(nil).
|
65
|
-
@db.sqls.
|
62
|
+
loader.first(1).must_equal @h
|
63
|
+
loader.first([1, 2]).must_equal @h
|
64
|
+
loader.first(nil).must_equal @h
|
65
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)", "SELECT * FROM items WHERE (a IN (1, 2))", "SELECT * FROM items WHERE (a IS NULL)"]
|
66
66
|
end
|
67
67
|
|
68
|
-
|
68
|
+
it "should handle calls with a placeholder used multiple times" do
|
69
69
|
loader = @c.loader(@ds){|pl, ds| a = pl.arg; ds.where(:a=>a).where(:b=>a)}
|
70
|
-
loader.first(1).
|
71
|
-
loader.first(2).
|
72
|
-
@db.sqls.
|
70
|
+
loader.first(1).must_equal @h
|
71
|
+
loader.first(2).must_equal @h
|
72
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE ((a = 1) AND (b = 1))", "SELECT * FROM items WHERE ((a = 2) AND (b = 2))"]
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
it "should handle calls with a placeholder used multiple times in different capacities" do
|
76
76
|
loader = @c.loader(@ds){|pl, ds| a = pl.arg; ds.where(a).where(:b=>a)}
|
77
|
-
loader.first("a = 1").
|
78
|
-
loader.first(["a = ?", 2]).
|
79
|
-
@db.sqls.
|
77
|
+
loader.first("a = 1").must_equal @h
|
78
|
+
loader.first(["a = ?", 2]).must_equal @h
|
79
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE ((a = 1) AND (b = 'a = 1'))", "SELECT * FROM items WHERE ((a = 2) AND (b IN ('a = ?', 2)))"]
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
it "should handle calls with manually specified argument positions" do
|
83
83
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg(1)).where(:b=>pl.arg(0))}
|
84
|
-
loader.first(1, 2).
|
85
|
-
loader.first(2, 1).
|
86
|
-
@db.sqls.
|
84
|
+
loader.first(1, 2).must_equal @h
|
85
|
+
loader.first(2, 1).must_equal @h
|
86
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE ((a = 2) AND (b = 1))", "SELECT * FROM items WHERE ((a = 1) AND (b = 2))"]
|
87
87
|
end
|
88
88
|
|
89
|
-
|
89
|
+
it "should handle dataset with row procs" do
|
90
90
|
@ds.row_proc = proc{|r| {:foo=>r[:id]+1}}
|
91
91
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
92
|
-
loader.first(1).
|
93
|
-
@db.sqls.
|
92
|
+
loader.first(1).must_equal(:foo=>2)
|
93
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)"]
|
94
94
|
end
|
95
95
|
|
96
|
-
|
96
|
+
it "should return all rows for #all" do
|
97
97
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
98
|
-
loader.all(1).
|
99
|
-
@db.sqls.
|
98
|
+
loader.all(1).must_equal [@h]
|
99
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)"]
|
100
100
|
end
|
101
101
|
|
102
|
-
|
102
|
+
it "should iterate over block for #all" do
|
103
103
|
a = []
|
104
104
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
105
|
-
loader.all(1){|r| a << r}.
|
106
|
-
a.
|
107
|
-
@db.sqls.
|
105
|
+
loader.all(1){|r| a << r}.must_equal [@h]
|
106
|
+
a.must_equal [@h]
|
107
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)"]
|
108
108
|
end
|
109
109
|
|
110
|
-
|
110
|
+
it "should iterate over block for #each" do
|
111
111
|
a = []
|
112
112
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
113
113
|
loader.each(1){|r| a << r}
|
114
|
-
a.
|
115
|
-
@db.sqls.
|
114
|
+
a.must_equal [@h]
|
115
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)"]
|
116
116
|
end
|
117
117
|
|
118
|
-
|
118
|
+
it "should return first value for #get" do
|
119
119
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
120
|
-
loader.get(2).
|
121
|
-
@db.sqls.
|
120
|
+
loader.get(2).must_equal 1
|
121
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 2)"]
|
122
122
|
end
|
123
123
|
|
124
|
-
|
124
|
+
it "should support modifying dataset used on per-call basis with #run" do
|
125
125
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
126
126
|
loader.with_dataset do |ds|
|
127
127
|
ds = ds.clone
|
128
128
|
ds.row_proc = lambda{|row| [row]}
|
129
129
|
ds
|
130
|
-
end.all(1).
|
131
|
-
@db.sqls.
|
130
|
+
end.all(1).must_equal [[@h]]
|
131
|
+
@db.sqls.must_equal ["SELECT * FROM items WHERE (a = 1)"]
|
132
132
|
end
|
133
133
|
|
134
|
-
|
134
|
+
it "should literalize args as NULL if :placeholder_literal_null is set" do
|
135
135
|
loader = @c.loader(@ds){|pl, ds| ds.where(pl.arg=>:a).clone(:placeholder_literal_null=>true)}
|
136
|
-
loader.sql(1).
|
136
|
+
loader.sql(1).must_equal "SELECT * FROM items WHERE (NULL = a)"
|
137
137
|
end
|
138
138
|
|
139
|
-
|
139
|
+
it "should raise an error if called with an incorrect number of arguments" do
|
140
140
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg)}
|
141
|
-
proc{loader.first}.
|
142
|
-
proc{loader.first(1, 2)}.
|
141
|
+
proc{loader.first}.must_raise(Sequel::Error)
|
142
|
+
proc{loader.first(1, 2)}.must_raise(Sequel::Error)
|
143
143
|
end
|
144
144
|
|
145
|
-
|
145
|
+
it "should raise an error if called with an incorrect number of arguments when manually providing argument positions" do
|
146
146
|
loader = @c.loader(@ds){|pl, ds| ds.where(:a=>pl.arg(1))}
|
147
|
-
proc{loader.first}.
|
148
|
-
proc{loader.first(1)}.
|
149
|
-
proc{loader.first(1, 2, 3)}.
|
147
|
+
proc{loader.first}.must_raise(Sequel::Error)
|
148
|
+
proc{loader.first(1)}.must_raise(Sequel::Error)
|
149
|
+
proc{loader.first(1, 2, 3)}.must_raise(Sequel::Error)
|
150
150
|
end
|
151
151
|
|
152
|
-
|
152
|
+
it "should raise an error if argument literalized into a different string than returned by query" do
|
153
153
|
o = Object.new
|
154
154
|
def o.wrap(v)
|
155
155
|
@v = v
|
@@ -158,6 +158,6 @@ describe "Dataset::PlaceholderLiteralizer" do
|
|
158
158
|
def o.sql_literal(ds)
|
159
159
|
ds.literal(@v)
|
160
160
|
end
|
161
|
-
proc{@c.loader(@ds){|pl, ds| ds.where(o.wrap(pl.arg))}}.
|
161
|
+
proc{@c.loader(@ds){|pl, ds| ds.where(o.wrap(pl.arg))}}.must_raise(Sequel::Error)
|
162
162
|
end
|
163
163
|
end
|