zuul 0.2.7 → 0.2.8

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.
@@ -1,5 +1,6 @@
1
1
  module Zuul
2
2
  class Context < Struct.new(:class_name, :id)
3
+ alias_attribute :klass, :class_name
3
4
 
4
5
  def self.parse(*args)
5
6
  if args.length >= 2
@@ -24,9 +25,22 @@ module Zuul
24
25
  !class_name.nil? && id.nil?
25
26
  end
26
27
 
27
- def nil?
28
+ def global?
28
29
  class_name.nil? && id.nil?
29
30
  end
31
+ alias_method :nil?, :global?
32
+
33
+ def ==(kontext)
34
+ class_name == kontext.class_name && id == kontext.id
35
+ end
36
+
37
+ def <=(kontext)
38
+ kontext.global? || (class_name == kontext.class_name && (kontext.id.nil? || id == kontext.id))
39
+ end
40
+
41
+ def >=(kontext)
42
+ kontext <= self
43
+ end
30
44
 
31
45
  def type
32
46
  return :nil if class_name.nil?
@@ -1,3 +1,3 @@
1
1
  module Zuul
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -1,20 +1,17 @@
1
1
  # Default Subject, Role, Permission and Context models
2
2
  Object.send(:remove_const, :User) if defined?(User) # we do this to undefine the model and start fresh, without any of the authorization stuff applied by tests
3
3
  class User < ActiveRecord::Base
4
- attr_accessible :name if ::Zuul
5
- .should_whitelist?
4
+ attr_accessible :name if ::Zuul.should_whitelist?
6
5
  end
7
6
 
8
7
  Object.send(:remove_const, :Role) if defined?(Role)
9
8
  class Role < ActiveRecord::Base
10
- attr_accessible :name, :slug, :level, :context_type, :context_id if ::Zuul
11
- .should_whitelist?
9
+ attr_accessible :name, :slug, :level, :context_type, :context_id if ::Zuul.should_whitelist?
12
10
  end
13
11
 
14
12
  Object.send(:remove_const, :Permission) if defined?(Permission)
15
13
  class Permission < ActiveRecord::Base
16
- attr_accessible :name, :slug, :context_type, :context_id if ::Zuul
17
- .should_whitelist?
14
+ attr_accessible :name, :slug, :context_type, :context_id if ::Zuul.should_whitelist?
18
15
  end
19
16
 
20
17
  Object.send(:remove_const, :Context) if defined?(Context)
@@ -49,12 +46,12 @@ end
49
46
  # Additional models to test scoping
50
47
  Object.send(:remove_const, :Level) if defined?(Level)
51
48
  class Level < ActiveRecord::Base
52
- attr_accessible :name, :slug, :level, :context_type, :context_id
49
+ attr_accessible :name, :slug, :level, :context_type, :context_id if ::Zuul.should_whitelist?
53
50
  end
54
51
 
55
52
  Object.send(:remove_const, :Ability) if defined?(Ability)
56
53
  class Ability < ActiveRecord::Base
57
- attr_accessible :name, :slug, :context_type, :context_id
54
+ attr_accessible :name, :slug, :context_type, :context_id if ::Zuul.should_whitelist?
58
55
  end
59
56
 
60
57
  Object.send(:remove_const, :AbilityLevel) if defined?(AbilityLevel)
@@ -84,20 +81,17 @@ end
84
81
  # Custom named Subject, Role, Permission and Context models
85
82
  Object.send(:remove_const, :Soldier) if defined?(Soldier)
86
83
  class Soldier < ActiveRecord::Base
87
- attr_accessible :name if ::Zuul
88
- .should_whitelist?
84
+ attr_accessible :name if ::Zuul.should_whitelist?
89
85
  end
90
86
 
91
87
  Object.send(:remove_const, :Rank) if defined?(Rank)
92
88
  class Rank < ActiveRecord::Base
93
- attr_accessible :name, :slug, :level, :context_type, :context_id if ::Zuul
94
- .should_whitelist?
89
+ attr_accessible :name, :slug, :level, :context_type, :context_id if ::Zuul.should_whitelist?
95
90
  end
96
91
 
97
92
  Object.send(:remove_const, :Skill) if defined?(Skill)
98
93
  class Skill < ActiveRecord::Base
99
- attr_accessible :name, :slug, :context_type, :context_id if ::Zuul
100
- .should_whitelist?
94
+ attr_accessible :name, :slug, :context_type, :context_id if ::Zuul.should_whitelist?
101
95
  end
102
96
 
103
97
  Object.send(:remove_const, :Weapon) if defined?(Weapon)
@@ -136,20 +130,17 @@ module ZuulModels
136
130
 
137
131
  send(:remove_const, :User) if defined?(ZuulModels::User)
138
132
  class User < ActiveRecord::Base
139
- attr_accessible :name if ::Zuul
140
- .should_whitelist?
133
+ attr_accessible :name if ::Zuul.should_whitelist?
141
134
  end
142
135
 
143
136
  send(:remove_const, :Role) if defined?(ZuulModels::Role)
144
137
  class Role < ActiveRecord::Base
145
- attr_accessible :name, :slug, :level, :context_type, :context_id if ::Zuul
146
- .should_whitelist?
138
+ attr_accessible :name, :slug, :level, :context_type, :context_id if ::Zuul.should_whitelist?
147
139
  end
148
140
 
149
141
  send(:remove_const, :Permission) if defined?(ZuulModels::Permission)
150
142
  class Permission < ActiveRecord::Base
151
- attr_accessible :name, :slug, :context_type, :context_id if ::Zuul
152
- .should_whitelist?
143
+ attr_accessible :name, :slug, :context_type, :context_id if ::Zuul.should_whitelist?
153
144
  end
154
145
 
155
146
  send(:remove_const, :Context) if defined?(ZuulModels::Context)
@@ -77,7 +77,7 @@ describe "Zuul::ActiveRecord::PermissionRole" do
77
77
  it "should provide the model with belongs_to associations for permissions and roles" do
78
78
  PermissionRole.reflections.keys.should include(:permission)
79
79
  PermissionRole.reflections.keys.should include(:role)
80
- pu = PermissionRole.create(:permission_id => 1, :use_id => 1)
80
+ pu = PermissionRole.create(:permission_id => 1, :role_id => 1)
81
81
  pu.should respond_to(:permission)
82
82
  pu.should respond_to(:role)
83
83
  end
@@ -77,7 +77,7 @@ describe "Zuul::ActiveRecord::PermissionSubject" do
77
77
  it "should provide the model with belongs_to associations for permissions and subjects" do
78
78
  PermissionUser.reflections.keys.should include(:permission)
79
79
  PermissionUser.reflections.keys.should include(:user)
80
- pu = PermissionUser.create(:permission_id => 1, :use_id => 1)
80
+ pu = PermissionUser.create(:permission_id => 1, :user_id => 1)
81
81
  pu.should respond_to(:permission)
82
82
  pu.should respond_to(:user)
83
83
  end
@@ -338,19 +338,19 @@ describe "Zuul::ActiveRecord::Role" do
338
338
  nil_permission_role.id.should_not be_nil
339
339
  nil_permission_role.context_type.should be_nil
340
340
  nil_permission_role.context_id.should be_nil
341
- nil_permission_role.permission.should == nil_permission
341
+ nil_permission_role.permission.id.should == nil_permission.id
342
342
 
343
343
  class_permission_role = @role.assign_permission(:edit, Context)
344
344
  class_permission_role.id.should_not be_nil
345
345
  class_permission_role.context_type.should == 'Context'
346
346
  class_permission_role.context_id.should be_nil
347
- class_permission_role.permission.should == class_permission
347
+ class_permission_role.permission.id.should == class_permission.id
348
348
 
349
349
  inst_permission_role = @role.assign_permission(:edit, context)
350
350
  inst_permission_role.id.should_not be_nil
351
351
  inst_permission_role.context_type.should == 'Context'
352
352
  inst_permission_role.context_id.should == context.id
353
- inst_permission_role.permission.should == inst_permission
353
+ inst_permission_role.permission.id.should == inst_permission.id
354
354
  end
355
355
 
356
356
  it "should use the permission object when one is provided" do
@@ -393,15 +393,18 @@ describe "Zuul::ActiveRecord::Role" do
393
393
  PermissionRole.where(:role_id => @role.id, :permission_id => permission.id).count.should == 1
394
394
  end
395
395
 
396
- it "should fail and return false if the provided permission is already assigned in the provided context" do
396
+ it "should return the assigned permission if it is already assigned withinin the provided context" do
397
397
  permission = Permission.create(:name => 'Edit', :slug => 'edit')
398
398
  context = Context.create(:name => "Test Context")
399
399
  @role.assign_permission(permission)
400
- @role.assign_permission(permission).should be_false
400
+ @role.assign_permission(permission).should be_an_instance_of(PermissionRole)
401
+ PermissionRole.where(:role_id => @role.id, :permission_id => permission.id, :context_type => nil, :context_id => nil).count.should == 1
401
402
  @role.assign_permission(permission, Context)
402
- @role.assign_permission(permission, Context).should be_false
403
+ @role.assign_permission(permission, Context).should be_an_instance_of(PermissionRole)
404
+ PermissionRole.where(:role_id => @role.id, :permission_id => permission.id, :context_type => 'Context', :context_id => nil).count.should == 1
403
405
  @role.assign_permission(permission, context)
404
- @role.assign_permission(permission, context).should be_false
406
+ @role.assign_permission(permission, context).should be_an_instance_of(PermissionRole)
407
+ PermissionRole.where(:role_id => @role.id, :permission_id => permission.id, :context_type => 'Context', :context_id => context.id).count.should == 1
405
408
  end
406
409
 
407
410
  context "when forcing context" do
@@ -77,7 +77,7 @@ describe "Zuul::ActiveRecord::RoleSubject" do
77
77
  it "should provide the model with belongs_to associations for roles and subjects" do
78
78
  RoleUser.reflections.keys.should include(:role)
79
79
  RoleUser.reflections.keys.should include(:user)
80
- ru = RoleUser.create(:role_id => 1, :use_id => 1)
80
+ ru = RoleUser.create(:role_id => 1, :user_id => 1)
81
81
  ru.should respond_to(:role)
82
82
  ru.should respond_to(:user)
83
83
  end
@@ -150,15 +150,18 @@ describe "Zuul::ActiveRecord::Subject" do
150
150
  RoleUser.where(:user_id => @user.id, :role_id => role.id).count.should == 1
151
151
  end
152
152
 
153
- it "should fail and return false if the provided role is already assigned in the provided context" do
153
+ it "should return the assigned role if it is already assigned within the provided context" do
154
154
  role = Role.create(:name => 'Admin', :slug => 'admin', :level => 100)
155
155
  context = Context.create(:name => "Test Context")
156
156
  @user.assign_role(role)
157
- @user.assign_role(role).should be_false
157
+ @user.assign_role(role).should be_an_instance_of(RoleUser)
158
+ RoleUser.where(:user_id => @user.id, :role_id => role.id, :context_type => nil, :context_id => nil).count.should == 1
158
159
  @user.assign_role(role, Context)
159
- @user.assign_role(role, Context).should be_false
160
+ @user.assign_role(role, Context).should be_an_instance_of(RoleUser)
161
+ RoleUser.where(:user_id => @user.id, :role_id => role.id, :context_type => 'Context', :context_id => nil).count.should == 1
160
162
  @user.assign_role(role, context)
161
- @user.assign_role(role, context).should be_false
163
+ @user.assign_role(role, context).should be_an_instance_of(RoleUser)
164
+ RoleUser.where(:user_id => @user.id, :role_id => role.id, :context_type => 'Context', :context_id => context.id).count.should == 1
162
165
  end
163
166
 
164
167
  context "when forcing context" do
@@ -847,15 +850,18 @@ describe "Zuul::ActiveRecord::Subject" do
847
850
  PermissionUser.where(:user_id => @user.id, :permission_id => permission.id).count.should == 1
848
851
  end
849
852
 
850
- it "should fail and return false if the provided permission is already assigned in the provided context" do
853
+ it "should return the assigned permission if it is already assigned within the provided context" do
851
854
  permission = Permission.create(:name => 'Edit', :slug => 'edit')
852
855
  context = Context.create(:name => "Test Context")
853
856
  @user.assign_permission(permission)
854
- @user.assign_permission(permission).should be_false
857
+ @user.assign_permission(permission).should be_an_instance_of(PermissionUser)
858
+ PermissionUser.where(:user_id => @user.id, :permission_id => permission.id, :context_type => nil, :context_id => nil).count.should == 1
855
859
  @user.assign_permission(permission, Context)
856
- @user.assign_permission(permission, Context).should be_false
860
+ @user.assign_permission(permission, Context).should be_an_instance_of(PermissionUser)
861
+ PermissionUser.where(:user_id => @user.id, :permission_id => permission.id, :context_type => 'Context', :context_id => nil).count.should == 1
857
862
  @user.assign_permission(permission, context)
858
- @user.assign_permission(permission, context).should be_false
863
+ @user.assign_permission(permission, context).should be_an_instance_of(PermissionUser)
864
+ PermissionUser.where(:user_id => @user.id, :permission_id => permission.id, :context_type => 'Context', :context_id => context.id).count.should == 1
859
865
  end
860
866
 
861
867
  context "when forcing context" do
@@ -159,9 +159,9 @@ describe "Zuul::ActiveRecord" do
159
159
  Role.ancestors.include?(Zuul::ActiveRecord::Role).should be_true
160
160
  end
161
161
 
162
- it "should extend the model with Zuul::ActiveRecord::ContextMethods" do
162
+ it "should extend the model with Zuul::ActiveRecord::ContextAccessors" do
163
163
  Role.acts_as_authorization_role
164
- Role.ancestors.include?(Zuul::ActiveRecord::ContextMethods).should be_true
164
+ Role.ancestors.include?(Zuul::ActiveRecord::ContextAccessors).should be_true
165
165
  end
166
166
 
167
167
  it "should extend the model with Zuul::ActiveRecord::Role::PermissionMethods if permissions enabled" do
@@ -181,9 +181,9 @@ describe "Zuul::ActiveRecord" do
181
181
  Permission.ancestors.include?(Zuul::ActiveRecord::Permission).should be_true
182
182
  end
183
183
 
184
- it "should extend the model with Zuul::ActiveRecord::ContextMethods" do
184
+ it "should extend the model with Zuul::ActiveRecord::ContextAccessors" do
185
185
  Permission.acts_as_authorization_permission
186
- Permission.ancestors.include?(Zuul::ActiveRecord::ContextMethods).should be_true
186
+ Permission.ancestors.include?(Zuul::ActiveRecord::ContextAccessors).should be_true
187
187
  end
188
188
  end
189
189
 
@@ -2,6 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe "Zuul::Context" do
4
4
 
5
+ it "should alias :klass to :class_name" do
6
+ context = Zuul::Context.parse(Context)
7
+ expect(context.klass).to eql(context.class_name)
8
+ end
9
+
5
10
  describe "parse" do
6
11
  it "should allow passing nil" do
7
12
  expect { Zuul::Context.parse(nil) }.to_not raise_exception
@@ -96,21 +101,363 @@ describe "Zuul::Context" do
96
101
  end
97
102
  end
98
103
 
99
- describe "#nil?" do
104
+ describe "#global?" do
100
105
  it "should return true for a nil context" do
101
- Zuul::Context.new.nil?.should be_true
106
+ Zuul::Context.new.global?.should be_true
102
107
  end
103
108
 
104
109
  it "should return false for a class context" do
105
- Zuul::Context.new('Context', nil).nil?.should be_false
110
+ Zuul::Context.new('Context', nil).global?.should be_false
106
111
  end
107
112
 
108
113
  it "should return false for an instance context" do
114
+ obj = Context.create(:name => "Test Context")
115
+ Zuul::Context.new('Context', obj.id).global?.should be_false
116
+ end
117
+
118
+ it "should be aliased to #nil? for deprecation and compatibility" do
119
+ Zuul::Context.new.nil?.should be_true
120
+ Zuul::Context.new('Context', nil).nil?.should be_false
109
121
  obj = Context.create(:name => "Test Context")
110
122
  Zuul::Context.new('Context', obj.id).nil?.should be_false
111
123
  end
112
124
  end
113
125
 
126
+ describe "#==" do
127
+ it "should return true if the classes and ids are equal" do
128
+ obj = Context.create(:name => "Test Context")
129
+
130
+ Zuul::Context.new.should == Zuul::Context.new
131
+ Zuul::Context.new('Context', nil).should == Zuul::Context.new('Context', nil)
132
+ Zuul::Context.new('Context', obj.id).should == Zuul::Context.new('Context', obj.id)
133
+ end
134
+
135
+ it "should return false if the classes are not equal" do
136
+ obj = Context.create(:name => "Test Context")
137
+
138
+ Zuul::Context.new.should_not == Zuul::Context.new('Context', nil)
139
+ Zuul::Context.new('Context', nil).should_not == Zuul::Context.new('OtherContext', nil)
140
+ end
141
+
142
+ it "should return false if the ids are not equal" do
143
+ obj1 = Context.create(:name => "Test Context One")
144
+ obj2 = Context.create(:name => "Test Context Two")
145
+
146
+ Zuul::Context.new('Context', obj1.id).should_not == Zuul::Context.new('Context', nil)
147
+ Zuul::Context.new('Context', obj1.id).should_not == Zuul::Context.new('Context', obj2.id)
148
+ end
149
+ end
150
+
151
+ describe "#<=" do
152
+ context "with a global context" do
153
+ let(:context) { Zuul::Context.new }
154
+
155
+ context "when compared a global context" do
156
+ let(:kontext) { Zuul::Context.new }
157
+
158
+ it "should return true" do
159
+ expect(context <= kontext).to be_true
160
+ end
161
+ end
162
+
163
+ context "when compared to a class context" do
164
+ let(:kontext) { Zuul::Context.new('Context') }
165
+
166
+ it "should return false" do
167
+ expect(context <= kontext).to be_false
168
+ end
169
+ end
170
+
171
+ context "when compared to an instance context" do
172
+ let(:kontext) do
173
+ obj = Context.create(:name => "Test Context")
174
+ Zuul::Context.new('Context', obj.id)
175
+ end
176
+
177
+ it "should return false" do
178
+ expect(context <= kontext).to be_false
179
+ end
180
+ end
181
+ end
182
+
183
+ context "with a class context" do
184
+ let(:context) { Zuul::Context.new('Context') }
185
+
186
+ context "when compared a global context" do
187
+ let(:kontext) { Zuul::Context.new }
188
+
189
+ it "should return true" do
190
+ expect(context <= kontext).to be_true
191
+ end
192
+ end
193
+
194
+ context "when compared to a class context" do
195
+ context "with the same class" do
196
+ let(:kontext) { Zuul::Context.new('Context') }
197
+
198
+ it "should return true" do
199
+ expect(context <= kontext).to be_true
200
+ end
201
+ end
202
+
203
+ context "with a different class" do
204
+ let(:kontext) { Zuul::Context.new('OtherContext') }
205
+
206
+ it "should return false" do
207
+ expect(context <= kontext).to be_false
208
+ end
209
+ end
210
+ end
211
+
212
+ context "when compared to an instance context" do
213
+ context "with the same class" do
214
+ let(:kontext) do
215
+ obj = Context.create(:name => "Test Context")
216
+ Zuul::Context.new('Context', obj.id)
217
+ end
218
+
219
+ it "should return false" do
220
+ expect(context <= kontext).to be_false
221
+ end
222
+ end
223
+
224
+ context "with a different class" do
225
+ let(:kontext) do
226
+ obj = ZuulModels::Context.create(:name => "Test Context")
227
+ Zuul::Context.new('OtherContext', obj.id)
228
+ end
229
+
230
+ it "should return false" do
231
+ expect(context <= kontext).to be_false
232
+ end
233
+ end
234
+ end
235
+ end
236
+
237
+ context "with an instance context" do
238
+ let(:obj) { Context.create(:name => "Test Context") }
239
+ let(:context) do
240
+ Zuul::Context.new('Context', obj.id)
241
+ end
242
+
243
+ context "when compared a global context" do
244
+ let(:kontext) { Zuul::Context.new }
245
+
246
+ it "should return true" do
247
+ expect(context <= kontext).to be_true
248
+ end
249
+ end
250
+
251
+ context "when compared to a class context" do
252
+ context "with the same class" do
253
+ let(:kontext) { Zuul::Context.new('Context') }
254
+
255
+ it "should return true" do
256
+ expect(context <= kontext).to be_true
257
+ end
258
+ end
259
+
260
+ context "with a different class" do
261
+ let(:kontext) { Zuul::Context.new('OtherContext') }
262
+
263
+ it "should return false" do
264
+ expect(context <= kontext).to be_false
265
+ end
266
+ end
267
+ end
268
+
269
+ context "when compared to an instance context" do
270
+ context "with the same class" do
271
+ context "with the same id" do
272
+ let(:kontext) do
273
+ Zuul::Context.new('Context', obj.id)
274
+ end
275
+
276
+ it "should return true" do
277
+ expect(context <= kontext).to be_true
278
+ end
279
+ end
280
+
281
+ context "with a different id" do
282
+ let(:kontext) do
283
+ other_obj = Context.create(:name => "Other Context")
284
+ Zuul::Context.new('Context', other_obj.id)
285
+ end
286
+
287
+ it "should return false" do
288
+ expect(context <= kontext).to be_false
289
+ end
290
+ end
291
+ end
292
+
293
+ context "with a different class" do
294
+ let(:kontext) do
295
+ Zuul::Context.new('OtherContext', obj.id)
296
+ end
297
+
298
+ it "should return false" do
299
+ expect(context <= kontext).to be_false
300
+ end
301
+ end
302
+ end
303
+ end
304
+ end
305
+
306
+ describe "#>=" do
307
+ context "with a global context" do
308
+ let(:context) { Zuul::Context.new }
309
+
310
+ context "when compared a global context" do
311
+ let(:kontext) { Zuul::Context.new }
312
+
313
+ it "should return true" do
314
+ expect(context >= kontext).to be_true
315
+ end
316
+ end
317
+
318
+ context "when compared to a class context" do
319
+ let(:kontext) { Zuul::Context.new('Context') }
320
+
321
+ it "should return true" do
322
+ expect(context >= kontext).to be_true
323
+ end
324
+ end
325
+
326
+ context "when compared to an instance context" do
327
+ let(:kontext) do
328
+ obj = Context.create(:name => "Test Context")
329
+ Zuul::Context.new('Context', obj.id)
330
+ end
331
+
332
+ it "should return true" do
333
+ expect(context >= kontext).to be_true
334
+ end
335
+ end
336
+ end
337
+
338
+ context "with a class context" do
339
+ let(:context) { Zuul::Context.new('Context') }
340
+
341
+ context "when compared a global context" do
342
+ let(:kontext) { Zuul::Context.new }
343
+
344
+ it "should return false" do
345
+ expect(context >= kontext).to be_false
346
+ end
347
+ end
348
+
349
+ context "when compared to a class context" do
350
+ context "with the same class" do
351
+ let(:kontext) { Zuul::Context.new('Context') }
352
+
353
+ it "should return true" do
354
+ expect(context >= kontext).to be_true
355
+ end
356
+ end
357
+
358
+ context "with a different class" do
359
+ let(:kontext) { Zuul::Context.new('OtherContext') }
360
+
361
+ it "should return false" do
362
+ expect(context >= kontext).to be_false
363
+ end
364
+ end
365
+ end
366
+
367
+ context "when compared to an instance context" do
368
+ context "with the same class" do
369
+ let(:kontext) do
370
+ obj = Context.create(:name => "Test Context")
371
+ Zuul::Context.new('Context', obj.id)
372
+ end
373
+
374
+ it "should return true" do
375
+ expect(context >= kontext).to be_true
376
+ end
377
+ end
378
+
379
+ context "with a different class" do
380
+ let(:kontext) do
381
+ obj = ZuulModels::Context.create(:name => "Test Context")
382
+ Zuul::Context.new('OtherContext', obj.id)
383
+ end
384
+
385
+ it "should return false" do
386
+ expect(context >= kontext).to be_false
387
+ end
388
+ end
389
+ end
390
+ end
391
+
392
+ context "with an instance context" do
393
+ let(:obj) { Context.create(:name => "Test Context") }
394
+ let(:context) do
395
+ Zuul::Context.new('Context', obj.id)
396
+ end
397
+
398
+ context "when compared a global context" do
399
+ let(:kontext) { Zuul::Context.new }
400
+
401
+ it "should return false" do
402
+ expect(context >= kontext).to be_false
403
+ end
404
+ end
405
+
406
+ context "when compared to a class context" do
407
+ context "with the same class" do
408
+ let(:kontext) { Zuul::Context.new('Context') }
409
+
410
+ it "should return false" do
411
+ expect(context >= kontext).to be_false
412
+ end
413
+ end
414
+
415
+ context "with a different class" do
416
+ let(:kontext) { Zuul::Context.new('OtherContext') }
417
+
418
+ it "should return false" do
419
+ expect(context >= kontext).to be_false
420
+ end
421
+ end
422
+ end
423
+
424
+ context "when compared to an instance context" do
425
+ context "with the same class" do
426
+ context "with the same id" do
427
+ let(:kontext) do
428
+ Zuul::Context.new('Context', obj.id)
429
+ end
430
+
431
+ it "should return true" do
432
+ expect(context >= kontext).to be_true
433
+ end
434
+ end
435
+
436
+ context "with a different id" do
437
+ let(:kontext) do
438
+ other_obj = Context.create(:name => "Other Context")
439
+ Zuul::Context.new('Context', other_obj.id)
440
+ end
441
+
442
+ it "should return false" do
443
+ expect(context >= kontext).to be_false
444
+ end
445
+ end
446
+ end
447
+
448
+ context "with a different class" do
449
+ let(:kontext) do
450
+ Zuul::Context.new('OtherContext', obj.id)
451
+ end
452
+
453
+ it "should return false" do
454
+ expect(context >= kontext).to be_false
455
+ end
456
+ end
457
+ end
458
+ end
459
+ end
460
+
114
461
  describe "#type" do
115
462
  it "should return :nil for a nil context" do
116
463
  Zuul::Context.new.type.should == :nil