mintdigital-has_roles 1.0.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/MIT-LICENSE +20 -0
- data/Manifest +18 -0
- data/README +35 -0
- data/Rakefile +31 -0
- data/generators/has_roles/USAGE +7 -0
- data/generators/has_roles/has_roles_generator.rb +10 -0
- data/generators/has_roles/templates/migration.rb +17 -0
- data/has_roles.gemspec +37 -0
- data/install.rb +1 -0
- data/lib/has_roles.rb +64 -0
- data/lib/role.rb +6 -0
- data/lib/role_assignment.rb +6 -0
- data/rails/init.rb +4 -0
- data/tasks/has_roles_tasks.rake +4 -0
- data/test/assertions.rb +82 -0
- data/test/has_roles_test.rb +144 -0
- data/test/test_helper.rb +24 -0
- data/uninstall.rb +1 -0
- metadata +99 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Krzysztof Zylawy
|
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/Manifest
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
generators/has_roles/has_roles_generator.rb
|
2
|
+
generators/has_roles/templates/migration.rb
|
3
|
+
generators/has_roles/USAGE
|
4
|
+
has_roles.gemspec
|
5
|
+
install.rb
|
6
|
+
lib/has_roles.rb
|
7
|
+
lib/role.rb
|
8
|
+
lib/role_assignment.rb
|
9
|
+
Manifest
|
10
|
+
MIT-LICENSE
|
11
|
+
rails/init.rb
|
12
|
+
Rakefile
|
13
|
+
README
|
14
|
+
tasks/has_roles_tasks.rake
|
15
|
+
test/assertions.rb
|
16
|
+
test/has_roles_test.rb
|
17
|
+
test/test_helper.rb
|
18
|
+
uninstall.rb
|
data/README
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
Install
|
2
|
+
=======
|
3
|
+
|
4
|
+
$ gem source -a http://gems.github.com/
|
5
|
+
$ sudo gem install mintdigital-has_roles
|
6
|
+
|
7
|
+
# environment.rb
|
8
|
+
config.gem 'mintdigital-has_roles', :lib => 'has_roles'
|
9
|
+
|
10
|
+
Example
|
11
|
+
=======
|
12
|
+
|
13
|
+
In an ActiveRecord class:
|
14
|
+
|
15
|
+
has_roles :admin, :moderator
|
16
|
+
|
17
|
+
Then run:
|
18
|
+
|
19
|
+
./script/generate has_roles && rake db:migrate
|
20
|
+
|
21
|
+
Now your model has these instance methods:
|
22
|
+
|
23
|
+
add_role(:moderator) #=> true
|
24
|
+
remove_role(:admin) #=> true (doesn't have role)
|
25
|
+
has_role?(:admin) #=> false
|
26
|
+
can_have_role?(:writer) #=> false
|
27
|
+
|
28
|
+
# These are auto-generated based on your defined roles.
|
29
|
+
# They just call has_role?(name)
|
30
|
+
admin? #=> false
|
31
|
+
moderator? #=> true
|
32
|
+
|
33
|
+
---
|
34
|
+
|
35
|
+
Copyright (c) 2008 Krzysztof Zylawy, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'echoe'
|
5
|
+
require File.join(File.dirname(__FILE__), %w[lib/has_roles])
|
6
|
+
|
7
|
+
Echoe.new('has_roles') do |a|
|
8
|
+
a.version = HasRoles::Version::STRING
|
9
|
+
a.summary = "Simple roles for ActiveRecord"
|
10
|
+
a.author = "Krzysztof Zylawy"
|
11
|
+
a.email = "krzysztof@mintdigital.com"
|
12
|
+
a.runtime_dependencies = ['activerecord']
|
13
|
+
a.development_dependencies = ['echoe']
|
14
|
+
a.has_rdoc = false
|
15
|
+
a.retain_gemspec = true
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Default: Run Tests'
|
19
|
+
Rake::TestTask.new do |t|
|
20
|
+
t.warning = true
|
21
|
+
t.pattern = 'test/**/*_test.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Generate documentation for the has_roles plugin.'
|
25
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = 'HasRoles'
|
28
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
29
|
+
rdoc.rdoc_files.include('README')
|
30
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateRoles < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :roles do |t|
|
4
|
+
t.string :name
|
5
|
+
end
|
6
|
+
|
7
|
+
create_table :role_assignments do |t|
|
8
|
+
t.integer :roleable_id, :role_id
|
9
|
+
t.string :roleable_type
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :role_assignments
|
15
|
+
drop_table :roles
|
16
|
+
end
|
17
|
+
end
|
data/has_roles.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{has_roles}
|
5
|
+
s.version = "1.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Krzysztof Zylawy"]
|
9
|
+
s.date = %q{2009-02-17}
|
10
|
+
s.description = %q{Simple roles for ActiveRecord}
|
11
|
+
s.email = %q{krzysztof@mintdigital.com}
|
12
|
+
s.extra_rdoc_files = ["lib/has_roles.rb", "lib/role.rb", "lib/role_assignment.rb", "README", "tasks/has_roles_tasks.rake"]
|
13
|
+
s.files = ["generators/has_roles/has_roles_generator.rb", "generators/has_roles/templates/migration.rb", "generators/has_roles/USAGE", "has_roles.gemspec", "install.rb", "lib/has_roles.rb", "lib/role.rb", "lib/role_assignment.rb", "Manifest", "MIT-LICENSE", "rails/init.rb", "Rakefile", "README", "tasks/has_roles_tasks.rake", "test/assertions.rb", "test/has_roles_test.rb", "test/test_helper.rb", "uninstall.rb"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Has_roles", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{has_roles}
|
18
|
+
s.rubygems_version = %q{1.3.1}
|
19
|
+
s.summary = %q{Simple roles for ActiveRecord}
|
20
|
+
s.test_files = ["test/has_roles_test.rb", "test/test_helper.rb"]
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 2
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
28
|
+
s.add_development_dependency(%q<echoe>, [">= 0"])
|
29
|
+
else
|
30
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
31
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
32
|
+
end
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
35
|
+
s.add_dependency(%q<echoe>, [">= 0"])
|
36
|
+
end
|
37
|
+
end
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/has_roles.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module HasRoles
|
2
|
+
|
3
|
+
module Version
|
4
|
+
MAJOR = 1
|
5
|
+
MINOR = 0
|
6
|
+
TINY = 0
|
7
|
+
|
8
|
+
STRING = [MAJOR,MINOR,TINY].join('.')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
base.extend HasMethods
|
13
|
+
end
|
14
|
+
|
15
|
+
module HasMethods
|
16
|
+
def has_roles(*roles)
|
17
|
+
roles.flatten!
|
18
|
+
write_inheritable_attribute(:available_roles, roles)
|
19
|
+
class_inheritable_reader :available_roles
|
20
|
+
|
21
|
+
unless included_modules.include? InstanceMethods
|
22
|
+
has_many :role_assignments, :as => :roleable, :dependent => :destroy
|
23
|
+
has_many :roles, :through => :role_assignments
|
24
|
+
|
25
|
+
extend ClassMethods
|
26
|
+
include InstanceMethods
|
27
|
+
available_roles.each do |role|
|
28
|
+
self.class_eval do
|
29
|
+
define_method "#{role}?".to_sym do
|
30
|
+
has_role?(role)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ClassMethods
|
39
|
+
end
|
40
|
+
|
41
|
+
module InstanceMethods
|
42
|
+
def can_have_role?(role_name)
|
43
|
+
available_roles.include?(role_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
def has_role?(rolename)
|
47
|
+
!self.roles.find_by_name(rolename.to_s).nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_role rolename
|
51
|
+
return false unless can_have_role?(rolename)
|
52
|
+
return true if has_role?(rolename)
|
53
|
+
self.roles << Role.find_or_create_by_name(rolename.to_s)
|
54
|
+
self.save
|
55
|
+
end
|
56
|
+
|
57
|
+
def remove_role name
|
58
|
+
return true if !has_role?(name)
|
59
|
+
role_assignment = self.role_assignments.detect { |x| x.role.name == name.to_s }
|
60
|
+
role_assignment.destroy if role_assignment
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
data/lib/role.rb
ADDED
data/rails/init.rb
ADDED
data/test/assertions.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Copyright (c) 2005-2009 David Heinemeier Hansson
|
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.
|
21
|
+
|
22
|
+
module ActiveSupport
|
23
|
+
module Testing
|
24
|
+
module Assertions
|
25
|
+
# Test numeric difference between the return value of an expression as a result of what is evaluated
|
26
|
+
# in the yielded block.
|
27
|
+
#
|
28
|
+
# assert_difference 'Article.count' do
|
29
|
+
# post :create, :article => {...}
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# An arbitrary expression is passed in and evaluated.
|
33
|
+
#
|
34
|
+
# assert_difference 'assigns(:article).comments(:reload).size' do
|
35
|
+
# post :create, :comment => {...}
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# An arbitrary positive or negative difference can be specified. The default is +1.
|
39
|
+
#
|
40
|
+
# assert_difference 'Article.count', -1 do
|
41
|
+
# post :delete, :id => ...
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# An array of expressions can also be passed in and evaluated.
|
45
|
+
#
|
46
|
+
# assert_difference [ 'Article.count', 'Post.count' ], +2 do
|
47
|
+
# post :create, :article => {...}
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# A error message can be specified.
|
51
|
+
#
|
52
|
+
# assert_difference 'Article.count', -1, "An Article should be destroyed" do
|
53
|
+
# post :delete, :id => ...
|
54
|
+
# end
|
55
|
+
def assert_difference(expressions, difference = 1, message = nil, &block)
|
56
|
+
expression_evaluations = Array(expressions).collect{ |expression| lambda { eval(expression, block.send(:binding)) } }
|
57
|
+
|
58
|
+
original_values = expression_evaluations.inject([]) { |memo, expression| memo << expression.call }
|
59
|
+
yield
|
60
|
+
expression_evaluations.each_with_index do |expression, i|
|
61
|
+
assert_equal original_values[i] + difference, expression.call, message
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Assertion that the numeric result of evaluating an expression is not changed before and after
|
66
|
+
# invoking the passed in block.
|
67
|
+
#
|
68
|
+
# assert_no_difference 'Article.count' do
|
69
|
+
# post :create, :article => invalid_attributes
|
70
|
+
# end
|
71
|
+
#
|
72
|
+
# A error message can be specified.
|
73
|
+
#
|
74
|
+
# assert_no_difference 'Article.count', "An Article should not be destroyed" do
|
75
|
+
# post :create, :article => invalid_attributes
|
76
|
+
# end
|
77
|
+
def assert_no_difference(expressions, message = nil, &block)
|
78
|
+
assert_difference expressions, 0, message, &block
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class RoleableSample < ActiveRecord::Base
|
4
|
+
has_roles [:sample_role_1, :sample_role_2]
|
5
|
+
end
|
6
|
+
|
7
|
+
class AnotherRoleable < ActiveRecord::Base
|
8
|
+
has_roles :another1, :another2
|
9
|
+
end
|
10
|
+
|
11
|
+
class HasRolesTest < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@roleable_sample = RoleableSample.create
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
[Role, RoleAssignment, RoleableSample].each {|klass| klass.delete_all }
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_active_record_should_respond_to_has_roles
|
22
|
+
assert ActiveRecord::Base.respond_to?(:has_roles)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_roleable_class_should_return_available_roles
|
26
|
+
assert_equal [:sample_role_1, :sample_role_2], RoleableSample.available_roles
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_roleable_object_can_have_its_class_roles
|
30
|
+
[:sample_role_1, :sample_role_2].each do |role_name|
|
31
|
+
assert_equal(true, @roleable_sample.can_have_role?(role_name))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_should_be_able_to_add_valid_role_to_roleable
|
36
|
+
assert_difference "RoleAssignment.count", 1 do
|
37
|
+
assert_difference "Role.count", 1 do
|
38
|
+
@roleable_sample.add_role(:sample_role_1)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_return_true_when_role_added
|
44
|
+
assert @roleable_sample.add_role(:sample_role_1)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_should_not_be_able_to_add_invalid_role_to_roleable
|
48
|
+
assert_no_difference "RoleAssignment.count", 1 do
|
49
|
+
assert_no_difference "Role.count", 1 do
|
50
|
+
@roleable_sample.add_role(:invalid_role)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
assert_equal(false, @roleable_sample.has_role?(:invalid_role))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_should_return_false_when_invalid_role_not_added
|
57
|
+
assert !@roleable_sample.add_role(:invalid_role)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_should_not_add_role_nor_assignment_if_already_has_role
|
61
|
+
@roleable_sample.add_role(:sample_role_1)
|
62
|
+
assert_no_difference "RoleAssignment.count" do
|
63
|
+
assert_no_difference "Role.count" do
|
64
|
+
@roleable_sample.add_role(:sample_role_1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
assert_equal(true, @roleable_sample.has_role?(:sample_role_1))
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_should_return_true_if_already_has_role
|
71
|
+
@roleable_sample.add_role(:sample_role_1)
|
72
|
+
assert @roleable_sample.has_role?(:sample_role_1), 'Precondition: has role'
|
73
|
+
assert @roleable_sample.add_role(:sample_role_1)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_should_add_assignment_but_not_role_nor_assignment_if_role_exists
|
77
|
+
Role.create(:name => 'sample_role_1')
|
78
|
+
assert_difference "RoleAssignment.count", 1 do
|
79
|
+
assert_no_difference "Role.count" do
|
80
|
+
@roleable_sample.add_role(:sample_role_1)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
assert_equal(true, @roleable_sample.has_role?(:sample_role_1))
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_should_have_added_role
|
87
|
+
@roleable_sample.add_role(:sample_role_1)
|
88
|
+
assert_equal(true, @roleable_sample.has_role?(:sample_role_1))
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_should_not_have_not_added_role
|
92
|
+
@roleable_sample.add_role(:sample_role_1)
|
93
|
+
assert_equal(false, @roleable_sample.has_role?(:sample_role_2))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_should_remove_role_assignment
|
97
|
+
@roleable_sample.add_role(:sample_role_1)
|
98
|
+
assert_difference "RoleAssignment.count", -1 do
|
99
|
+
assert_no_difference "Role.count" do
|
100
|
+
@roleable_sample.remove_role(:sample_role_1)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
assert_equal(false, @roleable_sample.has_role?(:sample_role_1))
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_should_return_true_when_role_removed
|
107
|
+
@roleable_sample.add_role(:sample_role_1)
|
108
|
+
assert @roleable_sample.has_role?(:sample_role_1), 'Precondition: has role'
|
109
|
+
assert @roleable_sample.remove_role(:sample_role_1)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_should_not_remove_role_assignment_when_removing_other_role
|
113
|
+
@roleable_sample.add_role(:sample_role_1)
|
114
|
+
assert_no_difference "RoleAssignment.count" do
|
115
|
+
assert_no_difference "Role.count" do
|
116
|
+
@roleable_sample.remove_role(:sample_role_2)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
assert_equal(true, @roleable_sample.has_role?(:sample_role_1))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_should_return_true_when_trying_to_remove_un_had_role
|
123
|
+
assert !@roleable_sample.has_role?(:sample_role_1), 'Precondition: does not have role'
|
124
|
+
assert @roleable_sample.remove_role(:sample_role_1)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_should_return_true_when_asking_if_is_existing_role
|
128
|
+
@roleable_sample.add_role(:sample_role_1)
|
129
|
+
assert_equal(true, @roleable_sample.sample_role_1?)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_should_return_false_when_asking_if_is_unexisting_role
|
133
|
+
@roleable_sample.add_role(:sample_role_1)
|
134
|
+
assert_equal(false, @roleable_sample.sample_role_2?)
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_should_raise_exception_when_asking_if_is_invalid_role
|
138
|
+
@roleable_sample.add_role(:sample_role_1)
|
139
|
+
assert_raise(NoMethodError) {
|
140
|
+
@roleable_sample.invalid_role?
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), 'assertions')
|
3
|
+
require File.join(File.dirname(__FILE__), %w[.. init.rb])
|
4
|
+
|
5
|
+
Test::Unit::TestCase.send :include, ActiveSupport::Testing::Assertions
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(
|
8
|
+
:adapter => 'sqlite3', :dbfile => ':memory:'
|
9
|
+
)
|
10
|
+
|
11
|
+
ActiveRecord::Schema.define(:version => 1) do
|
12
|
+
create_table :roleable_samples do |t|
|
13
|
+
end
|
14
|
+
|
15
|
+
create_table :roles do |t|
|
16
|
+
t.string :name
|
17
|
+
end
|
18
|
+
|
19
|
+
create_table :role_assignments do |t|
|
20
|
+
t.integer :roleable_id
|
21
|
+
t.string :roleable_type
|
22
|
+
t.integer :role_id
|
23
|
+
end
|
24
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mintdigital-has_roles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Krzysztof Zylawy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-02-17 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: echoe
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: Simple roles for ActiveRecord
|
36
|
+
email: krzysztof@mintdigital.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- lib/has_roles.rb
|
43
|
+
- lib/role.rb
|
44
|
+
- lib/role_assignment.rb
|
45
|
+
- README
|
46
|
+
- tasks/has_roles_tasks.rake
|
47
|
+
files:
|
48
|
+
- generators/has_roles/has_roles_generator.rb
|
49
|
+
- generators/has_roles/templates/migration.rb
|
50
|
+
- generators/has_roles/USAGE
|
51
|
+
- has_roles.gemspec
|
52
|
+
- install.rb
|
53
|
+
- lib/has_roles.rb
|
54
|
+
- lib/role.rb
|
55
|
+
- lib/role_assignment.rb
|
56
|
+
- Manifest
|
57
|
+
- MIT-LICENSE
|
58
|
+
- rails/init.rb
|
59
|
+
- Rakefile
|
60
|
+
- README
|
61
|
+
- tasks/has_roles_tasks.rake
|
62
|
+
- test/assertions.rb
|
63
|
+
- test/has_roles_test.rb
|
64
|
+
- test/test_helper.rb
|
65
|
+
- uninstall.rb
|
66
|
+
has_rdoc: false
|
67
|
+
homepage: ""
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --line-numbers
|
71
|
+
- --inline-source
|
72
|
+
- --title
|
73
|
+
- Has_roles
|
74
|
+
- --main
|
75
|
+
- README
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "1.2"
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project: has_roles
|
93
|
+
rubygems_version: 1.2.0
|
94
|
+
signing_key:
|
95
|
+
specification_version: 2
|
96
|
+
summary: Simple roles for ActiveRecord
|
97
|
+
test_files:
|
98
|
+
- test/has_roles_test.rb
|
99
|
+
- test/test_helper.rb
|