|
1 | 1 | require "test_helper" |
2 | 2 |
|
3 | 3 | class Identity::JoinableTest < ActiveSupport::TestCase |
4 | | - test "join" do |
| 4 | + test "join creates a new user and returns true" do |
5 | 5 | identity = identities(:david) |
6 | 6 |
|
7 | | - user = identity.join(accounts(:initech)) |
8 | | - assert_kind_of User, user |
9 | | - assert_equal accounts(:initech), user.account |
| 7 | + assert_difference -> { User.count }, 1 do |
| 8 | + result = identity.join(accounts(:initech)) |
| 9 | + assert result, "join should return true when creating a new user" |
| 10 | + end |
| 11 | + |
| 12 | + user = identity.users.find_by!(account: accounts(:initech)) |
10 | 13 | assert_equal identity.email_address, user.name |
| 14 | + end |
11 | 15 |
|
| 16 | + test "join with custom attributes" do |
12 | 17 | identity = identities(:mike) |
13 | 18 |
|
14 | | - user = identity.join(accounts("37s"), name: "Mike") |
15 | | - assert_kind_of User, user |
16 | | - assert_equal accounts("37s"), user.account |
| 19 | + result = identity.join(accounts("37s"), name: "Mike") |
| 20 | + assert result |
| 21 | + |
| 22 | + user = identity.users.find_by!(account: accounts("37s")) |
17 | 23 | assert_equal "Mike", user.name |
18 | 24 | end |
19 | 25 |
|
20 | | - test "member_of?" do |
| 26 | + test "join returns false if user already exists" do |
21 | 27 | identity = identities(:david) |
22 | | - assert identity.member_of?(accounts("37s")) |
23 | | - assert_not identity.member_of?(accounts(:initech)) |
| 28 | + account = accounts("37s") |
| 29 | + |
| 30 | + assert identity.users.exists?(account: account), "David should already be a member of 37s" |
| 31 | + |
| 32 | + assert_no_difference -> { User.count } do |
| 33 | + result = identity.join(account) |
| 34 | + assert_not result, "join should return false when user already exists" |
| 35 | + end |
24 | 36 | end |
25 | 37 | end |
0 commit comments