pulp 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +147 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/examples/repositories.rb +205 -0
- data/examples/test_pulp.yml +4 -0
- data/lib/pulp.rb +26 -0
- data/lib/pulp/cds.rb +25 -0
- data/lib/pulp/common/debug.rb +37 -0
- data/lib/pulp/common/lifecycle.rb +166 -0
- data/lib/pulp/common/lifecycle/create.rb +16 -0
- data/lib/pulp/common/lifecycle/delete.rb +23 -0
- data/lib/pulp/common/lifecycle/get.rb +22 -0
- data/lib/pulp/common/lifecycle/update.rb +23 -0
- data/lib/pulp/connection/base.rb +84 -0
- data/lib/pulp/connection/handler.rb +59 -0
- data/lib/pulp/consumer.rb +23 -0
- data/lib/pulp/consumergroup.rb +22 -0
- data/lib/pulp/content.rb +14 -0
- data/lib/pulp/distribution.rb +11 -0
- data/lib/pulp/errata.rb +17 -0
- data/lib/pulp/event.rb +8 -0
- data/lib/pulp/filter.rb +19 -0
- data/lib/pulp/package.rb +20 -0
- data/lib/pulp/package_group.rb +8 -0
- data/lib/pulp/package_group_category.rb +7 -0
- data/lib/pulp/repository.rb +114 -0
- data/lib/pulp/service.rb +51 -0
- data/lib/pulp/task.rb +37 -0
- data/lib/pulp/task_history.rb +10 -0
- data/lib/pulp/task_snapshot.rb +9 -0
- data/lib/pulp/user.rb +12 -0
- data/spec/pulp/common/debug_spec.rb +42 -0
- data/spec/pulp/common/lifecycle/create_spec.rb +21 -0
- data/spec/pulp/common/lifecycle/delete_spec.rb +40 -0
- data/spec/pulp/common/lifecycle/get_spec.rb +42 -0
- data/spec/pulp/common/lifecycle/update_spec.rb +48 -0
- data/spec/pulp/common/lifecycle_spec.rb +393 -0
- data/spec/pulp/connection/base_spec.rb +312 -0
- data/spec/pulp/connection/handler_spec.rb +123 -0
- data/spec/pulp/content_spec.rb +21 -0
- data/spec/pulp/package_spec.rb +14 -0
- data/spec/pulp/repository_spec.rb +14 -0
- data/spec/pulp/service_spec.rb +85 -0
- data/spec/pulp/task_spec.rb +48 -0
- data/spec/pulp_spec.rb +4 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +32 -0
- metadata +252 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestCreate
|
5
|
+
attr_reader :fields
|
6
|
+
def initialize(fields)
|
7
|
+
@fields = fields
|
8
|
+
end
|
9
|
+
|
10
|
+
include Pulp::Common::Lifecycle::Create
|
11
|
+
end
|
12
|
+
|
13
|
+
describe Pulp::Common::Lifecycle::Create do
|
14
|
+
it "should have a create method" do
|
15
|
+
TestCreate.should respond_to(:create)
|
16
|
+
end
|
17
|
+
it "should call post with the passed fields" do
|
18
|
+
TestCreate.expects(:base_post).with('',nil,{:a => 1}).returns(:b => 2)
|
19
|
+
TestCreate.create(:a => 1).fields[:b].should eql(2)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestDelete
|
5
|
+
attr_reader :fields
|
6
|
+
def initialize(fields)
|
7
|
+
@fields = fields
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
"blub"
|
12
|
+
end
|
13
|
+
|
14
|
+
include Pulp::Common::Lifecycle::Delete
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Pulp::Common::Lifecycle::Update do
|
18
|
+
it "should have a .delete method" do
|
19
|
+
TestDelete.should respond_to(:delete)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have a #delete method" do
|
23
|
+
TestDelete.new('ff').should respond_to(:delete)
|
24
|
+
end
|
25
|
+
context "when deleting" do
|
26
|
+
before(:each) do
|
27
|
+
TestDelete.expects(:base_delete).with('','blub',nil).returns(nil)
|
28
|
+
end
|
29
|
+
describe ".delete" do
|
30
|
+
it "should call delete with the passed item_id" do
|
31
|
+
TestDelete.delete('blub').should be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
describe "#delete" do
|
35
|
+
it "should call delete with the own id" do
|
36
|
+
TestDelete.new('aa').delete
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestGet
|
5
|
+
attr_reader :fields
|
6
|
+
def initialize(data)
|
7
|
+
@fields = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_fields(field_data)
|
11
|
+
@fields = field_data
|
12
|
+
end
|
13
|
+
|
14
|
+
def id
|
15
|
+
'aa'
|
16
|
+
end
|
17
|
+
|
18
|
+
include Pulp::Common::Lifecycle::Get
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Pulp::Common::Lifecycle::Get do
|
22
|
+
describe ".get" do
|
23
|
+
it "should have a get method" do
|
24
|
+
TestGet.should respond_to(:get)
|
25
|
+
end
|
26
|
+
it "should call get with the passed fields" do
|
27
|
+
TestGet.expects(:base_get).with('','aa',nil).returns(:b => 2)
|
28
|
+
TestGet.get('aa').fields[:b].should eql(2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
describe "#refresh" do
|
32
|
+
it "should have a refresh method" do
|
33
|
+
TestGet.new(1).should respond_to(:refresh)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should refresh the fields" do
|
37
|
+
TestGet.expects(:base_get).with('','aa',nil).returns(:b => 2)
|
38
|
+
(t=TestGet.new(1)).refresh.should eql(t)
|
39
|
+
t.fields[:b].should eql(2)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../../spec_helper'
|
3
|
+
|
4
|
+
class TestUpdate
|
5
|
+
attr_reader :fields
|
6
|
+
def initialize(fields)
|
7
|
+
@fields = fields
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
"blub"
|
12
|
+
end
|
13
|
+
|
14
|
+
include Pulp::Common::Lifecycle::Update
|
15
|
+
|
16
|
+
def self.special_fields
|
17
|
+
[:b]
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_fields
|
21
|
+
{ :a => 3, :b => 2}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Pulp::Common::Lifecycle::Update do
|
26
|
+
it "should have a update method" do
|
27
|
+
TestUpdate.should respond_to(:update)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have a save method" do
|
31
|
+
TestUpdate.new('ff').should respond_to(:save)
|
32
|
+
end
|
33
|
+
context "when saving" do
|
34
|
+
before(:each) do
|
35
|
+
TestUpdate.expects(:base_put).with('','blub',{:a => 3}).returns(:b => 2)
|
36
|
+
end
|
37
|
+
describe ".update" do
|
38
|
+
it "should call put with the passed fields" do
|
39
|
+
TestUpdate.update('blub',{:a => 3}).fields[:b].should eql(2)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
describe "#save" do
|
43
|
+
it "should call put with the user_fields fields that are not special fields" do
|
44
|
+
TestUpdate.new('aa').save.fields[:b].should eql(2)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,393 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
class CommonLifecycle
|
5
|
+
include Pulp::Common::Lifecycle
|
6
|
+
attr_reader :fields
|
7
|
+
def initialize(data={})
|
8
|
+
@fields = data
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class TestLifecycle < CommonLifecycle
|
13
|
+
pulp_field :normal_field
|
14
|
+
pulp_field :locked_field, :locked => true
|
15
|
+
pulp_field :options_field, :bla => true
|
16
|
+
|
17
|
+
pulp_fields :multiple_field1, :multiple_field2
|
18
|
+
|
19
|
+
pulp_locked_field :locked_field1
|
20
|
+
pulp_locked_field :locked_field1a, :foo => true
|
21
|
+
pulp_locked_fields :locked_field2, :locked_field3
|
22
|
+
|
23
|
+
pulp_special_field :special_field1
|
24
|
+
pulp_special_field :special_field1a, :foo => true
|
25
|
+
pulp_special_fields :special_field2, :special_field3
|
26
|
+
end
|
27
|
+
|
28
|
+
class Pulp::ActionLifecycle < CommonLifecycle
|
29
|
+
pulp_action :action1
|
30
|
+
pulp_action :action2, :method => :get
|
31
|
+
pulp_action :action3, :params => false
|
32
|
+
pulp_action :action4, :params => :optional
|
33
|
+
pulp_action :action5, :returns => Pulp::ActionLifecycle
|
34
|
+
pulp_action :action6, :append_slash => false
|
35
|
+
pulp_action :action7, :task_list => true
|
36
|
+
pulp_action :action8, :parse => false
|
37
|
+
|
38
|
+
def id
|
39
|
+
"foo"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Pulp::DeferredLifecycle < CommonLifecycle
|
44
|
+
pulp_deferred_field :deferred1
|
45
|
+
pulp_deferred_field :deferred2, :array => Pulp::DeferredLifecycle
|
46
|
+
pulp_deferred_field :deferred3, :returns => :plain
|
47
|
+
pulp_deferred_field :deferred4, :returns => Pulp::DeferredLifecycle
|
48
|
+
|
49
|
+
def id
|
50
|
+
"foo"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class CollectionLifecycle < CommonLifecycle
|
55
|
+
has_collection
|
56
|
+
end
|
57
|
+
|
58
|
+
class CollectionOptionLifecycle < CommonLifecycle
|
59
|
+
has_collection :all_filters => [ :foo, :bla ]
|
60
|
+
end
|
61
|
+
|
62
|
+
class GetLifecycle < CommonLifecycle
|
63
|
+
has_get
|
64
|
+
end
|
65
|
+
|
66
|
+
class DeleteLifecycle < CommonLifecycle
|
67
|
+
has_delete
|
68
|
+
end
|
69
|
+
|
70
|
+
class UpdateLifecycle < CommonLifecycle
|
71
|
+
has_update
|
72
|
+
end
|
73
|
+
|
74
|
+
class CreateLifecycle < CommonLifecycle
|
75
|
+
has_create
|
76
|
+
end
|
77
|
+
|
78
|
+
class CrudLifecycle < CommonLifecycle
|
79
|
+
has_crud
|
80
|
+
end
|
81
|
+
|
82
|
+
describe Pulp::Common::Lifecycle do
|
83
|
+
let(:instance){ TestLifecycle.new('options_field' => 'default') }
|
84
|
+
describe ".pulp_field" do
|
85
|
+
context "normal_field" do
|
86
|
+
it "should generate getters for it" do
|
87
|
+
instance.should respond_to(:normal_field)
|
88
|
+
end
|
89
|
+
it "should generate setters for it" do
|
90
|
+
instance.should respond_to(:normal_field=)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
context "locked_field" do
|
94
|
+
it "should have a getter" do
|
95
|
+
instance.should respond_to(:locked_field)
|
96
|
+
end
|
97
|
+
it "should not have a setter" do
|
98
|
+
instance.should_not respond_to(:locked_field=)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
context "options_field" do
|
102
|
+
it "should register the options" do
|
103
|
+
instance.record_fields[:options_field][:bla].should be_true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
describe "getter" do
|
107
|
+
context "nothing yet set" do
|
108
|
+
it "should return the initial value" do
|
109
|
+
instance.options_field.should eql('default')
|
110
|
+
end
|
111
|
+
it "should be nil without an initial value" do
|
112
|
+
instance.normal_field.should be_nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
context "something set" do
|
116
|
+
it "should return the new value instead of the initial value" do
|
117
|
+
instance.options_field = 'new'
|
118
|
+
instance.options_field.should eql('new')
|
119
|
+
end
|
120
|
+
it "should return the new value instead nil" do
|
121
|
+
instance.normal_field = 'new2'
|
122
|
+
instance.normal_field.should eql('new2')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
describe ".pulp_fields" do
|
128
|
+
it "should set multiple fields" do
|
129
|
+
instance.should respond_to(:multiple_field1)
|
130
|
+
instance.should respond_to(:multiple_field1=)
|
131
|
+
instance.should respond_to(:multiple_field2)
|
132
|
+
instance.should respond_to(:multiple_field2=)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def self.locked_field(field,options = false)
|
137
|
+
it "should have a getter" do
|
138
|
+
instance.should respond_to(field)
|
139
|
+
end
|
140
|
+
it "should not have a setter" do
|
141
|
+
instance.should_not respond_to(:"#{field}=")
|
142
|
+
end
|
143
|
+
if options
|
144
|
+
it "should merge the options" do
|
145
|
+
instance.record_fields[field][:foo].should be_true
|
146
|
+
end
|
147
|
+
end
|
148
|
+
it "should be registered as a locked field" do
|
149
|
+
instance.locked_fields.should include(field)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe ".pulp_locked_field" do
|
154
|
+
locked_field :locked_field1
|
155
|
+
locked_field :locked_field1a,true
|
156
|
+
end
|
157
|
+
|
158
|
+
describe ".pulp_locked_fields" do
|
159
|
+
context "should add multiple locked fields" do
|
160
|
+
locked_field :locked_field2
|
161
|
+
locked_field :locked_field3
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.special_field(field,options=false)
|
166
|
+
locked_field field,options
|
167
|
+
it "should be registered as special field" do
|
168
|
+
instance.special_fields.should include(field)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
describe ".pulp_special_field" do
|
172
|
+
special_field :special_field1
|
173
|
+
special_field :special_field1a,true
|
174
|
+
end
|
175
|
+
describe ".pulp_special_fields" do
|
176
|
+
context "should add multiple locked fields" do
|
177
|
+
special_field :special_field2
|
178
|
+
special_field :special_field3
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe ".has_collection" do
|
183
|
+
context "without options" do
|
184
|
+
it "should have an .all method" do
|
185
|
+
CollectionLifecycle.should respond_to(:all)
|
186
|
+
end
|
187
|
+
context "executing all" do
|
188
|
+
before(:each) do
|
189
|
+
CollectionLifecycle.expects(:base_get).with('',nil,nil).returns([{:a => 1},{:b => 2}])
|
190
|
+
end
|
191
|
+
let(:result) { CollectionLifecycle.all }
|
192
|
+
|
193
|
+
it "should return a collection" do
|
194
|
+
result.should be_kind_of(Array)
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should contain the result" do
|
198
|
+
result.first.fields[:a].should eql(1)
|
199
|
+
result.last.fields[:b].should eql(2)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
context "with finder options" do
|
204
|
+
it "should have an .all method" do
|
205
|
+
CollectionOptionLifecycle.should respond_to(:all)
|
206
|
+
end
|
207
|
+
it "should additionaly have finder options" do
|
208
|
+
CollectionOptionLifecycle.should respond_to(:find_by_foo)
|
209
|
+
CollectionOptionLifecycle.should respond_to(:find_by_bla)
|
210
|
+
end
|
211
|
+
context "executing the finder options" do
|
212
|
+
it "should call the index get with these options" do
|
213
|
+
CollectionOptionLifecycle.expects(:base_get).with('',nil,{:foo => 22}).returns([{:a => 1},{:b => 2}])
|
214
|
+
CollectionOptionLifecycle.find_by_foo(22).size.should eql(2)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
[:delete,:create,:get,:update].each do |action|
|
220
|
+
describe ".has_#{action}" do
|
221
|
+
it "should include the correct module" do
|
222
|
+
"#{action.to_s.classify}Lifecycle".constantize.included_modules.should include("Pulp::Common::Lifecycle::#{action.to_s.classify}".constantize)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe ".has_crud" do
|
228
|
+
|
229
|
+
context "without options" do
|
230
|
+
it "should have an .all method" do
|
231
|
+
CrudLifecycle.should respond_to(:all)
|
232
|
+
end
|
233
|
+
context "executing all" do
|
234
|
+
before(:each) do
|
235
|
+
CrudLifecycle.expects(:base_get).with('',nil,nil).returns([{:a => 1},{:b => 2}])
|
236
|
+
end
|
237
|
+
let(:result) { CrudLifecycle.all }
|
238
|
+
|
239
|
+
it "should return a collection" do
|
240
|
+
result.should be_kind_of(Array)
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should contain the result" do
|
244
|
+
result.first.fields[:a].should eql(1)
|
245
|
+
result.last.fields[:b].should eql(2)
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
[:delete,:create,:get,:update].each do |mod|
|
250
|
+
it "should include the #{mod} module" do
|
251
|
+
CrudLifecycle.included_modules.should include("Pulp::Common::Lifecycle::#{mod.to_s.classify}".constantize)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
#class Pulp::ActionLifecycle < CommonLifecycle
|
257
|
+
# pulp_action :action1
|
258
|
+
# pulp_action :action2, :method => :get
|
259
|
+
# pulp_action :action3, :params => false
|
260
|
+
# pulp_action :action4, :params => :optional
|
261
|
+
# pulp_action :action5, :returns => Pulp::ActionLifecycle
|
262
|
+
# pulp_action :action6, :append_slash => false
|
263
|
+
# pulp_action :action7, :task_list => true
|
264
|
+
# pulp_action :action8, :parse => false
|
265
|
+
#end
|
266
|
+
describe ".pulp_action" do
|
267
|
+
(1..8).each do |i|
|
268
|
+
it "should add a method #action#{i}" do
|
269
|
+
Pulp::ActionLifecycle.new('ffo').should respond_to(:"action#{i}")
|
270
|
+
|
271
|
+
end
|
272
|
+
end
|
273
|
+
context "without any options" do
|
274
|
+
it "should call post, add a slash" do
|
275
|
+
Pulp::ActionLifecycle.expects(:base_post).with('action1/','foo','aa').returns("foo")
|
276
|
+
Pulp::ActionLifecycle.new('ffo').action1('aa').should eql('foo')
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should also require params" do
|
280
|
+
lambda{ Pulp::ActionLifecycle.new('ffo').action1 }.should(raise_error(ArgumentError))
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context "with a method option" do
|
285
|
+
it "should call the exact method, add a slash" do
|
286
|
+
Pulp::ActionLifecycle.expects(:base_get).with('action2/','foo','aa').returns("foo")
|
287
|
+
Pulp::ActionLifecycle.new('ffo').action2('aa').should eql('foo')
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context "without any params" do
|
292
|
+
it "should not allow any params" do
|
293
|
+
Pulp::ActionLifecycle.expects(:base_post).returns "blub"
|
294
|
+
Pulp::ActionLifecycle.new('ffo').action3.should == 'blub'
|
295
|
+
lambda{ Pulp::ActionLifecycle.new('ffo').action3(1) }.should(raise_error(ArgumentError))
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
context "with optional params" do
|
300
|
+
it "should allow all or none params" do
|
301
|
+
Pulp::ActionLifecycle.expects(:base_post).twice
|
302
|
+
lambda{ Pulp::ActionLifecycle.new('ffo').action4 }.should_not(raise_error(ArgumentError))
|
303
|
+
lambda{ Pulp::ActionLifecycle.new('ffo').action4(1) }.should_not(raise_error(ArgumentError))
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
context "with a returns" do
|
308
|
+
it "should return a new object of type returns" do
|
309
|
+
Pulp::ActionLifecycle.expects(:base_post).returns "blub"
|
310
|
+
a = Pulp::ActionLifecycle.new('ffo').action5('aa')
|
311
|
+
a.should be_kind_of(Pulp::ActionLifecycle)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context "without adding a slash" do
|
316
|
+
it "should call post but without a slash" do
|
317
|
+
Pulp::ActionLifecycle.expects(:base_post).with('action6','foo','aa').returns("foo")
|
318
|
+
Pulp::ActionLifecycle.new('ffo').action6('aa').should eql('foo')
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
context "with a task lists" do
|
323
|
+
it "gets a get method for tasks" do
|
324
|
+
Pulp::ActionLifecycle.expects(:base_get).with('action7/','foo',nil).returns("foo")
|
325
|
+
(a=Pulp::ActionLifecycle.new('ffo').action7_tasks).should be_kind_of(Array)
|
326
|
+
a.first.should be_kind_of(Pulp::Task)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
context "without parsing" do
|
331
|
+
it "should call an unparsed post" do
|
332
|
+
Pulp::ActionLifecycle.expects(:base_unparsed_post).with('action8/','foo','aa').returns("foo")
|
333
|
+
Pulp::ActionLifecycle.new('ffo').action8('aa').should eql('foo')
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
338
|
+
#class Pulp::DeferredLifecycle < CommonLifecycle
|
339
|
+
# pulp_action :deferred1
|
340
|
+
# pulp_action :deferred2, :array => Pulp::DeferredLifecycle
|
341
|
+
# pulp_action :deferred3, :returns => :plain
|
342
|
+
# pulp_action :deferred4, :returns => Pulp::DeferredLifecycle
|
343
|
+
#
|
344
|
+
# def id
|
345
|
+
# "foo"
|
346
|
+
# end
|
347
|
+
#end
|
348
|
+
describe ".pulp_deferred_field" do
|
349
|
+
(1..4).each do |i|
|
350
|
+
it "provides a method for the deferred field name deferred#{i}" do
|
351
|
+
Pulp::DeferredLifecycle.new('a').should respond_to(:"deferred#{i}")
|
352
|
+
end
|
353
|
+
|
354
|
+
it "should have a method to obtain the link for deferred#{i}" do
|
355
|
+
Pulp::DeferredLifecycle.new("deferred#{i}" => 'a').send(:"deferred#{i}_link").should eql('a')
|
356
|
+
end
|
357
|
+
end
|
358
|
+
context "without any options" do
|
359
|
+
it "should return what it gets" do
|
360
|
+
Pulp::DeferredLifecycle.expects(:plain_get).with('a',nil,nil).returns('foo')
|
361
|
+
Pulp::DeferredLifecycle.new('deferred1' => 'a').deferred1.should eql('foo')
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
context "with an array to return" do
|
366
|
+
it "should return an array with these types" do
|
367
|
+
Pulp::DeferredLifecycle.expects(:plain_get).with('a',nil,nil).returns(['foo1','foo2'])
|
368
|
+
(a = Pulp::DeferredLifecycle.new('deferred2' => 'a').deferred2).size.should eql(2)
|
369
|
+
a.first.should be_kind_of(Pulp::DeferredLifecycle)
|
370
|
+
a.first.fields.should eql('foo1')
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
context "with a plain return" do
|
375
|
+
it "should return what it gets from the plain connection" do
|
376
|
+
a = Object.new
|
377
|
+
b = Object.new
|
378
|
+
b.expects(:get).returns('ff')
|
379
|
+
a.expects(:connection).returns(Hash.new(b))
|
380
|
+
Pulp::DeferredLifecycle.expects(:plain_base).returns(a)
|
381
|
+
Pulp::DeferredLifecycle.new('deferred3' => 'a').deferred3.should eql('ff')
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
context "with an object returns" do
|
386
|
+
it "should return an instance of that object" do
|
387
|
+
Pulp::DeferredLifecycle.expects(:plain_get).with('a',nil,nil).returns('foo1' => 2)
|
388
|
+
Pulp::DeferredLifecycle.new('deferred4' => 'a').deferred4.fields['foo1'].should eql(2)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
end
|