adhocracy 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.rdoc +16 -4
- data/lib/adhocracy/acts_as_group.rb +13 -9
- data/lib/adhocracy/acts_as_member.rb +30 -0
- data/lib/adhocracy/version.rb +1 -1
- data/spec/lib/adhocracy/acts_as_group_spec.rb +11 -12
- data/spec/lib/adhocracy/acts_as_member_spec.rb +63 -1
- metadata +29 -29
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NDgwMjJhOWRkMTNiNWVkODY3YjYwYWMzNjliZjNlZWQ5M2I2ODQwNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzVhY2E5Mjk0NzI3Yjk5NTJjMTg4NjgyZjg2MTA1MzcyMTZiZDJmZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjgxNmFmZjkxYzZiY2ZkMzZjNmI3MzQ3NTE1NjY1N2ZhMWMzOTQxNDk4YjVl
|
10
|
+
ZjZiMGE4MTE3YWY3NWVjOGMwYzdiZDU5ODFhMzE4MjNkYzZiM2QwNjA3ODkz
|
11
|
+
ZjY5YjY3N2Y0YjZkYzQ1YmVkODIyOGQzZWRkMTkwZWVlNmZiNzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWVkZmUzYWNmYTcyOTgwZjlmNGQ5Zjg4ZDAyYmIzNDc1YjczODM0NGZhZjUx
|
14
|
+
ZTVmZGYwMTVmMzIxMzczODljZWM1NzliZjllNWU0MzRhNzEyYWJhZGI0Mzg2
|
15
|
+
Yzc4NjQyNWZmYmVmOTBmNmM2OGU5M2MyYmRjMWE1ZWE4NGJiNzA=
|
data/README.rdoc
CHANGED
@@ -68,14 +68,26 @@ Scenario: You want a special class of membership that has the privilege to edit
|
|
68
68
|
Adhocracy allows for administrative members called officers. You can create a new officer with:
|
69
69
|
|
70
70
|
@club.add_officer(@student)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
@club.promote_to_officer(@student)
|
71
|
+
# or
|
72
|
+
@student.promote(@club)
|
75
73
|
|
76
74
|
Later, you can strip an officer of her title with:
|
77
75
|
|
78
76
|
@club.demote_officer(@student)
|
77
|
+
# or
|
78
|
+
@student.demote(@club)
|
79
|
+
|
80
|
+
You can check if a member is an officer with:
|
81
|
+
|
82
|
+
@club.has_officer?(@member)
|
83
|
+
# or
|
84
|
+
@member.officer_of?(@club)
|
85
|
+
|
86
|
+
Or get a full list of officers:
|
87
|
+
|
88
|
+
@club.officers
|
89
|
+
# or of administered groups
|
90
|
+
@member.administrations
|
79
91
|
|
80
92
|
=== Inviting Members
|
81
93
|
|
@@ -44,15 +44,14 @@ module Adhocracy
|
|
44
44
|
|
45
45
|
def add_officer(member)
|
46
46
|
membership = Adhocracy::Membership.where(member: member, group: self).
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
return
|
55
|
-
return membership.update_column(:officer, true)
|
47
|
+
first_or_initialize(officer: true)
|
48
|
+
if membership.new_record?
|
49
|
+
membership.save
|
50
|
+
else
|
51
|
+
return false if membership.officer?
|
52
|
+
membership.update_column(:officer, true)
|
53
|
+
end
|
54
|
+
return membership
|
56
55
|
end
|
57
56
|
|
58
57
|
def demote_officer(member)
|
@@ -75,6 +74,11 @@ module Adhocracy
|
|
75
74
|
MembershipAssociation.new(member: member, group: self).verify_membership
|
76
75
|
end
|
77
76
|
|
77
|
+
def has_officer?(member)
|
78
|
+
Adhocracy::Membership.where(member: member, group: self,
|
79
|
+
officer: true).exists?
|
80
|
+
end
|
81
|
+
|
78
82
|
def invited?(member, params = {})
|
79
83
|
params.merge!({ member: member, group: self })
|
80
84
|
MembershipAssociation.new(params).verify_membership_invitation
|
@@ -10,6 +10,8 @@ module Adhocracy
|
|
10
10
|
class_name: "Adhocracy::MembershipInvitation"
|
11
11
|
has_many :membership_requests, as: :member,
|
12
12
|
class_name: "Adhocracy::MembershipRequest"
|
13
|
+
has_many :officer_memberships, -> { where officer: true }, as: :member,
|
14
|
+
class_name: "Adhocracy::Membership"
|
13
15
|
|
14
16
|
send :include, InstanceMethods
|
15
17
|
end
|
@@ -20,6 +22,11 @@ module Adhocracy
|
|
20
22
|
MembershipAssociation.new(member: self).list_groups_for_membership
|
21
23
|
end
|
22
24
|
|
25
|
+
def administrations
|
26
|
+
Adhocracy::Membership.where(member: self, officer: true).
|
27
|
+
includes(:group).collect { |membership| membership.group }
|
28
|
+
end
|
29
|
+
|
23
30
|
def group_invitations
|
24
31
|
MembershipAssociation.new(member: self).
|
25
32
|
list_groups_for_membership_invitation
|
@@ -34,6 +41,24 @@ module Adhocracy
|
|
34
41
|
MembershipAssociation.new(member: self, group: group).create_membership
|
35
42
|
end
|
36
43
|
|
44
|
+
def promote(group)
|
45
|
+
membership = Adhocracy::Membership.where(member: self, group: group).
|
46
|
+
first_or_initialize(officer: true)
|
47
|
+
if membership.new_record?
|
48
|
+
membership.save
|
49
|
+
else
|
50
|
+
return false if membership.officer?
|
51
|
+
membership.update_column(:officer, true)
|
52
|
+
end
|
53
|
+
return membership
|
54
|
+
end
|
55
|
+
|
56
|
+
def demote(member)
|
57
|
+
membership = Adhocracy::Membership.find_by(member: self, group: member)
|
58
|
+
return false if !membership.present? || !membership.officer?
|
59
|
+
return membership.update_column(:officer, false)
|
60
|
+
end
|
61
|
+
|
37
62
|
def request_membership_in(group)
|
38
63
|
MembershipAssociation.new(member: self, group: group).
|
39
64
|
create_membership_request
|
@@ -47,6 +72,11 @@ module Adhocracy
|
|
47
72
|
MembershipAssociation.new(member: self, group: group).verify_membership
|
48
73
|
end
|
49
74
|
|
75
|
+
def officer_of?(group)
|
76
|
+
Adhocracy::Membership.where(member: self, group: group,
|
77
|
+
officer: true).exists?
|
78
|
+
end
|
79
|
+
|
50
80
|
def invited_to?(group, params = {})
|
51
81
|
params.merge!({ member: self, group: group })
|
52
82
|
MembershipAssociation.new(params).verify_membership_invitation
|
data/lib/adhocracy/version.rb
CHANGED
@@ -89,6 +89,15 @@ module Adhocracy
|
|
89
89
|
expect(@adhoc.has_member?(@user)).to be false
|
90
90
|
end
|
91
91
|
|
92
|
+
it "if an officer exists and returns true if it does" do
|
93
|
+
@adhoc.add_officer(@user)
|
94
|
+
expect(@adhoc.has_officer?(@user)).to be true
|
95
|
+
end
|
96
|
+
|
97
|
+
it "if an officer exists and returns false if it does not" do
|
98
|
+
expect(@adhoc.has_officer?(@user)).to be false
|
99
|
+
end
|
100
|
+
|
92
101
|
it "if an invitation exists and returns true if it does" do
|
93
102
|
@adhoc.invite_member(@user)
|
94
103
|
expect(@adhoc.invited?(@user)).to be true
|
@@ -155,7 +164,7 @@ module Adhocracy
|
|
155
164
|
|
156
165
|
it "not creating duplicate officers" do
|
157
166
|
@adhoc.add_officer(@user)
|
158
|
-
expect(@adhoc.add_officer(@user)
|
167
|
+
expect(@adhoc.add_officer(@user)).to be false
|
159
168
|
end
|
160
169
|
|
161
170
|
it "inviting members" do
|
@@ -210,24 +219,14 @@ module Adhocracy
|
|
210
219
|
end
|
211
220
|
|
212
221
|
it "if the member is a non-officer" do
|
213
|
-
@adhoc.add_member(@user)
|
214
|
-
@adhoc.promote_to_officer(@user)
|
215
|
-
expect(@adhoc.officers).to include @user
|
216
|
-
end
|
217
|
-
|
218
|
-
it "if the member is a non-officer member (and add_officer is used)" do
|
219
222
|
@adhoc.add_member(@user)
|
220
223
|
@adhoc.add_officer(@user)
|
221
224
|
expect(@adhoc.officers).to include @user
|
222
225
|
end
|
223
226
|
|
224
|
-
it "but returns false if the user is not a member" do
|
225
|
-
expect(@adhoc.promote_to_officer(@user)).to be false
|
226
|
-
end
|
227
|
-
|
228
227
|
it "but returns false if the member is already an officer" do
|
229
228
|
@adhoc.add_officer(@user)
|
230
|
-
expect(@adhoc.
|
229
|
+
expect(@adhoc.add_officer(@user)).to be false
|
231
230
|
end
|
232
231
|
end
|
233
232
|
|
@@ -30,7 +30,7 @@ module Adhocracy
|
|
30
30
|
@adhoc4 = FactoryGirl.create(:adhoc)
|
31
31
|
@adhoc5 = FactoryGirl.create(:adhoc)
|
32
32
|
@user.join_group(@adhoc1)
|
33
|
-
@user.
|
33
|
+
@user.promote(@adhoc3)
|
34
34
|
@adhoc4.invite_member(@user)
|
35
35
|
@user.request_membership_in(@adhoc5)
|
36
36
|
end
|
@@ -43,6 +43,14 @@ module Adhocracy
|
|
43
43
|
expect(@user.groups).to_not include @adhoc2, @adhoc4, @adhoc5
|
44
44
|
end
|
45
45
|
|
46
|
+
it "including all administered groups" do
|
47
|
+
expect(@user.administrations).to include @adhoc3
|
48
|
+
end
|
49
|
+
|
50
|
+
it "excluding non-administered groups" do
|
51
|
+
expect(@user.administrations).to_not include @adhoc1, @adhoc2, @adhoc4, @adhoc5
|
52
|
+
end
|
53
|
+
|
46
54
|
it "including all invited groups" do
|
47
55
|
expect(@user.group_invitations).to include @adhoc4
|
48
56
|
end
|
@@ -77,6 +85,15 @@ module Adhocracy
|
|
77
85
|
expect(@user.member_of?(@adhoc)).to be false
|
78
86
|
end
|
79
87
|
|
88
|
+
it "if an officer exists and returns true if it does" do
|
89
|
+
@user.promote(@adhoc)
|
90
|
+
expect(@user.officer_of?(@adhoc)).to be true
|
91
|
+
end
|
92
|
+
|
93
|
+
it "if an officer exists and returns false if it does not" do
|
94
|
+
expect(@user.officer_of?(@adhoc)).to be false
|
95
|
+
end
|
96
|
+
|
80
97
|
it "if an invitation exists and returns true if it does" do
|
81
98
|
@adhoc.invite_member(@user)
|
82
99
|
expect(@user.invited_to?(@adhoc)).to be true
|
@@ -142,6 +159,16 @@ module Adhocracy
|
|
142
159
|
expect(@user.join_group(@adhoc).valid?).to be false
|
143
160
|
end
|
144
161
|
|
162
|
+
it "creating officers" do
|
163
|
+
@user.promote(@adhoc)
|
164
|
+
expect(@user.administrations).to include @adhoc
|
165
|
+
end
|
166
|
+
|
167
|
+
it "not creating duplicate officers" do
|
168
|
+
@user.promote(@adhoc)
|
169
|
+
expect(@user.promote(@adhoc)).to be false
|
170
|
+
end
|
171
|
+
|
145
172
|
it "requesting memberships" do
|
146
173
|
@user.request_membership_in(@adhoc)
|
147
174
|
expect(@user.membership_requests).to include @adhoc
|
@@ -181,5 +208,40 @@ module Adhocracy
|
|
181
208
|
end
|
182
209
|
end
|
183
210
|
|
211
|
+
context "promotes members to officers" do
|
212
|
+
before :each do
|
213
|
+
@adhoc = FactoryGirl.create(:adhoc)
|
214
|
+
@user = FactoryGirl.create(:user)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "if the member is a non-officer" do
|
218
|
+
@user.promote(@adhoc)
|
219
|
+
expect(@adhoc.officers).to include @user
|
220
|
+
end
|
221
|
+
|
222
|
+
it "but returns false if the member is already an officer" do
|
223
|
+
@user.promote(@adhoc)
|
224
|
+
expect(@user.promote(@adhoc)).to be false
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context "demotes officers" do
|
229
|
+
before :each do
|
230
|
+
@adhoc = FactoryGirl.create(:adhoc)
|
231
|
+
@user = FactoryGirl.create(:user)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "if the member is an officer" do
|
235
|
+
@user.promote(@adhoc)
|
236
|
+
@user.demote(@adhoc)
|
237
|
+
expect(@adhoc.officers).to_not include @user
|
238
|
+
end
|
239
|
+
|
240
|
+
it "but returns false if the member is not an officer" do
|
241
|
+
@adhoc.add_member(@user)
|
242
|
+
expect(@user.demote(@adhoc)).to be false
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
184
246
|
end
|
185
247
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adhocracy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- timothycommoner
|
@@ -256,47 +256,47 @@ test_files:
|
|
256
256
|
- spec/lib/adhocracy/acts_as_group_spec.rb
|
257
257
|
- spec/lib/adhocracy/acts_as_member_spec.rb
|
258
258
|
- spec/dummy/README.rdoc
|
259
|
-
- spec/dummy/app/helpers/application_helper.rb
|
260
|
-
- spec/dummy/app/views/layouts/application.html.erb
|
261
|
-
- spec/dummy/app/assets/stylesheets/application.css
|
262
|
-
- spec/dummy/app/assets/javascripts/application.js
|
263
|
-
- spec/dummy/app/models/adhoc.rb
|
264
|
-
- spec/dummy/app/models/user.rb
|
265
|
-
- spec/dummy/app/controllers/application_controller.rb
|
266
|
-
- spec/dummy/db/migrate/20140306214611_create_users.rb
|
267
|
-
- spec/dummy/db/migrate/20140306214620_create_adhocs.rb
|
268
|
-
- spec/dummy/db/schema.rb
|
269
|
-
- spec/dummy/public/422.html
|
270
|
-
- spec/dummy/public/404.html
|
271
|
-
- spec/dummy/public/favicon.ico
|
272
|
-
- spec/dummy/public/500.html
|
273
|
-
- spec/dummy/Rakefile
|
274
259
|
- spec/dummy/bin/rails
|
275
260
|
- spec/dummy/bin/bundle
|
276
261
|
- spec/dummy/bin/rake
|
262
|
+
- spec/dummy/config.ru
|
263
|
+
- spec/dummy/db/schema.rb
|
264
|
+
- spec/dummy/db/migrate/20140306214611_create_users.rb
|
265
|
+
- spec/dummy/db/migrate/20140306214620_create_adhocs.rb
|
266
|
+
- spec/dummy/config/routes.rb
|
267
|
+
- spec/dummy/config/application.rb
|
268
|
+
- spec/dummy/config/environments/test.rb
|
269
|
+
- spec/dummy/config/environments/development.rb
|
270
|
+
- spec/dummy/config/environments/production.rb
|
277
271
|
- spec/dummy/config/initializers/mime_types.rb
|
278
|
-
- spec/dummy/config/initializers/
|
272
|
+
- spec/dummy/config/initializers/session_store.rb
|
279
273
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
280
274
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
281
|
-
- spec/dummy/config/initializers/session_store.rb
|
282
275
|
- spec/dummy/config/initializers/filter_parameter_logging.rb
|
283
276
|
- spec/dummy/config/initializers/secret_token.rb
|
284
|
-
- spec/dummy/config/
|
285
|
-
- spec/dummy/config/environments/test.rb
|
286
|
-
- spec/dummy/config/environments/development.rb
|
287
|
-
- spec/dummy/config/environments/production.rb
|
277
|
+
- spec/dummy/config/initializers/inflections.rb
|
288
278
|
- spec/dummy/config/boot.rb
|
289
|
-
- spec/dummy/config/
|
279
|
+
- spec/dummy/config/database.yml
|
290
280
|
- spec/dummy/config/locales/en.yml
|
291
281
|
- spec/dummy/config/environment.rb
|
292
|
-
- spec/dummy/
|
293
|
-
- spec/dummy/
|
294
|
-
- spec/
|
282
|
+
- spec/dummy/Rakefile
|
283
|
+
- spec/dummy/public/500.html
|
284
|
+
- spec/dummy/public/404.html
|
285
|
+
- spec/dummy/public/422.html
|
286
|
+
- spec/dummy/public/favicon.ico
|
287
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
288
|
+
- spec/dummy/app/helpers/application_helper.rb
|
289
|
+
- spec/dummy/app/assets/javascripts/application.js
|
290
|
+
- spec/dummy/app/assets/stylesheets/application.css
|
291
|
+
- spec/dummy/app/controllers/application_controller.rb
|
292
|
+
- spec/dummy/app/models/user.rb
|
293
|
+
- spec/dummy/app/models/adhoc.rb
|
294
|
+
- spec/factories/adhocracy_memberships.rb
|
295
295
|
- spec/factories/adhocracy_membership_requests.rb
|
296
|
-
- spec/factories/users.rb
|
297
296
|
- spec/factories/adhocracy_membership_invitations.rb
|
298
|
-
- spec/factories/adhocracy_memberships.rb
|
299
297
|
- spec/factories/adhoc.rb
|
298
|
+
- spec/factories/users.rb
|
299
|
+
- spec/spec_helper.rb
|
300
|
+
- spec/models/adhocracy/membership_invitation_spec.rb
|
300
301
|
- spec/models/adhocracy/membership_spec.rb
|
301
302
|
- spec/models/adhocracy/membership_request_spec.rb
|
302
|
-
- spec/models/adhocracy/membership_invitation_spec.rb
|