Sha256: 83f2913c73e61e19f52c28f72e8ea93b906741c0ef57a7b9c141321fce36467a

Contents?: true

Size: 1.21 KB

Versions: 4

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require_relative "../helper"

class Arel::Nodes::ExtractTest < Arel::Spec
  it "should extract field" do
    table = Arel::Table.new :users
    _(table[:timestamp].extract("date").to_sql).must_be_like %{
      EXTRACT(DATE FROM "users"."timestamp")
    }
  end

  describe "as" do
    it "should alias the extract" do
      table = Arel::Table.new :users
      _(table[:timestamp].extract("date").as("foo").to_sql).must_be_like %{
        EXTRACT(DATE FROM "users"."timestamp") AS foo
      }
    end

    it "should not mutate the extract" do
      table = Arel::Table.new :users
      extract = table[:timestamp].extract("date")
      before = extract.dup
      extract.as("foo")
      assert_equal extract, before
    end
  end

  describe "equality" do
    it "is equal with equal ivars" do
      table = Arel::Table.new :users
      array = [table[:attr].extract("foo"), table[:attr].extract("foo")]
      assert_equal 1, array.uniq.size
    end

    it "is not equal with different ivars" do
      table = Arel::Table.new :users
      array = [table[:attr].extract("foo"), table[:attr].extract("bar")]
      assert_equal 2, array.uniq.size
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ibm_db-5.5.0-x86-mingw32 test/cases/arel/nodes/extract_test.rb
ibm_db-5.4.1-x86-mingw32 test/cases/arel/nodes/extract_test.rb
ibm_db-5.4.0-x86-mingw32 test/cases/arel/nodes/extract_test.rb
ibm_db-5.3.2-x86-mingw32 test/cases/arel/nodes/extract_test.rb