roles_active_record 0.4.1 → 0.4.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.2
@@ -38,8 +38,7 @@ module Roles::ActiveRecord
38
38
 
39
39
  # one_role reference
40
40
  if strategy_name == :one_role
41
- puts "setup one_role"
42
- instance_eval "belongs_to :one_role, :class_name => '#{@role_class_name}'"
41
+ self.belongs_to :one_role, :foreign_key => 'role_id', :class_name => @role_class_name.to_s
43
42
  end
44
43
 
45
44
  # many_roles references
@@ -67,8 +66,7 @@ module Roles::ActiveRecord
67
66
  end
68
67
 
69
68
  def default_role_class strategy_name
70
- if defined? ::Role
71
- puts "require one_role"
69
+ if defined? ::Role
72
70
  require "roles_active_record/#{strategy_name}"
73
71
  return ::Role
74
72
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{roles_active_record}
8
- s.version = "0.4.1"
8
+ s.version = "0.4.2"
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"]
@@ -22,192 +22,192 @@ describe "Roles for Active Record: #{api_name}" do
22
22
  end
23
23
  end
24
24
 
25
- # describe '#in_any_role' do
26
- # it "should return first user matching role" do
27
- # if User.respond_to? :in_roles
28
- # User.in_any_role(:guest, :user).first.name.should == 'Guest user'
29
- # User.in_any_role(:admin, :guest).should be_empty
30
- # end
31
- # end
32
- # end
33
-
34
- # it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
35
- # # mutation API
36
- # [:roles=, :role=, :add_roles, :add_role, :remove_role, :remove_roles, :exchange_roles, :exchange_role].each do |api_method|
37
- # @admin_user.respond_to?(api_method).should be_true
38
- # end
39
- #
40
- # # inspection API
41
- # [:valid_role?, :valid_roles?, :has_roles?, :has_role?, :has?, :is?, :roles, :roles_list, :admin?].each do |api_method|
42
- # @admin_user.respond_to?(api_method).should be_true
43
- # end
44
- #
45
- # # class method API
46
- # [:valid_role?, :valid_roles?, :valid_roles].each do |class_api_method|
47
- # @admin_user.class.respond_to?(class_api_method).should be_true
48
- # end
49
- # end
50
- #
51
- # describe '#valid_role?' do
52
- # it "should be true that the admin user has a valid role of :guest" do
53
- # # @admin_user.valid_role?(:guest).should be_true
54
- # end
55
- #
56
- # it "should be true that the User class has a valid role of :guest" do
57
- # # User.valid_role?(:guest).should be_true
58
- # end
59
- # end
60
- #
61
- # describe '#valid_roles' do
62
- # it "should be true that the admin user has a valid role of :guest" do
63
- # # @admin_user.valid_roles.should include(:guest, :admin)
64
- # end
65
- #
66
- # it "should be true that the User class has a valid role of :guest" do
67
- # User.valid_roles.should include(:guest, :admin)
68
- # end
69
- # end
70
- #
71
- # describe '#valid_roles?' do
72
- # it "should be true that the admin user has a valid role of :guest" do
73
- # @admin_user.valid_roles?(:guest, :admin).should be_true
74
- # end
75
- #
76
- # it "should be true that the User class has a valid role of :guest" do
77
- # User.valid_roles?(:guest, :admin).should be_true
78
- # end
79
- # end
80
- #
81
- # describe '#has_role?' do
82
- # it "should have admin user role to :admin and not to :user" do
83
- # @admin_user.has_role?(:user).should be_false
84
- # @admin_user.has_role?(:admin).should be_true
85
- # end
86
- #
87
- # it "should be true that guest user has role :guest and not :admin" do
88
- # puts "Guest user: #{@guest_user.roles_list}"
89
- # @guest_user.has_role?(:guest).should be_true
90
- # @guest_user.has_role?(:admin).should be_false
91
- # end
92
- # end
93
- #
94
- # describe '#has?' do
95
- # it "should be true that the admin_user has the :admin role" do
96
- # @admin_user.has?(:admin).should be_true
97
- # end
98
- #
99
- # it "should NOT be true that the admin_user has the :admin role" do
100
- # @guest_user.has?(:admin).should be_false
101
- # end
102
- # end
103
- #
104
- # describe '#has_roles?' do
105
- # it "should be true that the admin_user has the roles :admin" do
106
- # # @admin_user.has_roles?(:admin).should be_true
107
- # end
108
- #
109
- # it "should NOT be true that the user has the roles :admin" do
110
- # @guest_user.has_roles?(:admin).should be_false
111
- # end
112
- # end
113
- #
114
- # describe '#roles_list' do
115
- # it "should be true that the first role of admin_user is the :admin role" do
116
- # @admin_user.roles_list.should include(:admin)
117
- # end
118
- #
119
- # it "should be true that the first role of admin_user is the :user role" do
120
- # case @normal_user.class.role_strategy.multiplicity
121
- # when :single
122
- # #if @normal_user.class.role_strategy.name == :admin_flag
123
- # @normal_user.roles_list.should include(:guest)
124
- # # else
125
- # # @normal_user.roles_list.should include(:user)
126
- # #end
127
- # when :multi
128
- # puts "Norm: #{@normal_user.roles}"
129
- # @normal_user.roles_list.should include(:user, :guest)
130
- # end
131
- # end
132
- # end
133
- #
134
- # describe '#roles' do
135
- # it "should be true that the roles of admin_user is an array with the role :admin" do
136
- # roles = @admin_user.roles
137
- # if defined?(Role) && roles.kind_of?(Role)
138
- # roles.name.to_sym.should == :admin
139
- # elsif roles.kind_of? Array
140
- # if @normal_user.class.role_strategy.type == :complex
141
- # roles.first.name.to_sym.should == :admin
142
- # end
143
- # if @normal_user.class.role_strategy.name == :admin_flag
144
- # roles.first.should == true
145
- # end
146
- # else
147
- # roles.to_sym.should == :admin
148
- # end
149
- # end
150
- # end
151
- #
152
- # describe '#admin?' do
153
- # it "should be true that admin_user is in the :admin role" do
154
- # @admin_user.admin?.should be_true
155
- # end
156
- #
157
- # it "should NOT be true that the user is in the :admin role" do
158
- # @guest_user.admin?.should be_false
159
- # end
160
- # end
161
- #
162
- # describe '#is?' do
163
- # it "should be true that admin_user is in the :admin role" do
164
- # @admin_user.is?(:admin).should be_true
165
- # end
166
- #
167
- # it "should NOT be true that the user is in the :admin role" do
168
- # @guest_user.is?(:admin).should be_false
169
- # end
170
- # end
171
- #
172
- # describe '#roles=' do
173
- # it "should set user role to :admin" do
174
- # @guest_user.roles = :admin
175
- # @guest_user.has_role?(:admin).should be_true
176
- # @guest_user.roles = :guest
177
- # end
178
- # end
179
- #
180
- # describe '#exchange_roles' do
181
- # it "should exchange user role :user with role :admin" do
182
- # @guest_user.exchange_role :guest, :with => :admin
183
- # @guest_user.has?(:guest).should be_false
184
- # @guest_user.has?(:admin).should be_true
185
- # end
186
- #
187
- # it "should exchange user role :admin with roles :user and :guest" do
188
- # case @admin_user.class.role_strategy.multiplicity
189
- # when :single
190
- # lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
191
- # when :multi
192
- # @admin_user.exchange_role :admin, :with => [:user, :guest]
193
- # @admin_user.has_role?(:user).should be_true
194
- # @admin_user.has_role?(:guest).should be_true
195
- # @admin_user.has?(:admin).should be_false
196
- # end
197
- # end
198
- # end
199
- #
200
- # describe '#remove_roles' do
201
- # it "should remove user role :admin using #remove_roles" do
202
- # @admin_user.remove_roles :admin
203
- # @admin_user.has_role?(:admin).should_not be_true
204
- # end
205
- #
206
- # it "should remove user role :admin using #remove_role" do
207
- # @guest_user.add_role :admin
208
- # @guest_user.has_role?(:admin).should be_true
209
- # @guest_user.remove_role :admin
210
- # @guest_user.has_role?(:admin).should_not be_true
211
- # end
212
- # end
25
+ describe '#in_any_role' do
26
+ it "should return first user matching role" do
27
+ if User.respond_to? :in_roles
28
+ User.in_any_role(:guest, :user).first.name.should == 'Guest user'
29
+ User.in_any_role(:admin, :guest).should be_empty
30
+ end
31
+ end
32
+ end
33
+
34
+ it "should be true that a User that includes Roles::Generic has a complete Roles::Generic interface" do
35
+ # mutation API
36
+ [:roles=, :role=, :add_roles, :add_role, :remove_role, :remove_roles, :exchange_roles, :exchange_role].each do |api_method|
37
+ @admin_user.respond_to?(api_method).should be_true
38
+ end
39
+
40
+ # inspection API
41
+ [:valid_role?, :valid_roles?, :has_roles?, :has_role?, :has?, :is?, :roles, :roles_list, :admin?].each do |api_method|
42
+ @admin_user.respond_to?(api_method).should be_true
43
+ end
44
+
45
+ # class method API
46
+ [:valid_role?, :valid_roles?, :valid_roles].each do |class_api_method|
47
+ @admin_user.class.respond_to?(class_api_method).should be_true
48
+ end
49
+ end
50
+
51
+ describe '#valid_role?' do
52
+ it "should be true that the admin user has a valid role of :guest" do
53
+ # @admin_user.valid_role?(:guest).should be_true
54
+ end
55
+
56
+ it "should be true that the User class has a valid role of :guest" do
57
+ # User.valid_role?(:guest).should be_true
58
+ end
59
+ end
60
+
61
+ describe '#valid_roles' do
62
+ it "should be true that the admin user has a valid role of :guest" do
63
+ # @admin_user.valid_roles.should include(:guest, :admin)
64
+ end
65
+
66
+ it "should be true that the User class has a valid role of :guest" do
67
+ User.valid_roles.should include(:guest, :admin)
68
+ end
69
+ end
70
+
71
+ describe '#valid_roles?' do
72
+ it "should be true that the admin user has a valid role of :guest" do
73
+ @admin_user.valid_roles?(:guest, :admin).should be_true
74
+ end
75
+
76
+ it "should be true that the User class has a valid role of :guest" do
77
+ User.valid_roles?(:guest, :admin).should be_true
78
+ end
79
+ end
80
+
81
+ describe '#has_role?' do
82
+ it "should have admin user role to :admin and not to :user" do
83
+ @admin_user.has_role?(:user).should be_false
84
+ @admin_user.has_role?(:admin).should be_true
85
+ end
86
+
87
+ it "should be true that guest user has role :guest and not :admin" do
88
+ puts "Guest user: #{@guest_user.roles_list}"
89
+ @guest_user.has_role?(:guest).should be_true
90
+ @guest_user.has_role?(:admin).should be_false
91
+ end
92
+ end
93
+
94
+ describe '#has?' do
95
+ it "should be true that the admin_user has the :admin role" do
96
+ @admin_user.has?(:admin).should be_true
97
+ end
98
+
99
+ it "should NOT be true that the admin_user has the :admin role" do
100
+ @guest_user.has?(:admin).should be_false
101
+ end
102
+ end
103
+
104
+ describe '#has_roles?' do
105
+ it "should be true that the admin_user has the roles :admin" do
106
+ # @admin_user.has_roles?(:admin).should be_true
107
+ end
108
+
109
+ it "should NOT be true that the user has the roles :admin" do
110
+ @guest_user.has_roles?(:admin).should be_false
111
+ end
112
+ end
113
+
114
+ describe '#roles_list' do
115
+ it "should be true that the first role of admin_user is the :admin role" do
116
+ @admin_user.roles_list.should include(:admin)
117
+ end
118
+
119
+ it "should be true that the first role of admin_user is the :user role" do
120
+ case @normal_user.class.role_strategy.multiplicity
121
+ when :single
122
+ #if @normal_user.class.role_strategy.name == :admin_flag
123
+ @normal_user.roles_list.should include(:guest)
124
+ # else
125
+ # @normal_user.roles_list.should include(:user)
126
+ #end
127
+ when :multi
128
+ puts "Norm: #{@normal_user.roles}"
129
+ @normal_user.roles_list.should include(:user, :guest)
130
+ end
131
+ end
132
+ end
133
+
134
+ describe '#roles' do
135
+ it "should be true that the roles of admin_user is an array with the role :admin" do
136
+ roles = @admin_user.roles
137
+ if defined?(Role) && roles.kind_of?(Role)
138
+ roles.name.to_sym.should == :admin
139
+ elsif roles.kind_of? Array
140
+ if @normal_user.class.role_strategy.type == :complex
141
+ roles.first.name.to_sym.should == :admin
142
+ end
143
+ if @normal_user.class.role_strategy.name == :admin_flag
144
+ roles.first.should == true
145
+ end
146
+ else
147
+ roles.to_sym.should == :admin
148
+ end
149
+ end
150
+ end
151
+
152
+ describe '#admin?' do
153
+ it "should be true that admin_user is in the :admin role" do
154
+ @admin_user.admin?.should be_true
155
+ end
156
+
157
+ it "should NOT be true that the user is in the :admin role" do
158
+ @guest_user.admin?.should be_false
159
+ end
160
+ end
161
+
162
+ describe '#is?' do
163
+ it "should be true that admin_user is in the :admin role" do
164
+ @admin_user.is?(:admin).should be_true
165
+ end
166
+
167
+ it "should NOT be true that the user is in the :admin role" do
168
+ @guest_user.is?(:admin).should be_false
169
+ end
170
+ end
171
+
172
+ describe '#roles=' do
173
+ it "should set user role to :admin" do
174
+ @guest_user.roles = :admin
175
+ @guest_user.has_role?(:admin).should be_true
176
+ @guest_user.roles = :guest
177
+ end
178
+ end
179
+
180
+ describe '#exchange_roles' do
181
+ it "should exchange user role :user with role :admin" do
182
+ @guest_user.exchange_role :guest, :with => :admin
183
+ @guest_user.has?(:guest).should be_false
184
+ @guest_user.has?(:admin).should be_true
185
+ end
186
+
187
+ it "should exchange user role :admin with roles :user and :guest" do
188
+ case @admin_user.class.role_strategy.multiplicity
189
+ when :single
190
+ lambda { @admin_user.exchange_role :admin, :with => [:user, :guest] }.should raise_error(ArgumentError)
191
+ when :multi
192
+ @admin_user.exchange_role :admin, :with => [:user, :guest]
193
+ @admin_user.has_role?(:user).should be_true
194
+ @admin_user.has_role?(:guest).should be_true
195
+ @admin_user.has?(:admin).should be_false
196
+ end
197
+ end
198
+ end
199
+
200
+ describe '#remove_roles' do
201
+ it "should remove user role :admin using #remove_roles" do
202
+ @admin_user.remove_roles :admin
203
+ @admin_user.has_role?(:admin).should_not be_true
204
+ end
205
+
206
+ it "should remove user role :admin using #remove_role" do
207
+ @guest_user.add_role :admin
208
+ @guest_user.has_role?(:admin).should be_true
209
+ @guest_user.remove_role :admin
210
+ @guest_user.has_role?(:admin).should_not be_true
211
+ end
212
+ end
213
213
  end
@@ -11,5 +11,5 @@ def default_user_setup
11
11
  @admin_user.roles = :admin
12
12
  @admin_user.save
13
13
 
14
- puts "Admin roles: #{@admin_user.roles_list}, #{@admin_user.inspect}"
14
+ # puts "Admin roles: #{@admin_user.roles_list}, #{@admin_user.inspect}, #{Role.all}"
15
15
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup