Sha256: b724584afd1443aef64274edbed138d13dfacfff3bbca1231e099c72a9300e9f

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

module UcbRails::LdapPerson
  class TestFinder
    PersonNotFound = Class.new(StandardError)

    def find_by_uid(uid)
      uid.presence and find_by_attributes(:uid => uid.to_s).first
    end

    def find_by_uid!(uid)
      find_by_uid(uid) || raise(PersonNotFound, "uid=#{uid.inspect}")
    end

    def find_by_first_last(first_name, last_name, options={})
      find_by_attributes(:first_name => first_name, :last_name => last_name)
    end

    def find_by_attributes(attributes)
      self.class.entries.select { |entry| entry_matches_attributes(entry, attributes) }
    end

    def entry_matches_attributes(entry, attributes)
      attributes.keys.all? do |key|
        value = attributes[key].to_s.downcase
        value.blank? || entry.send(key).downcase.include?(value)
      end
    end

    def self.entries
      [
        new_entry("1", 'art', "Art", "Andrews", "art@example.com", "999-999-0001", "Dept 1"),
        new_entry("2", 'beth', "Beth", "Brown", "beth@example.com", "999-999-0002", "Dept 2"),
        new_entry("61065", 'runner', "Steven", "Hansen", "runner@berkeley.edu", "999-999-9998", "EAS"),
        new_entry("191501", 'stevedowney', "Steve", "Downey", "sldowney@berkeley.edu", "999-999-9999", "EAS"),
      ]
    end

    def self.new_entry(uid, calnet_id, fn, ln, email, phone, depts)
      ::UcbRails::LdapPerson::Entry.new(
        :uid => uid,
        :calnet_id => calnet_id,
        :first_name => fn,
        :last_name => ln,
        :email => email,
        :phone => phone,
        :departments => depts
      )
    end
    
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ucb_rails-0.0.13 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.12 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.11 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.10 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.9 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.8 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.7 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.6 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.5 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.4 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.3 app/models/ucb_rails/ldap_person/test_finder.rb
ucb_rails-0.0.2 app/models/ucb_rails/ldap_person/test_finder.rb