roles_data_mapper 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -2,10 +2,7 @@
2
2
 
3
3
  A Data Mapper implementation of [roles generic](http://github.com/kristianmandrup/roles_generic)
4
4
 
5
- ## Update!
6
-
7
- Now implements the [roles generic](http://github.com/kristianmandrup/roles_generic) Roles API
8
- It also implements the following Role strategies:
5
+ The following role strategies from Roles Generic are currently supported
9
6
 
10
7
  * admin_flag
11
8
  * many_roles
@@ -25,7 +22,7 @@ This gem is based on Jeweler, so simply:
25
22
 
26
23
  <code>rake install</code>
27
24
 
28
- ## Rails generator
25
+ ## Roles Generator
29
26
 
30
27
  The library comes with a Rails 3 generator that lets you populate a user model with a given role strategy
31
28
  The following role strategies are included by default. Add your own by adding extra files inside the strategy folder, one file for each role strategy is recommended.
@@ -36,7 +33,11 @@ The following role strategies are included by default. Add your own by adding ex
36
33
  * roles_mask
37
34
  * role_string
38
35
 
39
- *Roles generator*
36
+ ### Update Oct 10.
37
+
38
+ Bugfix: Added dependencies to Rakefile for role generator so they should work out-of-the-box after gem is installed ;)
39
+
40
+ ## Usage examples
40
41
 
41
42
  Apply :admin_flag Role strategy to User model using default roles :admin and :guest (default)
42
43
 
data/Rakefile CHANGED
@@ -17,6 +17,9 @@ begin
17
17
  gem.add_dependency "require_all", '~> 1.2.0'
18
18
  gem.add_dependency "sugar-high", '~> 0.2.11'
19
19
  gem.add_dependency "roles_generic", '~> 0.2.7'
20
+
21
+ gem.add_dependency 'rails3_artifactor', '>= 0.2.6'
22
+ gem.add_dependency 'logging_assist', '>= 0.1.5'
20
23
 
21
24
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
25
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -1,8 +1,6 @@
1
1
  require 'rails3_artifactor'
2
2
  require 'logging_assist'
3
3
 
4
- puts "Included!"
5
-
6
4
  module DataMapper
7
5
  module Generators
8
6
  class RolesGenerator < Rails::Generators::NamedBase
@@ -15,8 +13,7 @@ module DataMapper
15
13
  class_option :roles, :type => :array, :aliases => "-r", :default => [], :desc => "Valid roles"
16
14
 
17
15
  def apply_role_strategy
18
- log.add_logfile
19
- log.debug "apply_role_strategy for : #{strategy} in model #{name}"
16
+ logger.debug "apply_role_strategy for : #{strategy} in model #{name}"
20
17
  begin
21
18
  insert_into_model name do
22
19
  insertion_text
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_data_mapper}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
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-07}
12
+ s.date = %q{2010-10-11}
13
13
  s.description = %q{Makes it easy to set a role strategy on your User model in DataMapper}
14
14
  s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  "spec/roles_data_mapper/strategy/one_role_spec.rb",
44
44
  "spec/roles_data_mapper/strategy/role_string_spec.rb",
45
45
  "spec/roles_data_mapper/strategy/roles_mask_spec.rb",
46
+ "spec/roles_data_mapper/strategy/user_setup.rb",
46
47
  "spec/spec_helper.rb",
47
48
  "tmp/rails/config/routes.rb"
48
49
  ]
@@ -59,6 +60,7 @@ Gem::Specification.new do |s|
59
60
  "spec/roles_data_mapper/strategy/one_role_spec.rb",
60
61
  "spec/roles_data_mapper/strategy/role_string_spec.rb",
61
62
  "spec/roles_data_mapper/strategy/roles_mask_spec.rb",
63
+ "spec/roles_data_mapper/strategy/user_setup.rb",
62
64
  "spec/spec_helper.rb"
63
65
  ]
64
66
 
@@ -75,6 +77,8 @@ Gem::Specification.new do |s|
75
77
  s.add_runtime_dependency(%q<require_all>, ["~> 1.2.0"])
76
78
  s.add_runtime_dependency(%q<sugar-high>, ["~> 0.2.11"])
77
79
  s.add_runtime_dependency(%q<roles_generic>, ["~> 0.2.7"])
80
+ s.add_runtime_dependency(%q<rails3_artifactor>, [">= 0.2.6"])
81
+ s.add_runtime_dependency(%q<logging_assist>, [">= 0.1.5"])
78
82
  else
79
83
  s.add_dependency(%q<rspec>, [">= 2.0.0.rc"])
80
84
  s.add_dependency(%q<dm-core>, ["~> 1.0"])
@@ -84,6 +88,8 @@ Gem::Specification.new do |s|
84
88
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
85
89
  s.add_dependency(%q<sugar-high>, ["~> 0.2.11"])
86
90
  s.add_dependency(%q<roles_generic>, ["~> 0.2.7"])
91
+ s.add_dependency(%q<rails3_artifactor>, [">= 0.2.6"])
92
+ s.add_dependency(%q<logging_assist>, [">= 0.1.5"])
87
93
  end
88
94
  else
89
95
  s.add_dependency(%q<rspec>, [">= 2.0.0.rc"])
@@ -94,6 +100,8 @@ Gem::Specification.new do |s|
94
100
  s.add_dependency(%q<require_all>, ["~> 1.2.0"])
95
101
  s.add_dependency(%q<sugar-high>, ["~> 0.2.11"])
96
102
  s.add_dependency(%q<roles_generic>, ["~> 0.2.7"])
103
+ s.add_dependency(%q<rails3_artifactor>, [">= 0.2.6"])
104
+ s.add_dependency(%q<logging_assist>, [">= 0.1.5"])
97
105
  end
98
106
  end
99
107
 
@@ -16,64 +16,7 @@ DataMapper.auto_migrate!
16
16
 
17
17
  User.valid_roles_are :admin, :guest
18
18
 
19
- describe "Roles for Mongoid" do
20
- before :each do
21
-
22
- @user = User.create(:name => 'Kristian')
23
- @user.roles = :guest
24
- @user.save
25
-
26
- @admin_user = User.create(:name => 'Admin user')
27
- @admin_user.roles = :admin
28
- @admin_user.save
29
-
30
- puts "user: #{@user.inspect}"
31
- puts "admin: #{@admin_user.inspect}"
32
- end
33
-
34
- describe "Admin flag strategy " do
35
-
36
- describe '#in_role' do
37
- it "should return first user maching role" do
38
- User.in_role(:guest).first.name.should == 'Kristian'
39
- User.in_role(:admin).first.name.should == 'Admin user'
40
- end
41
- end
42
-
43
- describe 'roles API' do
44
- it "should have admin user role to :admin" do
45
- @admin_user.role.should == :admin
46
- @admin_user.roles.should == [:admin]
47
- @admin_user.admin?.should be_true
48
-
49
- @admin_user.class.valid_roles.should == [:admin, :guest]
50
-
51
- @admin_user.has_role?(:guest).should be_false
52
-
53
- @admin_user.has_role?(:admin).should be_true
54
- @admin_user.is?(:admin).should be_true
55
- @admin_user.has_roles?(:admin).should be_true
56
- @admin_user.has?(:admin).should be_true
57
- end
58
-
59
- it "should have user role to :guest" do
60
- @user.roles.should == [:guest]
61
- # @user.admin?.should be_false
62
-
63
- # @user.has_role?(:guest).should be_true
64
- # @user.has_role?(:admin).should be_false
65
- # @user.is?(:admin).should be_false
66
- #
67
- # @user.has_roles?(:guest).should be_true
68
- # @user.has?(:admin).should be_false
69
- end
70
-
71
- it "should set user role to :admin using =" do
72
- @user.roles = :admin
73
- @user.role.should == :admin
74
- @user.has_role?(:admin).should be_true
75
- end
76
- end
77
- end
19
+ describe "Roles for DataMapper: :admin_flag strategy" do
20
+ require "roles_data_mapper/user_setup"
21
+ require "roles_generic/rspec/api"
78
22
  end
79
-
@@ -17,60 +17,7 @@ DataMapper.auto_migrate!
17
17
 
18
18
  User.valid_roles_are :admin, :guest
19
19
 
20
- describe "Roles for Mongoid" do
21
- context "default setup" do
22
-
23
- before :each do
24
- # DataMapper.finalize
25
- # DataMapper.auto_migrate!
26
-
27
- @user = User.create(:name => 'Kristian')
28
- @user.add_roles :guest
29
- @user.save
30
-
31
- @admin_user = User.create(:name => 'Admin user')
32
- @admin_user.roles = :admin
33
- @admin_user.save
34
- end
35
-
36
- describe '#in_role' do
37
- it "should return first user matching role" do
38
- User.in_roles(:guest).first.name.should == 'Kristian'
39
- User.in_role(:admin).first.name.should == 'Admin user'
40
- end
41
- end
42
-
43
- describe "Role API" do
44
- it "should have admin user role to :admin" do
45
- @admin_user.roles_list.first.should == :admin
46
- @admin_user.admin?.should be_true
47
-
48
- @admin_user.has_role?(:guest).should be_false
49
-
50
- @admin_user.has_role?(:admin).should be_true
51
- @admin_user.is?(:admin).should be_true
52
- @admin_user.has_roles?(:admin).should be_true
53
- @admin_user.has?(:admin).should be_true
54
- end
55
-
56
- it "should have user role to :guest" do
57
- @user.roles_list.first.should == :guest
58
- @user.admin?.should be_false
59
-
60
- @user.has_role?(:guest).should be_true
61
- @user.has_role?(:admin).should be_false
62
- @user.is?(:admin).should be_false
63
-
64
- @user.has_roles?(:admin).should be_false
65
- @user.has?(:admin).should be_false
66
- end
67
-
68
- it "should set user role to :admin using roles=" do
69
- @user.roles = :admin
70
- @user.roles_list.first.should == :admin
71
- @user.has_role?(:admin).should be_true
72
- end
73
- end
74
- end
20
+ describe "Roles for DataMapper: :many_roles strategy" do
21
+ require "roles_data_mapper/user_setup"
22
+ require "roles_generic/rspec/api"
75
23
  end
76
-
@@ -17,65 +17,7 @@ DataMapper.auto_migrate!
17
17
 
18
18
  User.valid_roles_are :admin, :guest
19
19
 
20
- describe "Roles for Mongoid" do
21
-
22
- context "default setup" do
23
-
24
- before :each do
25
- # DataMapper.finalize
26
- # DataMapper.auto_migrate!
27
-
28
- @user = User.create(:name => 'Kristian')
29
- @user.role = :guest
30
- @user.save
31
-
32
- @admin_user = User.create(:name => 'Admin user')
33
- @admin_user.role = :admin
34
- @admin_user.save
35
-
36
- puts "user: #{@user.inspect}"
37
- puts "admin: #{@admin_user.inspect}"
38
- puts "role: #{Role.first.inspect}"
39
- end
40
-
41
- describe '#in_role' do
42
- it "should return first user matching role" do
43
- User.in_role(:guest).first.name.should == 'Kristian'
44
- User.in_role(:admin).first.name.should == 'Admin user'
45
- end
46
- end
47
-
48
- describe "Role API" do
49
- it "should have admin user role to :admin" do
50
- @admin_user.roles_list.first.should == :admin
51
- @admin_user.admin?.should be_true
52
-
53
- @admin_user.has_role?(:guest).should be_false
54
-
55
- @admin_user.has_role?(:admin).should be_true
56
- @admin_user.is?(:admin).should be_true
57
- @admin_user.has_roles?(:admin).should be_true
58
- @admin_user.has?(:admin).should be_true
59
- end
60
-
61
- it "should have user role to :guest" do
62
- @user.roles_list.first.should == :guest
63
- @user.admin?.should be_false
64
-
65
- @user.has_role?(:guest).should be_true
66
- @user.has_role?(:admin).should be_false
67
- @user.is?(:admin).should be_false
68
-
69
- @user.has_roles?(:admin).should be_false
70
- @user.has?(:admin).should be_false
71
- end
72
-
73
- it "should set user role to :admin using roles=" do
74
- @user.roles = :admin
75
- @user.roles_list.first.should == :admin
76
- @user.has_role?(:admin).should be_true
77
- end
78
- end
79
- end
20
+ describe "Roles for DataMapper: :one_role strategy" do
21
+ require "roles_data_mapper/user_setup"
22
+ require "roles_generic/rspec/api"
80
23
  end
81
-
@@ -16,58 +16,7 @@ DataMapper.auto_migrate!
16
16
 
17
17
  User.valid_roles_are :admin, :guest
18
18
 
19
- describe "Roles for Mongoid" do
20
-
21
- context "default setup" do
22
- before :each do
23
-
24
- @user = User.create(:name => 'Kristian')
25
- @user.role = :guest
26
- @user.save
27
-
28
- @admin_user = User.create(:name => 'Admin user')
29
- @admin_user.roles = :admin
30
- @admin_user.save
31
- end
32
-
33
- describe '#in_role' do
34
- it "should return first user matching role" do
35
- User.in_role(:guest).first.name.should == 'Kristian'
36
- User.in_role(:admin).first.name.should == 'Admin user'
37
- end
38
- end
39
-
40
- describe "Role API" do
41
- it "should have admin user role to :admin" do
42
- @admin_user.roles_list.first.should == :admin
43
- @admin_user.admin?.should be_true
44
-
45
- @admin_user.has_role?(:guest).should be_false
46
-
47
- @admin_user.has_role?(:admin).should be_true
48
- @admin_user.is?(:admin).should be_true
49
- @admin_user.has_roles?(:admin).should be_true
50
- @admin_user.has?(:admin).should be_true
51
- end
52
-
53
- it "should have user role to :guest" do
54
- @user.roles_list.first.should == :guest
55
- @user.admin?.should be_false
56
-
57
- @user.has_role?(:guest).should be_true
58
- @user.has_role?(:admin).should be_false
59
- @user.is?(:admin).should be_false
60
-
61
- @user.has_roles?(:admin).should be_false
62
- @user.has?(:admin).should be_false
63
- end
64
-
65
- it "should set user role to :admin using roles=" do
66
- @user.roles = :admin
67
- @user.roles_list.first.should == :admin
68
- @user.has_role?(:admin).should be_true
69
- end
70
- end
71
- end
19
+ describe "Roles for DataMapper: :role_string strategy" do
20
+ require "roles_data_mapper/user_setup"
21
+ require "roles_generic/rspec/api"
72
22
  end
73
-
@@ -16,58 +16,7 @@ DataMapper.auto_migrate!
16
16
 
17
17
  User.valid_roles_are :admin, :guest
18
18
 
19
- describe "Roles for Mongoid" do
20
-
21
- context "default setup" do
22
-
23
- before :each do
24
- @user = User.create(:name => 'Kristian')
25
- @user.role = :guest
26
- @user.save
27
-
28
- @admin_user = User.create(:name => 'Admin user')
29
- @admin_user.roles = :admin
30
- @admin_user.save
31
- end
32
-
33
- describe '#in_role' do
34
- it "should return first user matching role" do
35
- User.in_role(:guest).first.name.should == 'Kristian'
36
- User.in_role(:admin).first.name.should == 'Admin user'
37
- end
38
- end
39
-
40
- describe "Role API" do
41
- it "should have admin user role to :admin" do
42
- @admin_user.roles_list.first.should == :admin
43
- @admin_user.admin?.should be_true
44
-
45
- @admin_user.has_role?(:guest).should be_false
46
-
47
- @admin_user.has_role?(:admin).should be_true
48
- @admin_user.is?(:admin).should be_true
49
- @admin_user.has_roles?(:admin).should be_true
50
- @admin_user.has?(:admin).should be_true
51
- end
52
-
53
- it "should have user role to :guest" do
54
- @user.roles_list.first.should == :guest
55
- @user.admin?.should be_false
56
-
57
- @user.has_role?(:guest).should be_true
58
- @user.has_role?(:admin).should be_false
59
- @user.is?(:admin).should be_false
60
-
61
- @user.has_roles?(:admin).should be_false
62
- @user.has?(:admin).should be_false
63
- end
64
-
65
- it "should set user role to :admin using roles=" do
66
- @user.roles = :admin
67
- @user.roles_list.first.should == :admin
68
- @user.has_role?(:admin).should be_true
69
- end
70
- end
71
- end
19
+ describe "Roles for DataMapper: :roles_mask strategy" do
20
+ require "roles_data_mapper/user_setup"
21
+ require "roles_generic/rspec/api"
72
22
  end
73
-
@@ -0,0 +1,13 @@
1
+ def default_user_setup
2
+ @guest_user = User.create(:name => 'Guest User')
3
+ @guest_user.add_roles :guest
4
+ @guest_user.save
5
+
6
+ @normal_user = User.create(:name => 'Normal User')
7
+ @normal_user.roles = :guest, :user
8
+ @normal_user.save
9
+
10
+ @admin_user = User.create(:name => 'Admin user')
11
+ @admin_user.roles = :admin
12
+ @admin_user.save
13
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
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-07 00:00:00 +02:00
17
+ date: 2010-10-11 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -135,6 +135,36 @@ dependencies:
135
135
  version: 0.2.7
136
136
  type: :runtime
137
137
  version_requirements: *id008
138
+ - !ruby/object:Gem::Dependency
139
+ name: rails3_artifactor
140
+ prerelease: false
141
+ requirement: &id009 !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ segments:
147
+ - 0
148
+ - 2
149
+ - 6
150
+ version: 0.2.6
151
+ type: :runtime
152
+ version_requirements: *id009
153
+ - !ruby/object:Gem::Dependency
154
+ name: logging_assist
155
+ prerelease: false
156
+ requirement: &id010 !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ segments:
162
+ - 0
163
+ - 1
164
+ - 5
165
+ version: 0.1.5
166
+ type: :runtime
167
+ version_requirements: *id010
138
168
  description: Makes it easy to set a role strategy on your User model in DataMapper
139
169
  email: kmandrup@gmail.com
140
170
  executables: []
@@ -171,6 +201,7 @@ files:
171
201
  - spec/roles_data_mapper/strategy/one_role_spec.rb
172
202
  - spec/roles_data_mapper/strategy/role_string_spec.rb
173
203
  - spec/roles_data_mapper/strategy/roles_mask_spec.rb
204
+ - spec/roles_data_mapper/strategy/user_setup.rb
174
205
  - spec/spec_helper.rb
175
206
  - tmp/rails/config/routes.rb
176
207
  has_rdoc: true
@@ -213,4 +244,5 @@ test_files:
213
244
  - spec/roles_data_mapper/strategy/one_role_spec.rb
214
245
  - spec/roles_data_mapper/strategy/role_string_spec.rb
215
246
  - spec/roles_data_mapper/strategy/roles_mask_spec.rb
247
+ - spec/roles_data_mapper/strategy/user_setup.rb
216
248
  - spec/spec_helper.rb