role_up 0.1.0
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.
- data/.gemtest +0 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/LICENSE +20 -0
- data/README.md +73 -0
- data/Rakefile +12 -0
- data/lib/role_up.rb +19 -0
- data/lib/role_up/ability.rb +106 -0
- data/lib/role_up/errors.rb +7 -0
- data/lib/role_up/version.rb +5 -0
- data/role_up.gemspec +29 -0
- data/test/ability_spec_test.rb +65 -0
- data/test/ability_test.rb +159 -0
- data/test/role_up_spec_test.rb +18 -0
- data/test/role_up_test.rb +20 -0
- data/test/support/helper_classes.rb +7 -0
- data/test/support/helper_methods.rb +38 -0
- data/test/test_helper.rb +12 -0
- metadata +122 -0
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
role_up (0.1.0)
|
5
|
+
active_support (~> 3.0.0)
|
6
|
+
cancan (~> 1.6.5)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
active_support (3.0.0)
|
12
|
+
activesupport (= 3.0.0)
|
13
|
+
activesupport (3.0.0)
|
14
|
+
cancan (1.6.5)
|
15
|
+
minitest (2.2.2)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
bundler (~> 1.0.0)
|
22
|
+
minitest (~> 2.2.2)
|
23
|
+
role_up!
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Quick Left, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
Role Up
|
2
|
+
===========
|
3
|
+
Rails 3 engine that adds some real-deal lovin' to `CanCan` authorization.
|
4
|
+
|
5
|
+
### Convention
|
6
|
+
Authorization definitions with `CanCan` quickly become verbose in complex
|
7
|
+
applications. By breaking them up per model and being able to depend on
|
8
|
+
a few common extras, we can drastically clean up our code. Let's look at
|
9
|
+
the following directory structure...
|
10
|
+
|
11
|
+
- app/
|
12
|
+
- abilities/
|
13
|
+
+ widget_ability.rb
|
14
|
+
- controllers/
|
15
|
+
- etc...
|
16
|
+
|
17
|
+
As you can see, we've added a new folder to the `app/` directory in our
|
18
|
+
project. Here, we'll create an ability file for each of our models that
|
19
|
+
need it to define our authorization abilities.
|
20
|
+
|
21
|
+
### Ability Files
|
22
|
+
Here's an example ability file...
|
23
|
+
|
24
|
+
# app/abilities/widget_ability.rb
|
25
|
+
class WidgetAbility < Ability
|
26
|
+
|
27
|
+
define_rules :widget do |user|
|
28
|
+
can :manage , Widget , :user_id => user.id
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
The `define_rules` method accepts a block and yields the current user.
|
34
|
+
In this block, the standard `CanCan` ability definitions methods apply. If
|
35
|
+
you have a set of standard authorization rules, you can reopen the
|
36
|
+
provided `Ability` class and define a `standard_rules` block. Check
|
37
|
+
it...
|
38
|
+
|
39
|
+
# app/abilities/ability.rb
|
40
|
+
class Ability
|
41
|
+
|
42
|
+
standard_rules do |user|
|
43
|
+
if user.admin?
|
44
|
+
can :manage , :all
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
Standard rules will get evaluated last, and therefore take highest
|
51
|
+
priority.
|
52
|
+
|
53
|
+
### Model and Controller Helpers
|
54
|
+
The standard `CanCan` helpers apply.
|
55
|
+
|
56
|
+
### Setup
|
57
|
+
You can configure the class that `RoleUp` will use to authorize with in
|
58
|
+
the gem's setup block. The default is `:user`. You can also pass class
|
59
|
+
constants or strings as opposed to a symbol e.g.
|
60
|
+
|
61
|
+
# app/initializers/role_up.rb
|
62
|
+
RoleUp.setup do |config|
|
63
|
+
config.authorization_class = :cool_user # => CoolUser
|
64
|
+
# or
|
65
|
+
config.authorization_class = CoolUser # => CoolUser
|
66
|
+
# or
|
67
|
+
config.authorization_class = "cool_user" # => CoolUser
|
68
|
+
# or
|
69
|
+
config.authorization_class = "my_namespace/cool_user" # => MyNamspace::CoolUser
|
70
|
+
# or
|
71
|
+
config.authorization_class = "MyNamespace::CoolUser" # => MyNamspace::CoolUser
|
72
|
+
end
|
73
|
+
|
data/Rakefile
ADDED
data/lib/role_up.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "active_support/core_ext/module/attribute_accessors"
|
2
|
+
require "cancan"
|
3
|
+
|
4
|
+
module RoleUp
|
5
|
+
|
6
|
+
# Lock 'n Load
|
7
|
+
autoload :Errors , 'role_up/errors'
|
8
|
+
require 'role_up/ability'
|
9
|
+
|
10
|
+
# The class we'll authorize against
|
11
|
+
mattr_accessor :authorization_class
|
12
|
+
@@authorization_class = :user
|
13
|
+
|
14
|
+
# Fancy setup block
|
15
|
+
def self.setup
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# Requires
|
2
|
+
require "active_support/core_ext/class/attribute_accessors"
|
3
|
+
require "active_support/core_ext/string/inflections"
|
4
|
+
require "cancan/ability"
|
5
|
+
|
6
|
+
class ::Ability
|
7
|
+
|
8
|
+
# Attributes
|
9
|
+
attr_reader :authorization_instance
|
10
|
+
|
11
|
+
# Class Attributes
|
12
|
+
cattr_reader :ability_definitions
|
13
|
+
@@ability_definitions = {}
|
14
|
+
|
15
|
+
# Includes
|
16
|
+
include CanCan::Ability
|
17
|
+
|
18
|
+
def initialize( current_authorization_instance = nil , *resources )
|
19
|
+
|
20
|
+
# Load our authorization class
|
21
|
+
if current_authorization_instance
|
22
|
+
@authorization_instance = current_authorization_instance
|
23
|
+
else
|
24
|
+
@authorization_instance = get_new_authorization_instance
|
25
|
+
end
|
26
|
+
|
27
|
+
# Load rules
|
28
|
+
if resources.empty?
|
29
|
+
load_all_rules
|
30
|
+
else
|
31
|
+
load_rules_for! *resources
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# Class Methods
|
37
|
+
|
38
|
+
def self.define_rules( &rule_set )
|
39
|
+
raise RoleUp::Errors::IncorrectAbilityClassDefinition unless self.to_s =~ /(\w+)Ability$/
|
40
|
+
resource = $1.underscore.to_sym
|
41
|
+
ability_definitions[ resource ] = rule_set
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.standard_rules( &rule_set )
|
45
|
+
ability_definitions[ :__standard ] = rule_set
|
46
|
+
end
|
47
|
+
|
48
|
+
# Instance Methods
|
49
|
+
|
50
|
+
def add_standard_rules_to_resources_hash_if_defined( resources )
|
51
|
+
resources.delete :__standard # just get rid of it - we'll add it back if it's really there
|
52
|
+
resources << :__standard if standard_rules_defined?
|
53
|
+
resources
|
54
|
+
end
|
55
|
+
|
56
|
+
def constantize_authorization_class
|
57
|
+
begin
|
58
|
+
if RoleUp.authorization_class.is_a? Symbol
|
59
|
+
return RoleUp.authorization_class.to_s.camelize.constantize
|
60
|
+
elsif RoleUp.authorization_class.is_a? Class
|
61
|
+
return RoleUp.authorization_class
|
62
|
+
elsif RoleUp.authorization_class.is_a? String
|
63
|
+
return RoleUp.authorization_class.camelize.constantize
|
64
|
+
end
|
65
|
+
rescue
|
66
|
+
raise RoleUp::Errors::BadAuthorizationClass.new "Provided authorization class is malformed :: #{RoleUp.authorization_class}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_new_authorization_instance
|
71
|
+
constantize_authorization_class.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def load_all_rules
|
75
|
+
load_rules_for *self.class.ability_definitions.keys
|
76
|
+
end
|
77
|
+
|
78
|
+
def load_resource_rules( resource )
|
79
|
+
rules_block = self.class.ability_definitions[ resource ]
|
80
|
+
self.instance_exec( authorization_instance , &rules_block )
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_resource_rules!( resource )
|
84
|
+
raise RoleUp::Errors::RulesNotDefinedError.new( "Rules not defined for #{resource}" ) unless rules_defined_for? resource
|
85
|
+
load_resource_rules resource
|
86
|
+
end
|
87
|
+
|
88
|
+
def load_rules_for( *resources )
|
89
|
+
add_standard_rules_to_resources_hash_if_defined resources
|
90
|
+
resources.each { |resource| load_resource_rules resource }
|
91
|
+
end
|
92
|
+
|
93
|
+
def load_rules_for!( *resources )
|
94
|
+
add_standard_rules_to_resources_hash_if_defined resources
|
95
|
+
resources.each { |resource| load_resource_rules! resource }
|
96
|
+
end
|
97
|
+
|
98
|
+
def rules_defined_for?( resource )
|
99
|
+
self.class.ability_definitions.include? resource
|
100
|
+
end
|
101
|
+
|
102
|
+
def standard_rules_defined?
|
103
|
+
rules_defined_for? :__standard
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
data/role_up.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "role_up/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "role_up"
|
7
|
+
s.version = RoleUp::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Ryan Cook"]
|
10
|
+
s.email = ["ryan@quickleft.com"]
|
11
|
+
s.homepage = "https://github.com/quickleft/role_up"
|
12
|
+
s.summary = "role_up-#{s.version}"
|
13
|
+
s.description = %q{Rails 3 engine that adds some real-deal lovin' to CanCan authorization.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "role_up"
|
16
|
+
|
17
|
+
# Runtime Dependencies
|
18
|
+
s.add_dependency "active_support" , "~> 3.0.0"
|
19
|
+
s.add_dependency "cancan" , "~> 1.6.5"
|
20
|
+
|
21
|
+
# Development Dependencies
|
22
|
+
s.add_development_dependency "bundler" , "~> 1.0.0"
|
23
|
+
s.add_development_dependency "minitest" , "~> 2.2.2"
|
24
|
+
|
25
|
+
s.files = `git ls-files`.split("\n")
|
26
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
27
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Ability do
|
4
|
+
|
5
|
+
describe "Class Level" do
|
6
|
+
|
7
|
+
it "should have a class var to hold our rule procs" do
|
8
|
+
Ability.class_variables.map { |var| var.to_sym }.must_include :@@ability_definitions
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should respond to define_rules" do
|
12
|
+
Ability.must_respond_to :define_rules
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should respond to standard_rules" do
|
16
|
+
Ability.must_respond_to :standard_rules
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "Instance Level" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
@ability = Ability.new( TestUser.new )
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should respond to constantize_authorization_class" do
|
28
|
+
@ability.must_respond_to :constantize_authorization_class
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should respond to get_new_authorization_instance" do
|
32
|
+
@ability.must_respond_to :get_new_authorization_instance
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should respond to load_all_rules" do
|
36
|
+
@ability.must_respond_to :load_all_rules
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should respond to load_resource_rules" do
|
40
|
+
@ability.must_respond_to :load_resource_rules
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should respond to load_resource_rules!" do
|
44
|
+
@ability.must_respond_to :load_resource_rules!
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should respond to load_rules_for" do
|
48
|
+
@ability.must_respond_to :load_rules_for
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should respond to load_rules_for!" do
|
52
|
+
@ability.must_respond_to :load_rules_for!
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should respond to rules_defined_for?" do
|
56
|
+
@ability.must_respond_to :rules_defined_for?
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should respond to standard_rules_defined?" do
|
60
|
+
@ability.must_respond_to :standard_rules_defined?
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class AbilityTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
reset_ability_class
|
7
|
+
end
|
8
|
+
|
9
|
+
## add_standard_rules_to_resources_hash_if_defined
|
10
|
+
#
|
11
|
+
|
12
|
+
def test_standard_rules_are_not_added_if_they_dont_exist
|
13
|
+
ability = Ability.new
|
14
|
+
resources = [ :test_widget ]
|
15
|
+
modified_resources_hash = ability.add_standard_rules_to_resources_hash_if_defined resources
|
16
|
+
refute_includes modified_resources_hash , :__standard
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_can_determine_whether_standard_rules_exist_and_add_them_to_resources_hash
|
20
|
+
load_standard_rules
|
21
|
+
ability = Ability.new
|
22
|
+
resources = [ :test_widget ]
|
23
|
+
modified_resources_hash = ability.add_standard_rules_to_resources_hash_if_defined resources
|
24
|
+
assert_includes modified_resources_hash , :__standard
|
25
|
+
end
|
26
|
+
|
27
|
+
## constantize_authorization_class
|
28
|
+
#
|
29
|
+
|
30
|
+
def test_can_constantize_authorization_class_with_symbol
|
31
|
+
RoleUp.setup do |config|
|
32
|
+
config.authorization_class = :test_user
|
33
|
+
end
|
34
|
+
ability = Ability.new
|
35
|
+
assert_equal TestUser , ability.constantize_authorization_class
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_can_constantize_authorization_class_with_constant
|
39
|
+
RoleUp.setup do |config|
|
40
|
+
config.authorization_class = TestUser
|
41
|
+
end
|
42
|
+
ability = Ability.new
|
43
|
+
assert_equal TestUser , ability.constantize_authorization_class
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_can_constantize_authorization_class_with_constant_when_nested_in_module
|
47
|
+
RoleUp.setup do |config|
|
48
|
+
config.authorization_class = MyModule::TestUser
|
49
|
+
end
|
50
|
+
ability = Ability.new
|
51
|
+
assert_equal MyModule::TestUser , ability.constantize_authorization_class
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_can_constantize_authorization_class_with_underscored_string
|
55
|
+
RoleUp.setup do |config|
|
56
|
+
config.authorization_class = "test_user"
|
57
|
+
end
|
58
|
+
ability = Ability.new
|
59
|
+
assert_equal TestUser , ability.constantize_authorization_class
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_can_constantize_authorization_class_with_classy_string
|
63
|
+
RoleUp.setup do |config|
|
64
|
+
config.authorization_class = "TestUser"
|
65
|
+
end
|
66
|
+
ability = Ability.new
|
67
|
+
assert_equal TestUser , ability.constantize_authorization_class
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_can_constantize_authorization_class_with_underscored_string_when_nested_in_module
|
71
|
+
RoleUp.setup do |config|
|
72
|
+
config.authorization_class = "my_module/test_user"
|
73
|
+
end
|
74
|
+
ability = Ability.new
|
75
|
+
assert_equal MyModule::TestUser , ability.constantize_authorization_class
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_can_constantize_authorization_class_with_classy_string_when_nested_in_module
|
79
|
+
RoleUp.setup do |config|
|
80
|
+
config.authorization_class = "MyModule::TestUser"
|
81
|
+
end
|
82
|
+
ability = Ability.new
|
83
|
+
assert_equal MyModule::TestUser , ability.constantize_authorization_class
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_can_raise_bad_authorization_class_error_when_bad_authorization_class_specified
|
87
|
+
RoleUp.setup do |config|
|
88
|
+
config.authorization_class = :bad_authorization_class!
|
89
|
+
end
|
90
|
+
assert_raises RoleUp::Errors::BadAuthorizationClass do
|
91
|
+
ability = Ability.new
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
## get_new_authorization_instance
|
96
|
+
#
|
97
|
+
|
98
|
+
def test_get_new_authorization_instance_returns_instance_of_authorization_class
|
99
|
+
reset_ability_class
|
100
|
+
assert_instance_of TestUser , Ability.new.get_new_authorization_instance
|
101
|
+
end
|
102
|
+
|
103
|
+
## load_resource_rules
|
104
|
+
#
|
105
|
+
|
106
|
+
def test_can_load_resource_rules
|
107
|
+
ability = Ability.new
|
108
|
+
load_test_widget_2_rules
|
109
|
+
ability.load_resource_rules(:test_widget2)
|
110
|
+
assert ability.can?( :manage , TestWidget2 )
|
111
|
+
end
|
112
|
+
|
113
|
+
## load_resource_rules!
|
114
|
+
#
|
115
|
+
|
116
|
+
def test_load_resource_rules_with_bad_resource_trows_error
|
117
|
+
ability = Ability.new
|
118
|
+
assert_raises RoleUp::Errors::RulesNotDefinedError do
|
119
|
+
ability.load_resource_rules! :bogus_resource
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
## load_rules_for
|
124
|
+
#
|
125
|
+
|
126
|
+
def test_standard_rules_override_other_rules_when_all_are_loaded
|
127
|
+
load_standard_rules
|
128
|
+
ability = Ability.new
|
129
|
+
refute ability.can? :manage , TestWidget
|
130
|
+
end
|
131
|
+
|
132
|
+
## load_rules_for!
|
133
|
+
#
|
134
|
+
|
135
|
+
def test_standard_rules_override_other_rules_when_resources_are_specified
|
136
|
+
load_standard_rules
|
137
|
+
ability = Ability.new( TestUser.new , :test_widget )
|
138
|
+
refute ability.can? :manage , TestWidget
|
139
|
+
end
|
140
|
+
|
141
|
+
## rules_defined_for?
|
142
|
+
#
|
143
|
+
|
144
|
+
def test_able_to_check_whether_rules_are_defined_for_a_resource
|
145
|
+
ability = Ability.new
|
146
|
+
assert ability.rules_defined_for? :test_widget
|
147
|
+
end
|
148
|
+
|
149
|
+
## standard_rules_defined?
|
150
|
+
#
|
151
|
+
|
152
|
+
def test_able_to_check_whether_standard_rules_are_defined
|
153
|
+
load_standard_rules
|
154
|
+
ability = Ability.new
|
155
|
+
assert ability.standard_rules_defined?
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe RoleUp do
|
4
|
+
|
5
|
+
it "must be a module" do
|
6
|
+
RoleUp.must_be_kind_of Module
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should respond to authorization_class" do
|
10
|
+
RoleUp.must_respond_to :authorization_class
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should respond to setup" do
|
14
|
+
RoleUp.must_respond_to :setup
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RoleUpTest < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
def test_that_ability_is_loaded
|
6
|
+
assert defined? Ability
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_that_our_errors_are_loadable
|
10
|
+
assert defined? RoleUp::Errors
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_that_role_up_yields_self_on_setup
|
14
|
+
RoleUp.setup do |config|
|
15
|
+
assert_equal RoleUp , config
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
def load_standard_rules
|
2
|
+
eval <<-___
|
3
|
+
class Ability
|
4
|
+
standard_rules do |test_user|
|
5
|
+
cannot :manage , TestWidget
|
6
|
+
end
|
7
|
+
end
|
8
|
+
___
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_test_widget_rules
|
12
|
+
eval <<-___
|
13
|
+
class TestWidgetAbility < Ability
|
14
|
+
define_rules do |test_user|
|
15
|
+
can :manage , TestWidget
|
16
|
+
end
|
17
|
+
end
|
18
|
+
___
|
19
|
+
end
|
20
|
+
|
21
|
+
def load_test_widget_2_rules
|
22
|
+
eval <<-___
|
23
|
+
class TestWidget2Ability < Ability
|
24
|
+
define_rules do |test_user|
|
25
|
+
can :manage , TestWidget2
|
26
|
+
end
|
27
|
+
end
|
28
|
+
___
|
29
|
+
end
|
30
|
+
|
31
|
+
def reset_ability_class
|
32
|
+
RoleUp.setup do |config|
|
33
|
+
config.authorization_class = :test_user
|
34
|
+
end
|
35
|
+
Ability.send :class_variable_set , :@@ability_definitions , {}
|
36
|
+
load_test_widget_rules
|
37
|
+
end
|
38
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
# make sure we're using the minitest gem
|
5
|
+
gem "minitest"
|
6
|
+
|
7
|
+
require "role_up"
|
8
|
+
require "minitest/autorun"
|
9
|
+
|
10
|
+
# Load support files
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
12
|
+
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: role_up
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Cook
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-02 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: active_support
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 3.0.0
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: cancan
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.5
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: bundler
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: minitest
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.2.2
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
description: Rails 3 engine that adds some real-deal lovin' to CanCan authorization.
|
60
|
+
email:
|
61
|
+
- ryan@quickleft.com
|
62
|
+
executables: []
|
63
|
+
|
64
|
+
extensions: []
|
65
|
+
|
66
|
+
extra_rdoc_files: []
|
67
|
+
|
68
|
+
files:
|
69
|
+
- .gemtest
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- LICENSE
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- lib/role_up.rb
|
77
|
+
- lib/role_up/ability.rb
|
78
|
+
- lib/role_up/errors.rb
|
79
|
+
- lib/role_up/version.rb
|
80
|
+
- role_up.gemspec
|
81
|
+
- test/ability_spec_test.rb
|
82
|
+
- test/ability_test.rb
|
83
|
+
- test/role_up_spec_test.rb
|
84
|
+
- test/role_up_test.rb
|
85
|
+
- test/support/helper_classes.rb
|
86
|
+
- test/support/helper_methods.rb
|
87
|
+
- test/test_helper.rb
|
88
|
+
homepage: https://github.com/quickleft/role_up
|
89
|
+
licenses: []
|
90
|
+
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: "0"
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project: role_up
|
111
|
+
rubygems_version: 1.7.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: role_up-0.1.0
|
115
|
+
test_files:
|
116
|
+
- test/ability_spec_test.rb
|
117
|
+
- test/ability_test.rb
|
118
|
+
- test/role_up_spec_test.rb
|
119
|
+
- test/role_up_test.rb
|
120
|
+
- test/support/helper_classes.rb
|
121
|
+
- test/support/helper_methods.rb
|
122
|
+
- test/test_helper.rb
|