File: current_datetime_timestamp_spec.rb

package info (click to toggle)
ruby-sequel 5.63.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,408 kB
  • sloc: ruby: 113,747; makefile: 3
file content (34 lines) | stat: -rw-r--r-- 1,102 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require_relative "spec_helper"

describe "current_datetime_timestamp extension" do
  before do
    @ds = Sequel.mock[:table].extension(:current_datetime_timestamp)
  end
  after do
    Sequel.datetime_class = Time
  end

  it "should have current_timestamp respect Sequel.datetime_class" do
    t = Sequel::Dataset.new(nil).current_datetime 
    t.must_be_kind_of(Time)
    (Time.now - t < 0.1).must_equal true

    Sequel.datetime_class = DateTime
    t = Sequel::Dataset.new(nil).current_datetime 
    t.must_be_kind_of(DateTime)
    (DateTime.now - t < (0.1/86400)).must_equal true
  end

  it "should have current_timestamp value be literalized as CURRENT_TIMESTAMP" do
    @ds.literal(@ds.current_datetime).must_equal 'CURRENT_TIMESTAMP'
    Sequel.datetime_class = DateTime
    @ds.literal(@ds.current_datetime).must_equal 'CURRENT_TIMESTAMP'
  end


  it "should have other Date/Time values literalized normally" do
    t = Time.at(1594239778).getutc
    @ds.literal(t).must_equal "'2020-07-08 20:22:58.000000'"
    @ds.literal(t.to_datetime).must_equal "'2020-07-08 20:22:58.000000'"
  end
end