invitational 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/Rakefile +6 -1
  4. data/lib/invitational/version.rb +1 -1
  5. data/spec/internal/app/models/ability.rb +28 -0
  6. data/spec/internal/app/models/child.rb +5 -0
  7. data/spec/internal/app/models/entity.rb +9 -0
  8. data/spec/internal/app/models/grandparent.rb +9 -0
  9. data/spec/internal/app/models/invitation.rb +10 -0
  10. data/spec/internal/app/models/other_entity.rb +7 -0
  11. data/spec/internal/app/models/system_thing.rb +5 -0
  12. data/spec/internal/app/models/user.rb +6 -0
  13. data/spec/internal/config/database.yml +3 -0
  14. data/spec/internal/config/routes.rb +3 -0
  15. data/spec/internal/db/combustion_test.sqlite +0 -0
  16. data/spec/internal/db/schema.rb +35 -0
  17. data/spec/internal/log/test.log +5958 -0
  18. data/spec/internal/public/favicon.ico +0 -0
  19. data/spec/invitational/models/ability_spec.rb +94 -0
  20. data/spec/invitational/models/entity_spec.rb +51 -0
  21. data/spec/invitational/models/invitation_spec.rb +145 -0
  22. data/spec/invitational/models/user_spec.rb +107 -0
  23. data/spec/invitational/services/checks_for_invitation_spec.rb +91 -0
  24. data/spec/invitational/services/claims_all_invitations_spec.rb +29 -0
  25. data/spec/invitational/services/claims_invitation_spec.rb +49 -0
  26. data/spec/invitational/services/creates_invitation_spec.rb +55 -0
  27. data/spec/invitational/services/creates_system_user_invitation_spec.rb +52 -0
  28. data/spec/invitational/services/creates_uber_admin_invitation_spec.rb +52 -0
  29. data/spec/invitational/services/service_helper.rb +78 -0
  30. data/spec/spec_helper.rb +18 -0
  31. metadata +60 -8
File without changes
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+ require 'cancan/matchers'
3
+ require 'invitational/services/service_helper'
4
+
5
+ describe Ability do
6
+
7
+ Given(:user1) { setup_user "test1@d-i.co" }
8
+ Given(:user2) { setup_user "test2@d-i.co" }
9
+ Given(:user3) { setup_user "test3@d-i.co" }
10
+ Given(:user4) { setup_user "test4@d-i.co" }
11
+ Given(:user5) { setup_user "test5@d-i.co" }
12
+
13
+ Given(:entity1) { setup_entity "Test entity 1"}
14
+ Given(:entity2) { setup_entity "Test entity 2"}
15
+ Given(:child1) {setup_child "Child 1", entity2}
16
+ Given(:grandparent) {setup_grandparent "A Grandparent", entity2}
17
+
18
+ Given(:other_entity) { setup_other_entity "Test other entity"}
19
+ Given(:system_thing) { setup_system_thing "A System Object" }
20
+
21
+ Given {invite_user user1, entity1, :user}
22
+ Given {invite_user user2, entity2, :admin}
23
+ Given {invite_user user5, grandparent, :admin}
24
+
25
+ Given {invite_uber_admin user3}
26
+ Given {invite_system_role user4, :employer}
27
+
28
+ context "User" do
29
+ Given (:i) { Ability.new(user1) }
30
+ When (:role) {:user}
31
+
32
+ Then { i.should be_able_to(:read, entity1) }
33
+ And { i.should_not be_able_to(:manage, entity1) }
34
+ And { i.should_not be_able_to(:read, entity2) }
35
+ end
36
+
37
+ context "Admin" do
38
+ Given (:i) { Ability.new(user2) }
39
+ When (:role) {:admin}
40
+
41
+ Then { i.should be_able_to(:read, entity2) }
42
+ And { i.should be_able_to(:manage, entity2) }
43
+ And { i.should_not be_able_to(:read, entity1) }
44
+ end
45
+
46
+ context "System - Employer" do
47
+ Given (:i) { Ability.new(user4) }
48
+ When (:role) {:employer}
49
+
50
+ Then { i.should be_able_to(:manage, system_thing) }
51
+ end
52
+
53
+ context "Uber Admin" do
54
+ Given (:i) { Ability.new(user3) }
55
+ When (:role) {:uberadmin}
56
+
57
+ Then { i.should be_able_to(:manage, entity1) }
58
+ And { i.should be_able_to(:manage, entity2) }
59
+ And {i.should be_able_to(:manage, child1)}
60
+ And { i.should be_able_to(:manage, other_entity) }
61
+ And { i.should be_able_to(:manage, system_thing) }
62
+ end
63
+
64
+ context "Uber Admin only permissions" do
65
+ Given (:i) { Ability.new(user3) }
66
+ When (:role) {:uberadmin}
67
+
68
+ Then { i.should be_able_to(:manage, other_entity) }
69
+ end
70
+
71
+ context "Cascading Permissions" do
72
+ context "One level" do
73
+ Given (:i) { Ability.new(user2) }
74
+ When (:role) {:admin}
75
+
76
+ Then {i.should be_able_to(:manage, child1)}
77
+ end
78
+
79
+ context "Two levels" do
80
+ Given (:i) { Ability.new(user5) }
81
+ When (:role) {:admin}
82
+
83
+ Then {i.should be_able_to(:manage, child1)}
84
+ end
85
+ end
86
+
87
+ context "Access to everybody" do
88
+ Given (:i) { Ability.new(user1) }
89
+ When (:role) {:admin}
90
+
91
+ Then {i.should be_able_to(:read, child1) }
92
+ end
93
+
94
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe Entity do
5
+ Given {no_invitations_exist}
6
+
7
+ Given(:user) { setup_user "test1@d-i.co" }
8
+ Given(:entity) { setup_entity "Test entity 1"}
9
+
10
+ context "relationships" do
11
+ When {invite_user user, entity, :admin}
12
+
13
+ Then {entity.admins.should include(user)}
14
+ end
15
+
16
+ context "inviting" do
17
+ context "Users can be invited with a defined role" do
18
+ When(:result) {entity.invite user, :admin}
19
+
20
+ Then {result.should_not be_nil}
21
+ And {result.invitable.should == entity}
22
+ And {result.user.should == user }
23
+ And {result.role.should == :admin}
24
+ And {result.claimed?.should be_true}
25
+ end
26
+
27
+ context "Users cannot be invited again if they are already invited" do
28
+ Given {invite_user user, entity, :admin}
29
+
30
+ When(:result) {entity.invite user, :user}
31
+
32
+ Then { expect(result).to have_failed(Invitational::AlreadyInvitedError) }
33
+ end
34
+
35
+ context "Users cannot be invited with a role that isn't defined on the entity" do
36
+ When(:result) {entity.invite user, :client}
37
+
38
+ Then { expect(result).to have_failed(Invitational::InvalidRoleError) }
39
+ end
40
+ end
41
+
42
+ context "cleans up invitations when an entity is deleted" do
43
+ Given! (:invite) {invite_user user, entity, :admin}
44
+ Given {entity.destroy}
45
+
46
+ When (:result) {Invitation.find(invite.id)}
47
+
48
+ Then {expect(result).to have_failed(ActiveRecord::RecordNotFound)}
49
+ end
50
+
51
+ end
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe Invitational::Invitation do
5
+ Given {no_invitations_exist}
6
+
7
+ Given(:user1) { setup_user "test1@d-i.co" }
8
+ Given(:user2) { setup_user "test2@d-i.co" }
9
+ Given(:user3) { setup_user "test3@d-i.co" }
10
+ Given(:user4) { setup_user "test4@d-i.co" }
11
+ Given(:user5) { setup_user "test5@d-i.co" }
12
+
13
+ Given(:entity1) { setup_entity "Test entity 1"}
14
+ Given(:entity2) { setup_entity "Test entity 2"}
15
+ Given(:entity3) { setup_entity "Test entity 3"}
16
+
17
+ Given (:unclaimed) {invite_by_email user1.email, entity1, :user}
18
+ Given (:claimed) {invite_user user2, entity2, :admin}
19
+ Given (:uber_admin) {invite_uber_admin user3}
20
+
21
+ context "Initialization" do
22
+ context "Creates Claim hash and date sent on creation" do
23
+ Given(:new_invite) {Invitation.new(email: "test999@d-i.co", invitable: entity1, role: :user)}
24
+
25
+ When {new_invite.save}
26
+
27
+ Then {new_invite.claim_hash.should_not be_nil}
28
+ And {new_invite.date_sent.should_not be_nil}
29
+ end
30
+ end
31
+
32
+ context "Role Title" do
33
+ context "Standard Role" do
34
+ Then {unclaimed.role_title.should == "User"}
35
+ end
36
+
37
+ context "Uber Admin" do
38
+ Then {uber_admin.role_title.should == "Uber Admin"}
39
+ end
40
+ end
41
+
42
+ context "Type" do
43
+ context "Standard Role" do
44
+ Then {unclaimed.uberadmin?.should_not be_true}
45
+ And {claimed.uberadmin?.should_not be_true}
46
+ end
47
+
48
+ context "Uber Admin" do
49
+ Then {uber_admin.uberadmin?.should be_true}
50
+ end
51
+ end
52
+
53
+ context "Claim Status" do
54
+ context "Unclaimed" do
55
+ Then {unclaimed.claimed?.should_not be_true}
56
+ And {unclaimed.unclaimed?.should be_true}
57
+ end
58
+
59
+ context "Claimed" do
60
+ Then {claimed.claimed?.should be_true}
61
+ And {claimed.unclaimed?.should_not be_true}
62
+ end
63
+ end
64
+
65
+ context "Claiming" do
66
+ context "By Hash" do
67
+ When (:result) {Invitation.claim unclaimed.claim_hash, user1}
68
+
69
+ Then { result.id.should == unclaimed.id}
70
+ And { user1.invitations.should include(result) }
71
+ end
72
+
73
+ context "All for a given user" do
74
+ Given {invite_by_email user4.email, entity3, :user}
75
+
76
+ When (:result) {Invitation.claim_all_for user4}
77
+
78
+ Then {user4.entities.should include(entity3)}
79
+ end
80
+ end
81
+
82
+ context "Invites Uberadmin" do
83
+ context "By email" do
84
+ When (:result) {Invitation.invite_uberadmin user4.email}
85
+
86
+ Then {result.should_not be_nil}
87
+ And {result.invitable.should be_nil}
88
+ And {result.email.should == user4.email}
89
+ And {result.role.should == :uberadmin }
90
+ And {result.unclaimed?.should be_true}
91
+ end
92
+
93
+ context "Existing user" do
94
+ When (:result) {Invitation.invite_uberadmin user4}
95
+
96
+ Then {result.should_not be_nil}
97
+ And {result.invitable.should be_nil}
98
+ And {result.email.should == user4.email}
99
+ And {result.role.should == :uberadmin}
100
+ And {result.claimed?.should be_true}
101
+ And {result.user.should == user4 }
102
+ end
103
+
104
+ context "When already invited" do
105
+ Given {invite_uber_admin user4}
106
+
107
+ When (:result) {Invitation.invite_uberadmin user4}
108
+
109
+ Then { expect(result).to have_failed(Invitational::AlreadyInvitedError) }
110
+ end
111
+
112
+ context "Invites to System Role" do
113
+ context "By email" do
114
+ When (:result) {Invitation.invite_system_user user4.email, :employer}
115
+
116
+ Then {result.should_not be_nil}
117
+ And {result.invitable.should be_nil}
118
+ And {result.email.should == user4.email}
119
+ And {result.role.should == :employer }
120
+ And {result.unclaimed?.should be_true}
121
+ end
122
+
123
+ context "Existing user" do
124
+ When (:result) {Invitation.invite_system_user user4, :employer}
125
+
126
+ Then {result.should_not be_nil}
127
+ And {result.invitable.should be_nil}
128
+ And {result.email.should == user4.email}
129
+ And {result.role.should == :employer}
130
+ And {result.claimed?.should be_true}
131
+ And {result.user.should == user4 }
132
+ end
133
+
134
+ context "When already invited" do
135
+ Given {invite_system_role user4, :employer}
136
+
137
+ When (:result) {Invitation.invite_system_user user4, :employer}
138
+
139
+ Then { expect(result).to have_failed(Invitational::AlreadyInvitedError) }
140
+ end
141
+ end
142
+ end
143
+
144
+
145
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe User do
5
+ Given {no_invitations_exist}
6
+
7
+ Given(:user1) { setup_user "test1@d-i.co" }
8
+ Given(:user2) { setup_user "test2@d-i.co" }
9
+ Given(:user3) { setup_user "test2@d-i.co" }
10
+
11
+ Given(:entity1) { setup_entity "Test entity 1"}
12
+
13
+ context 'invited_to creates a has_many_through relationship' do
14
+ When {invite_user user1, entity1, :admin}
15
+
16
+ Then {user1.entities.should include(entity1)}
17
+ And {user1.children.count.should == 0}
18
+ end
19
+
20
+ context 'indicates if a user is an uberadmin' do
21
+ context 'when an uberadmin' do
22
+ When {invite_uber_admin user2}
23
+
24
+ Then {user2.uberadmin?.should be_true}
25
+ end
26
+
27
+ context 'when not an uberadmin' do
28
+ When {invite_user user1, entity1, :admin}
29
+
30
+ Then {user1.uberadmin?.should_not be_true}
31
+ end
32
+ end
33
+
34
+ context 'checks to see if a user is invited to a given system role' do
35
+ context 'when an invited' do
36
+ When {invite_system_role user2, :employer}
37
+
38
+ Then {user2.invited_to_system?(:employer).should be_true}
39
+ end
40
+
41
+ context 'when not invited' do
42
+ When {invite_user user1, entity1, :admin}
43
+
44
+ Then {user1.invited_to_system?(:employer).should_not be_true}
45
+ end
46
+ end
47
+
48
+ context 'checks to see if a user is invited to a given entity' do
49
+
50
+ context 'for any role' do
51
+ context 'when invited' do
52
+ When {invite_user user1, entity1, :admin}
53
+
54
+ Then {user1.invited_to?(entity1).should be_true}
55
+ end
56
+
57
+ context 'when not invited' do
58
+ When {invite_user user2, entity1, :admin}
59
+
60
+ Then {user1.invited_to?(entity1).should_not be_true}
61
+ end
62
+ end
63
+
64
+
65
+ context 'for a specific role' do
66
+ When {invite_user user1, entity1, :admin}
67
+
68
+ context 'when invited' do
69
+ Then {user1.invited_to?(entity1, :admin).should be_true}
70
+ end
71
+
72
+ context 'when not invited' do
73
+ Then {user2.invited_to?(entity1, :admin).should_not be_true}
74
+ end
75
+
76
+ context 'when invited to a different role' do
77
+ Then {user1.invited_to?(entity1, :user).should_not be_true}
78
+ end
79
+ end
80
+
81
+ end
82
+
83
+ context "cleans up invitations when a user is deleted" do
84
+ Given! (:invite) {invite_user user1, entity1, :admin}
85
+ Given {user1.destroy}
86
+
87
+ When (:result) {Invitation.find(invite.id)}
88
+
89
+ Then {expect(result).to have_failed(ActiveRecord::RecordNotFound)}
90
+ end
91
+
92
+ context "creates named scopes for system roles" do
93
+ context 'when an uberadmin' do
94
+ When {invite_uber_admin user2}
95
+ Then {User.uberadmins.should include(user2)}
96
+ And {User.uberadmins.should_not include(user1)}
97
+ end
98
+
99
+ context 'when an employer' do
100
+ When {invite_system_role user2, :employer}
101
+ Then {User.employers.should include(user2)}
102
+ And {User.employers.should_not include(user1)}
103
+ end
104
+ end
105
+
106
+ end
107
+
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe Invitational::ChecksForInvitation do
5
+ Given {no_invitations_exist}
6
+
7
+ Given(:user1) { setup_user "test1@d-i.co" }
8
+ Given(:user2) { setup_user "test2@d-i.co" }
9
+ Given(:user3) { setup_user "test3@d-i.co" }
10
+
11
+ Given(:entity) { setup_entity "Test entity"}
12
+
13
+ Given {invite_user user1, entity, :user}
14
+ Given {invite_uber_admin user3}
15
+
16
+ context "checking for any role" do
17
+
18
+ context "when invited" do
19
+ When(:result) { Invitational::ChecksForInvitation.for user1, entity }
20
+
21
+ Then {result.should be_true}
22
+ end
23
+
24
+ context "when not invited" do
25
+ When(:result) { Invitational::ChecksForInvitation.for user2, entity }
26
+
27
+ Then {result.should_not be_true}
28
+ end
29
+
30
+ context "when uber admin" do
31
+ When(:result) { Invitational::ChecksForInvitation.for user3, entity }
32
+
33
+ Then {result.should be_true}
34
+ end
35
+
36
+ end
37
+
38
+ context "checking for specific role" do
39
+ context "when invited in that role" do
40
+ When(:result) { Invitational::ChecksForInvitation.for user1, entity, :user }
41
+
42
+ Then {result.should be_true}
43
+ end
44
+
45
+ context "when invited in another role" do
46
+ When(:result) { Invitational::ChecksForInvitation.for user1, entity, :admin }
47
+
48
+ Then {result.should_not be_true}
49
+ end
50
+
51
+ context "when not invited" do
52
+ When(:result) { Invitational::ChecksForInvitation.for user2, entity, :user }
53
+
54
+ Then {result.should_not be_true}
55
+ end
56
+
57
+ context "when uber admin" do
58
+ When(:result) { Invitational::ChecksForInvitation.for user3, entity, :user }
59
+
60
+ Then {result.should be_true}
61
+ end
62
+ end
63
+
64
+ context "checking for any of an array of roles" do
65
+ context "when invited to one of the roles" do
66
+ When(:result) { Invitational::ChecksForInvitation.for user1, entity, [:user, :admin] }
67
+
68
+ Then {result.should be_true}
69
+ end
70
+
71
+ context "when invited in another role" do
72
+ When(:result) { Invitational::ChecksForInvitation.for user1, entity, [:none, :admin] }
73
+
74
+ Then {result.should_not be_true}
75
+ end
76
+
77
+ context "when not invited" do
78
+ When(:result) { Invitational::ChecksForInvitation.for user2, entity, [:user, :admin] }
79
+
80
+ Then {result.should_not be_true}
81
+ end
82
+
83
+ context "when uber admin" do
84
+ When(:result) { Invitational::ChecksForInvitation.for user3, entity, [:user, :admin] }
85
+
86
+ Then {result.should be_true}
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe Invitational::ClaimsAllInvitations do
5
+ Given {no_invitations_exist}
6
+
7
+ Given(:user) { setup_user "test@d-i.co" }
8
+ Given(:entity1) { setup_entity "Test entity 1"}
9
+ Given(:entity2) { setup_entity "Test entity 2"}
10
+
11
+ context "with pending invitation for email" do
12
+ Given!(:invitation1) {invite_by_email user.email, entity1, :user}
13
+ Given!(:invitation2) {invite_by_email user.email, entity2, :user}
14
+
15
+ When { Invitational::ClaimsAllInvitations.for user }
16
+
17
+ Then { user.invitations.should include(invitation1) }
18
+ And { user.invitations.should include(invitation2) }
19
+ end
20
+
21
+ context "with pending invitation for another email" do
22
+ Given!(:invitation) {invite_by_email "foo@d-i.co", entity1, :user}
23
+
24
+ When { Invitational::ClaimsAllInvitations.for user }
25
+
26
+ Then { user.invitations.should_not include(invitation) }
27
+ end
28
+
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe Invitational::ClaimsInvitation do
5
+ Given {no_invitations_exist}
6
+
7
+ Given(:user) { setup_user "test@d-i.co" }
8
+ Given(:entity) { setup_entity "Test entity"}
9
+
10
+ context "for unclaimed invitation" do
11
+ context "invitation is to the user's email" do
12
+ Given!(:invitation) {invite_by_email user.email, entity, :admin}
13
+
14
+ When (:result) { Invitational::ClaimsInvitation.for invitation.claim_hash, user }
15
+
16
+ Then { result.should == invitation}
17
+ And { user.invitations.should include(invitation) }
18
+ end
19
+
20
+ context "invitation is to another email" do
21
+ Given!(:invitation) {invite_by_email "foo@d-i.co", entity, :admin}
22
+
23
+ When (:result) { Invitational::ClaimsInvitation.for invitation.claim_hash, user }
24
+
25
+ Then { result.should == invitation}
26
+ And { user.invitations.should include(invitation) }
27
+ end
28
+ end
29
+
30
+ context "for claimed invitation" do
31
+ Given(:user2) {setup_user "foo@bar.com"}
32
+ Given(:invitation) {invite_user user2, entity, :admin}
33
+
34
+ When (:result) { Invitational::ClaimsInvitation.for invitation.claim_hash, user }
35
+
36
+ Then { expect(result).to have_failed(Invitational::AlreadyClaimedError) }
37
+ And { user.invitations.should_not include(invitation) }
38
+ end
39
+
40
+ context "If the invitation hash is bad" do
41
+ Given!(:invitation) {invite_by_email user.email, entity, :admin}
42
+
43
+ When (:result) { Invitational::ClaimsInvitation.for "THIS_IS_A_BAD_HASH", user }
44
+
45
+ Then { expect(result).to have_failed(Invitational::InvitationNotFoundError) }
46
+ And { user.invitations.should_not include(invitation) }
47
+ end
48
+
49
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe Invitational::CreatesInvitation do
5
+ Given {no_invitations_exist}
6
+
7
+ Given(:entity) { setup_entity "Test Entity"}
8
+
9
+ context "by email" do
10
+
11
+ context "when not already invited" do
12
+ When (:result) {Invitational::CreatesInvitation.for entity, "test@d-i.co", :admin}
13
+
14
+ Then {result.should_not be_nil}
15
+ And {result.invitable.should == entity}
16
+ And {result.email.should == "test@d-i.co"}
17
+ And {result.role.should == :admin}
18
+ And {result.unclaimed?.should be_true}
19
+ end
20
+
21
+ context "when already invited" do
22
+ Given {::Invitation.new(invitable: entity, role: :admin, email: 'test@d-i.co').save}
23
+
24
+ When (:result) {Invitational::CreatesInvitation.for entity, "test@d-i.co", :admin}
25
+
26
+ Then { expect(result).to have_failed(Invitational::AlreadyInvitedError) }
27
+ end
28
+
29
+ end
30
+
31
+ context "to be immediately claimed" do
32
+ Given(:user) { setup_user "test@d-i.co" }
33
+
34
+ context "when not already invited" do
35
+ When (:result) {Invitational::CreatesInvitation.for entity, user, :admin}
36
+
37
+ Then {result.should_not be_nil}
38
+ And {result.invitable.should == entity}
39
+ And {result.email.should == "test@d-i.co"}
40
+ And {result.role.should == :admin}
41
+ And {result.claimed?.should be_true}
42
+ And {result.user.should == user }
43
+ end
44
+
45
+ context "when already invited" do
46
+ Given {::Invitation.new(invitable: entity, role: :admin, email: 'test@d-i.co', user: user).save}
47
+
48
+ When (:result) {Invitational::CreatesInvitation.for entity, user, :admin}
49
+
50
+ Then { expect(result).to have_failed(Invitational::AlreadyInvitedError) }
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'invitational/services/service_helper'
3
+
4
+ describe Invitational::CreatesSystemUserInvitation do
5
+ Given {no_invitations_exist}
6
+
7
+ context "by email" do
8
+ context "when not already invited" do
9
+ When (:result) {Invitational::CreatesSystemUserInvitation.for "test@d-i.co", :employer}
10
+
11
+ Then {result.should_not be_nil}
12
+ And {result.invitable.should be_nil}
13
+ And {result.email.should == "test@d-i.co"}
14
+ And {result.role.should == :employer }
15
+ And {result.unclaimed?.should be_true}
16
+ end
17
+
18
+ context "when already invited" do
19
+ Given {::Invitation.new(role: :employer, email: 'test@d-i.co').save}
20
+
21
+ When (:result) {Invitational::CreatesSystemUserInvitation.for "test@d-i.co", :employer}
22
+
23
+ Then { expect(result).to have_failed(Invitational::AlreadyInvitedError) }
24
+ end
25
+
26
+ end
27
+
28
+ context "to be immediately claimed" do
29
+ Given(:user) { setup_user "test2@d-i.co" }
30
+
31
+ context "when not already invited" do
32
+ When (:result) {Invitational::CreatesSystemUserInvitation.for user, :employer}
33
+
34
+ Then {result.should_not be_nil}
35
+ And {result.invitable.should be_nil}
36
+ And {result.email.should == "test2@d-i.co"}
37
+ And {result.role.should == :employer}
38
+ And {result.claimed?.should be_true}
39
+ And {result.user.should == user }
40
+ end
41
+
42
+ context "when already invited" do
43
+ Given {::Invitation.new(role: :employer, email: 'test2@d-i.co', user: user).save}
44
+
45
+ When (:result) {Invitational::CreatesSystemUserInvitation.for user, :employer}
46
+
47
+ Then { expect(result).to have_failed(Invitational::AlreadyInvitedError) }
48
+ end
49
+
50
+ end
51
+
52
+ end