dm-ldap-adapter 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ version 0.3.3
2
+ =============
3
+
4
+ * fix bug with empty LdapArray for ruby-ldap-adapter
5
+
6
+ * added order option to search with just using the first order attribute and ignoring the direction and other attributes
7
+
1
8
  version 0.3.2
2
9
  =============
3
10
 
data/Manifest.txt CHANGED
@@ -18,14 +18,12 @@ lib/ldap/net_ldap_facade.rb
18
18
  lib/ldap/ruby_ldap_facade.rb
19
19
  lib/ldap/version.rb
20
20
  lib/ldap_resource.rb
21
- net-ldap.txt
22
- ruby-ldap.txt
23
21
  spec/assiociations_ldap_adapter_spec.rb
24
22
  spec/authentication_ldap_adapter_spec.rb
25
23
  spec/ldap_adapter_spec.rb
26
24
  spec/multi_repository_spec.rb
27
25
  spec/multi_value_attributes_spec.rb
26
+ spec/sorting_spec.rb
28
27
  spec/spec.opts
29
28
  spec/spec_helper.rb
30
- test.db
31
29
  test.ldif
data/README.txt CHANGED
@@ -16,7 +16,9 @@ the usecase for that implementation was using an ldap server for user authentica
16
16
 
17
17
  === low level ldap library
18
18
 
19
- the ldap library which does the actual ldap protocol stuff is [http://rubyforge.org/projects/net-ldap] and it is hidden behind a facade, so one could replace it with a different library or make it pluggable.
19
+ the ldap library which does the actual ldap protocol stuff is [http://rubyforge.org/projects/net-ldap] which is the default. the other ldap library is [http://rubyforge.org/projects/ruby-ldap]. these libraries are behind a facade, if you want to use the ruby-ldap library you need to require the right facade before the ldap-adapter:
20
+
21
+ require 'ldap/ruby_ldap_facade'
20
22
 
21
23
  === examples
22
24
 
@@ -26,9 +28,9 @@ the 'example/identity_map.rb' shows the usage of identity maps, see also below.
26
28
 
27
29
  == FEATURES/PROBLEMS:
28
30
 
29
- * the net-ldap has some issues with not closing the connections when an exception/error got raised
31
+ * the net-ldap has some issues with not closing the connections when an exception/error got raised, with limit the search result to 126 entries which gets fixed by making consecutives searches and collect the result.
30
32
 
31
- * error from the ldap server are only logged and do not raise any exceptions (to be changed in next release)
33
+ * error from the ldap server are only logged and do not raise any exceptions (to be changed in next release) with one exception: when creating a new ldap entry a duplicated entry will raise DataMapper::PersistenceError
32
34
 
33
35
  == SYNOPSIS:
34
36
 
@@ -165,7 +167,7 @@ staying with posix example there the groups has a memberuid attribute BUT unlike
165
167
 
166
168
  === ldap attributes with many values
167
169
 
168
- let's say your LDAP has multiple email values for a users then you can define your resource class like that using the type LdapArray for such multivalue fields
170
+ let's say your LDAP has multiple email values for a users then you can define your resource class like that using the type *LdapArray* for such multivalue fields
169
171
 
170
172
  class User
171
173
  include DataMapper::Resource
@@ -271,12 +271,13 @@ module DataMapper
271
271
  # @return [Array<DataMapper::Resource]
272
272
  # the array of found resources
273
273
  # @see SimpleAdapter#read_resources
274
- def read_resources(query)
274
+ def read_resources(query)
275
+ order_by = query.order.first.property.field
275
276
  field_names = query.fields.collect {|f| f.field }
276
277
  result = ldap.read_objects(query.model.treebase,
277
278
  query.model.key.collect { |k| k.field },
278
279
  to_ldap_conditions(query),
279
- field_names)
280
+ field_names, order_by)
280
281
  if query.model.multivalue_field
281
282
  props_result = []
282
283
  result.each do |props|
data/lib/ldap/array.rb CHANGED
@@ -3,6 +3,15 @@ module DataMapper
3
3
  class LdapArray < DataMapper::Type
4
4
  primitive Array
5
5
  default Proc.new { Array.new }
6
+
7
+ def self.dump(value, property)
8
+ value || []
9
+ end
10
+
11
+ def self.load(value, property)
12
+ value || []
13
+ end
14
+
6
15
  end
7
16
  end
8
17
  Property::TYPES << Types::LdapArray unless Property::TYPES.member? Types::LdapArray
@@ -63,7 +63,7 @@ module Ldap
63
63
  # @param key_fields Array of fields which carries the integer unique id(s) of the entity
64
64
  # @param Array of conditions for the search
65
65
  # @return Array of Hashes with a name/values pair for each attribute
66
- def read_objects(treebase, key_fields, conditions, field_names)
66
+ def read_objects(treebase, key_fields, conditions, field_names, order_field = nil)
67
67
  filters = []
68
68
  conditions.each do |cond|
69
69
  c = cond[2]
@@ -83,7 +83,7 @@ module Ldap
83
83
  # @param key_fields Array of fields which carries the integer unique id(s) of the entity
84
84
  # @param Array of conditions for the search
85
85
  # @return Array of Hashes with a name/values pair for each attribute
86
- def read_objects(treebase, key_fields, conditions, field_names)
86
+ def read_objects(treebase, key_fields, conditions, field_names, order_field = '')
87
87
  filters = []
88
88
  conditions.each do |cond|
89
89
  c = cond[2]
@@ -169,7 +169,7 @@ module Ldap
169
169
  @ldap2.search("#{treebase},#{@ldap2.base}",
170
170
  LDAP::LDAP_SCOPE_SUBTREE,
171
171
  filter.to_s == "" ? "(objectclass=*)" : filter.to_s.gsub(/\(\(/, "(").gsub(/\)\)/, ")"),
172
- field_names) do |res|
172
+ field_names, false, 0, 0, order_field) do |res|
173
173
 
174
174
  map = to_map(res)
175
175
  #puts map[key_field.to_sym]
data/lib/ldap/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ldap
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
@@ -92,7 +92,7 @@ require 'spec_helper'
92
92
  @user1.groups << @group2
93
93
  @user1.save
94
94
  User.get(@user1.id)
95
- @user1.groups.should == [@group1, @group2]
95
+ @user1.groups.sort{|g1, g2| g1.id <=> g2.id}.should == [@group1, @group2]
96
96
  @user1.groups.delete(@group1)
97
97
  @user1.save
98
98
  User.get(@user1.id).groups.should == [@group2]
@@ -109,13 +109,13 @@ require 'spec_helper'
109
109
  @user1.groups << @group1
110
110
  @user1.groups << @group2
111
111
  @user1.save
112
- User.get(@user1.id).groups.should == [@group1, @group2]
112
+ User.get(@user1.id).groups.sort{|g1, g2| g1.id <=> g2.id}.should == [@group1, @group2]
113
113
  @user2.groups << @group1
114
114
  @user2.save
115
115
  end
116
116
  DataMapper.repository(adapter) do
117
117
  User.get(@user2.id).groups.should == [@group1]
118
- User.get(@user1.id).groups.should == [@group1, @group2]
118
+ User.get(@user1.id).groups.sort{|g1, g2| g1.id <=> g2.id}.should == [@group1, @group2]
119
119
  end
120
120
  end
121
121
 
@@ -130,11 +130,11 @@ require 'spec_helper'
130
130
  @user1 = User.get!(@user1.id)
131
131
  @user1.groups << @group1
132
132
  @user1.groups << @group2
133
- @user1.groups.should == [@group1, @group2]
133
+ @user1.groups.sort{|g1, g2| g1.id <=> g2.id}.should == [@group1, @group2]
134
134
  @user2.groups << @group1
135
135
  end
136
136
  DataMapper.repository(adapter) do
137
- User.get(@user1.id).groups.should == [@group1, @group2]
137
+ User.get(@user1.id).groups.sort{|g1, g2| g1.id <=> g2.id}.should == [@group1, @group2]
138
138
  User.get(@user2.id).groups.should == [@group1]
139
139
  end
140
140
  end
@@ -33,7 +33,8 @@ describe DataMapper.repository(:ldap).adapter.class do
33
33
 
34
34
  before :each do
35
35
  DataMapper.repository(:ldap) do
36
- @contact = Contact.first(:login => "beige") || Contact.new(:login => "beige", :name => 'Beige')
36
+ Contact.all(:login => "beige").destroy!
37
+ @contact = Contact.new(:login => "beige", :name => 'Beige')
37
38
  @contact.password = "asd123"
38
39
  @contact.save
39
40
  end
@@ -72,7 +73,7 @@ describe DataMapper.repository(:ldap).adapter.class do
72
73
  end
73
74
 
74
75
  it 'should get an LdapArray on retrieving collection' do
75
- DataMapper.repository(:ldap) do
76
+ DataMapper.repository(:ldap) do
76
77
  @contact.mail.should == []
77
78
 
78
79
  @contact.mail << "email1"
@@ -96,5 +97,16 @@ describe DataMapper.repository(:ldap).adapter.class do
96
97
  @contact.mail.should == []
97
98
  end
98
99
  end
100
+
101
+ it 'should allow to replace the LdapArray' do
102
+ DataMapper.repository(:ldap) do
103
+ @contact = Contact.get(@contact.id)
104
+ @contact.mail.should == []
105
+ @contact.mail = ['foo', 'bar']
106
+ @contact.save
107
+ @contact = Contact.get(@contact.id)
108
+ @contact.mail.should == ['foo', 'bar']
109
+ end
110
+ end
99
111
  end
100
112
  end
@@ -0,0 +1,47 @@
1
+ $LOAD_PATH << File.dirname(__FILE__)
2
+ require 'spec_helper'
3
+
4
+ if Object.const_defined?('LDAP')
5
+ describe DataMapper.repository(:ldap).adapter do
6
+
7
+ describe 'belongs_to association' do
8
+
9
+ before do
10
+ DataMapper.repository(:ldap) do
11
+ User.all.destroy!
12
+ @user1 = User.create(:login => "black", :name => 'Black', :age => 0)
13
+ @user2 = User.create(:login => "brown", :name => 'Brown', :age => 25)
14
+ @user3 = User.create(:login => "blue", :name => 'Blue', :age => nil)
15
+ end
16
+ end
17
+
18
+ after do
19
+ DataMapper.repository(:ldap) do
20
+ @user1.destroy
21
+ @user2.destroy
22
+ @user3.destroy
23
+ end
24
+ end
25
+
26
+ it 'should sort descending without order option' do
27
+ DataMapper.repository(:ldap) do
28
+ expected = User.all().sort do |u1, u2|
29
+ u1.id <=> u2.id
30
+ end
31
+ User.all.should == expected
32
+ end
33
+ end
34
+
35
+ it 'should sort descending with order option' do
36
+ DataMapper.repository(:ldap) do
37
+ expected = User.all().sort do |u1, u2|
38
+ u1.login <=> u2.login
39
+ end
40
+ User.all(:order => [:login]).should == expected
41
+ end
42
+ end
43
+ end
44
+ end
45
+ else
46
+ puts 'skip sorting spec for non "ruby-ldap" library'
47
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,8 +6,8 @@ require 'do_sqlite3'
6
6
  require 'pathname'
7
7
  $LOAD_PATH << Pathname(__FILE__).dirname.parent.expand_path + 'lib'
8
8
 
9
+ #require 'ldap/ruby_ldap_facade'
9
10
  require 'ldap_resource'
10
- #require 'ldap_facade_mock' # uncomment this to use the mock facade
11
11
  require 'adapters/ldap_adapter'
12
12
  require 'adapters/memory_adapter'
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-ldap-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - mkristian
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-21 00:00:00 +05:30
12
+ date: 2009-07-03 00:00:00 +05:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -64,8 +64,6 @@ extra_rdoc_files:
64
64
  - Manifest.txt
65
65
  - README.txt
66
66
  - ldap-commands.txt
67
- - net-ldap.txt
68
- - ruby-ldap.txt
69
67
  files:
70
68
  - History.txt
71
69
  - MIT-LICENSE
@@ -87,16 +85,14 @@ files:
87
85
  - lib/ldap/ruby_ldap_facade.rb
88
86
  - lib/ldap/version.rb
89
87
  - lib/ldap_resource.rb
90
- - net-ldap.txt
91
- - ruby-ldap.txt
92
88
  - spec/assiociations_ldap_adapter_spec.rb
93
89
  - spec/authentication_ldap_adapter_spec.rb
94
90
  - spec/ldap_adapter_spec.rb
95
91
  - spec/multi_repository_spec.rb
96
92
  - spec/multi_value_attributes_spec.rb
93
+ - spec/sorting_spec.rb
97
94
  - spec/spec.opts
98
95
  - spec/spec_helper.rb
99
- - test.db
100
96
  - test.ldif
101
97
  has_rdoc: true
102
98
  homepage: http://dm-ldap-adapter.rubyforge.org
data/net-ldap.txt DELETED
@@ -1,11 +0,0 @@
1
- 6.225829
2
- 6.410389
3
- 6.462378
4
- 6.227339
5
- 6.324937
6
- 6.55648
7
- 6.331228
8
- 6.729877
9
- 6.416464
10
- 6.99718
11
- 0
data/ruby-ldap.txt DELETED
@@ -1,11 +0,0 @@
1
- 4.534209
2
- 4.659179
3
- 4.688091
4
- 4.721425
5
- 4.495823
6
- 4.260121
7
- 4.656991
8
- 4.024788
9
- 4.444355
10
- 4.283845
11
- 0
data/test.db DELETED
Binary file