File: pg_timestamptz_spec.rb

package info (click to toggle)
ruby-sequel 5.97.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,188 kB
  • sloc: ruby: 123,115; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 1,158 bytes parent folder | download
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
require_relative "spec_helper"

describe "pg_timestamptz extension" do
  before do
    @db = Sequel.mock(:host=>'postgres').extension :pg_timestamptz
  end

  it "should use timestamptz as default timestamp type" do
    @db.create_table(:t){Time :t; DateTime :tz; Time :ot, :only_time=>true}
    @db.sqls.must_equal ['CREATE TABLE "t" ("t" timestamptz, "tz" timestamptz, "ot" time)']
  end

  it "should automatically cast Time and DateTime instances using TIMESTAMP WITH TIME ZONE when using auto_cast_date_and_time " do
    t = Time.utc(2000)
    dt = DateTime.new(2000)
    expected = "TIMESTAMP WITH TIME ZONE '2000-01-01 00:00:00.000000+0000'"

    @db.timezone = :utc
    @db.extension :auto_cast_date_and_time
    @db.literal(t).must_equal expected
    @db.literal(dt).must_equal expected

    db = Sequel.mock(:host=>'postgres').extension :auto_cast_date_and_time
    db.extension :pg_timestamptz
    db.literal(t).must_equal expected
    db.literal(dt).must_equal expected
  end

  it "should use timestamptz when casting" do
    @db.get(Sequel.cast('a', Time))
    @db.sqls.must_equal ["SELECT CAST('a' AS timestamptz) AS \"v\" LIMIT 1"]
  end
end