Sha256: 1b00c918d22863d6b0a8e49515e96a8c173e0aed54430b819eb103c54bdbeb36

Contents?: true

Size: 1.92 KB

Versions: 8

Compression:

Stored size: 1.92 KB

Contents

$LOAD_PATH << File.dirname(__FILE__)
require 'spec_helper'

describe DataMapper.repository(:ldap).adapter do

  describe 'belongs_to association' do

    before do
      DataMapper.repository(:ldap) do
        User.all.destroy!
        @user1 = User.create(:login => "black", :name => 'Black', :mail => ["blackmail@example.com"], :age => 100)
        @user2 = User.create(:login => "brown", :name => 'brown', :mail => ["brownmail@example.com"], :age => 25)
        @user3 = User.create(:login => "blue", :name => 'Yellow')
        @user4 = User.create(:login => "baluh", :name => 'Hmm')
      end
    end

    it 'should sort descending without order option' do
      DataMapper.repository(:ldap) do
        expected = User.all().sort do |u1, u2|
          u1.id <=> u2.id
        end
        User.all.should == expected
      end
    end

    it 'should sort descending with order option' do
      DataMapper.repository(:ldap) do
        expected = User.all().sort do |u1, u2|
          u1.login <=> u2.login
        end
        User.all(:order => [:login]).should == expected
      end
      DataMapper.repository(:ldap) do
        expected = User.all().sort do |u1, u2|
          -1 * (u1.login <=> u2.login)
        end
        User.all(:order => [:login]).reverse.should == expected
      end
    end
    it 'should sort case insensitive with order option' do
      DataMapper.repository(:ldap) do
        expected = User.all().sort do |u1, u2|
          u1.name.upcase <=> u2.name.upcase
        end
        User.all(:order => [:name]).should == expected
      end
    end

    it 'should sort with nil values' do
      DataMapper.repository(:ldap) do
        users = User.all(:order => [:name]).select { |u| !u.mail.nil? }
        users.should == [@user1, @user2]
      end
      DataMapper.repository(:ldap) do
        users = User.all(:order => [:name]).reverse.select { |u| !u.mail.nil? }
        users.should == [@user2, @user1]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dm-ldap-adapter-0.4.3-java spec/sorting_spec.rb
dm-ldap-adapter-0.4.3 spec/sorting_spec.rb
dm-ldap-adapter-0.4.2 spec/sorting_spec.rb
dm-ldap-adapter-0.4.1 spec/sorting_spec.rb
dm-ldap-adapter-0.4.0 spec/sorting_spec.rb
dm-ldap-adapter-0.4.0.alpha4 spec/sorting_spec.rb
dm-ldap-adapter-0.4.0.alpha3 spec/sorting_spec.rb
dm-ldap-adapter-0.4.0.alpha2 spec/sorting_spec.rb