DG RS; made an instantiate method for user which makes a person and profile
This commit is contained in:
parent
b5f962c725
commit
a8b77cf868
4 changed files with 25 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
|||
class UsersController < ApplicationController
|
||||
before_filter :authenticate_user!, :except => [:new, :create]
|
||||
|
||||
before_filter :authenticate_user!
|
||||
def index
|
||||
@users = User.sort(:created_at.desc).all
|
||||
end
|
||||
|
|
@ -29,7 +29,7 @@ class UsersController < ApplicationController
|
|||
def create
|
||||
@user = User.new(params[:user])
|
||||
|
||||
if @user.save!
|
||||
if @user.person.save! && @user.save!
|
||||
flash[:notice] = "Successfully signed up."
|
||||
redirect_to root_path
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module StatusMessagesHelper
|
||||
|
||||
def my_latest_message
|
||||
unless @latest_status_message.nil?
|
||||
return @latest_status_message.message
|
||||
|
|
@ -7,7 +6,4 @@ module StatusMessagesHelper
|
|||
return "No message to display."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -118,7 +118,17 @@ class User
|
|||
|
||||
|
||||
###Helpers############
|
||||
|
||||
def self.instantiate( opts = {} )
|
||||
User.create(
|
||||
:email => opts[:email],
|
||||
:password => opts[:password],
|
||||
:password_confirmation => opts[:password_confirmation],
|
||||
:person => Person.new(
|
||||
:email => opts[:email],
|
||||
:profile => Profile.new(
|
||||
:first_name => opts[:first_name],
|
||||
:last_name => opts[:last_name])))
|
||||
end
|
||||
|
||||
def terse_url
|
||||
terse= self.url.gsub(/https?:\/\//, '')
|
||||
|
|
|
|||
|
|
@ -11,6 +11,18 @@ describe User do
|
|||
Person.count.should == n+1
|
||||
end
|
||||
|
||||
it 'should instantiate with a person and be valid' do
|
||||
user = User.instantiate(:email => "bob@bob.com",
|
||||
:password => "password",
|
||||
:password_confirmation => "password",
|
||||
:first_name => "bob",
|
||||
:last_name => "grimm")
|
||||
|
||||
user.save.should be true
|
||||
user.person.should_not be nil
|
||||
user.person.profile.should_not be nil
|
||||
end
|
||||
|
||||
describe 'friend requesting' do
|
||||
it "should be able to accept a pending friend request" do
|
||||
friend = Factory.create(:person)
|
||||
|
|
|
|||
Loading…
Reference in a new issue