forked from exercism/exercism
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store GitHub user data for v2 prototype
- Loading branch information
Katrina Owen
committed
Aug 24, 2017
1 parent
372702a
commit f961b18
Showing
4 changed files
with
19 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
class Authentication | ||
def self.perform(code, client_id, client_secret, target_profile) | ||
id, username, email, avatar_url = Github.authenticate(code, client_id, client_secret) | ||
User.from_github(id, username, email, avatar_url, target_profile) | ||
id, username, email, avatar_url, bio, name = Github.authenticate(code, client_id, client_secret) | ||
User.from_github(id, username, email, avatar_url, bio, name, target_profile) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,54 +19,55 @@ def test_flipper_id_is_username | |
end | ||
|
||
def test_create_user_from_github | ||
user = User.from_github(23, 'alice', '[email protected]', 'avatar_url', 'polyglot') | ||
user = User.from_github(23, 'alice', '[email protected]', 'avatar_url', 'I am Alice', 'Alice Jones', 'polyglot') | ||
assert_equal 1, User.count | ||
assert_equal 23, user.github_id | ||
assert_equal 'alice', user.username | ||
assert_equal '[email protected]', user.email | ||
assert_equal 'avatar_url', user.avatar_url | ||
assert_equal 'polyglot', user.joined_as | ||
assert_equal 'I am Alice', user.bio | ||
assert_equal 'Alice Jones', user.name | ||
end | ||
|
||
def test_update_username_from_github | ||
User.create(github_id: 23) | ||
user = User.from_github(23, 'bob', nil, nil).reload | ||
user = User.from_github(23, 'bob', nil, nil, nil, nil).reload | ||
assert_equal 'bob', user.username | ||
end | ||
|
||
def test_does_not_overwrite_email_or_joined_as_if_present | ||
User.create(github_id: 23, email: '[email protected]', joined_as: 'polyglot') | ||
user = User.from_github(23, nil, '[email protected]', nil, 'artisan').reload | ||
assert_equal '[email protected]', user.email | ||
def test_does_not_overwrite_joined_as_if_present | ||
User.create(github_id: 23, joined_as: 'polyglot') | ||
user = User.from_github(23, nil, nil, nil, nil, nil, 'artisan').reload | ||
assert_equal 'polyglot', user.joined_as | ||
end | ||
|
||
def test_sets_avatar_url | ||
User.create(github_id: 23) | ||
user = User.from_github(23, nil, nil, 'new?1234').reload | ||
user = User.from_github(23, nil, nil, 'new?1234', nil, nil).reload | ||
assert_equal 'new', user.avatar_url | ||
end | ||
|
||
def test_overwrites_avatar_url_if_present | ||
User.create(github_id: 23, avatar_url: 'old') | ||
user = User.from_github(23, nil, nil, 'new?1234').reload | ||
user = User.from_github(23, nil, nil, 'new?1234', nil, nil).reload | ||
assert_equal 'new', user.avatar_url | ||
end | ||
|
||
def test_from_github_unsets_old_duplicate_username | ||
u1 = User.create(github_id: 23, username: 'alice') | ||
u2 = User.from_github(31, 'alice', nil, nil).reload | ||
u2 = User.from_github(31, 'alice', nil, nil, nil, nil).reload | ||
assert_equal 'alice', u2.username | ||
assert_equal '', u1.reload.username | ||
|
||
# it doesn't overwrite it's own username next time | ||
u3 = User.from_github(31, 'alice', nil, nil).reload | ||
u3 = User.from_github(31, 'alice', nil, nil, nil, nil).reload | ||
assert_equal 'alice', u3.username | ||
end | ||
|
||
def test_from_github_connects_invited_user | ||
u1 = User.create(username: 'alice') | ||
u2 = User.from_github(42, 'alice', '[email protected]', 'avatar').reload | ||
u2 = User.from_github(42, 'alice', '[email protected]', 'avatar', nil, nil).reload | ||
|
||
u1.reload | ||
|
||
|