bumbleworks 0.0.70 → 0.0.71

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,18 @@
1
1
  module Bumbleworks
2
2
  module User
3
+ # This exception is raised if the including class has no #role_identifiers
4
+ # method defined. See #role_identifiers below for details.
3
5
  class NoRoleIdentifiersMethodDefined < StandardError; end
6
+ # This exception is raised if the including class has no #claim_token
7
+ # method defined, and also no fallback methods (#username or #email). See
8
+ # #claim_token below for details.
4
9
  class NoClaimTokenMethodDefined < StandardError; end
5
- class MissingRoleQueryMethod < StandardError; end
6
- class AmbiguousRoleQueryMethod < StandardError; end
10
+
11
+ # Attempting to #claim a task that the user is not authorized for will raise
12
+ # this exception.
7
13
  class UnauthorizedClaimAttempt < StandardError; end
14
+ # Attempting to #release a task that is claimed by another token will raise
15
+ # this exception.
8
16
  class UnauthorizedReleaseAttempt < StandardError; end
9
17
 
10
18
  # The return value from this method is used as the "claimant" token on
@@ -41,17 +49,19 @@ module Bumbleworks
41
49
  # Attempts to set self as the claimant of the given task. If not authorized
42
50
  # to claim the task, raises exception. Also bubbles exception from Task
43
51
  # when task is already claimed by a different claimant.
44
- def claim(task)
52
+ def claim(task, force = false)
45
53
  raise UnauthorizedClaimAttempt unless has_role?(task.role)
54
+ release!(task) if force
46
55
  task.claim(claim_token)
47
56
  end
48
57
 
49
- # Same as #claim, but first releases (by force) the task, to avoid any
50
- # possible UnauthorizedClaimAttempt or AlreadyClaimed exceptions. Should
51
- # only be made available to supervisory roles.
58
+ # Same as #claim, but first releases (by force) the task, to avoid an
59
+ # AlreadyClaimed exceptions. Note that this may still raise an
60
+ # UnauthorizedClaimAttempt exception - this method does not allow a user
61
+ # to claim a task they are not authorized for. Should only be made
62
+ # available to supervisory roles.
52
63
  def claim!(task)
53
- release!(task)
54
- claim(task)
64
+ claim(task, true)
55
65
  end
56
66
 
57
67
  # If we are the current claimant of the given task, release the task. Does
@@ -1,3 +1,3 @@
1
1
  module Bumbleworks
2
- VERSION = "0.0.70"
2
+ VERSION = "0.0.71"
3
3
  end
@@ -65,6 +65,15 @@ describe Bumbleworks::User do
65
65
  task.should_receive(:claim).with("the umpire of snorts").ordered
66
66
  subject.claim!(task)
67
67
  end
68
+
69
+ it 'raises exception (and does not release) if unauthorized' do
70
+ task = double('task', :role => 'fashbone')
71
+ task.should_receive(:release).never
72
+ task.should_receive(:claim).never
73
+ expect {
74
+ subject.claim!(task)
75
+ }.to raise_error(Bumbleworks::User::UnauthorizedClaimAttempt)
76
+ end
68
77
  end
69
78
  end
70
79
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bumbleworks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.70
4
+ version: 0.0.71
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-02-19 00:00:00.000000000 Z
15
+ date: 2014-02-20 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: ruote
@@ -266,7 +266,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
266
266
  version: '0'
267
267
  segments:
268
268
  - 0
269
- hash: -1442108325624690777
269
+ hash: 53431836910523847
270
270
  required_rubygems_version: !ruby/object:Gem::Requirement
271
271
  none: false
272
272
  requirements:
@@ -275,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
275
  version: '0'
276
276
  segments:
277
277
  - 0
278
- hash: -1442108325624690777
278
+ hash: 53431836910523847
279
279
  requirements: []
280
280
  rubyforge_project:
281
281
  rubygems_version: 1.8.23