sequel 4.35.0 → 4.36.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 +32 -0
- data/doc/association_basics.rdoc +27 -4
- data/doc/migration.rdoc +24 -0
- data/doc/release_notes/4.36.0.txt +116 -0
- data/lib/sequel/adapters/jdbc/h2.rb +1 -1
- data/lib/sequel/adapters/mysql2.rb +11 -1
- data/lib/sequel/adapters/oracle.rb +3 -5
- data/lib/sequel/adapters/postgres.rb +2 -2
- data/lib/sequel/adapters/shared/access.rb +1 -1
- data/lib/sequel/adapters/shared/oracle.rb +1 -1
- data/lib/sequel/adapters/shared/postgres.rb +1 -1
- data/lib/sequel/adapters/shared/sqlite.rb +1 -1
- data/lib/sequel/connection_pool.rb +5 -0
- data/lib/sequel/connection_pool/sharded_single.rb +1 -1
- data/lib/sequel/connection_pool/sharded_threaded.rb +29 -14
- data/lib/sequel/connection_pool/single.rb +1 -1
- data/lib/sequel/connection_pool/threaded.rb +5 -3
- data/lib/sequel/database/schema_methods.rb +7 -1
- data/lib/sequel/dataset/sql.rb +4 -0
- data/lib/sequel/extensions/arbitrary_servers.rb +1 -1
- data/lib/sequel/extensions/connection_expiration.rb +89 -0
- data/lib/sequel/extensions/connection_validator.rb +11 -3
- data/lib/sequel/extensions/constraint_validations.rb +28 -0
- data/lib/sequel/extensions/string_agg.rb +178 -0
- data/lib/sequel/model.rb +13 -56
- data/lib/sequel/model/associations.rb +3 -1
- data/lib/sequel/model/base.rb +104 -7
- data/lib/sequel/plugins/constraint_validations.rb +17 -3
- data/lib/sequel/plugins/validation_helpers.rb +1 -1
- data/lib/sequel/sql.rb +8 -0
- data/lib/sequel/version.rb +1 -1
- data/spec/adapters/postgres_spec.rb +4 -0
- data/spec/core/dataset_spec.rb +4 -0
- data/spec/core/expression_filters_spec.rb +4 -0
- data/spec/extensions/connection_expiration_spec.rb +121 -0
- data/spec/extensions/connection_validator_spec.rb +7 -0
- data/spec/extensions/constraint_validations_plugin_spec.rb +14 -0
- data/spec/extensions/constraint_validations_spec.rb +64 -0
- data/spec/extensions/string_agg_spec.rb +85 -0
- data/spec/extensions/validation_helpers_spec.rb +2 -0
- data/spec/integration/plugin_test.rb +37 -2
- data/spec/model/association_reflection_spec.rb +10 -0
- data/spec/model/model_spec.rb +49 -0
- metadata +8 -2
@@ -78,6 +78,13 @@ connection_validator_specs = shared_description do
|
|
78
78
|
c3.wont_be_same_as(c2)
|
79
79
|
end
|
80
80
|
|
81
|
+
it "should not leak connection references during disconnect" do
|
82
|
+
@db.synchronize{}
|
83
|
+
@db.pool.instance_variable_get(:@connection_timestamps).size.must_equal 1
|
84
|
+
@db.disconnect
|
85
|
+
@db.pool.instance_variable_get(:@connection_timestamps).size.must_equal 0
|
86
|
+
end
|
87
|
+
|
81
88
|
it "should not leak connection references" do
|
82
89
|
c1 = @db.synchronize do |c|
|
83
90
|
@db.pool.instance_variable_get(:@connection_timestamps).must_equal({})
|
@@ -185,6 +185,20 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
185
185
|
@c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\Afoo\z/i}]])
|
186
186
|
end
|
187
187
|
|
188
|
+
it "should handle operator validation" do
|
189
|
+
[[:str_lt, :<], [:str_lte, :<=], [:str_gt, :>], [:str_gte, :>=]].each do |vt, op|
|
190
|
+
model_class(:validation_type=>vt.to_s, :argument=>'a').constraint_validations.must_equal [[:validates_operator, op, 'a', :name]]
|
191
|
+
@c.constraint_validation_reflections.must_equal(:name=>[[:operator, {:operator=>op, :argument=>'a'}]])
|
192
|
+
@c = @c.db.constraint_validations = nil
|
193
|
+
end
|
194
|
+
|
195
|
+
[[:int_lt, :<], [:int_lte, :<=], [:int_gt, :>], [:int_gte, :>=]].each do |vt, op|
|
196
|
+
model_class(:validation_type=>vt.to_s, :argument=>'1').constraint_validations.must_equal [[:validates_operator, op, 1, :name]]
|
197
|
+
@c.constraint_validation_reflections.must_equal(:name=>[[:operator, {:operator=>op, :argument=>1}]])
|
198
|
+
@c = @c.db.constraint_validations = nil
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
188
202
|
it "should handle like validation with % metacharacter" do
|
189
203
|
model_class(:validation_type=>'like', :argument=>'%foo%').constraint_validations.must_equal [[:validates_format, /\A.*foo.*\z/, :name]]
|
190
204
|
@c.constraint_validation_reflections.must_equal(:name=>[[:format, {:argument=>/\A.*foo.*\z/}]])
|
@@ -252,6 +252,62 @@ describe "constraint_validations extension" do
|
|
252
252
|
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name varchar(255), CHECK ((name IS NOT NULL) AND (UPPER(name) LIKE UPPER('foo%') ESCAPE '\\')))"]
|
253
253
|
end
|
254
254
|
|
255
|
+
it "should support :operator :< constraint validation with string" do
|
256
|
+
@db.create_table(:foo){String :name; validate{operator :<, 'a', :name}}
|
257
|
+
sqls = @db.sqls
|
258
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"str_lt", :column=>"name", :table=>"foo", :argument=>'a')
|
259
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name varchar(255), CHECK ((name IS NOT NULL) AND (name < 'a')))"]
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should support :operator :<= constraint validation with string" do
|
263
|
+
@db.create_table(:foo){String :name; validate{operator :<=, 'a', :name}}
|
264
|
+
sqls = @db.sqls
|
265
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"str_lte", :column=>"name", :table=>"foo", :argument=>'a')
|
266
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name varchar(255), CHECK ((name IS NOT NULL) AND (name <= 'a')))"]
|
267
|
+
end
|
268
|
+
|
269
|
+
it "should support :operator :> constraint validation with string" do
|
270
|
+
@db.create_table(:foo){String :name; validate{operator :>, 'a', :name}}
|
271
|
+
sqls = @db.sqls
|
272
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"str_gt", :column=>"name", :table=>"foo", :argument=>'a')
|
273
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name varchar(255), CHECK ((name IS NOT NULL) AND (name > 'a')))"]
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should support :operator :>= constraint validation with string" do
|
277
|
+
@db.create_table(:foo){String :name; validate{operator :>=, 'a', :name}}
|
278
|
+
sqls = @db.sqls
|
279
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"str_gte", :column=>"name", :table=>"foo", :argument=>'a')
|
280
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name varchar(255), CHECK ((name IS NOT NULL) AND (name >= 'a')))"]
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should support :operator :< constraint validation with integer" do
|
284
|
+
@db.create_table(:foo){Integer :name; validate{operator :<, 2, :name}}
|
285
|
+
sqls = @db.sqls
|
286
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"int_lt", :column=>"name", :table=>"foo", :argument=>'2')
|
287
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name integer, CHECK ((name IS NOT NULL) AND (name < 2)))"]
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should support :operator :<= constraint validation with integer" do
|
291
|
+
@db.create_table(:foo){Integer :name; validate{operator :<=, 2, :name}}
|
292
|
+
sqls = @db.sqls
|
293
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"int_lte", :column=>"name", :table=>"foo", :argument=>'2')
|
294
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name integer, CHECK ((name IS NOT NULL) AND (name <= 2)))"]
|
295
|
+
end
|
296
|
+
|
297
|
+
it "should support :operator :> constraint validation with integer" do
|
298
|
+
@db.create_table(:foo){Integer :name; validate{operator :>, 2, :name}}
|
299
|
+
sqls = @db.sqls
|
300
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"int_gt", :column=>"name", :table=>"foo", :argument=>'2')
|
301
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name integer, CHECK ((name IS NOT NULL) AND (name > 2)))"]
|
302
|
+
end
|
303
|
+
|
304
|
+
it "should support :operator :>= constraint validation with integer" do
|
305
|
+
@db.create_table(:foo){Integer :name; validate{operator :>=, 2, :name}}
|
306
|
+
sqls = @db.sqls
|
307
|
+
parse_insert(sqls.slice!(1)).must_equal(:validation_type=>"int_gte", :column=>"name", :table=>"foo", :argument=>'2')
|
308
|
+
sqls.must_equal ["BEGIN", "COMMIT", "CREATE TABLE foo (name integer, CHECK ((name IS NOT NULL) AND (name >= 2)))"]
|
309
|
+
end
|
310
|
+
|
255
311
|
it "should support :unique constraint validation" do
|
256
312
|
@db.create_table(:foo){String :name; validate{unique :name}}
|
257
313
|
sqls = @db.sqls
|
@@ -297,6 +353,14 @@ describe "constraint_validations extension" do
|
|
297
353
|
proc{@db.create_table(:foo){String :name; validate{includes 'a', :name}}}.must_raise(Sequel::Error)
|
298
354
|
end
|
299
355
|
|
356
|
+
it "should raise an error if attempting attempting to process an operator validation with an unsupported operator" do
|
357
|
+
proc{@db.alter_table(:foo){String :name; validate{operator :===, 'a', :name}}}.must_raise(Sequel::Error)
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should raise an error if attempting attempting to process an operator validation with an unsupported argument" do
|
361
|
+
proc{@db.alter_table(:foo){String :name; validate{operator :>, [], :name}}}.must_raise(Sequel::Error)
|
362
|
+
end
|
363
|
+
|
300
364
|
it "should raise an error if attempting to drop a constraint validation in a create_table generator" do
|
301
365
|
proc{@db.create_table(:foo){String :name; validate{drop :foo}}}.must_raise(Sequel::Error)
|
302
366
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), "spec_helper")
|
2
|
+
|
3
|
+
|
4
|
+
describe "string_agg extension" do
|
5
|
+
dbf = lambda do |db_type|
|
6
|
+
db = Sequel.connect("mock://#{db_type}")
|
7
|
+
db.extension :string_agg
|
8
|
+
db
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:all) do
|
12
|
+
Sequel.extension :string_agg
|
13
|
+
end
|
14
|
+
before do
|
15
|
+
@sa1 = Sequel.string_agg(:c)
|
16
|
+
@sa2 = Sequel.string_agg(:c, '-')
|
17
|
+
@sa3 = Sequel.string_agg(:c, '-').order(:o)
|
18
|
+
@sa4 = Sequel.string_agg(:c).order(:o).distinct
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should use existing method" do
|
22
|
+
db = Sequel.mock
|
23
|
+
db.extend_datasets do
|
24
|
+
def string_agg_sql_append(sql, sa)
|
25
|
+
sql << "sa(#{sa.expr})"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
db.extension :string_agg
|
29
|
+
db.literal(Sequel.string_agg(:c)).must_equal "sa(c)"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should correctly literalize on Postgres" do
|
33
|
+
db = dbf.call(:postgres)
|
34
|
+
db.literal(@sa1).must_equal "string_agg(c, ',')"
|
35
|
+
db.literal(@sa2).must_equal "string_agg(c, '-')"
|
36
|
+
db.literal(@sa3).must_equal "string_agg(c, '-' ORDER BY o)"
|
37
|
+
db.literal(@sa4).must_equal "string_agg(DISTINCT c, ',' ORDER BY o)"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should correctly literalize on SQLAnywhere" do
|
41
|
+
db = dbf.call(:sqlanywhere)
|
42
|
+
db.literal(@sa1).must_equal "list(c, ',')"
|
43
|
+
db.literal(@sa2).must_equal "list(c, '-')"
|
44
|
+
db.literal(@sa3).must_equal "list(c, '-' ORDER BY o)"
|
45
|
+
db.literal(@sa4).must_equal "list(DISTINCT c, ',' ORDER BY o)"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should correctly literalize on MySQL, H2, HSQLDB, CUBRID" do
|
49
|
+
[:mysql, :h2, :hsqldb, :cubrid].each do |type|
|
50
|
+
db = dbf.call(type)
|
51
|
+
db.meta_def(:database_type){type}
|
52
|
+
db.literal(@sa1).must_equal "GROUP_CONCAT(c SEPARATOR ',')"
|
53
|
+
db.literal(@sa2).must_equal "GROUP_CONCAT(c SEPARATOR '-')"
|
54
|
+
db.literal(@sa3).must_equal "GROUP_CONCAT(c ORDER BY o SEPARATOR '-')"
|
55
|
+
db.literal(@sa4).must_equal "GROUP_CONCAT(DISTINCT c ORDER BY o SEPARATOR ',')"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should correctly literalize on Oracle and DB2" do
|
60
|
+
[:oracle, :db2].each do |type|
|
61
|
+
db = dbf.call(type)
|
62
|
+
db.literal(@sa1).must_equal "listagg(c, ',') WITHIN GROUP (ORDER BY 1)"
|
63
|
+
db.literal(@sa2).must_equal "listagg(c, '-') WITHIN GROUP (ORDER BY 1)"
|
64
|
+
db.literal(@sa3).must_equal "listagg(c, '-') WITHIN GROUP (ORDER BY o)"
|
65
|
+
proc{db.literal(@sa4)}.must_raise Sequel::Error
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should handle order without arguments" do
|
70
|
+
db = dbf.call(:postgres)
|
71
|
+
db.literal(@sa1.order).must_equal "string_agg(c, ',')"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should handle operations on object" do
|
75
|
+
db = dbf.call(:postgres)
|
76
|
+
db.literal(@sa1 + 'b').must_equal "(string_agg(c, ',') || 'b')"
|
77
|
+
db.literal(@sa1.like('b')).must_equal "(string_agg(c, ',') LIKE 'b' ESCAPE '\\')"
|
78
|
+
db.literal(@sa1 < 'b').must_equal "(string_agg(c, ',') < 'b')"
|
79
|
+
db.literal(@sa1.as(:b)).must_equal "string_agg(c, ',') AS b"
|
80
|
+
db.literal(@sa1.cast(:b)).must_equal "CAST(string_agg(c, ',') AS b)"
|
81
|
+
db.literal(@sa1.desc).must_equal "string_agg(c, ',') DESC"
|
82
|
+
db.literal(@sa1 =~ /a/).must_equal "(string_agg(c, ',') ~ 'a')"
|
83
|
+
db.literal(@sa1.sql_subscript(1)).must_equal "string_agg(c, ',')[1]"
|
84
|
+
end
|
85
|
+
end
|
@@ -2014,17 +2014,20 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
2014
2014
|
includes %w'abc def', :inc, opts.merge(:name=>:i)
|
2015
2015
|
unique :uniq, opts.merge(:name=>:u)
|
2016
2016
|
max_length 6, :minlen, opts.merge(:name=>:maxl2)
|
2017
|
+
operator :<, 'm', :exactlen, opts.merge(:name=>:lt)
|
2018
|
+
operator :>=, 5, :num, opts.merge(:name=>:gte)
|
2017
2019
|
end
|
2018
|
-
@valid_row = {:pre=>'a', :exactlen=>'12345', :minlen=>'12345', :maxlen=>'12345', :lenrange=>'1234', :lik=>'fooabc', :ilik=>'FooABC', :inc=>'abc', :uniq=>'u'}
|
2020
|
+
@valid_row = {:pre=>'a', :exactlen=>'12345', :minlen=>'12345', :maxlen=>'12345', :lenrange=>'1234', :lik=>'fooabc', :ilik=>'FooABC', :inc=>'abc', :uniq=>'u', :num=>5}
|
2019
2021
|
@violations = [
|
2020
2022
|
[:pre, [nil, '', ' ']],
|
2021
|
-
[:exactlen, [nil, '', '1234', '123456']],
|
2023
|
+
[:exactlen, [nil, '', '1234', '123456', 'n1234']],
|
2022
2024
|
[:minlen, [nil, '', '1234']],
|
2023
2025
|
[:maxlen, [nil, '123456']],
|
2024
2026
|
[:lenrange, [nil, '', '12', '123456']],
|
2025
2027
|
[:lik, [nil, '', 'fo', 'fotabc', 'FOOABC']],
|
2026
2028
|
[:ilik, [nil, '', 'fo', 'fotabc']],
|
2027
2029
|
[:inc, [nil, '', 'ab', 'abcd']],
|
2030
|
+
[:num, [nil, 3, 4]],
|
2028
2031
|
]
|
2029
2032
|
|
2030
2033
|
if @regexp
|
@@ -2101,6 +2104,7 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
2101
2104
|
String :ilik
|
2102
2105
|
String :inc
|
2103
2106
|
String :uniq, :null=>false
|
2107
|
+
Integer :num
|
2104
2108
|
validate(&validate_block)
|
2105
2109
|
end
|
2106
2110
|
end
|
@@ -2146,6 +2150,7 @@ describe "Sequel::Plugins::ConstraintValidations" do
|
|
2146
2150
|
if regexp
|
2147
2151
|
add_column :form, String
|
2148
2152
|
end
|
2153
|
+
add_column :num, Integer
|
2149
2154
|
validate(&validate_block)
|
2150
2155
|
end
|
2151
2156
|
end
|
@@ -2260,3 +2265,33 @@ describe "date_arithmetic extension" do
|
|
2260
2265
|
@check.call(:date_sub, @dt, @h2, @s2)
|
2261
2266
|
end
|
2262
2267
|
end
|
2268
|
+
|
2269
|
+
describe "string_agg extension" do
|
2270
|
+
before(:all) do
|
2271
|
+
@db = DB
|
2272
|
+
@db.extension(:string_agg)
|
2273
|
+
@db.create_table!(:string_agg_test) do
|
2274
|
+
Integer :id
|
2275
|
+
String :s
|
2276
|
+
Integer :o
|
2277
|
+
end
|
2278
|
+
@db[:string_agg_test].import([:id, :s, :o], [[1, 'a', 3], [1, 'a', 3], [1, 'b', 5], [1, 'c', 4], [2, 'aa', 2], [2, 'bb', 1]])
|
2279
|
+
@ds = @db[:string_agg_test].select_group(:id).order(:id)
|
2280
|
+
end
|
2281
|
+
after(:all) do
|
2282
|
+
@db.drop_table?(:string_agg_test)
|
2283
|
+
end
|
2284
|
+
|
2285
|
+
cspecify "should have string_agg return aggregated concatenation", :mssql, :sqlite, :derby do
|
2286
|
+
h = @ds.select_append(Sequel.string_agg(:s).as(:v)).to_hash(:id, :v)
|
2287
|
+
h[1].must_match(/\A[abc],[abc],[abc],[abc]\z/)
|
2288
|
+
h[2].must_match(/\A(aa|bb),(aa|bb)\z/)
|
2289
|
+
|
2290
|
+
@ds.select_append(Sequel.string_agg(:s).order(:o).as(:v)).map([:id, :v]).must_equal [[1, 'a,a,c,b'], [2, 'bb,aa']]
|
2291
|
+
@ds.select_append(Sequel.string_agg(:s, '-').order(:o).as(:v)).map([:id, :v]).must_equal [[1, 'a-a-c-b'], [2, 'bb-aa']]
|
2292
|
+
end
|
2293
|
+
|
2294
|
+
cspecify "should have string_agg return aggregated concatenation for distinct values", :mssql, :sqlite, :oracle, :db2, :derby do
|
2295
|
+
@ds.select_group(:id).select_append(Sequel.string_agg(:s).order(:s).distinct.as(:v)).map([:id, :v]).must_equal [[1, 'a,b,c'], [2, 'aa,bb']]
|
2296
|
+
end
|
2297
|
+
end
|
@@ -20,6 +20,16 @@ describe Sequel::Model::Associations::AssociationReflection, "#associated_class"
|
|
20
20
|
@c.association_reflection(:c).keys.wont_include(:class)
|
21
21
|
@c.association_reflection(:c).associated_class.must_equal ParParent
|
22
22
|
end
|
23
|
+
|
24
|
+
it "should respect :class_namespace option for specifying the namespace" do
|
25
|
+
class ::ParParent
|
26
|
+
class ParParent < Sequel::Model; end
|
27
|
+
end
|
28
|
+
ParParent.many_to_one :par_parent, :class=>'ParParent'
|
29
|
+
ParParent.association_reflection(:par_parent).associated_class.must_equal ParParent
|
30
|
+
ParParent.many_to_one :par_parent, :class=>'ParParent', :class_namespace=>'ParParent'
|
31
|
+
ParParent.association_reflection(:par_parent).associated_class.must_equal ParParent::ParParent
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
35
|
describe Sequel::Model::Associations::AssociationReflection, "#primary_key" do
|
data/spec/model/model_spec.rb
CHANGED
@@ -54,6 +54,40 @@ describe "Sequel::Model()" do
|
|
54
54
|
c.dataset.must_equal ds
|
55
55
|
end
|
56
56
|
|
57
|
+
it "should be callable on Sequel::Model" do
|
58
|
+
ds = @db[:blah]
|
59
|
+
c = Sequel::Model::Model(ds)
|
60
|
+
c.superclass.must_equal Sequel::Model
|
61
|
+
c.dataset.must_equal ds
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should be callable on subclasses of Sequel::Model" do
|
65
|
+
ds = @db[:blah]
|
66
|
+
c = Class.new(Sequel::Model)
|
67
|
+
sc = c::Model(ds)
|
68
|
+
sc.superclass.must_equal c
|
69
|
+
sc.dataset.must_equal ds
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be callable on other modules if def_Model is used" do
|
73
|
+
m = Module.new
|
74
|
+
Sequel::Model.def_Model(m)
|
75
|
+
ds = @db[:blah]
|
76
|
+
c = m::Model(ds)
|
77
|
+
c.superclass.must_equal Sequel::Model
|
78
|
+
c.dataset.must_equal ds
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should be callable using model subclasses on other modules if def_Model is used" do
|
82
|
+
m = Module.new
|
83
|
+
c = Class.new(Sequel::Model)
|
84
|
+
c.def_Model(m)
|
85
|
+
ds = @db[:blah]
|
86
|
+
sc = m::Model(ds)
|
87
|
+
sc.superclass.must_equal c
|
88
|
+
sc.dataset.must_equal ds
|
89
|
+
end
|
90
|
+
|
57
91
|
it "should return a model subclass associated to the given database if given a database" do
|
58
92
|
db = Sequel.mock
|
59
93
|
c = Sequel::Model(db)
|
@@ -122,6 +156,21 @@ describe "Sequel::Model()" do
|
|
122
156
|
class ::Album < Sequel::Model(@db[Sequel.identifier(:table)]); end
|
123
157
|
end.must_raise TypeError
|
124
158
|
end
|
159
|
+
|
160
|
+
it "should use separate cache and cache settings for subclasses" do
|
161
|
+
c = Class.new(Sequel::Model)
|
162
|
+
c.cache_anonymous_models.must_equal true
|
163
|
+
class ::Album < c::Model(:table); end
|
164
|
+
class ::Album < c::Model(:table); end
|
165
|
+
|
166
|
+
c1 = c::Model(:t1)
|
167
|
+
c1.must_equal c::Model(:t1)
|
168
|
+
c1.wont_equal Sequel::Model(:t1)
|
169
|
+
|
170
|
+
c.cache_anonymous_models = false
|
171
|
+
Sequel::Model.cache_anonymous_models.must_equal true
|
172
|
+
c1.wont_equal c::Model(:t1)
|
173
|
+
end
|
125
174
|
end
|
126
175
|
end
|
127
176
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -236,6 +236,7 @@ extra_rdoc_files:
|
|
236
236
|
- doc/release_notes/4.33.0.txt
|
237
237
|
- doc/release_notes/4.34.0.txt
|
238
238
|
- doc/release_notes/4.35.0.txt
|
239
|
+
- doc/release_notes/4.36.0.txt
|
239
240
|
files:
|
240
241
|
- CHANGELOG
|
241
242
|
- MIT-LICENSE
|
@@ -360,6 +361,7 @@ files:
|
|
360
361
|
- doc/release_notes/4.33.0.txt
|
361
362
|
- doc/release_notes/4.34.0.txt
|
362
363
|
- doc/release_notes/4.35.0.txt
|
364
|
+
- doc/release_notes/4.36.0.txt
|
363
365
|
- doc/release_notes/4.4.0.txt
|
364
366
|
- doc/release_notes/4.5.0.txt
|
365
367
|
- doc/release_notes/4.6.0.txt
|
@@ -475,6 +477,7 @@ files:
|
|
475
477
|
- lib/sequel/extensions/arbitrary_servers.rb
|
476
478
|
- lib/sequel/extensions/blank.rb
|
477
479
|
- lib/sequel/extensions/columns_introspection.rb
|
480
|
+
- lib/sequel/extensions/connection_expiration.rb
|
478
481
|
- lib/sequel/extensions/connection_validator.rb
|
479
482
|
- lib/sequel/extensions/constraint_validations.rb
|
480
483
|
- lib/sequel/extensions/core_extensions.rb
|
@@ -531,6 +534,7 @@ files:
|
|
531
534
|
- lib/sequel/extensions/split_array_nil.rb
|
532
535
|
- lib/sequel/extensions/sql_comments.rb
|
533
536
|
- lib/sequel/extensions/sql_expr.rb
|
537
|
+
- lib/sequel/extensions/string_agg.rb
|
534
538
|
- lib/sequel/extensions/string_date_time.rb
|
535
539
|
- lib/sequel/extensions/thread_local_timezones.rb
|
536
540
|
- lib/sequel/extensions/to_dot.rb
|
@@ -671,6 +675,7 @@ files:
|
|
671
675
|
- spec/extensions/column_select_spec.rb
|
672
676
|
- spec/extensions/columns_introspection_spec.rb
|
673
677
|
- spec/extensions/composition_spec.rb
|
678
|
+
- spec/extensions/connection_expiration_spec.rb
|
674
679
|
- spec/extensions/connection_validator_spec.rb
|
675
680
|
- spec/extensions/constraint_validations_plugin_spec.rb
|
676
681
|
- spec/extensions/constraint_validations_spec.rb
|
@@ -767,6 +772,7 @@ files:
|
|
767
772
|
- spec/extensions/sql_comments_spec.rb
|
768
773
|
- spec/extensions/sql_expr_spec.rb
|
769
774
|
- spec/extensions/static_cache_spec.rb
|
775
|
+
- spec/extensions/string_agg_spec.rb
|
770
776
|
- spec/extensions/string_date_time_spec.rb
|
771
777
|
- spec/extensions/string_stripper_spec.rb
|
772
778
|
- spec/extensions/subclasses_spec.rb
|