pebblebed 0.0.48 → 0.0.49

Sign up to get free protection for your applications and to get access to all the features.
@@ -73,14 +73,23 @@ module Pebblebed
73
73
  collected_roles << role
74
74
  end
75
75
  end
76
- the_role.merge(:upgrades => begin
77
- result = {}
78
- (self.class.roles - collected_roles).each{|r|
79
- result[:"#{r[:name]}"] = r[:requirements]
80
- }
81
- result
76
+ owned_capabilities = collected_roles.map{|c| c[:capabilities]}.flatten.compact.uniq
77
+ all_capabilities = self.class.roles.map{|r| r[:capabilities]}.flatten.compact.uniq
78
+ the_role.merge!(:upgrades => begin
79
+ upgraders = {}
80
+ all_capabilities.each do |c|
81
+ next if owned_capabilities.include?(c)
82
+ self.class.roles.select{|r| r[:capabilities].include?(c)}.each do |r|
83
+ upgraders[c] ||= []
84
+ upgraders[c] << r[:requirements]
85
+ upgraders[c].flatten!.uniq!
86
+ end
87
+ end
88
+ upgraders
82
89
  end
83
90
  )
91
+ the_role[:capabilities] = owned_capabilities
92
+ the_role
84
93
  end
85
94
  end
86
95
 
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.0.48"
2
+ VERSION = "0.0.49"
3
3
  end
@@ -15,7 +15,7 @@ describe Pebblebed::Security::RoleSchema do
15
15
  class CustomRoleSchema < Pebblebed::Security::RoleSchema
16
16
  role :guest, :capabilities => [], :requirements => []
17
17
  role :identified, :capabilities => [:kudo], :requirements => [:logged_in]
18
- role :contributor, :capabilities => [:comment, :kudo], :requirements => [:logged_in, :verified_mobile]
18
+ role :contributor, :capabilities => [:comment], :requirements => [:logged_in, :verified_mobile]
19
19
 
20
20
  def check_logged_in
21
21
  return true if identity and identity['identity']
@@ -69,7 +69,7 @@ describe Pebblebed::Security::RoleSchema do
69
69
  end
70
70
 
71
71
  it "has the correct roles defined" do
72
- CustomRoleSchema.roles.should == [{:capabilities=>[], :requirements=>[], :name=>:guest, :role_rank=>0}, {:capabilities=>[:kudo], :requirements=>[:logged_in], :name=>:identified, :role_rank=>1}, {:capabilities=>[:comment, :kudo], :requirements=>[:logged_in, :verified_mobile], :name=>:contributor, :role_rank=>2}]
72
+ CustomRoleSchema.roles.should == [{:capabilities=>[], :requirements=>[], :name=>:guest, :role_rank=>0, :upgrades=>{:kudo=>[:logged_in], :comment=>[:logged_in, :verified_mobile]}}, {:capabilities=>[:kudo], :requirements=>[:logged_in], :name=>:identified, :role_rank=>1}, {:capabilities=>[:comment], :requirements=>[:logged_in, :verified_mobile], :name=>:contributor, :role_rank=>2}]
73
73
  end
74
74
 
75
75
  it "has an answer to requirements for a role" do
@@ -97,7 +97,7 @@ describe Pebblebed::Security::RoleSchema do
97
97
  }
98
98
 
99
99
  it "returns the guest role" do
100
- schema.role.should == {:current=>:guest, :capabilities=>[], :upgrades=>{:identified=>[:logged_in], :contributor=>[:logged_in, :verified_mobile]}}
100
+ schema.role.should == {:current=>:guest, :capabilities=>[], :upgrades=>{:kudo=>[:logged_in], :comment=>[:logged_in, :verified_mobile]}}
101
101
  end
102
102
 
103
103
  end
@@ -111,7 +111,7 @@ describe Pebblebed::Security::RoleSchema do
111
111
  }
112
112
 
113
113
  it "returns the idenitified role" do
114
- schema.role.should == {:current=>:identified, :capabilities=>[:kudo], :upgrades=>{:contributor=>[:logged_in, :verified_mobile]}}
114
+ schema.role.should == {:current=>:identified, :capabilities=>[:kudo], :upgrades=>{:comment=>[:logged_in, :verified_mobile]}}
115
115
  end
116
116
 
117
117
  end
@@ -123,7 +123,7 @@ describe Pebblebed::Security::RoleSchema do
123
123
  }
124
124
 
125
125
  it "returns the contributor role" do
126
- schema.role.should == {:current=>:contributor, :capabilities=>[:comment, :kudo], :upgrades=>{}}
126
+ schema.role.should == {:current=>:contributor, :capabilities=>[:kudo, :comment], :upgrades=>{}}
127
127
  end
128
128
 
129
129
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.48
4
+ version: 0.0.49
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-04-05 00:00:00.000000000 Z
13
+ date: 2013-04-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec