Sha256: 10d65f9407977e7c3534bc1a2ded1477f43a87fb529d68bf87054a4929ee855e

Contents?: true

Size: 848 Bytes

Versions: 6

Compression:

Stored size: 848 Bytes

Contents

require 'spec_helper'

RSpec.describe ROM::SQL::RestrictionDSL, :sqlite, helpers: true do
  include_context 'database setup'

  subject(:dsl) do
    ROM::SQL::RestrictionDSL.new(schema)
  end

  let(:schema) do
    define_schema(:users, id: ROM::SQL::Types::Serial, name: ROM::SQL::Types::String)
  end

  let(:ds) do
    conn[:users]
  end

  describe '#call' do
    it 'evaluates the block and returns an SQL expression' do
      expect(conn[:users].literal(dsl.call { count(id) >= 3 })).to eql('(count(`id`) >= 3)')
    end
  end

  describe '#method_missing' do
    it 'responds to methods matching attribute names' do
      expect(dsl.id.name).to be(:id)
      expect(dsl.name.name).to be(:name)
    end

    it 'delegates to sequel virtual row' do
      expect(conn[:users].literal(dsl.count(dsl.id))).to eql('count(`id`)')
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rom-sql-1.3.5 spec/unit/restriction_dsl_spec.rb
rom-sql-1.3.4 spec/unit/restriction_dsl_spec.rb
rom-sql-2.0.0.beta2 spec/unit/restriction_dsl_spec.rb
rom-sql-2.0.0.beta1 spec/unit/restriction_dsl_spec.rb
rom-sql-1.3.3 spec/unit/restriction_dsl_spec.rb
rom-sql-1.3.2 spec/unit/restriction_dsl_spec.rb