From 842b321dfa6b85e25ac273846ce4e63c3dd6bdab Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 17 Aug 2010 13:02:42 -0700 Subject: [PATCH] User email checking, routes working again --- app/controllers/users_controller.rb | 14 -------------- app/models/user.rb | 28 +++++++++++++--------------- config/routes.rb | 2 +- spec/factories.rb | 2 +- spec/models/user_spec.rb | 14 -------------- spec/spec_helper.rb | 1 + 6 files changed, 16 insertions(+), 45 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 12f87c481..e5e2e263c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 9b6410966..197fc4ea0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 88c838d77..0cf622127 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 88f34e1f6..ba3aadeb9 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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)} diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index e0d2415c7..fd78af0a3 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0b2759cb..cadde8dcc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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