Introduce SpeakerProfile

All the personal data of the user that is not used for system
tasks (such as login) is held here.
This commit is contained in:
Petko Bordjukov 2014-08-07 14:05:13 +03:00
parent fc1605e4a0
commit 02059ad2a8
8 changed files with 84 additions and 3 deletions

View File

@ -0,0 +1,9 @@
class SpeakerProfile < ActiveRecord::Base
belongs_to :user
validates :first_name, presence: true
validates :last_name, presence: true
validates :photo_url, presence: true
validates :mobile_phone, presence: true
validates :biography, presence: true
end

View File

@ -3,4 +3,5 @@ class User < ActiveRecord::Base
# :lockable, :timeoutable and :omniauthable # :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable, devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable :recoverable, :rememberable, :trackable, :validatable
has_one :speaker_profile
end end

View File

@ -0,0 +1,17 @@
class CreateSpeakerProfiles < ActiveRecord::Migration
def change
create_table :speaker_profiles do |t|
t.string :first_name, null: false
t.string :last_name, null: false
t.string :organisation
t.string :public_email
t.string :photo_url, null: false
t.string :mobile_phone, null: false
t.text :biography, null: false
t.string :github, null: false
t.string :twitter, null: false
t.timestamps
end
end
end

View File

@ -0,0 +1,13 @@
class RemoveSpeakerProfileColumnsFromUsers < ActiveRecord::Migration
def change
remove_column :users, :first_name, :string
remove_column :users, :last_name, :string
remove_column :users, :organisation, :string
remove_column :users, :hide_email, :boolean
remove_column :users, :photo_url, :string
remove_column :users, :mobile_phone, :string
remove_column :users, :biography, :text
remove_column :users, :github, :string
remove_column :users, :twitter, :string
end
end

View File

@ -0,0 +1,5 @@
class AddUserReferenceToSpeakerProfiles < ActiveRecord::Migration
def change
add_reference :speaker_profiles, :user, index: true
end
end

View File

@ -0,0 +1,16 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :speaker_profile do
first_name "John"
last_name "Doe"
organisation "Example Org"
public_email "a@b.com"
photo_url "http://placehold.it/50x50"
mobile_phone "0883444555"
biography "Lorem ipsum"
github "octocat"
twitter "handle"
user
end
end

View File

@ -4,11 +4,8 @@ FactoryGirl.define do
sequence(:email) { |n| "user-#{n}@example.org" } sequence(:email) { |n| "user-#{n}@example.org" }
factory :user do factory :user do
first_name 'John'
last_name 'Doe'
password 'password' password 'password'
password_confirmation 'password' password_confirmation 'password'
mobile_phone '0883444555'
email email
end end
end end

View File

@ -0,0 +1,23 @@
require 'rails_helper'
RSpec.describe SpeakerProfile, :type => :model do
it 'is invalid without a first name' do
expect(build(:speaker_profile, first_name: nil)).to have_error_on :first_name
end
it 'is invalid without a last name' do
expect(build(:speaker_profile, last_name: nil)).to have_error_on :last_name
end
it 'is invalid without a photo' do
expect(build(:speaker_profile, photo_url: nil)).to have_error_on :photo_url
end
it 'is invalid without a mobile phone' do
expect(build(:speaker_profile, mobile_phone: nil)).to have_error_on :mobile_phone
end
it 'is invalid without a bio' do
expect(build(:speaker_profile, biography: nil)).to have_error_on :biography
end
end