cancan-permits 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -78,6 +78,10 @@ You can be enable this simply by setting the following class instance variable:
78
78
 
79
79
  <code>Permits::Configuration.localhost_manager = true</code>
80
80
 
81
+ ## Default roles
82
+
83
+ By default the permits for the roles System and Guest are also generated.
84
+
81
85
  ### Licenses
82
86
 
83
87
  Permits also supports creation more fine-grained permits through the use of Licenses.
@@ -147,6 +151,15 @@ with the roles found to be available in the app.
147
151
 
148
152
  <code>$ rails g permits --orm active_record --roles guest author admin</code>
149
153
 
154
+ ### What does the generator generate?
155
+
156
+ To get an understanding of what the generator generates for a Rails 3 application, try to run the spec permit_generator_spec.rb with rspec 2 as follows:
157
+
158
+ <code>$ rspec spec/generators/permit_generator_spec.rb</code>
159
+
160
+ In the file <code>permit_generator_spec.rb</code> make the following change <code>config.remove_temp_dir = false</code>
161
+ This will prevent the rails /tmp dir from being deleted after the test run, so you can inspect what is generated in the Rails app.
162
+
150
163
  ## Note on Patches/Pull Requests
151
164
 
152
165
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cancan-permits}
8
- s.version = "0.2.7"
8
+ s.version = "0.2.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = %q{2010-10-23}
12
+ s.date = %q{2010-11-24}
13
13
  s.description = %q{Role specific Permits for use with CanCan permission system}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -5,4 +5,6 @@ require_all File.dirname(__FILE__) + '/matchers'
5
5
 
6
6
  RSpec.configure do |config|
7
7
  config.include RSpec::RubyContentMatchers::License
8
+ config.include RSpec::RubyContentMatchers::LicenseClass
9
+ config.include RSpec::RubyContentMatchers::LicenseFile
8
10
  end
@@ -1,11 +1,14 @@
1
1
  module RSpec::RubyContentMatchers
2
- module License
3
- def have_license_class name, superclass = nil
2
+ module LicenseClass
3
+ def have_license_class name, superclass = 'License::Base'
4
4
  superclass ? have_subclass(name, :superclass => superclass) : have_class(name)
5
5
  end
6
6
 
7
7
  def have_license_classes *names
8
- have_classes names
8
+ names.each do |name|
9
+ return false if !have_license_class(name)
10
+ end
11
+ true
9
12
  end
10
13
  end
11
14
  end
@@ -1,17 +1,20 @@
1
1
  require 'rails-app-spec'
2
2
 
3
- module RSpec::RailsApp::File
4
- module Matchers
3
+ module RSpec::RubyContentMatchers
4
+ module LicenseFile
5
5
  class HaveLicenseFile
6
- include ::Rails3::Assist::Artifact
7
- include ::Rails3::Assist::File
8
-
6
+ include ::Rails3::Assist::Artifact::Directory
7
+
9
8
  attr_reader :name
10
-
9
+
11
10
  def initialize name
12
11
  @name = name
13
12
  end
14
13
 
14
+ def license_file name
15
+ File.join(permit_dir, "#{name}.rb")
16
+ end
17
+
15
18
  def matches? obj, &block
16
19
  found = File.file? license_file(name)
17
20
  yield if block && found
@@ -23,4 +26,4 @@ module RSpec::RailsApp::File
23
26
  HaveLicenseFile.new name
24
27
  end
25
28
  end
26
- end
29
+ end
@@ -12,14 +12,21 @@ class PermitsGenerator < Rails::Generators::Base
12
12
 
13
13
  source_root File.dirname(__FILE__) + '/templates'
14
14
 
15
+ def default_roles
16
+ [:guest, :admin]
17
+ end
18
+
15
19
  def main_flow
20
+ default_roles.each do |role|
21
+ template_permit role
22
+ end
16
23
  template_permit :admin, :admin_permit
17
24
  template_permit :any, :any_permit
18
25
  template_permit :system, :barebones_permit
19
26
 
20
27
  permit_logic = base_logic
21
28
  roles.each do |role|
22
- template_permit role if !role == :admin
29
+ template_permit role if !default_roles.include?(role)
23
30
  end
24
31
  template "licenses.rb", "app/permits/licenses.rb"
25
32
  permits_initializer
@@ -87,4 +94,11 @@ class PermitsGenerator < Rails::Generators::Base
87
94
  can :manage, :all
88
95
  }
89
96
  end
97
+
98
+ def guest_logic
99
+ %{
100
+ return if !role_match? user
101
+ can :read, :all
102
+ }
103
+ end
90
104
  end
@@ -33,35 +33,34 @@ describe 'Permits generator' do
33
33
  end
34
34
 
35
35
  it "should generate a permits initializer file with orm set to mongoid" do
36
- File.read(initializer_file(:permits)).should match /Permits::Application.orm = mongoid/
36
+ File.read(initializer_file(:permits)).should match /Permits::Ability.orm = :mongoid/
37
37
  end
38
38
  end
39
39
  end
40
40
 
41
- # TODO
41
+ describe 'result of running generator with option to create permit for each registered role' do
42
+ context "Registered roles :editor, :admin" do
43
+ before :each do
44
+ @generator = with_generator do |g|
45
+ g.run_generator "--roles admin editor".args
46
+ end
47
+ end
48
+
49
+ it "should have created Guest and Admin permits" do
50
+ @generator.should have_permit_files :guest, :admin
51
+ end
52
+
53
+ it "should have created the Editor permit for the :editor role" do
54
+ @generator.should have_permit_file :editor do |editor_permit|
55
+ # guest_permit.should have_licenses :user_admin, :blogging
56
+ end
57
+ end
42
58
 
43
- # describe 'result of running generator with option to create permit for each registered role' do
44
- # context "Registered roles :guest, :admin"
45
- # before :each do
46
- # with_generator do |g|
47
- # g.run_generator "--roles admin editor"
48
- # end
49
- # end
50
- #
51
- # it "should have created Guest and Admin permits" do
52
- # # Find at: 'app/permits/admin_permit.rb'
53
- # g.should have_permit_files :guest, :admin
54
- #
55
- # # g.should have_permit_file :guest do |guest_permit|
56
- # # guest_permit.should have_licenses :user_admin, :blogging
57
- # # end
58
- # #
59
- # # g.should have_license_file :licenses do |license_file|
60
- # # license_file.should have_module :license do |license_module|
61
- # # license_module.should have_license_classes :user_admin, :blogging, :superclass => :base
62
- # # end
63
- # # end
64
- # end
65
- # end #ctx
66
- # end
59
+ it "should have created the License file with the :user_admin and :blogging licenses used by the :editor permit" do
60
+ @generator.should have_license_file :licenses do |license_file|
61
+ # license_file.should have_license_classes :user_admin, :blogging
62
+ end
63
+ end
64
+ end #ctx
65
+ end
67
66
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 7
9
- version: 0.2.7
8
+ - 8
9
+ version: 0.2.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-23 00:00:00 +02:00
17
+ date: 2010-11-24 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency