From 33c2bbd68ebf389a4c7d79b25c08afd739e6a522 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Mon, 12 Nov 2012 07:26:02 -0600 Subject: [PATCH] * VRFS-72 --- lib/jam_ruby/models/user.rb | 6 +----- lib/jam_ruby/user_manager.rb | 21 +++++++++++++-------- spec/jam_ruby/models/search_spec.rb | 2 +- spec/jam_ruby/models/user_search_spec.rb | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/jam_ruby/models/user.rb b/lib/jam_ruby/models/user.rb index 239239443..a41f69b8b 100644 --- a/lib/jam_ruby/models/user.rb +++ b/lib/jam_ruby/models/user.rb @@ -2,11 +2,7 @@ module JamRuby class User < ActiveRecord::Base include Tire::Model::Search -<<<<<<< HEAD - attr_accessible :name, :email, :password, :password_confirmation, :city, :state, :country -======= - attr_accessible :first_name, :last_name, :name, :email, :password, :password_confirmation ->>>>>>> b2880dc65a3e361fbef0727657fa368336d712ba + attr_accessible :first_name, :last_name, :name, :email, :password, :password_confirmation, :city, :state, :country attr_accessor :updating_password self.primary_key = 'id' diff --git a/lib/jam_ruby/user_manager.rb b/lib/jam_ruby/user_manager.rb index 33b64b4ba..cbcf746f0 100644 --- a/lib/jam_ruby/user_manager.rb +++ b/lib/jam_ruby/user_manager.rb @@ -50,15 +50,20 @@ module JamRuby return user end - # throws RecordNotFound if signup token is invalid + # throws RecordNotFound if signup token is invalid; i.e., if it's nil, empty string, or not belonging to a user def signup_confirm(signup_token) - UserManager.active_record_transaction do |user_manager| - # throws ActiveRecord::RecordNotFound if invalid - user = User.find_by_signup_token!(signup_token) - user.signup_token = nil - user.email_confirmed = true - user.save - return user + if signup_token.nil? || signup_token.empty? + # there are plenty of confirmed users with nil signup_tokens, so we can't look on it + raise ActiveRecord::RecordNotFound + else + UserManager.active_record_transaction do |user_manager| + # throws ActiveRecord::RecordNotFound if invalid + user = User.find_by_signup_token!(signup_token) + user.signup_token = nil + user.email_confirmed = true + user.save + return user + end end end end diff --git a/spec/jam_ruby/models/search_spec.rb b/spec/jam_ruby/models/search_spec.rb index e3f6b0868..dfcc79692 100644 --- a/spec/jam_ruby/models/search_spec.rb +++ b/spec/jam_ruby/models/search_spec.rb @@ -12,7 +12,7 @@ describe Search do def create_peachy_data @user = FactoryGirl.create(:user, first_name: "Peach", last_name: "Pit", name: "peachy", email: "user@example.com", musician: true) - @fan = FactoryGirl.create(:user, first_name: "Peach Peach", last_name: "Pit", name: "peachy", email: "fan@example.com", musician: false) + @fan = FactoryGirl.create(:user, first_name: "Peach Peach", last_name: "Pit", name: "peachy2", email: "fan@example.com", musician: false) @band = FactoryGirl.create(:band, name: "Peach pit", website: "www.bands.com", biography: "zomg we rock") end diff --git a/spec/jam_ruby/models/user_search_spec.rb b/spec/jam_ruby/models/user_search_spec.rb index 3d50ec8af..20525778e 100644 --- a/spec/jam_ruby/models/user_search_spec.rb +++ b/spec/jam_ruby/models/user_search_spec.rb @@ -60,7 +60,7 @@ describe User do end it "should tokenize correctly" do - @user2 = FactoryGirl.create(:user, first_name: "peaches", last_name: "test", name: "peachy", email: "peach@example.com", + @user2 = FactoryGirl.create(:user, first_name: "peaches", last_name: "test", name: "peachy2", email: "peach@example.com", password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: true) User.search_index.refresh ws = User.search("pea") @@ -71,7 +71,7 @@ describe User do it "users who have signed up, but not confirmed should not show up in search index" do - @user3 = FactoryGirl.create(:user, name: "unconfirmed", email: "unconfirmed@example.com", + @user3 = FactoryGirl.create(:user, first_name: "unconfirmed", last_name: "unconfirmed", name: "unconfirmed", email: "unconfirmed@example.com", password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: false) User.search_index.refresh ws = User.search("unconfirmed")