moulin_rouge 0.0.1.beta1 → 0.0.1.beta2
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/CHANGELOG.md +5 -0
- data/MIT-LICENSE +1 -1
- data/README.md +72 -51
- data/lib/generators/moulin_rouge/auth_generator.rb +18 -0
- data/lib/generators/moulin_rouge/install_generator.rb +3 -3
- data/lib/generators/moulin_rouge/templates/authorization.rb +21 -0
- data/lib/generators/moulin_rouge/templates/initializer.rb +14 -0
- data/lib/moulin_rouge.rb +2 -2
- data/lib/moulin_rouge/{permission.rb → ability.rb} +35 -62
- data/lib/moulin_rouge/authorization.rb +46 -0
- data/lib/moulin_rouge/cancan/ability.rb +6 -6
- data/lib/moulin_rouge/version.rb +1 -1
- data/spec/fixtures/fixture_authorization.rb +5 -0
- data/spec/moulin_rouge/ability_spec.rb +229 -0
- data/spec/moulin_rouge/authorization_spec.rb +120 -0
- data/spec/moulin_rouge/cancan/ability_spec.rb +5 -5
- data/spec/moulin_rouge_spec.rb +9 -19
- data/spec/spec_helper.rb +9 -9
- metadata +51 -38
- data/lib/generators/moulin_rouge/permission_generator.rb +0 -18
- data/lib/generators/moulin_rouge/templates/install/config/initializers/moulin_rouge.rb +0 -15
- data/lib/generators/moulin_rouge/templates/permission.rb +0 -19
- data/spec/fixtures/role.rb +0 -3
- data/spec/moulin_rouge/permission_spec.rb +0 -316
data/spec/moulin_rouge_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe MoulinRouge do
|
4
|
-
it "
|
4
|
+
it "is a module" do
|
5
5
|
MoulinRouge.should be_a(Module)
|
6
6
|
end
|
7
7
|
|
@@ -22,7 +22,7 @@ describe MoulinRouge do
|
|
22
22
|
|
23
23
|
describe "#run!" do
|
24
24
|
it "calls the load! method" do
|
25
|
-
MoulinRouge.should_receive(:load!).
|
25
|
+
MoulinRouge.should_receive(:load!).twice # Here and inside spec_helpe.rb before(:each)
|
26
26
|
MoulinRouge.run!
|
27
27
|
end
|
28
28
|
|
@@ -43,33 +43,23 @@ describe MoulinRouge do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#load!" do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
MoulinRouge.load!
|
50
|
-
MoulinRouge::Permission.main.should_not be_nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "(without stubs)" do
|
55
|
-
it "evaluate all permissions in the path" do
|
56
|
-
MoulinRouge.load!
|
57
|
-
MoulinRouge::Permission.main.childrens.should_not be_empty
|
58
|
-
end
|
46
|
+
it "compile authorizations" do
|
47
|
+
MoulinRouge::Authorization.should_receive(:compile!).twice # Here and inside spec_helpe.rb before(:each)
|
48
|
+
MoulinRouge.load!
|
59
49
|
end
|
60
50
|
end
|
61
51
|
|
62
52
|
describe "reset!" do
|
63
|
-
it "calls the reset! method on
|
64
|
-
MoulinRouge::
|
53
|
+
it "calls the reset! method on Authorization" do
|
54
|
+
MoulinRouge::Authorization.should_receive(:reset!).twice # One in before(:each) inside spec_helper.rb and another here
|
65
55
|
MoulinRouge.reset!
|
66
56
|
end
|
67
57
|
end
|
68
58
|
|
69
59
|
describe "#reload!" do
|
70
60
|
it "Reset all permissions and load them again" do
|
71
|
-
MoulinRouge.should_receive(:reset!).twice #
|
72
|
-
MoulinRouge.should_receive(:load!).
|
61
|
+
MoulinRouge.should_receive(:reset!).twice # Here and inside spec_helpe.rb before(:each)
|
62
|
+
MoulinRouge.should_receive(:load!).twice # Here and inside spec_helpe.rb before(:each)
|
73
63
|
MoulinRouge.reload!
|
74
64
|
end
|
75
65
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,23 +4,23 @@ SimpleCov.start
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'bundler/setup'
|
6
6
|
require 'rspec'
|
7
|
+
require 'moulin_rouge'
|
7
8
|
|
8
9
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
10
|
# in spec/support/ and its subdirectories.
|
10
11
|
Dir[File.expand_path("spec/support/**/*.rb")].each {|f| require f}
|
11
12
|
|
12
|
-
# Require all files from the project, except the generators
|
13
|
-
Dir[File.expand_path("lib/**/*.rb")].each do |f|
|
14
|
-
require f unless f =~ /lib\/generators/
|
15
|
-
end
|
16
|
-
|
17
13
|
def permission_file
|
18
|
-
File.expand_path("spec/fixtures/
|
14
|
+
File.expand_path("spec/fixtures/spec_authorization.rb")
|
19
15
|
end
|
20
16
|
|
21
|
-
def
|
17
|
+
def create_authorization(content)
|
22
18
|
f = File.open(permission_file, 'w')
|
23
|
-
f.write
|
19
|
+
f.write %|
|
20
|
+
class SpecAuthorization < MoulinRouge::Authorization
|
21
|
+
#{content}
|
22
|
+
end
|
23
|
+
|
|
24
24
|
ensure
|
25
25
|
f.close
|
26
26
|
end
|
@@ -35,7 +35,7 @@ RSpec.configure do |config|
|
|
35
35
|
# Reset the MoulinRouge global variables
|
36
36
|
# Remove the permission file created by the helper
|
37
37
|
config.after(:each) do
|
38
|
-
MoulinRouge.
|
38
|
+
MoulinRouge.reload!
|
39
39
|
MoulinRouge.configuration.cache = true
|
40
40
|
FileUtils.rm_rf(permission_file) if File.exists?(permission_file)
|
41
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moulin_rouge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cancan
|
16
|
-
requirement: &
|
16
|
+
requirement: &70337309588420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70337309588420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
requirement: &70337309587920 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70337309587920
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rdoc
|
27
|
-
requirement: &
|
38
|
+
requirement: &70337309587500 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :development
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *70337309587500
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: rspec
|
38
|
-
requirement: &
|
49
|
+
requirement: &70337309587040 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,10 +54,10 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :development
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *70337309587040
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: guard-rspec
|
49
|
-
requirement: &
|
60
|
+
requirement: &70337309586620 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70337309586620
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: simplecov
|
60
|
-
requirement: &
|
71
|
+
requirement: &70337309586200 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,9 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
-
description:
|
70
|
-
|
71
|
-
and DRY.
|
79
|
+
version_requirements: *70337309586200
|
80
|
+
description: An DSL to manage your authorizations and groups of access with CanCan
|
81
|
+
without repeating yourself using as many files you want.
|
72
82
|
email:
|
73
83
|
- edson.hilios@gmail.com
|
74
84
|
executables: []
|
@@ -78,29 +88,31 @@ files:
|
|
78
88
|
- CHANGELOG.md
|
79
89
|
- MIT-LICENSE
|
80
90
|
- README.md
|
81
|
-
- lib/
|
82
|
-
- lib/generators/moulin_rouge/templates/install/config/initializers/moulin_rouge.rb
|
83
|
-
- lib/generators/moulin_rouge/templates/permission.rb
|
84
|
-
- lib/generators/moulin_rouge/permission_generator.rb
|
91
|
+
- lib/generators/moulin_rouge/auth_generator.rb
|
85
92
|
- lib/generators/moulin_rouge/install_generator.rb
|
86
|
-
- lib/moulin_rouge.rb
|
87
|
-
- lib/moulin_rouge/
|
88
|
-
- lib/moulin_rouge/
|
89
|
-
- lib/moulin_rouge/
|
90
|
-
- lib/moulin_rouge/cancan/responder.rb
|
93
|
+
- lib/generators/moulin_rouge/templates/authorization.rb
|
94
|
+
- lib/generators/moulin_rouge/templates/initializer.rb
|
95
|
+
- lib/moulin_rouge/ability.rb
|
96
|
+
- lib/moulin_rouge/authorization.rb
|
91
97
|
- lib/moulin_rouge/cancan/ability.rb
|
92
98
|
- lib/moulin_rouge/cancan/method.rb
|
99
|
+
- lib/moulin_rouge/cancan/responder.rb
|
93
100
|
- lib/moulin_rouge/configuration.rb
|
101
|
+
- lib/moulin_rouge/model_double.rb
|
102
|
+
- lib/moulin_rouge/version.rb
|
103
|
+
- lib/moulin_rouge.rb
|
104
|
+
- lib/tasks/moulin_rouge_tasks.rake
|
94
105
|
- init.rb
|
95
|
-
- spec/fixtures/
|
96
|
-
- spec/
|
97
|
-
- spec/
|
98
|
-
- spec/moulin_rouge/
|
99
|
-
- spec/moulin_rouge/configuration_spec.rb
|
106
|
+
- spec/fixtures/fixture_authorization.rb
|
107
|
+
- spec/moulin_rouge/ability_spec.rb
|
108
|
+
- spec/moulin_rouge/authorization_spec.rb
|
109
|
+
- spec/moulin_rouge/cancan/ability_spec.rb
|
100
110
|
- spec/moulin_rouge/cancan/method_spec.rb
|
101
111
|
- spec/moulin_rouge/cancan/responder_spec.rb
|
102
|
-
- spec/moulin_rouge/
|
112
|
+
- spec/moulin_rouge/configuration_spec.rb
|
103
113
|
- spec/moulin_rouge/model_double_spec.rb
|
114
|
+
- spec/moulin_rouge_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
104
116
|
homepage: https://github.com/hilios/moulin_rouge
|
105
117
|
licenses: []
|
106
118
|
post_install_message:
|
@@ -121,17 +133,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
133
|
version: 1.3.1
|
122
134
|
requirements: []
|
123
135
|
rubyforge_project:
|
124
|
-
rubygems_version: 1.8.
|
136
|
+
rubygems_version: 1.8.15
|
125
137
|
signing_key:
|
126
138
|
specification_version: 3
|
127
|
-
summary:
|
139
|
+
summary: An DSL to manage your authorizations DRY in CanCan
|
128
140
|
test_files:
|
129
|
-
- spec/fixtures/
|
130
|
-
- spec/
|
131
|
-
- spec/
|
132
|
-
- spec/moulin_rouge/
|
133
|
-
- spec/moulin_rouge/configuration_spec.rb
|
141
|
+
- spec/fixtures/fixture_authorization.rb
|
142
|
+
- spec/moulin_rouge/ability_spec.rb
|
143
|
+
- spec/moulin_rouge/authorization_spec.rb
|
144
|
+
- spec/moulin_rouge/cancan/ability_spec.rb
|
134
145
|
- spec/moulin_rouge/cancan/method_spec.rb
|
135
146
|
- spec/moulin_rouge/cancan/responder_spec.rb
|
136
|
-
- spec/moulin_rouge/
|
147
|
+
- spec/moulin_rouge/configuration_spec.rb
|
137
148
|
- spec/moulin_rouge/model_double_spec.rb
|
149
|
+
- spec/moulin_rouge_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'rails/generators'
|
2
|
-
|
3
|
-
module MoulinRouge
|
4
|
-
module Generators
|
5
|
-
class PermissionGenerator < ::Rails::Generators::Base
|
6
|
-
|
7
|
-
source_root File.expand_path('../templates', __FILE__)
|
8
|
-
|
9
|
-
desc "Creates a new permission file inside the permission folder"
|
10
|
-
|
11
|
-
argument :name
|
12
|
-
|
13
|
-
def creates_a_permission_file
|
14
|
-
copy_file("permission.rb", "app/permissions/#{name}.rb")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
MoulinRouge.configure do |config|
|
2
|
-
# Cache permissions
|
3
|
-
config.cache = Rails.env.production?
|
4
|
-
# The search path for permissions
|
5
|
-
config.path = 'app/permissions/**/*.rb'
|
6
|
-
# The method that will test the permission
|
7
|
-
config.test_method = :is?
|
8
|
-
# The class of the model
|
9
|
-
config.model = User
|
10
|
-
# How you like to call the active user model
|
11
|
-
config.model_instance = :current_user
|
12
|
-
end
|
13
|
-
|
14
|
-
# Creates the Ability class
|
15
|
-
MoulinRouge.run!
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# can :read, Post
|
2
|
-
# can :read, Comment
|
3
|
-
# can :manage, Comment do |comment|
|
4
|
-
# comment.user_id == current_user.id
|
5
|
-
# end
|
6
|
-
#
|
7
|
-
# role :admin do
|
8
|
-
# can :manage, :all
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# group :main do
|
12
|
-
# role :editor do
|
13
|
-
# can :manage, Post
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# role :author do
|
17
|
-
# can :manage, Post, :user_id => current_user.id
|
18
|
-
# end
|
19
|
-
# end
|
data/spec/fixtures/role.rb
DELETED
@@ -1,316 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MoulinRouge::Permission do
|
4
|
-
let(:permission) { MoulinRouge::Permission.new(:name) }
|
5
|
-
|
6
|
-
describe "#initialize" do
|
7
|
-
it "evaluate the groups and authorizations to the class scope" do
|
8
|
-
permission = MoulinRouge::Permission.new(:scope) do
|
9
|
-
self.class.should == MoulinRouge::Permission
|
10
|
-
can :do, :something
|
11
|
-
role :for
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
it "append the new instance to #all and #list if it's a role" do
|
16
|
-
MoulinRouge::Permission.new(:main) do
|
17
|
-
role(:one)
|
18
|
-
end
|
19
|
-
MoulinRouge::Permission.all.should include(:one)
|
20
|
-
MoulinRouge::Permission.list.should include(:one)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "inherits all abilities from parent if this is a group" do
|
24
|
-
role = nil
|
25
|
-
MoulinRouge::Permission.new(:main) do
|
26
|
-
group(:group) do
|
27
|
-
can :do, :this
|
28
|
-
role = role(:role)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
role.abilities.first.args.should include(:do, :this)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe "#name" do
|
36
|
-
it "returns the given name on class initialization" do
|
37
|
-
permission.name.should be(:name)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#parent" do
|
42
|
-
it "returns nil when for main" do
|
43
|
-
permission.parent.should be_nil
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns a instance of the MoulinRouge::Permission" do
|
47
|
-
another = MoulinRouge::Permission.new(:another, :parent => permission)
|
48
|
-
another.parent.should be_a(MoulinRouge::Permission)
|
49
|
-
another.parent.should be(permission)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#childrens" do
|
54
|
-
it "returns an array" do
|
55
|
-
permission.childrens.should be_an(Array)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#abilities" do
|
60
|
-
it "returns an array" do
|
61
|
-
permission.abilities.should be_a(Array)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "#inherithed_abilities" do
|
66
|
-
it "returns all abilities from self and their childrens" do
|
67
|
-
permission.can :do, :this
|
68
|
-
# First nested level
|
69
|
-
one = permission.role(:one) do
|
70
|
-
can :do, :one
|
71
|
-
end
|
72
|
-
# Second nested level
|
73
|
-
two = one.role(:two) do
|
74
|
-
can :do, :two
|
75
|
-
end
|
76
|
-
permission.inherithed_abilities.should be_an(Array)
|
77
|
-
permission.inherithed_abilities.length.should be(3)
|
78
|
-
one.inherithed_abilities.length.should be(2)
|
79
|
-
two.inherithed_abilities.length.should be(1)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "#role" do
|
84
|
-
it "returns a new permission with the parent setted to the class that are calling" do
|
85
|
-
role = permission.role(:test)
|
86
|
-
role.should be_a(MoulinRouge::Permission)
|
87
|
-
role.parent.should be(permission)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "adds a new instance on children" do
|
91
|
-
permission.childrens.should be_empty
|
92
|
-
permission.role(:name)
|
93
|
-
permission.childrens.should_not be_empty
|
94
|
-
end
|
95
|
-
|
96
|
-
it "appends the content if the name is already present" do
|
97
|
-
permission.role(:test) { can :do, :this }
|
98
|
-
# should create one children ...
|
99
|
-
permission.childrens.length.should be(1)
|
100
|
-
# ... and one ability
|
101
|
-
permission.childrens.first.abilities.length.should be(1)
|
102
|
-
|
103
|
-
permission.role(:test) { can :do, :this }
|
104
|
-
# should not create other children ...
|
105
|
-
permission.childrens.length.should be(1)
|
106
|
-
# ... and append the new ability
|
107
|
-
permission.childrens.first.abilities.length.should be(2)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "#group" do
|
112
|
-
it "not add the group name to permission list" do
|
113
|
-
permission.group(:test)
|
114
|
-
MoulinRouge::Permission.list.should_not include(:test)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "#group?" do
|
119
|
-
it "returns true if is a group and false otherwise" do
|
120
|
-
role = permission.role(:role)
|
121
|
-
group = permission.group(:group)
|
122
|
-
role.group?.should be_false
|
123
|
-
group.group?.should be_true
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe "#method_missing" do
|
128
|
-
let(:args) { [:one, :two] }
|
129
|
-
let(:proc) { Proc.new { :block } }
|
130
|
-
|
131
|
-
context "collect all cancan methods and store under abilities" do
|
132
|
-
MoulinRouge::Permission::CANCAN_METHODS.each do |method_name|
|
133
|
-
describe "##{method_name}" do
|
134
|
-
it "adds a new ability to this permission" do
|
135
|
-
permission.abilities.should be_empty
|
136
|
-
permission.send(method_name, *args, &proc)
|
137
|
-
permission.abilities.should_not be_empty
|
138
|
-
end
|
139
|
-
|
140
|
-
it "stores nil on block attribute when no block is given" do
|
141
|
-
permission.send(method_name, *args)
|
142
|
-
permission.abilities.first.block.should be_nil
|
143
|
-
end
|
144
|
-
|
145
|
-
it "stores the method" do
|
146
|
-
permission.abilities.should be_empty
|
147
|
-
permission.send(method_name, *args, &proc)
|
148
|
-
permission.abilities.should_not be_empty
|
149
|
-
|
150
|
-
method = permission.abilities.first
|
151
|
-
method.should be_a(MoulinRouge::CanCan::Method)
|
152
|
-
# Evaluate the class of the arguments and block
|
153
|
-
method.args.should be_a(Array)
|
154
|
-
method.block.should be_a(Proc)
|
155
|
-
# Just check the value
|
156
|
-
method.args.should eq(args)
|
157
|
-
method.block.call.should be(:block)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
it "receives and stores in a proc calls on the model object" do
|
164
|
-
ability = nil
|
165
|
-
permission.role(:test) do
|
166
|
-
ability = can :do, :this, :user_id => current_user.id
|
167
|
-
end
|
168
|
-
ability.args.last[:user_id].should be_a(Proc)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "raise an error if the method is not registered has a cancan method" do
|
172
|
-
lambda { permission.send(:abcdefg, *args, &proc) }.should raise_error(NoMethodError)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
describe "#import" do
|
177
|
-
let(:files_opened) { [] }
|
178
|
-
|
179
|
-
it "glob all files in the given path and evaluate their content in the class scope" do
|
180
|
-
File.stub(:open) { |file| files_opened << file; double("file", :read => "") }
|
181
|
-
permission.import(MoulinRouge.configuration.path)
|
182
|
-
files_opened.should include(*Dir[MoulinRouge.configuration.path])
|
183
|
-
end
|
184
|
-
|
185
|
-
it "let raise exceptions when there are syntax errors" do
|
186
|
-
tests = []
|
187
|
-
tests << %|
|
188
|
-
# Wrong method name
|
189
|
-
roe :name do
|
190
|
-
end
|
191
|
-
|
|
192
|
-
tests << %|
|
193
|
-
# Wrong method name
|
194
|
-
groups :name do
|
195
|
-
end
|
196
|
-
|
|
197
|
-
tests << %|
|
198
|
-
# Wrong method name
|
199
|
-
cn :
|
200
|
-
|
|
201
|
-
tests << %|
|
202
|
-
# Wrong method name
|
203
|
-
role do
|
204
|
-
end
|
205
|
-
|
|
206
|
-
# Execute them all
|
207
|
-
tests.each do |test|
|
208
|
-
create_permission test
|
209
|
-
lambda { permission.import(MoulinRouge.configuration.path) }.should raise_error
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
describe "#find" do
|
215
|
-
it "returns the instance of the permission if there is children with this name and nil otherwise" do
|
216
|
-
role = permission.role(:test)
|
217
|
-
permission.find(:test).should be(role)
|
218
|
-
permission.find(:bad).should be_nil
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
describe "#name" do
|
223
|
-
it "returns an symbol containing the name with the parents separeted by a underscore" do
|
224
|
-
first_children, second_children = nil
|
225
|
-
MoulinRouge::Permission.new(:main) do
|
226
|
-
first_children = role(:one) do
|
227
|
-
second_children = role(:two)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
first_children.name.should be(:one)
|
231
|
-
second_children.name.should be(:one_two)
|
232
|
-
end
|
233
|
-
end
|
234
|
-
|
235
|
-
describe "#include" do
|
236
|
-
it "appends all childrens and abilities from one object to another" do
|
237
|
-
one, another = nil
|
238
|
-
one = permission.role(:one) do
|
239
|
-
role(:nested)
|
240
|
-
can :do, :something
|
241
|
-
end
|
242
|
-
another = permission.role(:another) do
|
243
|
-
include :one
|
244
|
-
end
|
245
|
-
another.childrens.should_not be_empty
|
246
|
-
another.abilities.should_not be_empty
|
247
|
-
another.childrens.first.singular_name.should be(:nested)
|
248
|
-
another.abilities.first.args.should include(:do, :something)
|
249
|
-
end
|
250
|
-
|
251
|
-
it "raises an error if could not find the requested permission" do
|
252
|
-
lambda {
|
253
|
-
permission.role(:name) do
|
254
|
-
include :not_found
|
255
|
-
end
|
256
|
-
}.should raise_error(MoulinRouge::RoleNotFound)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
context "self" do
|
261
|
-
describe "#main" do
|
262
|
-
it "returns the main MoulinRouge::Permission instance" do
|
263
|
-
MoulinRouge::Permission.main.should be_instance_of(permission.class)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
describe "#list" do
|
268
|
-
it "returns an array" do
|
269
|
-
MoulinRouge::Permission.list.should be_a(Array)
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
describe "#all" do
|
274
|
-
it "returns an hash with all created permissions" do
|
275
|
-
MoulinRouge::Permission.all.should be_a(Hash)
|
276
|
-
end
|
277
|
-
|
278
|
-
it "store all permissions instantiated unless the main one" do
|
279
|
-
hello_world = permission.role(:hello_world) do
|
280
|
-
can :do
|
281
|
-
end
|
282
|
-
MoulinRouge::Permission.all[hello_world.name].should be(hello_world)
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
describe "#add" do
|
287
|
-
it "should append the object instance on Permission.all and Permission.names" do
|
288
|
-
object = double(:name => :foo)
|
289
|
-
MoulinRouge::Permission.stub(:all) { @all ||= double() }
|
290
|
-
MoulinRouge::Permission.stub(:list) { @list ||= double(:include? => false) }
|
291
|
-
MoulinRouge::Permission.list.should_receive(:'<<').with(object.name)
|
292
|
-
MoulinRouge::Permission.all.should_receive(:'[]=').with(object.name, object)
|
293
|
-
MoulinRouge::Permission.add(object)
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
describe "#reset!" do
|
298
|
-
it "sets to nil the main, list and all constants" do
|
299
|
-
# Create some
|
300
|
-
permission.role(:one)
|
301
|
-
permission.role(:two)
|
302
|
-
MoulinRouge::Permission.all.should_not be_empty
|
303
|
-
MoulinRouge::Permission.list.should_not be_empty
|
304
|
-
# Apply
|
305
|
-
MoulinRouge::Permission.reset!
|
306
|
-
# Evaluate constants
|
307
|
-
MoulinRouge::Permission.instance_variable_get(:'@main').should be_nil
|
308
|
-
MoulinRouge::Permission.instance_variable_get(:'@all').should be_nil
|
309
|
-
MoulinRouge::Permission.instance_variable_get(:'@list').should be_nil
|
310
|
-
# Evaluate has arrays
|
311
|
-
MoulinRouge::Permission.all.should be_empty
|
312
|
-
MoulinRouge::Permission.list.should be_empty
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
end
|