adhocracy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +13 -5
  2. data/README.rdoc +1 -1
  3. data/app/models/adhocracy/membership.rb +15 -0
  4. data/app/models/adhocracy/membership_invitation.rb +31 -0
  5. data/app/models/adhocracy/membership_request.rb +31 -0
  6. data/config/locales/en.yml +14 -0
  7. data/db/migrate/20140306214416_create_adhocracy_memberships.rb +19 -0
  8. data/db/migrate/20140306214532_create_adhocracy_membership_requests.rb +23 -0
  9. data/db/migrate/20140306214552_create_adhocracy_membership_invitations.rb +23 -0
  10. data/lib/adhocracy/acceptable.rb +18 -0
  11. data/lib/adhocracy/acts_as_group.rb +65 -0
  12. data/lib/adhocracy/acts_as_member.rb +63 -0
  13. data/lib/adhocracy/membership_association.rb +49 -0
  14. data/lib/adhocracy/version.rb +1 -1
  15. data/lib/adhocracy.rb +4 -0
  16. data/spec/dummy/app/models/adhoc.rb +3 -0
  17. data/spec/dummy/app/models/user.rb +3 -0
  18. data/spec/dummy/config/application.rb +1 -0
  19. data/spec/dummy/db/migrate/20140306214611_create_users.rb +6 -0
  20. data/spec/dummy/db/migrate/20140306214620_create_adhocs.rb +6 -0
  21. data/spec/dummy/db/schema.rb +67 -0
  22. data/spec/factories/adhoc.rb +4 -0
  23. data/spec/factories/adhocracy_membership_invitations.rb +8 -0
  24. data/spec/factories/adhocracy_membership_requests.rb +8 -0
  25. data/spec/factories/adhocracy_memberships.rb +7 -0
  26. data/spec/factories/users.rb +4 -0
  27. data/spec/lib/adhocracy/acts_as_group_spec.rb +179 -0
  28. data/spec/lib/adhocracy/acts_as_member_spec.rb +179 -0
  29. data/spec/models/adhocracy/membership_invitation_spec.rb +84 -0
  30. data/spec/models/adhocracy/membership_request_spec.rb +84 -0
  31. data/spec/models/adhocracy/membership_spec.rb +21 -0
  32. metadata +114 -75
  33. data/spec/dummy/log/test.log +0 -0
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhocracy
4
+ describe ActsAsGroup do
5
+
6
+ context "has many" do
7
+ before :each do
8
+ @adhoc = FactoryGirl.build(:adhoc)
9
+ end
10
+
11
+ it "memberships" do
12
+ expect(@adhoc).to have_many(:memberships)
13
+ end
14
+
15
+ it "membership requests" do
16
+ expect(@adhoc).to have_many(:membership_requests)
17
+ end
18
+
19
+ it "membership invitations" do
20
+ expect(@adhoc).to have_many(:membership_invitations)
21
+ end
22
+ end
23
+
24
+ context "produces a list" do
25
+ before :each do
26
+ @adhoc = FactoryGirl.create(:adhoc)
27
+ @user1 = FactoryGirl.create(:user)
28
+ @user2 = FactoryGirl.create(:user)
29
+ @user3 = FactoryGirl.create(:user)
30
+ @user4 = FactoryGirl.create(:user)
31
+ @user5 = FactoryGirl.create(:user)
32
+ @adhoc.add_member(@user1)
33
+ @adhoc.add_member(@user3)
34
+ @adhoc.invite_member(@user4)
35
+ @user5.request_membership_in(@adhoc)
36
+ end
37
+
38
+ it "including all active members" do
39
+ expect(@adhoc.members).to include @user1, @user3
40
+ end
41
+
42
+ it "excluding non-active members" do
43
+ expect(@adhoc.members).to_not include @user2, @user4, @user5
44
+ end
45
+
46
+ it "including all invited members" do
47
+ expect(@adhoc.invited_members).to include @user4
48
+ end
49
+
50
+ it "excluding non-invited members" do
51
+ expect(@adhoc.invited_members).to_not include @user1, @user2, @user3,
52
+ @user5
53
+ end
54
+
55
+ it "including all requested members" do
56
+ expect(@adhoc.membership_requests).to include @user5
57
+ end
58
+
59
+ it "excluding non-requests members" do
60
+ expect(@adhoc.membership_requests).to_not include @user1, @user2,
61
+ @user3, @user4
62
+ end
63
+ end
64
+
65
+ context "checks" do
66
+ before :each do
67
+ @adhoc = FactoryGirl.create(:adhoc)
68
+ @user = FactoryGirl.create(:user)
69
+ end
70
+
71
+ it "if a membership exists and returns true if it does" do
72
+ @adhoc.add_member(@user)
73
+ expect(@adhoc.has_member?(@user)).to be true
74
+ end
75
+
76
+ it "if a membership exists and returns false if it does not" do
77
+ expect(@adhoc.has_member?(@user)).to be false
78
+ end
79
+
80
+ it "if an invitation exists and returns true if it does" do
81
+ @adhoc.invite_member(@user)
82
+ expect(@adhoc.invited?(@user)).to be true
83
+ end
84
+
85
+ it "if an invitation exists and returns false if it does not" do
86
+ expect(@adhoc.invited?(@user)).to be false
87
+ end
88
+
89
+ it "if a pending invitation exists and returns true if it does" do
90
+ @adhoc.invite_member(@user)
91
+ expect(@adhoc.invited?(@user, { pending: true })).to be true
92
+ end
93
+
94
+ it "if a pending invite exists and returns false if it does not" do
95
+ invitation = @adhoc.invite_member(@user)
96
+ invitation.accept
97
+ expect(@adhoc.invited?(@user, { pending: true })).to be false
98
+ end
99
+
100
+ it "if a request exists and returns true if it does" do
101
+ @user.request_membership_in(@adhoc)
102
+ expect(@adhoc.recieved_request_from?(@user)).to be true
103
+ end
104
+
105
+ it "if a request exists and returns false if it does not" do
106
+ expect(@adhoc.recieved_request_from?(@user)).to be false
107
+ end
108
+
109
+ it "if a pending request exists and returns true if it does" do
110
+ @user.request_membership_in(@adhoc)
111
+ expect(@adhoc.recieved_request_from?(@user, { pending: true })).
112
+ to be true
113
+ end
114
+
115
+ it "if a pending request exists and returns false if it does not" do
116
+ request = @user.request_membership_in(@adhoc)
117
+ request.accept
118
+ expect(@adhoc.recieved_request_from?(@user, { pending: true })).
119
+ to be false
120
+ end
121
+ end
122
+
123
+ context "handles prospective members by" do
124
+ before :each do
125
+ @adhoc = FactoryGirl.create(:adhoc)
126
+ @user = FactoryGirl.create(:user)
127
+ end
128
+
129
+ it "creating memberships" do
130
+ @adhoc.add_member(@user)
131
+ expect(@adhoc.members).to include @user
132
+ end
133
+
134
+ it "not creating duplicate memberships" do
135
+ @adhoc.add_member(@user)
136
+ expect(@adhoc.add_member(@user).valid?).to be false
137
+ end
138
+
139
+ it "inviting members" do
140
+ @adhoc.invite_member(@user)
141
+ expect(@adhoc.invited_members).to include @user
142
+ end
143
+
144
+ it "not allowing new invites while one is still pending" do
145
+ @adhoc.invite_member(@user)
146
+ expect(@adhoc.invite_member(@user).valid?).to be false
147
+ end
148
+
149
+ it "not allowing new invites if a previous one was declined" do
150
+ membership_request = @adhoc.invite_member(@user)
151
+ membership_request.decline
152
+ expect(@adhoc.invite_member(@user).valid?).to be false
153
+ end
154
+
155
+ it "not allowing new invites if already a member" do
156
+ @adhoc.add_member(@user)
157
+ expect(@adhoc.invite_member(@user).valid?).to be false
158
+ end
159
+ end
160
+
161
+ context "destroys memberships" do
162
+ before :each do
163
+ @adhoc = FactoryGirl.create(:adhoc)
164
+ @user = FactoryGirl.create(:user)
165
+ end
166
+
167
+ it "if the membership exists" do
168
+ @adhoc.add_member(@user)
169
+ @adhoc.remove_member(@user)
170
+ expect(@adhoc.members).to_not include @user
171
+ end
172
+
173
+ it "but returns false if the membership does not exist" do
174
+ expect(@adhoc.remove_member(@user)).to be false
175
+ end
176
+ end
177
+
178
+ end
179
+ end
@@ -0,0 +1,179 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhocracy
4
+ describe ActsAsMember do
5
+
6
+ context "has many" do
7
+ before :each do
8
+ @user = FactoryGirl.build(:user)
9
+ end
10
+
11
+ it "memberships" do
12
+ expect(@user).to have_many(:memberships)
13
+ end
14
+
15
+ it "membership requests" do
16
+ expect(@user).to have_many(:membership_requests)
17
+ end
18
+
19
+ it "membership invitations" do
20
+ expect(@user).to have_many(:membership_invitations)
21
+ end
22
+ end
23
+
24
+ context "produces a list" do
25
+ before :each do
26
+ @user = FactoryGirl.create(:user)
27
+ @adhoc1 = FactoryGirl.create(:adhoc)
28
+ @adhoc2 = FactoryGirl.create(:adhoc)
29
+ @adhoc3 = FactoryGirl.create(:adhoc)
30
+ @adhoc4 = FactoryGirl.create(:adhoc)
31
+ @adhoc5 = FactoryGirl.create(:adhoc)
32
+ @user.join_group(@adhoc1)
33
+ @user.join_group(@adhoc3)
34
+ @adhoc4.invite_member(@user)
35
+ @user.request_membership_in(@adhoc5)
36
+ end
37
+
38
+ it "including all joined groups" do
39
+ expect(@user.groups).to include @adhoc1, @adhoc3
40
+ end
41
+
42
+ it "excluding non-joined groups" do
43
+ expect(@user.groups).to_not include @adhoc2, @adhoc4, @adhoc5
44
+ end
45
+
46
+ it "including all invited groups" do
47
+ expect(@user.group_invitations).to include @adhoc4
48
+ end
49
+
50
+ it "excluding non-invited groups" do
51
+ expect(@user.group_invitations).to_not include @adhoc1, @adhoc2,
52
+ @adhoc3, @adhoc5
53
+ end
54
+
55
+ it "including all requested groups" do
56
+ expect(@user.membership_requests).to include @adhoc5
57
+ end
58
+
59
+ it "excluding non-requested groups" do
60
+ expect(@user.membership_requests).to_not include @adhoc1, @adhoc2,
61
+ @adhoc3, @adhoc4
62
+ end
63
+ end
64
+
65
+ context "checks" do
66
+ before :each do
67
+ @adhoc = FactoryGirl.create(:adhoc)
68
+ @user = FactoryGirl.create(:user)
69
+ end
70
+
71
+ it "if a membership exists and returns true if it does" do
72
+ @user.join_group(@adhoc)
73
+ expect(@user.member_of?(@adhoc)).to be true
74
+ end
75
+
76
+ it "if a membership exists and returns false if it does not" do
77
+ expect(@user.member_of?(@adhoc)).to be false
78
+ end
79
+
80
+ it "if an invitation exists and returns true if it does" do
81
+ @adhoc.invite_member(@user)
82
+ expect(@user.invited_to?(@adhoc)).to be true
83
+ end
84
+
85
+ it "if an invitation request exists and returns false if it does not" do
86
+ expect(@user.invited_to?(@adhoc)).to be false
87
+ end
88
+
89
+ it "if a pending invitation exists and returns true if it does" do
90
+ @adhoc.invite_member(@user)
91
+ expect(@user.invited_to?(@adhoc, { pending: true })).to be true
92
+ end
93
+
94
+ it "if a pending invite exists and returns false if it does not" do
95
+ invitation = @adhoc.invite_member(@user)
96
+ invitation.accept
97
+ expect(@user.invited_to?(@adhoc, { pending: false })).to be true
98
+ end
99
+
100
+ it "if a request exists and returns true if it does" do
101
+ @user.request_membership_in(@adhoc)
102
+ expect(@user.requested_membership_in?(@adhoc)).to be true
103
+ end
104
+
105
+ it "if a request exists and returns false if it does not" do
106
+ expect(@user.requested_membership_in?(@adhoc)).to be false
107
+ end
108
+
109
+ it "if a pending request exists and returns true if it does" do
110
+ @user.request_membership_in(@adhoc)
111
+ expect(@user.requested_membership_in?(@adhoc, { pending: true })).
112
+ to be true
113
+ end
114
+
115
+ it "if a pending request exists and returns false if it does not" do
116
+ request = @user.request_membership_in(@adhoc)
117
+ request.accept
118
+ expect(@user.requested_membership_in?(@adhoc, { pending: true })).
119
+ to be false
120
+ end
121
+ end
122
+
123
+ context "handles prospective groups by" do
124
+ before :each do
125
+ @adhoc = FactoryGirl.create(:adhoc)
126
+ @user = FactoryGirl.create(:user)
127
+ end
128
+
129
+ it "creating memberships" do
130
+ @user.join_group(@adhoc)
131
+ expect(@user.groups).to include @adhoc
132
+ end
133
+
134
+ it "not creating duplicate memberships" do
135
+ @user.join_group(@adhoc)
136
+ expect(@user.join_group(@adhoc).valid?).to be false
137
+ end
138
+
139
+ it "requesting memberships" do
140
+ @user.request_membership_in(@adhoc)
141
+ expect(@user.membership_requests).to include @adhoc
142
+ end
143
+
144
+ it "not allowing new requests while one is still pending" do
145
+ @user.request_membership_in(@adhoc)
146
+ expect(@user.request_membership_in(@adhoc).valid?).to be false
147
+ end
148
+
149
+ it "not allowing new requests if a previous one was declined" do
150
+ membership_request = @user.request_membership_in(@adhoc)
151
+ membership_request.decline
152
+ expect(@user.request_membership_in(@adhoc).valid?).to be false
153
+ end
154
+
155
+ it "not allowing new requests if already a member" do
156
+ @user.join_group(@adhoc)
157
+ expect(@user.request_membership_in(@adhoc).valid?).to be false
158
+ end
159
+ end
160
+
161
+ context "destroys memberships" do
162
+ before :each do
163
+ @adhoc = FactoryGirl.create(:adhoc)
164
+ @user = FactoryGirl.create(:user)
165
+ end
166
+
167
+ it "if the membership exists" do
168
+ @user.join_group(@adhoc)
169
+ @user.leave_group(@adhoc)
170
+ expect(@user.groups).to_not include @adhoc
171
+ end
172
+
173
+ it "but returns false if the membership does not exist" do
174
+ expect(@user.leave_group(@adhoc)).to be false
175
+ end
176
+ end
177
+
178
+ end
179
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhocracy
4
+ describe MembershipInvitation do
5
+
6
+ context "belongs to" do
7
+ before :each do
8
+ @membership_invitation = FactoryGirl.build(:membership_invitation)
9
+ end
10
+
11
+ it "a member" do
12
+ expect(@membership_invitation).to belong_to(:member)
13
+ end
14
+
15
+ it "a group" do
16
+ expect(@membership_invitation).to belong_to(:group)
17
+ end
18
+ end
19
+
20
+ it "defaults to pending" do
21
+ membership_invitation = FactoryGirl.build(:membership_invitation)
22
+ expect(membership_invitation.pending).to be true
23
+ expect(membership_invitation.accepted).to be false
24
+ expect(membership_invitation.declined).to be false
25
+ end
26
+
27
+ context "can be accepted" do
28
+ before :each do
29
+ @user = FactoryGirl.create(:user)
30
+ @adhoc = FactoryGirl.create(:adhoc)
31
+ @membership_invitation = @adhoc.invite_member(@user)
32
+ end
33
+
34
+ it "if it is still pending" do
35
+ @membership_invitation.accept
36
+ expect(@membership_invitation.pending).to be false
37
+ expect(@membership_invitation.accepted).to be true
38
+ expect(@membership_invitation.declined).to be false
39
+ end
40
+
41
+ it "but not if it isn't pending" do
42
+ @membership_invitation.decline
43
+ @membership_invitation.accept
44
+ expect(@membership_invitation.pending).to be false
45
+ expect(@membership_invitation.accepted).to be false
46
+ expect(@membership_invitation.declined).to be true
47
+ end
48
+
49
+ it "which creates a membership for the group" do
50
+ @membership_invitation.accept
51
+ expect(@adhoc.members).to include @user
52
+ end
53
+ end
54
+
55
+ context "can be declined" do
56
+ before :each do
57
+ @user = FactoryGirl.create(:user)
58
+ @adhoc = FactoryGirl.create(:adhoc)
59
+ @membership_invitation = @adhoc.invite_member(@user)
60
+ end
61
+
62
+ it "if it is still pending" do
63
+ @membership_invitation.decline
64
+ expect(@membership_invitation.pending).to be false
65
+ expect(@membership_invitation.accepted).to be false
66
+ expect(@membership_invitation.declined).to be true
67
+ end
68
+
69
+ it "but not if it isn't pending" do
70
+ @membership_invitation.accept
71
+ @membership_invitation.decline
72
+ expect(@membership_invitation.pending).to be false
73
+ expect(@membership_invitation.accepted).to be true
74
+ expect(@membership_invitation.declined).to be false
75
+ end
76
+
77
+ it "which does not create a membership for the group" do
78
+ @membership_invitation.decline
79
+ expect(@adhoc.members).to_not include @user
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhocracy
4
+ describe MembershipRequest do
5
+
6
+ context "belongs to" do
7
+ before :each do
8
+ @membership_request = FactoryGirl.build(:membership_request)
9
+ end
10
+
11
+ it "a member" do
12
+ expect(@membership_request).to belong_to(:member)
13
+ end
14
+
15
+ it "a group" do
16
+ expect(@membership_request).to belong_to(:group)
17
+ end
18
+ end
19
+
20
+ it "defaults to pending" do
21
+ membership_request = FactoryGirl.build(:membership_request)
22
+ expect(membership_request.pending).to be true
23
+ expect(membership_request.accepted).to be false
24
+ expect(membership_request.declined).to be false
25
+ end
26
+
27
+ context "can be accepted" do
28
+ before :each do
29
+ @user = FactoryGirl.create(:user)
30
+ @adhoc = FactoryGirl.create(:adhoc)
31
+ @membership_request = @user.request_membership_in(@adhoc)
32
+ end
33
+
34
+ it "if it is still pending" do
35
+ @membership_request.accept
36
+ expect(@membership_request.pending).to be false
37
+ expect(@membership_request.accepted).to be true
38
+ expect(@membership_request.declined).to be false
39
+ end
40
+
41
+ it "but not if it isn't pending" do
42
+ @membership_request.decline
43
+ @membership_request.accept
44
+ expect(@membership_request.pending).to be false
45
+ expect(@membership_request.accepted).to be false
46
+ expect(@membership_request.declined).to be true
47
+ end
48
+
49
+ it "which created a membership for the group" do
50
+ @membership_request.accept
51
+ expect(@user.groups).to include @adhoc
52
+ end
53
+ end
54
+
55
+ context "can be declined" do
56
+ before :each do
57
+ @user = FactoryGirl.create(:user)
58
+ @adhoc = FactoryGirl.create(:adhoc)
59
+ @membership_request = @user.request_membership_in(@adhoc)
60
+ end
61
+
62
+ it "if it is still pending" do
63
+ @membership_request.decline
64
+ expect(@membership_request.pending).to be false
65
+ expect(@membership_request.accepted).to be false
66
+ expect(@membership_request.declined).to be true
67
+ end
68
+
69
+ it "but not if it isn't pending" do
70
+ @membership_request.accept
71
+ @membership_request.decline
72
+ expect(@membership_request.pending).to be false
73
+ expect(@membership_request.accepted).to be true
74
+ expect(@membership_request.declined).to be false
75
+ end
76
+
77
+ it "which does not create a membership for the group" do
78
+ @membership_request.decline
79
+ expect(@user.groups).to_not include @adhoc
80
+ end
81
+ end
82
+
83
+ end
84
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ module Adhocracy
4
+ describe Membership do
5
+
6
+ context "belongs to" do
7
+ before :each do
8
+ @membership = FactoryGirl.build(:membership)
9
+ end
10
+
11
+ it "a member" do
12
+ expect(@membership).to belong_to(:member)
13
+ end
14
+
15
+ it "a group" do
16
+ expect(@membership).to belong_to(:group)
17
+ end
18
+ end
19
+
20
+ end
21
+ end