sequel 5.22.0 → 5.23.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ Sequel.extension :thread_local_timezones
9
9
  Sequel.extension :named_timezones
10
10
  Sequel.datetime_class = Time
11
11
 
12
- describe "Sequel named_timezones extension" do
12
+ describe "Sequel named_timezones extension with DateTime class" do
13
13
  before do
14
14
  @tz_in = TZInfo::Timezone.get('America/Los_Angeles')
15
15
  @tz_out = TZInfo::Timezone.get('America/New_York')
@@ -54,10 +54,12 @@ describe "Sequel named_timezones extension" do
54
54
 
55
55
  it "should convert datetimes coming out of the database from database_timezone to application_timezone" do
56
56
  dt = Sequel.database_to_application_timestamp('2009-06-01 06:20:30-0400')
57
+ dt.must_be_instance_of DateTime
57
58
  dt.must_equal @dt
58
59
  dt.offset.must_equal(-7/24.0)
59
60
 
60
61
  dt = Sequel.database_to_application_timestamp('2009-06-01 10:20:30+0000')
62
+ dt.must_be_instance_of DateTime
61
63
  dt.must_equal @dt
62
64
  dt.offset.must_equal(-7/24.0)
63
65
  end
@@ -68,7 +70,9 @@ describe "Sequel named_timezones extension" do
68
70
 
69
71
  it "should support tzinfo_disambiguator= to handle ambiguous timezones automatically" do
70
72
  Sequel.tzinfo_disambiguator = proc{|datetime, periods| periods.first}
71
- Sequel.database_to_application_timestamp('2004-10-31T01:30:00').must_equal DateTime.parse('2004-10-30T22:30:00-07:00')
73
+ dt = Sequel.database_to_application_timestamp('2004-10-31T01:30:00')
74
+ dt.must_equal DateTime.parse('2004-10-30T22:30:00-07:00')
75
+ dt.offset.must_equal(-7/24.0)
72
76
  end
73
77
 
74
78
  it "should assume datetimes coming out of the database that don't have an offset as coming from database_timezone" do
@@ -108,4 +112,107 @@ describe "Sequel named_timezones extension" do
108
112
  tz2.must_equal @tz_in
109
113
  end
110
114
  end
115
+
116
+ describe "Sequel named_timezones extension with Time class" do
117
+ before do
118
+ @tz_in = TZInfo::Timezone.get('America/Los_Angeles')
119
+ @tz_out = TZInfo::Timezone.get('America/New_York')
120
+ @db = Sequel.mock
121
+ Sequel.application_timezone = 'America/Los_Angeles'
122
+ Sequel.database_timezone = 'America/New_York'
123
+ end
124
+ after do
125
+ Sequel.tzinfo_disambiguator = nil
126
+ Sequel.default_timezone = nil
127
+ Sequel.datetime_class = Time
128
+ end
129
+
130
+ it "should convert string arguments to *_timezone= to TZInfo::Timezone instances" do
131
+ Sequel.application_timezone.must_equal @tz_in
132
+ Sequel.database_timezone.must_equal @tz_out
133
+ end
134
+
135
+ it "should convert string arguments for Database#timezone= to TZInfo::Timezone instances for database-specific timezones" do
136
+ @db.extension :named_timezones
137
+ @db.timezone = 'America/Los_Angeles'
138
+ @db.timezone.must_equal @tz_in
139
+ end
140
+
141
+ it "should accept TZInfo::Timezone instances in *_timezone=" do
142
+ Sequel.application_timezone = @tz_in
143
+ Sequel.database_timezone = @tz_out
144
+ Sequel.application_timezone.must_equal @tz_in
145
+ Sequel.database_timezone.must_equal @tz_out
146
+ end
147
+
148
+ it "should convert datetimes going into the database to named database_timezone" do
149
+ ds = @db[:a].with_extend do
150
+ def supports_timestamp_timezones?; true; end
151
+ def supports_timestamp_usecs?; false; end
152
+ end
153
+ ds.insert([Time.new(2009,6,1,3,20,30, RUBY_VERSION >= '2.6' ? @tz_in : -25200), Time.new(2009,6,1,3,20,30,-25200), Time.new(2009,6,1,6,20,30,-14400)])
154
+ @db.sqls.must_equal ["INSERT INTO a VALUES ('2009-06-01 06:20:30-0400', '2009-06-01 06:20:30-0400', '2009-06-01 06:20:30-0400')"]
155
+ end
156
+
157
+ it "should convert datetimes coming out of the database from database_timezone to application_timezone" do
158
+ dt = Sequel.database_to_application_timestamp('2009-06-01 06:20:30-0400')
159
+ dt.must_be_instance_of Time
160
+ dt.must_equal Time.new(2009,6,1,3,20,30,-25200)
161
+ dt.utc_offset.must_equal -25200
162
+
163
+ dt = Sequel.database_to_application_timestamp('2009-06-01 10:20:30+0000')
164
+ dt.must_be_instance_of Time
165
+ dt.must_equal Time.new(2009,6,1,3,20,30,-25200)
166
+ dt.utc_offset.must_equal -25200
167
+ end
168
+
169
+ it "should raise an error for ambiguous timezones by default" do
170
+ proc{Sequel.database_to_application_timestamp('2004-10-31T01:30:00')}.must_raise(Sequel::InvalidValue)
171
+ end
172
+
173
+ it "should support tzinfo_disambiguator= to handle ambiguous timezones automatically" do
174
+ Sequel.tzinfo_disambiguator = proc{|datetime, periods| periods.first}
175
+ Sequel.database_to_application_timestamp('2004-10-31T01:30:00').must_equal Time.new(2004, 10, 30, 22, 30, 0, -25200)
176
+ dt = Sequel.database_to_application_timestamp('2004-10-31T01:30:00')
177
+ dt.must_equal Time.new(2004, 10, 30, 22, 30, 0, -25200)
178
+ dt.utc_offset.must_equal -25200
179
+ end
180
+
181
+ it "should assume datetimes coming out of the database that don't have an offset as coming from database_timezone" do
182
+ dt = Sequel.database_to_application_timestamp('2009-06-01 06:20:30')
183
+ dt.must_be_instance_of Time
184
+ dt.must_equal Time.new(2009,6,1,3,20,30, -25200)
185
+ dt.utc_offset.must_equal -25200
186
+
187
+ dt = Sequel.database_to_application_timestamp('2009-06-01 10:20:30')
188
+ dt.must_be_instance_of Time
189
+ dt.must_equal Time.new(2009,6,1,7,20,30, -25200)
190
+ dt.utc_offset.must_equal -25200
191
+ end
192
+
193
+ it "should work with the thread_local_timezones extension" do
194
+ q, q1, q2 = Queue.new, Queue.new, Queue.new
195
+ tz1, tz2 = nil, nil
196
+ t1 = Thread.new do
197
+ Sequel.thread_application_timezone = 'America/New_York'
198
+ q2.push nil
199
+ q.pop
200
+ tz1 = Sequel.application_timezone
201
+ end
202
+ t2 = Thread.new do
203
+ Sequel.thread_application_timezone = 'America/Los_Angeles'
204
+ q2.push nil
205
+ q1.pop
206
+ tz2 = Sequel.application_timezone
207
+ end
208
+ q2.pop
209
+ q2.pop
210
+ q.push nil
211
+ q1.push nil
212
+ t1.join
213
+ t2.join
214
+ tz1.must_equal @tz_out
215
+ tz2.must_equal @tz_in
216
+ end
217
+ end
111
218
  end
@@ -241,6 +241,18 @@ describe "pg_json extension" do
241
241
  Sequel.pg_json_wrap(false).must_equal false
242
242
  Sequel.pg_json_wrap(nil).class.must_equal Sequel::Postgres::JSONNull
243
243
  Sequel.pg_json_wrap(nil).must_be_nil
244
+
245
+ c = Class.new(Hash).new
246
+ Sequel.pg_json_wrap(c).class.must_equal Sequel::Postgres::JSONHash
247
+ Sequel.pg_json_wrap(c).must_equal(c)
248
+
249
+ c = Class.new(Array).new
250
+ Sequel.pg_json_wrap(c).class.must_equal Sequel::Postgres::JSONArray
251
+ Sequel.pg_json_wrap(c).must_equal c
252
+
253
+ c = Class.new(String).new('a')
254
+ Sequel.pg_json_wrap(c).class.must_equal Sequel::Postgres::JSONString
255
+ Sequel.pg_json_wrap(c).must_equal c
244
256
  end
245
257
 
246
258
  it "Sequel.pg_json_wrap should fail when passed an unsupported object" do
@@ -429,12 +429,12 @@ describe "pg_range extension" do
429
429
  @R.new(nil, nil).wont_equal @R.new(nil, nil, :empty=>true)
430
430
  end
431
431
 
432
- it "should only consider empty PGRanges equal if they have the same bounds" do
432
+ it "should only consider PGRanges equal if they have the same bounds" do
433
433
  @R.new(1, 2).must_equal @R.new(1, 2)
434
434
  @R.new(1, 2).wont_equal @R.new(1, 3)
435
435
  end
436
436
 
437
- it "should only consider empty PGRanges equal if they have the same bound exclusions" do
437
+ it "should only consider PGRanges equal if they have the same bound exclusions" do
438
438
  @R.new(1, 2, :exclude_begin=>true).must_equal @R.new(1, 2, :exclude_begin=>true)
439
439
  @R.new(1, 2, :exclude_end=>true).must_equal @R.new(1, 2, :exclude_end=>true)
440
440
  @R.new(1, 2, :exclude_begin=>true).wont_equal @R.new(1, 2, :exclude_end=>true)
@@ -450,6 +450,9 @@ describe "pg_range extension" do
450
450
 
451
451
  it "should not consider a PGRange equal with a Range if it can't be expressed as a range" do
452
452
  @R.new(nil, nil).wont_be :==, (1..2)
453
+ if startless_range_support
454
+ @R.new(nil, nil, :exclude_begin=>true).wont_be :==, eval('nil..nil')
455
+ end
453
456
  end
454
457
 
455
458
  it "should consider PGRanges equal with a endless Range they represent" do
@@ -16,6 +16,11 @@ require_relative "../../lib/sequel"
16
16
 
17
17
  require_relative '../deprecation_helper'
18
18
 
19
+ if ENV['SEQUEL_TZINFO_VERSION']
20
+ # Allow forcing specific TZInfo versions, useful when testing
21
+ gem 'tzinfo', ENV['SEQUEL_TZINFO_VERSION']
22
+ end
23
+
19
24
  begin
20
25
  # Attempt to load ActiveSupport blank extension and inflector first, so Sequel
21
26
  # can override them.
@@ -26,7 +31,9 @@ rescue LoadError
26
31
  nil
27
32
  end
28
33
 
29
- Sequel.extension :core_refinements if RUBY_VERSION >= '2.0.0' && RUBY_ENGINE == 'ruby'
34
+ if (RUBY_VERSION >= '2.0.0' && RUBY_ENGINE == 'ruby') || (RUBY_ENGINE == 'jruby' && (JRUBY_VERSION >= '9.3' || (JRUBY_VERSION.match(/\A9\.2\.(\d+)/) && $1.to_i >= 7)))
35
+ Sequel.extension :core_refinements
36
+ end
30
37
 
31
38
  class << Sequel::Model
32
39
  attr_writer :db_schema
@@ -2394,3 +2394,30 @@ describe "string_agg extension" do
2394
2394
  @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']]
2395
2395
  end
2396
2396
  end
2397
+
2398
+ describe "insert_conflict plugin" do
2399
+ before(:all) do
2400
+ @db = DB
2401
+ @db.create_table!(:ic_test) do
2402
+ primary_key :id
2403
+ String :s, :unique=>true
2404
+ Integer :o
2405
+ end
2406
+ @model = Class.new(Sequel::Model)
2407
+ @model.set_dataset @db[:ic_test]
2408
+ @model.plugin :insert_conflict
2409
+ end
2410
+ after(:all) do
2411
+ @db.drop_table?(:ic_test)
2412
+ end
2413
+
2414
+ it "should allow Model#insert_conflict to work" do
2415
+ ic_opts = {:target=>:s, :update => {:o => Sequel[:excluded][:o]}}
2416
+ @model.new(:s=>'A', :o=>1).insert_conflict(ic_opts).save
2417
+ @model.select_order_map([:s, :o]).must_equal [['A', 1]]
2418
+ @model.new(:s=>'A', :o=>2).insert_conflict(ic_opts).save
2419
+ @model.select_order_map([:s, :o]).must_equal [['A', 2]]
2420
+ @model.new(:s=>'B', :o=>3).insert_conflict(ic_opts).save
2421
+ @model.select_order_map([:s, :o]).must_equal [['A', 2], ['B', 3]]
2422
+ end
2423
+ end if (DB.database_type == :postgres && DB.server_version >= 90500) || (DB.database_type == :sqlite && DB.sqlite_version >= 32400)
@@ -750,10 +750,15 @@ describe "Database schema modifiers" do
750
750
  @db.create_table!(:items) do
751
751
  primary_key :id
752
752
  Integer :i, :default=>20
753
+ Integer :j, :default=>10
754
+ String :s, :default=>'a'
753
755
  end
754
- @ds.insert(:i=>10)
756
+ @ds.insert(:i=>10, :j=>20, :s=>'b')
755
757
  @db.drop_column(:items, :i)
756
- @db.schema(:items, :reload=>true).map{|x| x.first}.must_equal [:id]
758
+ @db.schema(:items, :reload=>true).map{|x| x.first}.must_equal [:id, :j, :s]
759
+ @ds.first.must_equal(:id=>1, :j=>20, :s=>'b')
760
+ @ds.insert
761
+ @ds.first(:id=>2).must_equal(:id=>2, :j=>10, :s=>'a')
757
762
  end
758
763
 
759
764
  it "should remove foreign key columns from tables correctly" do
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: 5.22.0
4
+ version: 5.23.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: 2019-07-01 00:00:00.000000000 Z
11
+ date: 2019-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -206,6 +206,7 @@ extra_rdoc_files:
206
206
  - doc/release_notes/5.20.0.txt
207
207
  - doc/release_notes/5.21.0.txt
208
208
  - doc/release_notes/5.22.0.txt
209
+ - doc/release_notes/5.23.0.txt
209
210
  files:
210
211
  - CHANGELOG
211
212
  - MIT-LICENSE
@@ -299,6 +300,7 @@ files:
299
300
  - doc/release_notes/5.20.0.txt
300
301
  - doc/release_notes/5.21.0.txt
301
302
  - doc/release_notes/5.22.0.txt
303
+ - doc/release_notes/5.23.0.txt
302
304
  - doc/release_notes/5.3.0.txt
303
305
  - doc/release_notes/5.4.0.txt
304
306
  - doc/release_notes/5.5.0.txt
@@ -513,6 +515,7 @@ files:
513
515
  - lib/sequel/plugins/force_encoding.rb
514
516
  - lib/sequel/plugins/hook_class_methods.rb
515
517
  - lib/sequel/plugins/input_transformer.rb
518
+ - lib/sequel/plugins/insert_conflict.rb
516
519
  - lib/sequel/plugins/insert_returning_select.rb
517
520
  - lib/sequel/plugins/instance_filters.rb
518
521
  - lib/sequel/plugins/instance_hooks.rb
@@ -644,6 +647,7 @@ files:
644
647
  - spec/extensions/index_caching_spec.rb
645
648
  - spec/extensions/inflector_spec.rb
646
649
  - spec/extensions/input_transformer_spec.rb
650
+ - spec/extensions/insert_conflict_spec.rb
647
651
  - spec/extensions/insert_returning_select_spec.rb
648
652
  - spec/extensions/instance_filters_spec.rb
649
653
  - spec/extensions/instance_hooks_spec.rb