User email checking, routes working again
This commit is contained in:
parent
ccbbf40584
commit
842b321dfa
6 changed files with 16 additions and 45 deletions
|
|
@ -26,19 +26,5 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.instantiate(params[:user])
|
||||
|
||||
if @user.created_at && @user.person.created_at
|
||||
flash[:notice] = "Successfully signed up."
|
||||
redirect_to root_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -16,17 +16,22 @@ class User
|
|||
|
||||
many :groups, :class_name => 'Group'
|
||||
|
||||
before_validation_on_create :assign_key
|
||||
before_validation :do_bad_things
|
||||
|
||||
before_validation_on_create :setup_person
|
||||
before_create :pivotal_only
|
||||
|
||||
######## Making things work ########
|
||||
key :email, String
|
||||
validates_true_for :email, :logic => lambda { self.pivotal_email?}
|
||||
#validates_true_for :email, :logic => lambda {self.pivotal_email?}
|
||||
|
||||
|
||||
def pivotal_email?
|
||||
email.include?('@pivotallabs.com')
|
||||
end
|
||||
|
||||
def pivotal_only
|
||||
raise "pivotal only" unless pivotal_email?
|
||||
end
|
||||
|
||||
def method_missing(method, *args)
|
||||
self.person.send(method, *args)
|
||||
end
|
||||
|
|
@ -234,12 +239,7 @@ class User
|
|||
end
|
||||
|
||||
###Helpers############
|
||||
def self.instantiate( opts = {} )
|
||||
opts[:person][:email] = opts[:email]
|
||||
opts[:person][:serialized_key] = generate_key
|
||||
User.create( opts)
|
||||
end
|
||||
|
||||
|
||||
def terse_url
|
||||
terse= self.url.gsub(/https?:\/\//, '')
|
||||
terse.gsub!(/www\./, '')
|
||||
|
|
@ -247,10 +247,6 @@ class User
|
|||
terse
|
||||
end
|
||||
|
||||
def do_bad_things
|
||||
self.password_confirmation = self.password
|
||||
end
|
||||
|
||||
def friend_by_id( id )
|
||||
friends.detect{|x| x.id == ensure_bson( id ) }
|
||||
end
|
||||
|
|
@ -261,8 +257,10 @@ class User
|
|||
|
||||
protected
|
||||
|
||||
def assign_key
|
||||
def setup_person
|
||||
self.person.serialized_key ||= generate_key.export
|
||||
self.person.email = email
|
||||
self.person.save
|
||||
end
|
||||
|
||||
def generate_key
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ Diaspora::Application.routes.draw do |map|
|
|||
resources :blogs
|
||||
resources :bookmarks
|
||||
resources :people
|
||||
resources :users
|
||||
resources :users, :except => [:new, :create]
|
||||
resources :status_messages
|
||||
resources :comments
|
||||
resources :requests
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ Factory.define :person_with_user, :parent => :person_with_private_key do |p|
|
|||
end
|
||||
|
||||
Factory.define :user do |u|
|
||||
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
||||
u.sequence(:email) {|n| "bob#{n}@pivotallabs.com"}
|
||||
u.password "bluepin7"
|
||||
u.password_confirmation "bluepin7"
|
||||
u.person { |a| Factory.create(:person_with_user, :owner_id => a._id)}
|
||||
|
|
|
|||
|
|
@ -6,20 +6,6 @@ describe User do
|
|||
@group = @user.group(:name => 'heroes')
|
||||
end
|
||||
|
||||
it 'should instantiate with a person and be valid' do
|
||||
user = User.instantiate(:email => "bob@bob.com",
|
||||
:password => "password",
|
||||
:password_confirmation => "password",
|
||||
:person =>
|
||||
{:profile => {
|
||||
: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 assign a request to a group" do
|
||||
friend = Factory.create(:person)
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ RSpec.configure do |config|
|
|||
config.before(:each) do
|
||||
DatabaseCleaner.start
|
||||
stub_sockets_controller
|
||||
User.stub(:pivotal_only).and_return(:true)
|
||||
end
|
||||
|
||||
config.after(:each) do
|
||||
|
|
|
|||
Loading…
Reference in a new issue