|
1 | 1 | require "../spec_helper" |
2 | 2 |
|
3 | | -describe App::Models::OrganizationUser do |
4 | | - org_user = App::Models::OrganizationUser.new |
5 | | - org = App::Models::Organization.new |
6 | | - user = App::Models::User.new |
7 | | - |
8 | | - Spec.around_each do |test| |
9 | | - org_user = App::Models::OrganizationUser.new |
10 | | - org = App::Models::Organization.new |
11 | | - org.name = "Testing" |
12 | | - org.save! |
13 | | - |
14 | | - user = App::Models::User.new |
15 | | - user.name = "Testing" |
16 | | - user.email = "steve@orguser.com" |
17 | | - user.save! |
18 | | - |
19 | | - test.run |
20 | | - |
21 | | - org_user.destroy |
22 | | - org.destroy |
23 | | - user.destroy |
24 | | - end |
| 3 | +module App::Models |
| 4 | + describe OrganizationUser do |
| 5 | + org = Organization.new |
| 6 | + user = User.new |
| 7 | + |
| 8 | + Spec.around_each do |test| |
| 9 | + org = Organization.new(name: "Testing").save! |
| 10 | + user = User.new(name: "Testing", email: "steve@orguser.com").save! |
| 11 | + |
| 12 | + test.run |
| 13 | + |
| 14 | + org.destroy |
| 15 | + user.destroy |
| 16 | + end |
| 17 | + |
| 18 | + it "should be able to associate a user with an organisation" do |
| 19 | + org.add user |
| 20 | + org.users.to_a.map(&.id).first?.should eq user.id |
| 21 | + user.organizations.first.id.should eq org.id |
| 22 | + end |
| 23 | + |
| 24 | + it "should be able to associate multiple users with an organisation" do |
| 25 | + user2 = User.new(name: "User2", email: "user2@org.com").save! |
| 26 | + user3 = User.new(name: "User3", email: "user3@org.com").save! |
| 27 | + |
| 28 | + org.add user |
| 29 | + org.add user2 |
| 30 | + |
| 31 | + org.users.map(&.id).to_set.should eq [user.id, user2.id].to_set |
| 32 | + user3.organizations.to_a.should be_empty |
| 33 | + |
| 34 | + user2.destroy |
| 35 | + user3.destroy |
| 36 | + # we've left the original user |
| 37 | + OrganizationUser.all.count.should eq 1 |
| 38 | + end |
| 39 | + |
| 40 | + it "should be able to associate multiple organisations with a user" do |
| 41 | + org2 = Organization.new(name: "org2").save! |
| 42 | + org3 = Organization.new(name: "org3").save! |
| 43 | + |
| 44 | + org.add user |
| 45 | + org2.add user |
| 46 | + |
| 47 | + user.organizations.map(&.id).to_set.should eq [org.id, org2.id].to_set |
| 48 | + org3.users.to_a.should be_empty |
| 49 | + |
| 50 | + org2.destroy |
| 51 | + org3.destroy |
| 52 | + # we've left the original org |
| 53 | + OrganizationUser.all.count.should eq 1 |
| 54 | + end |
| 55 | + |
| 56 | + it "use helper functions to manage users" do |
| 57 | + user2 = User.new(name: "User2", email: "user2@org.com").save! |
| 58 | + user3 = User.new(name: "User3", email: "user3@org.com").save! |
| 59 | + |
| 60 | + org.add user |
| 61 | + org.add user2 |
| 62 | + org.add user3 |
| 63 | + org.users.map(&.id).to_set.should eq [user.id, user2.id, user3.id].to_set |
| 64 | + |
| 65 | + org.remove user |
| 66 | + org.remove user2 |
| 67 | + org.users.count.should eq 1 |
| 68 | + org.remove user3 |
| 69 | + org.users.count.should eq 0 |
| 70 | + OrganizationUser.all.count.should eq 0 |
25 | 71 |
|
26 | | - it "should be able to associate a user with an organisation" do |
27 | | - org_user.user = user |
28 | | - org_user.organization = org |
29 | | - org_user.permission = App::Permissions::Admin |
30 | | - org_user.save! |
| 72 | + user2.destroy |
| 73 | + user3.destroy |
| 74 | + end |
31 | 75 | end |
32 | 76 | end |
0 commit comments