-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Media Ranker Revisited - Angela - Octos #34
base: master
Are you sure you want to change the base?
Changes from all commits
f7fa2fb
80eb376
7f0e89a
0723307
575a020
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,8 @@ | |
!/log/.keep | ||
!/tmp/.keep | ||
|
||
#ignore env file | ||
.env | ||
|
||
# Ignore Byebug command history file. | ||
.byebug_history |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,13 @@ class User < ApplicationRecord | |
has_many :votes | ||
has_many :ranked_works, through: :votes, source: :work | ||
|
||
validates :username, uniqueness: true, presence: true | ||
validates :name, uniqueness: true, presence: true | ||
|
||
def build_from_github(auth_hash) | ||
return User.new( | ||
name: auth_hash['info']['name'], | ||
email: auth_hash['info']['email'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a I'm guessing you made the change after logging in for the first time, so you never hit it in a real workflow. That's why thorough testing is important, it's not always plausible to manually test things. |
||
uid: auth_hash['uid'], | ||
provider: auth_hash['provider']) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,4 @@ def fix_category | |
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :github, ENV["GITHUB_CLIENT_ID"], ENV["GITHUB_CLIENT_SECRET"], scope: "user:email" | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddUid < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :users, :email, :string | ||
add_column :users, :uid, :integer, null: false # this is the identifier provided by GitHub | ||
add_column :users, :provider, :string, null: false # this tells us who provided the identifier | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ReplaceUsernameWithName < ActiveRecord::Migration[5.0] | ||
def change | ||
rename_column :users, :username, :name | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,56 @@ | ||
require "test_helper" | ||
|
||
describe SessionsController do | ||
describe 'auth_callback' do | ||
# it 'creates a DB entry for a new user' do | ||
# old_user_count = User.count | ||
# | ||
# user = User.new( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the test that would have caught those two bugs |
||
# provider: 'github', | ||
# uid: 80085, | ||
# email: '[email protected]', | ||
# name: 'test userr' | ||
# ) | ||
# user.must_be :valid? | ||
# | ||
# login(user) | ||
# | ||
# User.count.must_equal old_user_count + 1 | ||
# session[:user_id].must_equal User.last.id | ||
# end | ||
|
||
it 'logs in an existing user' do | ||
#arrange | ||
user = User.first | ||
old_user_count = User.count | ||
|
||
login(user) | ||
User.count.must_equal old_user_count | ||
session[:user_id].must_equal user.id | ||
end | ||
|
||
it 'does not log in with insufficient data' do | ||
user = User.new( | ||
provider: 'github', | ||
email: '[email protected]', | ||
) | ||
user.wont_be :valid? | ||
old_user_count = User.count | ||
|
||
login(user) | ||
User.count.must_equal old_user_count | ||
end | ||
|
||
it 'does not log in if the user data is invalid' do | ||
user = User.first | ||
dup_user = User.new( | ||
provider: 'github', | ||
uid: 80085, | ||
email: '[email protected]', | ||
name: user.name | ||
) | ||
end | ||
|
||
#what about if the user is already logged in? | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 18 should be
@user =
.