sequel 4.46.0 → 4.49.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +210 -0
- data/Rakefile +1 -1
- data/doc/advanced_associations.rdoc +1 -1
- data/doc/opening_databases.rdoc +3 -2
- data/doc/release_notes/4.47.0.txt +56 -0
- data/doc/release_notes/4.48.0.txt +293 -0
- data/doc/release_notes/4.49.0.txt +222 -0
- data/lib/sequel/adapters/ado/access.rb +2 -1
- data/lib/sequel/adapters/do/postgres.rb +5 -2
- data/lib/sequel/adapters/ibmdb.rb +30 -8
- data/lib/sequel/adapters/jdbc/as400.rb +1 -1
- data/lib/sequel/adapters/jdbc/db2.rb +12 -3
- data/lib/sequel/adapters/jdbc/derby.rb +4 -5
- data/lib/sequel/adapters/jdbc/h2.rb +10 -1
- data/lib/sequel/adapters/jdbc/oracle.rb +16 -2
- data/lib/sequel/adapters/jdbc/postgresql.rb +46 -20
- data/lib/sequel/adapters/jdbc/sqlanywhere.rb +9 -7
- data/lib/sequel/adapters/jdbc/sqlserver.rb +20 -6
- data/lib/sequel/adapters/jdbc.rb +39 -23
- data/lib/sequel/adapters/mock.rb +27 -19
- data/lib/sequel/adapters/mysql.rb +17 -16
- data/lib/sequel/adapters/mysql2.rb +5 -6
- data/lib/sequel/adapters/oracle.rb +5 -9
- data/lib/sequel/adapters/postgres.rb +91 -103
- data/lib/sequel/adapters/shared/db2.rb +22 -6
- data/lib/sequel/adapters/shared/mssql.rb +5 -4
- data/lib/sequel/adapters/shared/mysql.rb +79 -25
- data/lib/sequel/adapters/shared/oracle.rb +26 -3
- data/lib/sequel/adapters/shared/postgres.rb +199 -95
- data/lib/sequel/adapters/shared/sqlanywhere.rb +23 -10
- data/lib/sequel/adapters/shared/sqlite.rb +72 -82
- data/lib/sequel/adapters/sqlanywhere.rb +4 -1
- data/lib/sequel/adapters/sqlite.rb +5 -3
- data/lib/sequel/adapters/swift/postgres.rb +5 -2
- data/lib/sequel/adapters/tinytds.rb +0 -5
- data/lib/sequel/adapters/utils/mysql_mysql2.rb +1 -1
- data/lib/sequel/adapters/utils/pg_types.rb +2 -76
- data/lib/sequel/ast_transformer.rb +1 -1
- data/lib/sequel/connection_pool/sharded_single.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +1 -1
- data/lib/sequel/connection_pool/single.rb +2 -2
- data/lib/sequel/connection_pool/threaded.rb +2 -2
- data/lib/sequel/connection_pool.rb +9 -2
- data/lib/sequel/core.rb +2 -2
- data/lib/sequel/database/connecting.rb +8 -8
- data/lib/sequel/database/dataset.rb +6 -3
- data/lib/sequel/database/dataset_defaults.rb +14 -1
- data/lib/sequel/database/misc.rb +1 -1
- data/lib/sequel/database/query.rb +3 -0
- data/lib/sequel/database/schema_methods.rb +1 -1
- data/lib/sequel/dataset/actions.rb +72 -10
- data/lib/sequel/dataset/dataset_module.rb +58 -0
- data/lib/sequel/dataset/graph.rb +1 -1
- data/lib/sequel/dataset/misc.rb +1 -0
- data/lib/sequel/dataset/prepared_statements.rb +3 -3
- data/lib/sequel/dataset/query.rb +22 -11
- data/lib/sequel/dataset.rb +1 -1
- data/lib/sequel/exceptions.rb +8 -0
- data/lib/sequel/extensions/_model_pg_row.rb +5 -2
- data/lib/sequel/extensions/core_extensions.rb +4 -1
- data/lib/sequel/extensions/current_datetime_timestamp.rb +2 -1
- data/lib/sequel/extensions/date_arithmetic.rb +1 -0
- data/lib/sequel/extensions/duplicate_columns_handler.rb +3 -3
- data/lib/sequel/extensions/empty_array_ignore_nulls.rb +3 -0
- data/lib/sequel/extensions/filter_having.rb +2 -0
- data/lib/sequel/extensions/freeze_datasets.rb +2 -0
- data/lib/sequel/extensions/from_block.rb +1 -1
- data/lib/sequel/extensions/graph_each.rb +2 -2
- data/lib/sequel/extensions/hash_aliases.rb +2 -0
- data/lib/sequel/extensions/identifier_mangling.rb +0 -7
- data/lib/sequel/extensions/meta_def.rb +2 -0
- data/lib/sequel/extensions/migration.rb +11 -8
- data/lib/sequel/extensions/no_auto_literal_strings.rb +1 -1
- data/lib/sequel/extensions/null_dataset.rb +1 -0
- data/lib/sequel/extensions/pagination.rb +1 -1
- data/lib/sequel/extensions/pg_array.rb +207 -130
- data/lib/sequel/extensions/pg_hstore.rb +38 -20
- data/lib/sequel/extensions/pg_inet.rb +18 -6
- data/lib/sequel/extensions/pg_interval.rb +19 -12
- data/lib/sequel/extensions/pg_json.rb +25 -14
- data/lib/sequel/extensions/pg_json_ops.rb +2 -2
- data/lib/sequel/extensions/pg_range.rb +133 -100
- data/lib/sequel/extensions/pg_range_ops.rb +4 -3
- data/lib/sequel/extensions/pg_row.rb +68 -39
- data/lib/sequel/extensions/pg_row_ops.rb +11 -5
- data/lib/sequel/extensions/query_literals.rb +2 -0
- data/lib/sequel/extensions/ruby18_symbol_extensions.rb +2 -0
- data/lib/sequel/extensions/s.rb +1 -1
- data/lib/sequel/extensions/schema_dumper.rb +29 -25
- data/lib/sequel/extensions/sequel_3_dataset_methods.rb +3 -1
- data/lib/sequel/extensions/sequel_4_dataset_methods.rb +83 -0
- data/lib/sequel/extensions/server_block.rb +32 -15
- data/lib/sequel/extensions/set_overrides.rb +2 -2
- data/lib/sequel/extensions/string_agg.rb +0 -1
- data/lib/sequel/extensions/symbol_aref.rb +0 -4
- data/lib/sequel/model/associations.rb +35 -7
- data/lib/sequel/model/base.rb +113 -87
- data/lib/sequel/model/dataset_module.rb +5 -43
- data/lib/sequel/model/errors.rb +2 -1
- data/lib/sequel/model/inflections.rb +17 -5
- data/lib/sequel/model.rb +26 -58
- data/lib/sequel/plugins/active_model.rb +2 -2
- data/lib/sequel/plugins/association_autoreloading.rb +2 -0
- data/lib/sequel/plugins/association_dependencies.rb +3 -3
- data/lib/sequel/plugins/association_pks.rb +73 -46
- data/lib/sequel/plugins/association_proxies.rb +1 -1
- data/lib/sequel/plugins/auto_validations.rb +6 -2
- data/lib/sequel/plugins/boolean_readers.rb +2 -2
- data/lib/sequel/plugins/boolean_subsets.rb +1 -1
- data/lib/sequel/plugins/caching.rb +19 -13
- data/lib/sequel/plugins/class_table_inheritance.rb +24 -13
- data/lib/sequel/plugins/column_conflicts.rb +7 -2
- data/lib/sequel/plugins/column_select.rb +3 -3
- data/lib/sequel/plugins/composition.rb +2 -2
- data/lib/sequel/plugins/csv_serializer.rb +8 -8
- data/lib/sequel/plugins/dataset_associations.rb +25 -13
- data/lib/sequel/plugins/defaults_setter.rb +13 -1
- data/lib/sequel/plugins/eager_each.rb +1 -1
- data/lib/sequel/plugins/force_encoding.rb +2 -2
- data/lib/sequel/plugins/hook_class_methods.rb +9 -12
- data/lib/sequel/plugins/identifier_columns.rb +2 -0
- data/lib/sequel/plugins/instance_filters.rb +3 -1
- data/lib/sequel/plugins/instance_hooks.rb +17 -9
- data/lib/sequel/plugins/json_serializer.rb +19 -12
- data/lib/sequel/plugins/lazy_attributes.rb +8 -7
- data/lib/sequel/plugins/many_to_one_pk_lookup.rb +2 -0
- data/lib/sequel/plugins/modification_detection.rb +3 -0
- data/lib/sequel/plugins/nested_attributes.rb +6 -2
- data/lib/sequel/plugins/pg_array_associations.rb +5 -0
- data/lib/sequel/plugins/pg_row.rb +4 -2
- data/lib/sequel/plugins/pg_typecast_on_load.rb +2 -0
- data/lib/sequel/plugins/prepared_statements.rb +1 -0
- data/lib/sequel/plugins/rcte_tree.rb +4 -24
- data/lib/sequel/plugins/serialization.rb +9 -15
- data/lib/sequel/plugins/single_table_inheritance.rb +8 -3
- data/lib/sequel/plugins/split_values.rb +6 -5
- data/lib/sequel/plugins/static_cache.rb +31 -25
- data/lib/sequel/plugins/subset_conditions.rb +3 -1
- data/lib/sequel/plugins/table_select.rb +1 -1
- data/lib/sequel/plugins/touch.rb +4 -2
- data/lib/sequel/plugins/validation_class_methods.rb +5 -6
- data/lib/sequel/plugins/validation_helpers.rb +14 -8
- data/lib/sequel/plugins/xml_serializer.rb +4 -4
- data/lib/sequel/sql.rb +18 -9
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/db2_spec.rb +115 -14
- data/spec/adapters/mssql_spec.rb +4 -4
- data/spec/adapters/mysql_spec.rb +83 -29
- data/spec/adapters/oracle_spec.rb +28 -24
- data/spec/adapters/postgres_spec.rb +40 -24
- data/spec/adapters/sqlanywhere_spec.rb +88 -86
- data/spec/adapters/sqlite_spec.rb +29 -24
- data/spec/bin_spec.rb +7 -1
- data/spec/core/connection_pool_spec.rb +45 -14
- data/spec/core/database_spec.rb +155 -0
- data/spec/core/dataset_spec.rb +219 -36
- data/spec/core/schema_spec.rb +16 -0
- data/spec/core/spec_helper.rb +1 -0
- data/spec/core_extensions_spec.rb +6 -2
- data/spec/extensions/active_model_spec.rb +1 -1
- data/spec/extensions/arbitrary_servers_spec.rb +1 -1
- data/spec/extensions/association_pks_spec.rb +34 -2
- data/spec/extensions/auto_literal_strings_spec.rb +5 -1
- data/spec/extensions/auto_validations_spec.rb +2 -0
- data/spec/extensions/boolean_readers_spec.rb +1 -1
- data/spec/extensions/boolean_subsets_spec.rb +1 -1
- data/spec/extensions/class_table_inheritance_spec.rb +106 -19
- data/spec/extensions/column_conflicts_spec.rb +11 -0
- data/spec/extensions/column_select_spec.rb +1 -0
- data/spec/extensions/composition_spec.rb +13 -0
- data/spec/extensions/connection_validator_spec.rb +1 -1
- data/spec/extensions/dataset_associations_spec.rb +20 -8
- data/spec/extensions/defaults_setter_spec.rb +15 -1
- data/spec/extensions/filter_having_spec.rb +5 -3
- data/spec/extensions/hash_aliases_spec.rb +3 -1
- data/spec/extensions/identifier_columns_spec.rb +3 -1
- data/spec/extensions/implicit_subquery_spec.rb +4 -2
- data/spec/extensions/json_serializer_spec.rb +18 -0
- data/spec/extensions/lazy_attributes_spec.rb +3 -3
- data/spec/extensions/many_through_many_spec.rb +4 -4
- data/spec/extensions/meta_def_spec.rb +9 -0
- data/spec/extensions/migration_spec.rb +3 -3
- data/spec/extensions/nested_attributes_spec.rb +14 -3
- data/spec/extensions/no_auto_literal_strings_spec.rb +8 -4
- data/spec/extensions/null_dataset_spec.rb +1 -1
- data/spec/extensions/pg_array_associations_spec.rb +29 -18
- data/spec/extensions/pg_array_spec.rb +44 -25
- data/spec/extensions/pg_hstore_spec.rb +10 -0
- data/spec/extensions/pg_inet_spec.rb +26 -0
- data/spec/extensions/pg_interval_spec.rb +20 -0
- data/spec/extensions/pg_json_spec.rb +24 -0
- data/spec/extensions/pg_range_spec.rb +98 -14
- data/spec/extensions/pg_row_spec.rb +14 -4
- data/spec/extensions/pg_typecast_on_load_spec.rb +11 -9
- data/spec/extensions/prepared_statements_safe_spec.rb +1 -1
- data/spec/extensions/query_literals_spec.rb +3 -1
- data/spec/extensions/schema_dumper_spec.rb +108 -94
- data/spec/extensions/sequel_3_dataset_methods_spec.rb +10 -6
- data/spec/extensions/sequel_4_dataset_methods_spec.rb +121 -0
- data/spec/extensions/serialization_spec.rb +1 -1
- data/spec/extensions/server_block_spec.rb +7 -0
- data/spec/extensions/single_table_inheritance_spec.rb +17 -1
- data/spec/extensions/spec_helper.rb +7 -1
- data/spec/extensions/static_cache_spec.rb +75 -24
- data/spec/extensions/string_agg_spec.rb +1 -1
- data/spec/extensions/touch_spec.rb +9 -0
- data/spec/extensions/validation_helpers_spec.rb +10 -5
- data/spec/extensions/whitelist_security_spec.rb +26 -0
- data/spec/integration/associations_test.rb +8 -0
- data/spec/integration/dataset_test.rb +45 -44
- data/spec/integration/model_test.rb +53 -4
- data/spec/integration/plugin_test.rb +28 -4
- data/spec/integration/prepared_statement_test.rb +3 -0
- data/spec/integration/schema_test.rb +21 -1
- data/spec/integration/transaction_test.rb +40 -40
- data/spec/model/association_reflection_spec.rb +43 -1
- data/spec/model/associations_spec.rb +29 -9
- data/spec/model/class_dataset_methods_spec.rb +20 -4
- data/spec/model/dataset_methods_spec.rb +12 -3
- data/spec/model/eager_loading_spec.rb +8 -8
- data/spec/model/model_spec.rb +45 -1
- data/spec/model/plugins_spec.rb +34 -0
- data/spec/model/record_spec.rb +1 -1
- data/spec/spec_config.rb +2 -0
- metadata +11 -4
- data/spec/adapters/firebird_spec.rb +0 -405
- data/spec/adapters/informix_spec.rb +0 -100
@@ -8,6 +8,13 @@ with_server_specs = shared_description do
|
|
8
8
|
@db.sqls.must_equal ["SELECT * FROM t -- b"]
|
9
9
|
end
|
10
10
|
|
11
|
+
it "should set the default server to use in the block" do
|
12
|
+
@db.with_server(:a, :b){@db[:t].all}
|
13
|
+
@db.sqls.must_equal ["SELECT * FROM t -- b"]
|
14
|
+
@db.with_server(:a, :b){@db[:t].insert}
|
15
|
+
@db.sqls.must_equal ["INSERT INTO t DEFAULT VALUES -- a"]
|
16
|
+
end
|
17
|
+
|
11
18
|
it "should have no affect after the block" do
|
12
19
|
@db.with_server(:a){@db[:t].all}
|
13
20
|
@db.sqls.must_equal ["SELECT * FROM t -- a"]
|
@@ -19,6 +19,22 @@ describe Sequel::Model, "single table inheritance plugin" do
|
|
19
19
|
Object.send(:remove_const, :StiTest)
|
20
20
|
end
|
21
21
|
|
22
|
+
describe ".sti_load" do
|
23
|
+
it "should load instances of the correct type" do
|
24
|
+
StiTest.sti_load(:id => 3).must_be_instance_of StiTest
|
25
|
+
StiTest.sti_load(:id => 3, :kind => 'StiTestSub1').must_be_instance_of StiTestSub1
|
26
|
+
StiTest.sti_load(:id => 3, :kind => 'StiTestSub2').must_be_instance_of StiTestSub2
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".sti_class_from_sti_key" do
|
31
|
+
it "should load the correct subclass based on the key" do
|
32
|
+
StiTest.sti_class_from_sti_key('StiTest').must_equal StiTest
|
33
|
+
StiTest.sti_class_from_sti_key('StiTestSub1').must_equal StiTestSub1
|
34
|
+
StiTest.sti_class_from_sti_key('StiTestSub2').must_equal StiTestSub2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
22
38
|
it "should freeze sti metadata when freezing model class" do
|
23
39
|
StiTest.freeze
|
24
40
|
StiTest.sti_dataset.frozen?.must_equal true
|
@@ -90,7 +106,7 @@ describe Sequel::Model, "single table inheritance plugin" do
|
|
90
106
|
|
91
107
|
it "should fallback to the main class if the sti_key field is empty or nil without calling constantize" do
|
92
108
|
called = false
|
93
|
-
StiTest.
|
109
|
+
def StiTest.constantize(s)
|
94
110
|
called = true
|
95
111
|
Object
|
96
112
|
end
|
@@ -28,13 +28,19 @@ rescue LoadError
|
|
28
28
|
nil
|
29
29
|
end
|
30
30
|
|
31
|
-
Sequel.extension :meta_def
|
32
31
|
Sequel.extension :core_refinements if RUBY_VERSION >= '2.0.0' && RUBY_ENGINE == 'ruby'
|
33
32
|
|
34
33
|
def skip_warn(s)
|
35
34
|
warn "Skipping test of #{s}" if ENV["SKIPPED_TEST_WARN"]
|
36
35
|
end
|
37
36
|
|
37
|
+
class Minitest::HooksSpec
|
38
|
+
# SEQUEL5: Replace with define_singleton_method
|
39
|
+
def meta_def(obj, name, &block)
|
40
|
+
(class << obj; self end).send(:define_method, name, &block)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
38
44
|
# SEQUEL5: Remove
|
39
45
|
output = Sequel::Deprecation.output
|
40
46
|
Sequel::Deprecation.output = nil
|
@@ -113,35 +113,58 @@ describe "Sequel::Plugins::StaticCache" do
|
|
113
113
|
@c.all.must_equal [@c1, @c2]
|
114
114
|
end
|
115
115
|
|
116
|
-
it "should have to_hash without arguments run without a query" do
|
116
|
+
it "should have as_hash/to_hash without arguments run without a query" do
|
117
117
|
a = @c.to_hash
|
118
118
|
a.must_equal(1=>@c1, 2=>@c2)
|
119
119
|
a[1].must_equal @c1
|
120
120
|
a[2].must_equal @c2
|
121
|
+
|
122
|
+
a = @c.as_hash
|
123
|
+
a.must_equal(1=>@c1, 2=>@c2)
|
124
|
+
a[1].must_equal @c1
|
125
|
+
a[2].must_equal @c2
|
126
|
+
@db.sqls.must_equal []
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should have as_hash handle :hash option" do
|
130
|
+
h = {}
|
131
|
+
a = @c.as_hash(nil, nil, :hash=>h)
|
132
|
+
a.must_be_same_as h
|
133
|
+
a.must_equal(1=>@c1, 2=>@c2)
|
134
|
+
a[1].must_equal @c1
|
135
|
+
a[2].must_equal @c2
|
136
|
+
|
137
|
+
h = {}
|
138
|
+
a = @c.as_hash(:id, nil, :hash=>h)
|
139
|
+
a.must_be_same_as h
|
140
|
+
a.must_equal(1=>@c1, 2=>@c2)
|
141
|
+
a[1].must_equal @c1
|
142
|
+
a[2].must_equal @c2
|
143
|
+
|
121
144
|
@db.sqls.must_equal []
|
122
145
|
end
|
123
146
|
|
124
|
-
it "should have
|
125
|
-
a = @c.
|
147
|
+
it "should have as_hash with arguments return results without a query" do
|
148
|
+
a = @c.as_hash(:id)
|
126
149
|
a.must_equal(1=>@c1, 2=>@c2)
|
127
150
|
a[1].must_equal @c1
|
128
151
|
a[2].must_equal @c2
|
129
152
|
|
130
|
-
a = @c.
|
153
|
+
a = @c.as_hash([:id])
|
131
154
|
a.must_equal([1]=>@c1, [2]=>@c2)
|
132
155
|
a[[1]].must_equal @c1
|
133
156
|
a[[2]].must_equal @c2
|
134
157
|
|
135
|
-
@c.
|
136
|
-
@c.
|
137
|
-
@c.
|
138
|
-
@c.
|
158
|
+
@c.as_hash(:id, :id).must_equal(1=>1, 2=>2)
|
159
|
+
@c.as_hash([:id], :id).must_equal([1]=>1, [2]=>2)
|
160
|
+
@c.as_hash(:id, [:id]).must_equal(1=>[1], 2=>[2])
|
161
|
+
@c.as_hash([:id], [:id]).must_equal([1]=>[1], [2]=>[2])
|
139
162
|
|
140
163
|
@db.sqls.must_equal []
|
141
164
|
end
|
142
165
|
|
143
|
-
it "should have
|
144
|
-
@c.
|
166
|
+
it "should have as_hash not return a frozen object" do
|
167
|
+
@c.as_hash.frozen?.must_equal false
|
145
168
|
end
|
146
169
|
|
147
170
|
it "should have to_hash_groups without arguments return the cached objects without a query" do
|
@@ -163,10 +186,38 @@ describe "Sequel::Plugins::StaticCache" do
|
|
163
186
|
@db.sqls.must_equal []
|
164
187
|
end
|
165
188
|
|
189
|
+
it "should have to_hash_groups handle :hash option" do
|
190
|
+
h = {}
|
191
|
+
a = @c.to_hash_groups(:id, nil, :hash=>h)
|
192
|
+
a.must_be_same_as h
|
193
|
+
a.must_equal(1=>[@c1], 2=>[@c2])
|
194
|
+
a[1].first.must_equal @c1
|
195
|
+
a[2].first.must_equal @c2
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should have as_hash_groups without arguments return the cached objects without a query" do
|
199
|
+
a = @c.to_hash_groups(:id)
|
200
|
+
a.must_equal(1=>[@c1], 2=>[@c2])
|
201
|
+
a[1].first.must_equal @c1
|
202
|
+
a[2].first.must_equal @c2
|
203
|
+
|
204
|
+
a = @c.to_hash_groups([:id])
|
205
|
+
a.must_equal([1]=>[@c1], [2]=>[@c2])
|
206
|
+
a[[1]].first.must_equal @c1
|
207
|
+
a[[2]].first.must_equal @c2
|
208
|
+
|
209
|
+
@c.to_hash_groups(:id, :id).must_equal(1=>[1], 2=>[2])
|
210
|
+
@c.to_hash_groups([:id], :id).must_equal([1]=>[1], [2]=>[2])
|
211
|
+
@c.to_hash_groups(:id, [:id]).must_equal(1=>[[1]], 2=>[[2]])
|
212
|
+
@c.to_hash_groups([:id], [:id]).must_equal([1]=>[[1]], [2]=>[[2]])
|
213
|
+
|
214
|
+
@db.sqls.must_equal []
|
215
|
+
end
|
216
|
+
|
166
217
|
it "subclasses should work correctly" do
|
167
218
|
c = Class.new(@c)
|
168
219
|
c.all.must_equal [c.load(:id=>1), c.load(:id=>2)]
|
169
|
-
c.
|
220
|
+
c.as_hash.must_equal(1=>c.load(:id=>1), 2=>c.load(:id=>2))
|
170
221
|
@db.sqls.must_equal ['SELECT * FROM t']
|
171
222
|
end
|
172
223
|
|
@@ -174,8 +225,8 @@ describe "Sequel::Plugins::StaticCache" do
|
|
174
225
|
ds = @c.dataset.from(:t2).columns(:id).with_fetch(:id=>3)
|
175
226
|
@c.dataset = ds
|
176
227
|
@c.all.must_equal [@c.load(:id=>3)]
|
177
|
-
@c.
|
178
|
-
@c.
|
228
|
+
@c.as_hash.must_equal(3=>@c.load(:id=>3))
|
229
|
+
@c.as_hash[3].must_equal @c.all.first
|
179
230
|
@db.sqls.must_equal ['SELECT * FROM t2']
|
180
231
|
end
|
181
232
|
end
|
@@ -238,18 +289,18 @@ describe "Sequel::Plugins::StaticCache" do
|
|
238
289
|
a.last.must_be_same_as(@c2)
|
239
290
|
end
|
240
291
|
|
241
|
-
it "should have
|
242
|
-
a = @c.
|
292
|
+
it "should have as_hash without arguments use cached instances" do
|
293
|
+
a = @c.as_hash
|
243
294
|
a[1].must_be_same_as(@c1)
|
244
295
|
a[2].must_be_same_as(@c2)
|
245
296
|
end
|
246
297
|
|
247
|
-
it "should have
|
248
|
-
a = @c.
|
298
|
+
it "should have as_hash with arguments return cached instances" do
|
299
|
+
a = @c.as_hash(:id)
|
249
300
|
a[1].must_be_same_as(@c1)
|
250
301
|
a[2].must_be_same_as(@c2)
|
251
302
|
|
252
|
-
a = @c.
|
303
|
+
a = @c.as_hash([:id])
|
253
304
|
a[[1]].must_be_same_as(@c1)
|
254
305
|
a[[2]].must_be_same_as(@c2)
|
255
306
|
end
|
@@ -313,16 +364,16 @@ describe "Sequel::Plugins::StaticCache" do
|
|
313
364
|
@c.map.all?{|o| !o.frozen?}.must_equal true
|
314
365
|
end
|
315
366
|
|
316
|
-
it "none of values in the hash returned by
|
317
|
-
@c.
|
367
|
+
it "none of values in the hash returned by as_hash without an argument should be frozen" do
|
368
|
+
@c.as_hash.values.all?{|o| !o.frozen?}.must_equal true
|
318
369
|
end
|
319
370
|
|
320
|
-
it "none of values in the hash returned by
|
321
|
-
@c.
|
371
|
+
it "none of values in the hash returned by as_hash with a single argument should be frozen" do
|
372
|
+
@c.as_hash(:id).values.all?{|o| !o.frozen?}.must_equal true
|
322
373
|
end
|
323
374
|
|
324
|
-
it "none of values in the hash returned by
|
325
|
-
@c.
|
375
|
+
it "none of values in the hash returned by as_hash with a single array argument should be frozen" do
|
376
|
+
@c.as_hash([:id, :id]).values.all?{|o| !o.frozen?}.must_equal true
|
326
377
|
end
|
327
378
|
|
328
379
|
it "none of values in the hash returned by to_hash_groups with a single argument should be frozen" do
|
@@ -48,7 +48,7 @@ describe "string_agg extension" do
|
|
48
48
|
it "should correctly literalize on MySQL, H2, HSQLDB" do
|
49
49
|
[:mysql, :h2, :hsqldb].each do |type|
|
50
50
|
db = dbf.call(type)
|
51
|
-
|
51
|
+
meta_def(db, :database_type){type}
|
52
52
|
ds = db.dataset.with_quote_identifiers(false).with_extend{def input_identifier(v) v.to_s end}
|
53
53
|
ds.literal(@sa1).upcase.must_equal "GROUP_CONCAT(C SEPARATOR ',')"
|
54
54
|
ds.literal(@sa2).upcase.must_equal "GROUP_CONCAT(C SEPARATOR '-')"
|
@@ -67,6 +67,15 @@ describe "Touch plugin" do
|
|
67
67
|
"UPDATE albums SET updated_at = CURRENT_TIMESTAMP WHERE (albums.artist_id = 1)"]
|
68
68
|
end
|
69
69
|
|
70
|
+
it "should clear associations after touching them :associations option" do
|
71
|
+
@Artist.plugin :touch, :associations=>:albums
|
72
|
+
@a.associations[:albums] = [@Album.call(:id=>1)]
|
73
|
+
@a.touch
|
74
|
+
@a.associations[:albums].must_be_nil
|
75
|
+
DB.sqls.must_equal ["UPDATE artists SET updated_at = CURRENT_TIMESTAMP WHERE (id = 1)",
|
76
|
+
"UPDATE albums SET updated_at = CURRENT_TIMESTAMP WHERE (albums.artist_id = 1)"]
|
77
|
+
end
|
78
|
+
|
70
79
|
it "should be able to give an array to the :associations option specifying multiple associations" do
|
71
80
|
@Album.plugin :touch, :associations=>[:artist, :followup_albums]
|
72
81
|
@Album.load(:id=>4, :artist_id=>1).touch
|
@@ -18,6 +18,12 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
18
18
|
@m.wont_be :valid?
|
19
19
|
@m.value = '1_1'
|
20
20
|
@m.must_be :valid?
|
21
|
+
o = String.new
|
22
|
+
class << o
|
23
|
+
undef_method :blank?
|
24
|
+
end
|
25
|
+
@m.value = o
|
26
|
+
@m.must_be :valid?
|
21
27
|
o = Object.new
|
22
28
|
@m.value = o
|
23
29
|
@m.wont_be :valid?
|
@@ -80,7 +86,7 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
80
86
|
@m.must_be :valid?
|
81
87
|
end
|
82
88
|
|
83
|
-
|
89
|
+
deprecated "should support modifying default options for all models" do
|
84
90
|
@c.set_validations{validates_presence(:value)}
|
85
91
|
@m.wont_be :valid?
|
86
92
|
@m.errors.must_equal(:value=>['is not present'])
|
@@ -98,7 +104,6 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
98
104
|
@m.wont_be :valid?
|
99
105
|
@m.errors.must_equal(:value=>["was not entered"])
|
100
106
|
|
101
|
-
|
102
107
|
c = Class.new(Sequel::Model)
|
103
108
|
c.class_eval do
|
104
109
|
plugin :validation_helpers
|
@@ -248,17 +253,17 @@ describe "Sequel::Plugins::ValidationHelpers" do
|
|
248
253
|
@m.must_be :valid?
|
249
254
|
@m.value = '123'
|
250
255
|
@m.must_be :valid?
|
251
|
-
@m.
|
256
|
+
def @m.db_schema; {:value=>{:type=>:integer}} end
|
252
257
|
@m.wont_be :valid?
|
253
258
|
@m.errors.full_messages.must_equal ['value is not a valid integer']
|
254
259
|
|
255
260
|
@c.set_validations{validates_schema_types(:value)}
|
256
|
-
@m.
|
261
|
+
def @m.db_schema; {:value=>{:type=>:integer}} end
|
257
262
|
@m.wont_be :valid?
|
258
263
|
@m.errors.full_messages.must_equal ['value is not a valid integer']
|
259
264
|
|
260
265
|
@c.set_validations{validates_schema_types(:value, :message=>'is bad')}
|
261
|
-
@m.
|
266
|
+
def @m.db_schema; {:value=>{:type=>:integer}} end
|
262
267
|
@m.wont_be :valid?
|
263
268
|
@m.errors.full_messages.must_equal ['value is bad']
|
264
269
|
end
|
@@ -64,6 +64,19 @@ describe Sequel::Model, "#(set|update)_(all|only)" do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
describe Sequel::Model, "#(set|update)_(all|only) without set_allowed_columns" do
|
68
|
+
before do
|
69
|
+
@c = Class.new(Sequel::Model(:items)) do
|
70
|
+
set_primary_key :id
|
71
|
+
columns :x, :y, :z, :id
|
72
|
+
end
|
73
|
+
@c.plugin :whitelist_security
|
74
|
+
@c.strict_param_setting = false
|
75
|
+
@o1 = @c.new
|
76
|
+
DB.reset
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
67
80
|
describe Sequel::Model, ".strict_param_setting" do
|
68
81
|
before do
|
69
82
|
@c = Class.new(Sequel::Model(:blahblah)) do
|
@@ -105,6 +118,19 @@ describe Sequel::Model, ".allowed_columns " do
|
|
105
118
|
@c.allowed_columns.must_equal [:x, :y]
|
106
119
|
end
|
107
120
|
|
121
|
+
it "should not change behavior if allowed_columns are not set" do
|
122
|
+
i = @c.new(:x => 1, :y => 2, :z => 3)
|
123
|
+
i.values.must_equal(:x => 1, :y => 2, :z => 3)
|
124
|
+
i.set(:x => 4, :y => 5, :z => 6)
|
125
|
+
i.values.must_equal(:x => 4, :y => 5, :z => 6)
|
126
|
+
|
127
|
+
@c.dataset = @c.dataset.with_fetch(:x => 7)
|
128
|
+
i = @c.new
|
129
|
+
i.update(:x => 7)
|
130
|
+
i.values.must_equal(:x => 7)
|
131
|
+
DB.sqls.must_equal ["INSERT INTO blahblah (x) VALUES (7)", "SELECT * FROM blahblah WHERE id = 10"]
|
132
|
+
end
|
133
|
+
|
108
134
|
it "should only set allowed columns by default" do
|
109
135
|
@c.set_allowed_columns :x, :y
|
110
136
|
i = @c.new(:x => 1, :y => 2, :z => 3)
|
@@ -1621,6 +1621,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
|
|
1621
1621
|
Album.first_tags.all.must_equal []
|
1622
1622
|
Artist.tags.all.must_equal []
|
1623
1623
|
Artist.first_tags.all.must_equal []
|
1624
|
+
Tag.tags.all.must_equal []
|
1624
1625
|
end
|
1625
1626
|
Artist.albums.tags.all.must_equal []
|
1626
1627
|
|
@@ -1637,6 +1638,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
|
|
1637
1638
|
Album.first_tags.all.must_equal [@tag]
|
1638
1639
|
Artist.tags.all.must_equal [@tag]
|
1639
1640
|
Artist.first_tags.all.must_equal [@tag]
|
1641
|
+
Tag.tags.all.must_equal [@tag]
|
1640
1642
|
end
|
1641
1643
|
Artist.albums.tags.all.must_equal [@tag]
|
1642
1644
|
|
@@ -1652,6 +1654,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
|
|
1652
1654
|
Album.first_tags.order(:name).all.must_equal [@tag, tag]
|
1653
1655
|
Artist.tags.order(:name).all.must_equal [@tag, tag]
|
1654
1656
|
Artist.first_tags.order(:name).all.must_equal [@tag, tag]
|
1657
|
+
Tag.tags.order(:name).all.must_equal [@tag, tag]
|
1655
1658
|
end
|
1656
1659
|
Artist.albums.tags.order(:name).all.must_equal [@tag, tag]
|
1657
1660
|
|
@@ -1664,6 +1667,7 @@ BasicRegularAndCompositeKeyAssociations = shared_description do
|
|
1664
1667
|
Album.filter(Album.qualified_primary_key_hash(album.pk)).first_tags.all.must_equal [tag]
|
1665
1668
|
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).tags.all.must_equal [tag]
|
1666
1669
|
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).first_tags.all.must_equal [tag]
|
1670
|
+
Tag.filter(Tag.qualified_primary_key_hash(tag.pk)).tags.all.must_equal [tag]
|
1667
1671
|
end
|
1668
1672
|
Artist.filter(Artist.qualified_primary_key_hash(artist.pk)).albums.tags.all.must_equal [tag]
|
1669
1673
|
|
@@ -1891,6 +1895,8 @@ describe "Sequel::Model Simple Associations" do
|
|
1891
1895
|
class ::Tag < Sequel::Model(@db)
|
1892
1896
|
plugin :dataset_associations
|
1893
1897
|
many_to_many :albums
|
1898
|
+
plugin :many_through_many
|
1899
|
+
many_through_many :tags, [[:albums_tags, :tag_id, :album_id], [:albums, :id, :artist_id], [:albums, :artist_id, :id], [:albums_tags, :album_id, :tag_id]], :class=>:Tag
|
1894
1900
|
end
|
1895
1901
|
@album = Album.create(:name=>'Al')
|
1896
1902
|
@artist = Artist.create(:name=>'Ar')
|
@@ -2184,6 +2190,8 @@ describe "Sequel::Model Composite Key Associations" do
|
|
2184
2190
|
set_primary_key [:id1, :id2]
|
2185
2191
|
unrestrict_primary_key
|
2186
2192
|
many_to_many :albums, :right_key=>[:album_id1, :album_id2], :left_key=>[:tag_id1, :tag_id2]
|
2193
|
+
plugin :many_through_many
|
2194
|
+
many_through_many :tags, [[:albums_tags, [:tag_id1, :tag_id2], [:album_id1, :album_id2]], [:albums, [:id1, :id2], [:artist_id1, :artist_id2]], [:albums, [:artist_id1, :artist_id2], [:id1, :id2]], [:albums_tags, [:album_id1, :album_id2], [:tag_id1, :tag_id2]]], :class=>:Tag
|
2187
2195
|
end
|
2188
2196
|
@album = Album.create(:name=>'Al', :id1=>1, :id2=>2)
|
2189
2197
|
@artist = Artist.create(:name=>'Ar', :id1=>3, :id2=>4)
|
@@ -15,8 +15,8 @@ describe "Simple Dataset operations" do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should support sequential primary keys" do
|
18
|
-
@ds
|
19
|
-
@ds
|
18
|
+
@ds.insert(:number=>20)
|
19
|
+
@ds.insert(:number=>30)
|
20
20
|
@ds.order(:number).all.must_equal [
|
21
21
|
{:id => 1, :number=>10},
|
22
22
|
{:id => 2, :number=>20},
|
@@ -28,8 +28,8 @@ describe "Simple Dataset operations" do
|
|
28
28
|
primary_key :id, :type=>:Bignum
|
29
29
|
Integer :number
|
30
30
|
end
|
31
|
-
@ds
|
32
|
-
@ds
|
31
|
+
@ds.insert(:number=>20)
|
32
|
+
@ds.insert(:number=>30)
|
33
33
|
@ds.order(:number).all.must_equal [{:id => 1, :number=>20}, {:id => 2, :number=>30}]
|
34
34
|
end
|
35
35
|
|
@@ -49,7 +49,7 @@ describe "Simple Dataset operations" do
|
|
49
49
|
@ds.filter(:id=>2).first[:number].must_equal 20
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
deprecated "should have insert_multiple return primary key values" do
|
53
53
|
@ds.extension(:sequel_3_dataset_methods).insert_multiple([{:number=>20}, {:number=>30}]).must_equal [2, 3]
|
54
54
|
@ds.filter(:id=>2).get(:number).must_equal 20
|
55
55
|
@ds.filter(:id=>3).get(:number).must_equal 30
|
@@ -60,7 +60,7 @@ describe "Simple Dataset operations" do
|
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should handle LATERAL subqueries correctly" do
|
63
|
-
@ds
|
63
|
+
@ds.insert(:number=>20)
|
64
64
|
@ds.from(Sequel[:items].as(:i), @ds.where(Sequel[:items][:number]=>Sequel[:i][:number]).lateral).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, 10], [20, 20]]
|
65
65
|
@ds.from(Sequel[:items].as(:i)).cross_join(@ds.where(Sequel[:items][:number]=>Sequel[:i][:number]).lateral).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, 10], [20, 20]]
|
66
66
|
@ds.from(Sequel[:items].as(:i)).join(@ds.where(Sequel[:items][:number]=>Sequel[:i][:number]).lateral, 1=>1).select_order_map([Sequel[:i][:number].as(:n), Sequel[:t1][:number]]).must_equal [[10, 10], [20, 20]]
|
@@ -389,9 +389,9 @@ describe Sequel::Dataset do
|
|
389
389
|
|
390
390
|
it "should return the correct record count" do
|
391
391
|
@d.count.must_equal 0
|
392
|
-
@d
|
393
|
-
@d
|
394
|
-
@d
|
392
|
+
@d.insert(:name => 'abc', :value => 123)
|
393
|
+
@d.insert(:name => 'abc', :value => 456)
|
394
|
+
@d.insert(:name => 'def', :value => nil)
|
395
395
|
5.times do
|
396
396
|
@d.count.must_equal 3
|
397
397
|
@d.count(:name).must_equal 3
|
@@ -400,14 +400,14 @@ describe Sequel::Dataset do
|
|
400
400
|
end
|
401
401
|
|
402
402
|
it "should handle functions with identifier names correctly" do
|
403
|
-
@d
|
403
|
+
@d.insert(:name => 'abc', :value => 6)
|
404
404
|
@d.get{sum.function(:value)}.must_equal 6
|
405
405
|
end
|
406
406
|
|
407
407
|
it "should handle aggregate methods on limited datasets correctly" do
|
408
|
-
@d
|
409
|
-
@d
|
410
|
-
@d
|
408
|
+
@d.insert(:name => 'abc', :value => 6)
|
409
|
+
@d.insert(:name => 'bcd', :value => 12)
|
410
|
+
@d.insert(:name => 'def', :value => 18)
|
411
411
|
@d = @d.order(:name).limit(2)
|
412
412
|
@d.count.must_equal 2
|
413
413
|
@d.avg(:value).to_i.must_equal 9
|
@@ -415,14 +415,14 @@ describe Sequel::Dataset do
|
|
415
415
|
@d.reverse.min(:value).to_i.must_equal 12
|
416
416
|
@d.max(:value).to_i.must_equal 12
|
417
417
|
@d.sum(:value).to_i.must_equal 18
|
418
|
-
@d.interval(:value).to_i.must_equal 6
|
418
|
+
@d.extension(:sequel_4_dataset_methods).interval(:value).to_i.must_equal 6
|
419
419
|
end
|
420
420
|
|
421
421
|
it "should return the correct records" do
|
422
422
|
@d.to_a.must_equal []
|
423
|
-
@d
|
424
|
-
@d
|
425
|
-
@d
|
423
|
+
@d.insert(:name => 'abc', :value => 123)
|
424
|
+
@d.insert(:name => 'abc', :value => 456)
|
425
|
+
@d.insert(:name => 'def', :value => 789)
|
426
426
|
|
427
427
|
@d.order(:value).to_a.must_equal [
|
428
428
|
{:name => 'abc', :value => 123},
|
@@ -432,27 +432,27 @@ describe Sequel::Dataset do
|
|
432
432
|
end
|
433
433
|
|
434
434
|
it "should update records correctly" do
|
435
|
-
@d
|
436
|
-
@d
|
437
|
-
@d
|
435
|
+
@d.insert(:name => 'abc', :value => 123)
|
436
|
+
@d.insert(:name => 'abc', :value => 456)
|
437
|
+
@d.insert(:name => 'def', :value => 789)
|
438
438
|
@d.filter(:name => 'abc').update(:value => 530)
|
439
439
|
@d[:name => 'def'][:value].must_equal 789
|
440
440
|
@d.filter(:value => 530).count.must_equal 2
|
441
441
|
end
|
442
442
|
|
443
443
|
it "should delete records correctly" do
|
444
|
-
@d
|
445
|
-
@d
|
446
|
-
@d
|
444
|
+
@d.insert(:name => 'abc', :value => 123)
|
445
|
+
@d.insert(:name => 'abc', :value => 456)
|
446
|
+
@d.insert(:name => 'def', :value => 789)
|
447
447
|
@d.filter(:name => 'abc').delete
|
448
448
|
@d.count.must_equal 1
|
449
449
|
@d.first[:name].must_equal 'def'
|
450
450
|
end
|
451
451
|
|
452
452
|
it "should be able to truncate the table" do
|
453
|
-
@d
|
454
|
-
@d
|
455
|
-
@d
|
453
|
+
@d.insert(:name => 'abc', :value => 123)
|
454
|
+
@d.insert(:name => 'abc', :value => 456)
|
455
|
+
@d.insert(:name => 'def', :value => 789)
|
456
456
|
@d.count.must_equal 3
|
457
457
|
@d.truncate.must_be_nil
|
458
458
|
@d.count.must_equal 0
|
@@ -517,9 +517,9 @@ describe Sequel::Dataset do
|
|
517
517
|
Integer :value
|
518
518
|
end
|
519
519
|
@d = DB[:items]
|
520
|
-
@d
|
521
|
-
@d
|
522
|
-
@d
|
520
|
+
@d.insert(:value => 123)
|
521
|
+
@d.insert(:value => 456)
|
522
|
+
@d.insert(:value => 789)
|
523
523
|
end
|
524
524
|
after do
|
525
525
|
DB.drop_table?(:items)
|
@@ -1055,7 +1055,7 @@ describe "Sequel::Dataset convenience methods" do
|
|
1055
1055
|
@db.drop_table?(:a)
|
1056
1056
|
end
|
1057
1057
|
|
1058
|
-
|
1058
|
+
deprecated "#[]= should update matching rows" do
|
1059
1059
|
@ds.insert(20, 10)
|
1060
1060
|
@ds.extension(:sequel_3_dataset_methods)[:a=>20] = {:b=>30}
|
1061
1061
|
@ds.all.must_equal [{:a=>20, :b=>30}]
|
@@ -1104,7 +1104,7 @@ describe "Sequel::Dataset convenience methods" do
|
|
1104
1104
|
end
|
1105
1105
|
|
1106
1106
|
it "#range should return the range between the maximum and minimum values" do
|
1107
|
-
@ds = @ds.unordered
|
1107
|
+
@ds = @ds.unordered.extension(:sequel_4_dataset_methods)
|
1108
1108
|
@ds.insert(20, 10)
|
1109
1109
|
@ds.insert(30, 10)
|
1110
1110
|
@ds.range(:a).must_equal(20..30)
|
@@ -1112,7 +1112,7 @@ describe "Sequel::Dataset convenience methods" do
|
|
1112
1112
|
end
|
1113
1113
|
|
1114
1114
|
it "#interval should return the different between the maximum and minimum values" do
|
1115
|
-
@ds = @ds.unordered
|
1115
|
+
@ds = @ds.unordered.extension(:sequel_4_dataset_methods)
|
1116
1116
|
@ds.insert(20, 10)
|
1117
1117
|
@ds.insert(30, 10)
|
1118
1118
|
@ds.interval(:a).to_i.must_equal 10
|
@@ -1147,10 +1147,10 @@ describe "Sequel::Dataset main SQL methods" do
|
|
1147
1147
|
@ds.filter(Sequel.lit("b < ?", 15)).invert.all.must_equal [{:a=>20, :b=>30}]
|
1148
1148
|
end
|
1149
1149
|
|
1150
|
-
it "#
|
1150
|
+
it "#where and #or should work correctly" do
|
1151
1151
|
@ds.insert(20, 30)
|
1152
|
-
@ds.filter(:a=>20).
|
1153
|
-
@ds.filter(:a=>20).
|
1152
|
+
@ds.filter(:a=>20).where(:b=>30).all.must_equal [{:a=>20, :b=>30}]
|
1153
|
+
@ds.filter(:a=>20).where(:b=>15).all.must_equal []
|
1154
1154
|
@ds.filter(:a=>20).or(:b=>15).all.must_equal [{:a=>20, :b=>30}]
|
1155
1155
|
@ds.filter(:a=>10).or(:b=>15).all.must_equal []
|
1156
1156
|
end
|
@@ -1212,17 +1212,18 @@ describe "Sequel::Dataset convenience methods" do
|
|
1212
1212
|
@ds.map([:a, :b]).must_equal [[1, 2], [5, 6]]
|
1213
1213
|
end
|
1214
1214
|
|
1215
|
-
it "should have working #
|
1215
|
+
it "should have working #as_hash" do
|
1216
1216
|
@ds.to_hash(:a).must_equal(1=>{:a=>1, :b=>2, :c=>3, :d=>4}, 5=>{:a=>5, :b=>6, :c=>7, :d=>8})
|
1217
|
-
@ds.
|
1218
|
-
@ds.
|
1217
|
+
@ds.as_hash(:a).must_equal(1=>{:a=>1, :b=>2, :c=>3, :d=>4}, 5=>{:a=>5, :b=>6, :c=>7, :d=>8})
|
1218
|
+
@ds.as_hash(:b).must_equal(2=>{:a=>1, :b=>2, :c=>3, :d=>4}, 6=>{:a=>5, :b=>6, :c=>7, :d=>8})
|
1219
|
+
@ds.as_hash([:a, :b]).must_equal([1, 2]=>{:a=>1, :b=>2, :c=>3, :d=>4}, [5, 6]=>{:a=>5, :b=>6, :c=>7, :d=>8})
|
1219
1220
|
|
1220
|
-
@ds.
|
1221
|
-
@ds.
|
1222
|
-
@ds.
|
1223
|
-
@ds.
|
1221
|
+
@ds.as_hash(:a, :b).must_equal(1=>2, 5=>6)
|
1222
|
+
@ds.as_hash([:a, :c], :b).must_equal([1, 3]=>2, [5, 7]=>6)
|
1223
|
+
@ds.as_hash(:a, [:b, :c]).must_equal(1=>[2, 3], 5=>[6, 7])
|
1224
|
+
@ds.as_hash([:a, :c], [:b, :d]).must_equal([1, 3]=>[2, 4], [5, 7]=>[6, 8])
|
1224
1225
|
|
1225
|
-
@ds.
|
1226
|
+
@ds.as_hash(:a, :b, :hash => (tmp = {})).must_be_same_as(tmp)
|
1226
1227
|
end
|
1227
1228
|
|
1228
1229
|
it "should have working #to_hash_groups" do
|
@@ -1874,7 +1875,7 @@ describe "Dataset replace" do
|
|
1874
1875
|
end
|
1875
1876
|
|
1876
1877
|
it "should update a record if the condition is met" do
|
1877
|
-
@d
|
1878
|
+
@d.insert(:id => 111)
|
1878
1879
|
@d.all.must_equal [{:id => 111, :value => nil}]
|
1879
1880
|
@d.replace(:id => 111, :value => 333)
|
1880
1881
|
@d.all.must_equal [{:id => 111, :value => 333}]
|