User model
This commit is contained in:
parent
fb3e681203
commit
9ba59608cb
5 changed files with 68 additions and 0 deletions
11
app/models/user.rb
Normal file
11
app/models/user.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
class User < ActiveRecord::Base
|
||||||
|
def self.from_omniauth(auth)
|
||||||
|
where(provider: auth[:provider], uid: auth[:uid]).first_or_create do |user|
|
||||||
|
user.provider = auth[:provider]
|
||||||
|
user.uid = auth[:uid]
|
||||||
|
user.name = auth[:info][:name]
|
||||||
|
user.email = auth[:info][:email]
|
||||||
|
user.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
12
db/migrate/20141002202749_create_users.rb
Normal file
12
db/migrate/20141002202749_create_users.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class CreateUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :users do |t|
|
||||||
|
t.string :provider
|
||||||
|
t.string :uid
|
||||||
|
t.string :name
|
||||||
|
t.string :email
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
25
db/schema.rb
Normal file
25
db/schema.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# encoding: UTF-8
|
||||||
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
#
|
||||||
|
# Note that this schema.rb definition is the authoritative source for your
|
||||||
|
# database schema. If you need to create the application database on another
|
||||||
|
# system, you should be using db:schema:load, not running all the migrations
|
||||||
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||||
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||||
|
#
|
||||||
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
ActiveRecord::Schema.define(version: 20141002202749) do
|
||||||
|
|
||||||
|
create_table "users", force: true do |t|
|
||||||
|
t.string "provider"
|
||||||
|
t.string "uid"
|
||||||
|
t.string "name"
|
||||||
|
t.string "email"
|
||||||
|
t.datetime "created_at"
|
||||||
|
t.datetime "updated_at"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
13
test/fixtures/users.yml
vendored
Normal file
13
test/fixtures/users.yml
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
provider: MyString
|
||||||
|
uid: MyString
|
||||||
|
name: MyString
|
||||||
|
email: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
provider: MyString
|
||||||
|
uid: MyString
|
||||||
|
name: MyString
|
||||||
|
email: MyString
|
7
test/models/user_test.rb
Normal file
7
test/models/user_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class UserTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in a new issue