Sha256: a2b9c36cafa2fa6fdb419f3bdddd8c6795a8e868a0b372e1b562b62495ea3f95

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

require 'spec_helper'
module Alf
  module Sql
    describe Builder, "order_by_clause" do

      let(:ordering){ Ordering.new([[:name, :asc], [:city, :desc]]) }

      context 'without desaliaser' do
        subject{ builder.order_by_clause(ordering) }

        let(:expected){
          [:order_by_clause,
            [:order_by_term, [:column_name, 'name'], 'asc'],
            [:order_by_term, [:column_name, 'city'], 'desc'] ]
        }

        it{ should eq(expected) }
      end

      context 'with a desaliaser' do
        let(:desaliaser){
          ->(a){
            if a == "name"
              [:qualified_name, [:range_var_name, "t1"], [:column_name, a]]
            else
              nil
            end
          }
        }

        subject{ builder.order_by_clause(ordering, &desaliaser) }

        let(:expected){
          [:order_by_clause,
            [:order_by_term, [:qualified_name, [:range_var_name, "t1"], [:column_name, 'name']], 'asc'],
            [:order_by_term, [:column_name, 'city'], 'desc'] ]
        }

        it{ should eq(expected) }
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-sql-0.16.3 spec/builder/test_order_by_clause.rb
alf-sql-0.16.2 spec/builder/test_order_by_clause.rb
alf-sql-0.16.1 spec/builder/test_order_by_clause.rb
alf-sql-0.16.0 spec/builder/test_order_by_clause.rb
alf-sql-0.15.0 spec/builder/test_order_by_clause.rb