Sha256: 4ab28a116423bd351849fdf23ffc98822546c67442493c7ab278a771e40ad71d

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

require 'rom/sql/function'

RSpec.describe ROM::SQL::Function, :postgres do
  subject(:func) { ROM::SQL::Function.new(type) }

  include_context 'database setup'

  let(:ds) { container.gateways[:default][:users] }
  let(:type) { ROM::SQL::Types::Int }

  describe '#sql_literal' do
    context 'without alias' do
      specify do
        expect(func.count(:id).sql_literal(ds)).to eql(%(COUNT("id")))
      end
    end

    context 'with alias' do
      specify do
        expect(func.count(:id).as(:count).sql_literal(ds)).to eql(%(COUNT("id") AS "count"))
      end
    end
  end

  describe '#is' do
    it 'returns an sql boolean expression' do
      expect((func.count(:id).is(1)).sql_literal(ds)).to eql(%((COUNT("id") = 1)))
    end
  end

  describe '#method_missing' do
    it 'responds to anything when not set' do
      expect(func.count(:id)).to be_instance_of(func.class)
    end

    it 'raises error when is set already' do
      expect { func.count(:id).upper.sql_literal(ds) }.
        to raise_error(NoMethodError, /upper/)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rom-sql-1.3.1 spec/unit/function_spec.rb
rom-sql-1.3.0 spec/unit/function_spec.rb
rom-sql-1.2.2 spec/unit/function_spec.rb
rom-sql-1.2.1 spec/unit/function_spec.rb
rom-sql-1.2.0 spec/unit/function_spec.rb
rom-sql-1.1.2 spec/unit/function_spec.rb
rom-sql-1.1.1 spec/unit/function_spec.rb
rom-sql-1.1.0 spec/unit/function_spec.rb
rom-sql-1.0.3 spec/unit/function_spec.rb
rom-sql-1.0.2 spec/unit/function_spec.rb
rom-sql-1.0.1 spec/unit/function_spec.rb
rom-sql-1.0.0 spec/unit/function_spec.rb