dm-ldap-adapter 0.3.5 → 0.4.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- data/.project +11 -0
- data/.yardoc +0 -0
- data/Manifest.txt +5 -2
- data/README-example.markdown +0 -1
- data/README.txt +15 -15
- data/Rakefile +4 -3
- data/env.sh +2 -0
- data/example/identity_map.rb +10 -10
- data/example/posix.rb +9 -9
- data/ldap-commands.txt +3 -0
- data/lib/adapters/ldap_adapter.rb +155 -118
- data/lib/adapters/noop_transaction.rb +16 -0
- data/lib/dummy_ldap_resource.rb +6 -6
- data/lib/ldap/array.rb +96 -12
- data/lib/ldap/conditions_2_filter.rb +95 -0
- data/lib/ldap/digest.rb +3 -3
- data/lib/ldap/net_ldap_facade.rb +28 -110
- data/lib/ldap/ruby_ldap_facade.rb +31 -116
- data/lib/ldap/version.rb +1 -1
- data/lib/ldap_resource.rb +113 -26
- data/spec/assiociations_ldap_adapter_spec.rb +129 -130
- data/spec/authentication_ldap_adapter_spec.rb +1 -6
- data/spec/ldap_adapter_spec.rb +164 -177
- data/spec/multi_repository_spec.rb +41 -5
- data/spec/multi_value_attributes_spec.rb +64 -31
- data/spec/sorting_spec.rb +16 -15
- data/spec/spec_helper.rb +34 -20
- metadata +67 -27
- data/lib/adapters/memory_adapter.rb +0 -79
- data/lib/adapters/simple_adapter.rb +0 -198
data/spec/ldap_adapter_spec.rb
CHANGED
@@ -1,185 +1,160 @@
|
|
1
1
|
$LOAD_PATH << File.dirname(__FILE__)
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
describe "A #{DataMapper.repository(adapter).adapter.class.name}" do
|
13
|
-
|
14
|
-
before(:each) do
|
15
|
-
DataMapper.repository(adapter) do
|
16
|
-
@user1 = User.create(:login => "black", :name => 'Black', :age => 0)
|
17
|
-
@user2 = User.create(:login => "brown", :name => 'Brown', :age => 25)
|
18
|
-
@user3 = User.create(:login => "blue", :name => 'Blue', :age => nil)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
after(:each) do
|
23
|
-
DataMapper.repository(adapter) do
|
24
|
-
@user1.destroy
|
25
|
-
@user2.destroy
|
26
|
-
@user3.destroy
|
27
|
-
end
|
4
|
+
describe DataMapper::Adapters::LdapAdapter do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
DataMapper.repository(:ldap) do
|
8
|
+
User.all.destroy!
|
9
|
+
@user1 = User.create(:login => "black", :name => 'Black', :age => 0)
|
10
|
+
@user2 = User.create(:login => "brown", :name => 'Brown', :age => 25)
|
11
|
+
@user3 = User.create(:login => "blue", :name => 'Blue', :age => nil)
|
28
12
|
end
|
13
|
+
end
|
29
14
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
it 'should create an uid' do
|
16
|
+
class User
|
17
|
+
# put the assert here
|
18
|
+
dn_prefix { |user| user.id.should_not == nil; "uid=#{user.login}"}
|
19
|
+
end
|
35
20
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
21
|
+
DataMapper.repository(:ldap) do
|
22
|
+
id = @user1.id
|
23
|
+
@user1.destroy
|
24
|
+
@user1 = User.create(:login => "black", :name => 'Black', :age => 0)
|
25
|
+
@user1.id.should_not == id
|
42
26
|
end
|
27
|
+
end
|
43
28
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
29
|
+
it 'should successfully save an object' do
|
30
|
+
DataMapper.repository(:ldap) do
|
31
|
+
@user1.new?.should be_false
|
32
|
+
User.first(:login => @user1.login).new?.should be_false
|
49
33
|
end
|
34
|
+
end
|
50
35
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
36
|
+
it 'should raise an error when trying to create an entity with already used key' do
|
37
|
+
DataMapper.repository(:ldap) do
|
38
|
+
#p User.first(:login => "black")
|
39
|
+
lambda { User.create(:login => "black", :name => 'Black', :age => 0) }.should raise_error
|
55
40
|
#p User.all
|
56
|
-
end
|
57
41
|
end
|
42
|
+
end
|
58
43
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
44
|
+
it 'should be able to get all the objects' do
|
45
|
+
DataMapper.repository(:ldap) do
|
46
|
+
User.all(:login.like => "b%").should == [@user1, @user2, @user3]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should be able to search with empty result' do
|
51
|
+
DataMapper.repository(:ldap) do
|
52
|
+
User.all(:name => "blablublo").should == []
|
63
53
|
end
|
54
|
+
end
|
64
55
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
56
|
+
it 'should be able to search for objects with equal value' do
|
57
|
+
DataMapper.repository(:ldap) do
|
58
|
+
User.all(:name => "Brown").should == [@user2]
|
59
|
+
User.all(:age => 25).should == [@user2]
|
70
60
|
end
|
61
|
+
end
|
71
62
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
63
|
+
it 'should be able to search for objects included in an array of values' do
|
64
|
+
DataMapper.repository(:ldap) do
|
65
|
+
User.all(:age => [ 25, 50, 75, 100 ]).should == [@user2]
|
76
66
|
end
|
67
|
+
end
|
77
68
|
|
78
|
-
|
79
|
-
|
80
|
-
|
69
|
+
#it 'should be able to search for objects included in a range of values' do
|
70
|
+
# User.all(:age => 25..100).should == [@user2]
|
71
|
+
#end
|
81
72
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
end
|
73
|
+
it 'should be able to search for objects with nil value' do
|
74
|
+
DataMapper.repository(:ldap) do
|
75
|
+
User.all(:age => nil, :name.like => "B%").should == [@user3]
|
86
76
|
end
|
77
|
+
end
|
87
78
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
User.all(:age.not => [ 25, 50, 75, 100 ], :name.like => "B%").should == [@user1, @user3]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
else
|
101
|
-
puts
|
102
|
-
puts "NOTE"
|
103
|
-
puts "=================================================="
|
104
|
-
puts
|
105
|
-
puts "sqlite3 handles NULL different from values, i.e."
|
106
|
-
puts "select * from users where name = 'sd';"
|
107
|
-
puts "and"
|
108
|
-
puts "select * from users where name != 'sd';"
|
109
|
-
puts "gives the same result when all names are NULL !!!"
|
110
|
-
puts
|
111
|
-
puts "=================================================="
|
112
|
-
puts
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'should be able to search for objects with not equal value' do
|
116
|
-
DataMapper.repository(adapter) do
|
117
|
-
User.all(:age.not => nil, :name.like => "B%").should == [@user1, @user2]
|
118
|
-
end
|
79
|
+
it 'should be able to search for objects with not equal value' do
|
80
|
+
DataMapper.repository(:ldap) do
|
81
|
+
User.all(:age.not => 25, :name.like => "B%").should == [@user1, @user3]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should be able to search for objects not included in an array of values' do
|
86
|
+
DataMapper.repository(:ldap) do
|
87
|
+
User.all(:age.not => [ 25, 50, 75, 100 ], :name.like => "B%").should == [@user1, @user3]
|
119
88
|
end
|
89
|
+
end
|
120
90
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
User.all(:age.not => nil, :conditions => ["name='Black' or name='Blue'"]).should == [@user1]
|
125
|
-
User.all(:age.not => nil, :conditions => ["name='Black' or name='Brown'"]).should == [@user1, @user2]
|
126
|
-
User.all(:age => nil, :conditions => ["name='Black' or name='Brown'"]).should == []
|
127
|
-
User.all(:age => nil, :conditions => ["name='Black' or name='Brown' or name='Blue'"]).should == [@user3]
|
128
|
-
User.all(:conditions => ["name='Black' or name='Brown' or name='Blue'"]).should == [@user1, @user2, @user3]
|
129
|
-
User.all(:conditions => ["name='Black'"]).should == [@user1]
|
130
|
-
User.all(:conditions => ["name like 'Bl%'"]).should == [@user1, @user3]
|
131
|
-
User.all(:conditions => ["name like 'B%'"]).should == [@user1, @user2, @user3]
|
132
|
-
User.all(:conditions => ["name like 'X%X_X'"]).should == []
|
133
|
-
User.all(:conditions => ["name like 'Bla%' or name like 'Br%'"]).should == [@user1, @user2]
|
134
|
-
end
|
135
|
-
end
|
91
|
+
it 'should be able to search for objects with not equal value' do
|
92
|
+
DataMapper.repository(:ldap) do
|
93
|
+
User.all(:age.not => nil, :name.like => "B%").should == [@user1, @user2]
|
136
94
|
end
|
95
|
+
end
|
137
96
|
|
97
|
+
it 'should search objects with or conditions' do
|
98
|
+
DataMapper.repository(:ldap) do
|
99
|
+
User.all(:age.not => nil, :conditions => ["name='Black' or name='Blue'"]).should == [@user1]
|
100
|
+
User.all(:age.not => nil, :conditions => ["name='Black' or name='Brown'"]).should == [@user1, @user2]
|
101
|
+
User.all(:age => nil, :conditions => ["name='Black' or name='Brown'"]).should == []
|
102
|
+
User.all(:age => nil, :conditions => ["name='Black' or name='Brown' or name='Blue'"]).should == [@user3]
|
103
|
+
User.all(:conditions => ["name='Black' or name='Brown' or name='Blue'"]).should == [@user1, @user2, @user3]
|
104
|
+
User.all(:conditions => ["name='Black'"]).should == [@user1]
|
105
|
+
User.all(:conditions => ["name like 'Bl%'"]).should == [@user1, @user3]
|
106
|
+
User.all(:conditions => ["name like 'B%'"]).should == [@user1, @user2, @user3]
|
107
|
+
User.all(:conditions => ["name like 'X%X_X'"]).should == []
|
108
|
+
User.all(:conditions => ["name like 'Bla%' or name like 'Br%'"]).should == [@user1, @user2]
|
109
|
+
end
|
110
|
+
end
|
138
111
|
|
139
|
-
# it 'should be able to search for objects not included in a range of values' do
|
140
|
-
# User.all(:age.not => 25..100).should == [@user1, @user3]
|
141
|
-
# end
|
142
112
|
|
143
|
-
|
144
|
-
|
145
|
-
|
113
|
+
# it 'should be able to search for objects not included in a range of values' do
|
114
|
+
# User.all(:age.not => 25..100).should == [@user1, @user3]
|
115
|
+
# end
|
146
116
|
|
147
|
-
it 'should be able to search for objects
|
148
|
-
|
149
|
-
|
150
|
-
|
117
|
+
# it 'should be able to search for objects with not nil value' do
|
118
|
+
# User.all(:age.not => 25, :name.like => "B%").should == [@user1, @user2]
|
119
|
+
# end
|
120
|
+
|
121
|
+
it 'should be able to search for objects that match value' do
|
122
|
+
DataMapper.repository(:ldap) do
|
123
|
+
User.all(:name.like => 'Bl%').should == [@user1, @user3]
|
151
124
|
end
|
125
|
+
end
|
152
126
|
|
153
|
-
|
154
|
-
|
155
|
-
|
127
|
+
#it 'should be able to search for objects with value greater than' do
|
128
|
+
# User.all(:age.gt => 0).should == [@user2]
|
129
|
+
#end
|
156
130
|
|
157
|
-
|
158
|
-
|
159
|
-
|
131
|
+
#it 'should be able to search for objects with value greater than or equal to' do
|
132
|
+
# User.all(:age.gte => 0).should == [@user1, @user2]
|
133
|
+
#end
|
160
134
|
|
161
|
-
|
162
|
-
|
163
|
-
|
135
|
+
#it 'should be able to search for objects with value less than' do
|
136
|
+
# User.all(:age.lt => 1).should == [@user1]
|
137
|
+
#end
|
164
138
|
|
165
|
-
|
166
|
-
|
167
|
-
|
139
|
+
#it 'should be able to search for objects with value less than or equal to' do
|
140
|
+
# User.all(:age.lte => 0).should == [@user1]
|
141
|
+
#end
|
168
142
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
end
|
143
|
+
it 'should be able to update an object' do
|
144
|
+
DataMapper.repository(:ldap) do
|
145
|
+
@user1 = User.get(@user1.id)
|
146
|
+
@user1.age = 10
|
147
|
+
@user1.save
|
148
|
+
User.get(@user1.id).age.should == 10
|
149
|
+
@user1.age = 70
|
150
|
+
@user1.save
|
151
|
+
User.get(@user1.id).age.should == 70
|
179
152
|
end
|
153
|
+
end
|
180
154
|
|
181
|
-
|
182
|
-
|
155
|
+
it 'should be able to update an object with nil' do
|
156
|
+
DataMapper.repository(:ldap) do
|
157
|
+
begin
|
183
158
|
@user1 = User.get(@user1.id)
|
184
159
|
@user1.age = nil
|
185
160
|
@user1.save
|
@@ -187,59 +162,71 @@ User.all(:conditions => ["name like 'Bla%' or name like 'Br%'"]).should == [@use
|
|
187
162
|
@user1.age = 70
|
188
163
|
@user1.save
|
189
164
|
User.get(@user1.id).age.should == 70
|
165
|
+
rescue => e
|
166
|
+
puts e
|
167
|
+
puts e.backtrace.join "\n\t"
|
168
|
+
raise e
|
190
169
|
end
|
191
170
|
end
|
171
|
+
end
|
192
172
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
end
|
173
|
+
it 'should be able to destroy an object' do
|
174
|
+
DataMapper.repository(:ldap) do
|
175
|
+
size = User.all.size
|
176
|
+
@user1.destroy
|
177
|
+
User.all.size.should == size - 1
|
199
178
|
end
|
179
|
+
end
|
200
180
|
|
201
|
-
|
202
|
-
|
181
|
+
it 'should work with transactions' do
|
182
|
+
DataMapper.repository(:ldap) do
|
183
|
+
begin
|
203
184
|
User.transaction do
|
204
185
|
user = User.get(@user3.id)
|
205
186
|
user.name = "B new"
|
206
187
|
user.save
|
207
188
|
User.get(@user3.id).name.should == 'B new'
|
208
189
|
end
|
190
|
+
rescue => e
|
191
|
+
puts e
|
192
|
+
puts e.backtrace.join "\n\t"
|
193
|
+
raise e
|
209
194
|
end
|
210
195
|
end
|
196
|
+
end
|
211
197
|
|
212
|
-
|
213
|
-
|
214
|
-
it 'should use one connection for several actions' do
|
215
|
-
DataMapper.repository(adapter) do
|
216
|
-
DataMapper.repository.adapter.open_ldap_connection do
|
217
|
-
hash = DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash
|
218
|
-
User.all
|
219
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
220
|
-
user = User.get(@user3.id)
|
221
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
222
|
-
user.name = "another name"
|
223
|
-
user.save
|
224
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
225
|
-
end
|
226
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
227
|
-
end
|
228
|
-
end
|
198
|
+
if DataMapper.repository(:ldap).adapter.respond_to? :open_ldap_connection
|
229
199
|
|
230
|
-
|
231
|
-
|
200
|
+
it 'should use one connection for several actions' do
|
201
|
+
DataMapper.repository(:ldap) do
|
202
|
+
DataMapper.repository.adapter.open_ldap_connection do
|
232
203
|
hash = DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash
|
233
204
|
User.all
|
234
|
-
|
235
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
205
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
236
206
|
user = User.get(@user3.id)
|
237
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.
|
238
|
-
user.name = "
|
207
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
208
|
+
user.name = "another name"
|
239
209
|
user.save
|
240
|
-
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.
|
210
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should == hash
|
241
211
|
end
|
212
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should use new connection for each action' do
|
217
|
+
DataMapper.repository(:ldap) do
|
218
|
+
hash = DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash
|
219
|
+
User.all
|
220
|
+
|
221
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
222
|
+
user = User.get(@user3.id)
|
223
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
224
|
+
user.name = "yet another name"
|
225
|
+
user.save
|
226
|
+
DataMapper.repository.adapter.instance_variable_get(:@ldap_connection).current.hash.should_not == hash
|
242
227
|
end
|
243
228
|
end
|
244
229
|
end
|
245
230
|
end
|
231
|
+
|
232
|
+
\
|
@@ -6,12 +6,29 @@ class Order
|
|
6
6
|
|
7
7
|
property :id, Serial
|
8
8
|
|
9
|
-
repository
|
10
|
-
|
9
|
+
belongs_to :user, :required => false, :repository => :ldap
|
10
|
+
end
|
11
|
+
|
12
|
+
class Order2
|
13
|
+
include DataMapper::Resource
|
14
|
+
|
15
|
+
def self.repository_name
|
16
|
+
:default
|
17
|
+
end
|
18
|
+
|
19
|
+
property :id, Serial
|
20
|
+
|
21
|
+
belongs_to :user, :required => false
|
22
|
+
end
|
23
|
+
|
24
|
+
class User
|
25
|
+
def self.repository_name
|
26
|
+
:ldap
|
11
27
|
end
|
12
28
|
end
|
13
29
|
|
14
30
|
Order.auto_migrate!(:default)
|
31
|
+
Order2.auto_migrate!(:default)
|
15
32
|
|
16
33
|
describe DataMapper.repository(:ldap).adapter do
|
17
34
|
|
@@ -19,12 +36,16 @@ describe DataMapper.repository(:ldap).adapter do
|
|
19
36
|
|
20
37
|
before do
|
21
38
|
DataMapper.repository(:ldap) do
|
39
|
+
begin
|
40
|
+
User.all.destroy!
|
22
41
|
@user = User.new(:login => "beige", :name => 'Beige')
|
23
42
|
@user.password = "asd123"
|
24
43
|
@user.save
|
44
|
+
rescue => e
|
45
|
+
puts e.backtrace.join("\n\t")
|
46
|
+
raise e
|
47
|
+
end
|
25
48
|
end
|
26
|
-
|
27
|
-
@order = Order.create
|
28
49
|
end
|
29
50
|
|
30
51
|
after do
|
@@ -35,9 +56,24 @@ describe DataMapper.repository(:ldap).adapter do
|
|
35
56
|
end
|
36
57
|
|
37
58
|
it 'should create and load the association' do
|
59
|
+
@order = Order.create
|
38
60
|
@order.user = @user
|
39
61
|
@order.save
|
40
|
-
Order.get!(@order.id)
|
62
|
+
order = Order.get!(@order.id)
|
63
|
+
DataMapper.repository(:ldap) do
|
64
|
+
order.user.should == @user
|
65
|
+
end
|
66
|
+
end
|
67
|
+
it 'should create and load the association with fixed repositories' do
|
68
|
+
DataMapper.repository(:default) do
|
69
|
+
DataMapper.repository(:ldap) do
|
70
|
+
@order = Order2.create
|
71
|
+
@order.user = @user
|
72
|
+
@order.save
|
73
|
+
order = Order2.get!(@order.id)
|
74
|
+
order.user.should == @user
|
75
|
+
end
|
76
|
+
end
|
41
77
|
end
|
42
78
|
end
|
43
79
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
$LOAD_PATH << File.dirname(__FILE__)
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
class
|
4
|
+
class TestContact
|
5
5
|
include DataMapper::Resource
|
6
6
|
|
7
7
|
property :id, Serial, :field => "uidnumber"
|
8
8
|
property :login, String, :field => "uid", :unique_index => true
|
9
|
-
property :hashed_password, String, :field => "userpassword", :
|
9
|
+
property :hashed_password, String, :field => "userpassword", :lazy => true
|
10
10
|
property :name, String, :field => "cn"
|
11
|
-
property :mail, LdapArray
|
11
|
+
property :mail, ::Ldap::LdapArray
|
12
12
|
|
13
13
|
dn_prefix { |contact| "uid=#{contact.login}"}
|
14
14
|
|
@@ -33,16 +33,15 @@ describe DataMapper.repository(:ldap).adapter.class do
|
|
33
33
|
|
34
34
|
before :each do
|
35
35
|
DataMapper.repository(:ldap) do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
@contact.destroy
|
36
|
+
begin
|
37
|
+
TestContact.all(:login.like => "b%").destroy!
|
38
|
+
@contact = TestContact.new(:login => "beige", :name => 'Beige')
|
39
|
+
@contact.password = "asd123"
|
40
|
+
@contact.save
|
41
|
+
rescue => e
|
42
|
+
puts e.backtrace.join("\n\t")
|
43
|
+
raise e
|
44
|
+
end
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
@@ -50,24 +49,32 @@ describe DataMapper.repository(:ldap).adapter.class do
|
|
50
49
|
DataMapper.repository(:ldap) do
|
51
50
|
@contact.mail.should == []
|
52
51
|
|
53
|
-
@contact.mail
|
52
|
+
@contact.mail = ["email1"]
|
54
53
|
@contact.save
|
55
|
-
|
54
|
+
end
|
55
|
+
DataMapper.repository(:ldap) do
|
56
|
+
@contact = TestContact.get!(@contact.id)
|
56
57
|
@contact.mail.should == ["email1"]
|
57
|
-
|
58
58
|
@contact.mail << "email2"
|
59
59
|
@contact.save
|
60
|
-
|
60
|
+
end
|
61
|
+
DataMapper.repository(:ldap) do
|
62
|
+
@contact = TestContact.get!(@contact.id)
|
61
63
|
@contact.mail.should == ["email1", "email2"]
|
62
|
-
|
63
64
|
@contact.mail.delete("email1")
|
64
65
|
@contact.save
|
65
|
-
|
66
|
+
end
|
67
|
+
DataMapper.repository(:ldap) do
|
68
|
+
@contact = TestContact.get!(@contact.id)
|
66
69
|
@contact.mail.should == ["email2"]
|
67
70
|
|
68
|
-
@contact.mail.
|
71
|
+
mail = @contact.mail.dup
|
72
|
+
mail.delete("email2")
|
73
|
+
@contact.mail = mail
|
69
74
|
@contact.save
|
70
|
-
|
75
|
+
end
|
76
|
+
DataMapper.repository(:ldap) do
|
77
|
+
@contact = TestContact.get!(@contact.id)
|
71
78
|
@contact.mail.should == []
|
72
79
|
end
|
73
80
|
end
|
@@ -76,35 +83,61 @@ describe DataMapper.repository(:ldap).adapter.class do
|
|
76
83
|
DataMapper.repository(:ldap) do
|
77
84
|
@contact.mail.should == []
|
78
85
|
|
79
|
-
@contact.mail
|
86
|
+
@contact.mail = ["email1"]
|
80
87
|
@contact.save
|
81
|
-
|
88
|
+
end
|
89
|
+
DataMapper.repository(:ldap) do
|
90
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
82
91
|
@contact.mail.should == ["email1"]
|
83
92
|
|
84
|
-
@contact.mail << "email2"
|
93
|
+
@contact.mail = @contact.mail.dup << "email2"
|
85
94
|
@contact.save
|
86
|
-
|
95
|
+
end
|
96
|
+
DataMapper.repository(:ldap) do
|
97
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
87
98
|
@contact.mail.should == ["email1", "email2"]
|
88
99
|
|
89
|
-
@contact.mail.
|
100
|
+
mail = @contact.mail.dup
|
101
|
+
mail.delete("email1")
|
102
|
+
@contact.mail = mail
|
90
103
|
@contact.save
|
91
|
-
|
104
|
+
end
|
105
|
+
DataMapper.repository(:ldap) do
|
106
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
92
107
|
@contact.mail.should == ["email2"]
|
93
108
|
|
94
|
-
@contact.mail.
|
109
|
+
mail = @contact.mail.dup
|
110
|
+
mail.delete("email2")
|
111
|
+
@contact.mail = mail
|
95
112
|
@contact.save
|
96
|
-
|
113
|
+
end
|
114
|
+
DataMapper.repository(:ldap) do
|
115
|
+
@contact = TestContact.all.detect {|c| c.id = @contact.id}
|
97
116
|
@contact.mail.should == []
|
98
117
|
end
|
99
118
|
end
|
100
119
|
|
101
120
|
it 'should allow to replace the LdapArray' do
|
102
121
|
DataMapper.repository(:ldap) do
|
103
|
-
@contact =
|
122
|
+
@contact = TestContact.get(@contact.id)
|
104
123
|
@contact.mail.should == []
|
105
124
|
@contact.mail = ['foo', 'bar']
|
106
125
|
@contact.save
|
107
|
-
|
126
|
+
end
|
127
|
+
DataMapper.repository(:ldap) do
|
128
|
+
@contact = TestContact.get(@contact.id)
|
129
|
+
@contact.mail.should == ['foo', 'bar']
|
130
|
+
end
|
131
|
+
end
|
132
|
+
it 'should create resource with the LdapArray' do
|
133
|
+
DataMapper.repository(:ldap) do
|
134
|
+
@contact = TestContact.new(:login => "black", :name => 'Black')
|
135
|
+
@contact.password = "asd123"
|
136
|
+
@contact.mail = ['foo', 'bar']
|
137
|
+
@contact.save
|
138
|
+
end
|
139
|
+
DataMapper.repository(:ldap) do
|
140
|
+
@contact = TestContact.get(@contact.id)
|
108
141
|
@contact.mail.should == ['foo', 'bar']
|
109
142
|
end
|
110
143
|
end
|