adds Identity model and migration
This commit is contained in:
10
app/models/identity.rb
Normal file
10
app/models/identity.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class Identity < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
validates :provider, presence: true
|
||||||
|
validates :uid, presence: true, uniqueness: { scope: :provider }
|
||||||
|
|
||||||
|
def self.find_for_oauth(auth)
|
||||||
|
where(uid: auth.uid, provider: auth.provider).first_or_create
|
||||||
|
end
|
||||||
|
end
|
||||||
11
db/migrate/20150824144524_create_identities.rb
Normal file
11
db/migrate/20150824144524_create_identities.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class CreateIdentities < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :identities do |t|
|
||||||
|
t.references :user, index: true, foreign_key: true
|
||||||
|
t.string :provider
|
||||||
|
t.string :uid
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
17
db/schema.rb
17
db/schema.rb
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20150824113326) do
|
ActiveRecord::Schema.define(version: 20150824144524) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -66,8 +66,8 @@ ActiveRecord::Schema.define(version: 20150824113326) do
|
|||||||
t.integer "author_id"
|
t.integer "author_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.datetime "hidden_at"
|
|
||||||
t.string "visit_id"
|
t.string "visit_id"
|
||||||
|
t.datetime "hidden_at"
|
||||||
t.datetime "flagged_as_inappropiate_at"
|
t.datetime "flagged_as_inappropiate_at"
|
||||||
t.integer "inappropiate_flags_count", default: 0
|
t.integer "inappropiate_flags_count", default: 0
|
||||||
t.datetime "reviewed_at"
|
t.datetime "reviewed_at"
|
||||||
@@ -75,6 +75,16 @@ ActiveRecord::Schema.define(version: 20150824113326) do
|
|||||||
|
|
||||||
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
|
add_index "debates", ["hidden_at"], name: "index_debates_on_hidden_at", using: :btree
|
||||||
|
|
||||||
|
create_table "identities", force: :cascade do |t|
|
||||||
|
t.integer "user_id"
|
||||||
|
t.string "provider"
|
||||||
|
t.string "uid"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree
|
||||||
|
|
||||||
create_table "inappropiate_flags", force: :cascade do |t|
|
create_table "inappropiate_flags", force: :cascade do |t|
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.string "flaggable_type"
|
t.string "flaggable_type"
|
||||||
@@ -156,10 +166,10 @@ ActiveRecord::Schema.define(version: 20150824113326) do
|
|||||||
t.string "unconfirmed_email"
|
t.string "unconfirmed_email"
|
||||||
t.boolean "email_on_debate_comment", default: false
|
t.boolean "email_on_debate_comment", default: false
|
||||||
t.boolean "email_on_comment_reply", default: false
|
t.boolean "email_on_comment_reply", default: false
|
||||||
|
t.string "phone_number", limit: 30
|
||||||
t.string "official_position"
|
t.string "official_position"
|
||||||
t.integer "official_level", default: 0
|
t.integer "official_level", default: 0
|
||||||
t.datetime "hidden_at"
|
t.datetime "hidden_at"
|
||||||
t.string "phone_number", limit: 30
|
|
||||||
t.string "username"
|
t.string "username"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -214,6 +224,7 @@ ActiveRecord::Schema.define(version: 20150824113326) do
|
|||||||
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
|
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
|
||||||
|
|
||||||
add_foreign_key "administrators", "users"
|
add_foreign_key "administrators", "users"
|
||||||
|
add_foreign_key "identities", "users"
|
||||||
add_foreign_key "inappropiate_flags", "users"
|
add_foreign_key "inappropiate_flags", "users"
|
||||||
add_foreign_key "moderators", "users"
|
add_foreign_key "moderators", "users"
|
||||||
add_foreign_key "organizations", "users"
|
add_foreign_key "organizations", "users"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
|
|
||||||
factory :user do
|
factory :user do
|
||||||
username 'Manuela'
|
username 'Manuela'
|
||||||
sequence(:email) { |n| "manuela#{n}@madrid.es" }
|
sequence(:email) { |n| "manuela#{n}@madrid.es" }
|
||||||
@@ -7,6 +6,12 @@ FactoryGirl.define do
|
|||||||
confirmed_at { Time.now }
|
confirmed_at { Time.now }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :identity do
|
||||||
|
user nil
|
||||||
|
provider "Twitter"
|
||||||
|
uid "MyString"
|
||||||
|
end
|
||||||
|
|
||||||
factory :debate do
|
factory :debate do
|
||||||
sequence(:title) { |n| "Debate #{n} title" }
|
sequence(:title) { |n| "Debate #{n} title" }
|
||||||
description 'Debate description'
|
description 'Debate description'
|
||||||
|
|||||||
9
spec/models/identity_spec.rb
Normal file
9
spec/models/identity_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Identity, type: :model do
|
||||||
|
let(:identity) { build(:identity) }
|
||||||
|
|
||||||
|
it "should be valid" do
|
||||||
|
expect(identity).to be_valid
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -50,6 +50,26 @@ describe User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'OmniAuth' do
|
||||||
|
describe '#email_provided?' do
|
||||||
|
it "is false if the email matchs was temporarely assigned by the OmniAuth process" do
|
||||||
|
subject.email = 'omniauth@participacion-ABCD-twitter.com'
|
||||||
|
expect(subject.email_provided?).to eq(false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is true if the email is not omniauth-like" do
|
||||||
|
subject.email = 'manuelacarmena@example.com'
|
||||||
|
expect(subject.email_provided?).to eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is true if the user's real email is pending to be confirmed" do
|
||||||
|
subject.email = 'omniauth@participacion-ABCD-twitter.com'
|
||||||
|
subject.unconfirmed_email = 'manuelacarmena@example.com'
|
||||||
|
expect(subject.email_provided?).to eq(true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "administrator?" do
|
describe "administrator?" do
|
||||||
it "is false when the user is not an admin" do
|
it "is false when the user is not an admin" do
|
||||||
expect(subject.administrator?).to be false
|
expect(subject.administrator?).to be false
|
||||||
|
|||||||
Reference in New Issue
Block a user