* VRFS-72 merging conflicts, mostly because of FactoryGirl vs User.save

This commit is contained in:
Seth Call 2012-11-12 07:08:50 -06:00
commit 770134c883
5 changed files with 66 additions and 32 deletions

View File

@ -2,7 +2,11 @@ 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_accessor :updating_password
self.primary_key = 'id'
@ -31,7 +35,7 @@ module JamRuby
# band followings
has_many :band_followings, :class_name => "JamRuby::BandFollower", :foreign_key => "follower_id"
has_many :inverse_band_followings, :through => :band_followings, :foreign_key => "band_id"
has_many :inverse_band_followings, :through => :band_followings, :class_name => "JamRuby::Band", :foreign_key => "band_id"
# favorites (needs Recording model)
@ -59,6 +63,8 @@ module JamRuby
after_save :limit_to_five_instruments
validates :name, uniqueness: {case_sensitive: false}, presence: true, length: {maximum: 50}
validates :first_name, presence: true, length: {maximum: 50}
validates :last_name, presence: true, length: {maximum: 50}
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX},
uniqueness: {case_sensitive: false}
@ -87,6 +93,10 @@ module JamRuby
updating_password || new_record?
end
#def name
# return self.first_name + " " + self.last_name
#end
def friends?(user)
return self.friends.exists?(user)
end
@ -117,7 +127,17 @@ module JamRuby
user = User.find(params[:id])
end
# name
# first name
unless params[:first_name].nil?
user.first_name = params[:first_name]
end
# last name
unless params[:last_name].nil?
user.last_name = params[:last_name]
end
# username
unless params[:name].nil?
user.name = params[:name]
end
@ -199,7 +219,8 @@ module JamRuby
def to_indexed_json
{
:name => name,
:first_name => first_name,
:last_name => last_name,
:photo_url => photo_url,
:location => location,
:musician => musician
@ -225,8 +246,9 @@ module JamRuby
:properties => {
:photo_url => { :type => :string, :index => :not_analyzed, :include_in_all => false},
:location => { :type => :string },
:name => { :type => :string, :boost => 100 },
:is_musician => { :type => :boolean, :index => :not_analyzed, :include_in_all => false}
:first_name => { :type => :string, :boost => 100 },
:last_name => { :type => :string, :boost => 100 },
:musician => { :type => :boolean, :index => :not_analyzed, :include_in_all => false}
}
}
}

View File

@ -11,8 +11,8 @@ describe Search do
def create_peachy_data
@user = FactoryGirl.create(:user, name: "Peach", email: "user@example.com", musician: true)
@fan = FactoryGirl.create(:user, name: "Peach Peach", email: "fan@example.com", musician: false)
@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)
@band = FactoryGirl.create(:band, name: "Peach pit", website: "www.bands.com", biography: "zomg we rock")
end

View File

@ -20,8 +20,7 @@ describe "tire search" do
end
it "full search for single user" do
@user = FactoryGirl.create(:user, name: "User One", email: "user@example.com", musician: true)
@user = FactoryGirl.create(:user, first_name: "User", last_name: "One", name: "test", email: "user@example.com", musician: true)
User.search_index.refresh
s = Tire.search ['test-jamruby-users', 'test-jamruby-bands'], :load => true do
@ -49,8 +48,9 @@ describe "tire search" do
end
it "full search for a band & user" do
@user = FactoryGirl.create(:user, name: "Peach", email: "user@example.com", musician: true)
@user = FactoryGirl.create(:user, first_name: "Peach", last_name: "Foo", name: "test", email: "user@example.com", musician: true)
@band = FactoryGirl.create(:band, name: "Peach pit", website: "www.bands.com", biography: "zomg we rock")
User.search_index.refresh
Band.search_index.refresh
@ -61,17 +61,18 @@ describe "tire search" do
s.results.length.should == 2
result = s.results[0]
result.should be_a_kind_of User
result.id.should == @user.id
result = s.results[1]
result.should be_a_kind_of Band
result.id.should == @band.id
result = s.results[1]
result.should be_a_kind_of User
result.id.should == @user.id
end
it "pagination" do
@user = FactoryGirl.create(:user, name: "Peach", email: "user@example.com", musician: true)
@user = FactoryGirl.create(:user, first_name: "Peach", last_name: "foo", name: "test", email: "user@example.com", musician: true)
@band = FactoryGirl.create(:band, name: "Peach pit", website: "www.bands.com", biography: "zomg we rock")
User.search_index.refresh
Band.search_index.refresh
@ -84,8 +85,8 @@ describe "tire search" do
s.results.length.should == 1
result = s.results[0]
result.should be_a_kind_of User
result.id.should == @user.id
result.should be_a_kind_of Band
result.id.should == @band.id
s = Tire.search ['test-jamruby-users', 'test-jamruby-bands'], :load => true do
query { string 'peach' }
@ -96,8 +97,8 @@ describe "tire search" do
s.results.length.should == 1
result = s.results[0]
result.should be_a_kind_of Band
result.id.should == @band.id
result.should be_a_kind_of User
result.id.should == @user.id
end
it "should fail to search deleted index" do
@ -110,8 +111,7 @@ describe "tire search" do
s.results.total.should == 0
@user = FactoryGirl.create(:user, name: "Peach", email: "user@example.com", musician: true)
@user = FactoryGirl.create(:user, first_name: "Peach", last_name: "Pit", name: "peachy", email: "user@example.com", musician: true)
User.search_index.refresh
sleep 1 # https://jamkazam.atlassian.net/browse/VRFS-69

View File

@ -6,9 +6,8 @@ describe User do
User.delete_search_index
User.create_search_index
@user = FactoryGirl.create(:user, name: "Example User", email: "user@example.com",
@user = FactoryGirl.create(:user, first_name: "Example", last_name: "User", name: "peachy", email: "user@example.com",
password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: true)
# you have to poke elasticsearch because it will batch requests internally for a second
User.search_index.refresh
end
@ -18,7 +17,8 @@ describe User do
ws.results.length.should == 1
user_result = ws.results[0]
user_result._type.should == "jam_ruby/user"
user_result.name.should == @user.name
user_result.first_name.should == @user.first_name
user_result.last_name.should == @user.last_name
user_result.id.should == @user.id
user_result.location.should == @user.location
user_result.musician.should == true
@ -44,7 +44,8 @@ describe User do
user_result = ws.results[0]
user_result.id.should == @user.id
@user.name = "bonus-junk"
@user.first_name = "bonus-junk"
@user.last_name = "more-junk"
@user.save
User.search_index.refresh
@ -55,11 +56,11 @@ describe User do
ws.results.length.should == 1
user_result = ws.results[0]
user_result.id.should == @user.id
user_result.name.should == "bonus-junk"
user_result.first_name.should == "bonus-junk"
end
it "should tokenize correctly" do
@user2 = FactoryGirl.create(:user, name: "peaches", email: "peach@example.com",
@user2 = FactoryGirl.create(:user, first_name: "peaches", last_name: "test", name: "peachy", email: "peach@example.com",
password: "foobar", password_confirmation: "foobar", musician: true, email_confirmed: true)
User.search_index.refresh
ws = User.search("pea")

View File

@ -3,13 +3,14 @@ require 'spec_helper'
describe User do
before do
@user = User.new(name: "Example User", email: "user@example.com",
@user = User.new(first_name: "Example", last_name: "User", name: "test", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
end
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:first_name) }
it { should respond_to(:last_name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
@ -39,8 +40,13 @@ describe User do
it { should be_admin }
end
describe "when name is not present" do
before { @user.name = " " }
describe "when first name is not present" do
before { @user.first_name = " " }
it { should_not be_valid }
end
describe "when last name is not present" do
before { @user.last_name = " " }
it { should_not be_valid }
end
@ -49,8 +55,13 @@ describe User do
it { should_not be_valid }
end
describe "when name is too long" do
before { @user.name = "a" * 51 }
describe "when first name is too long" do
before { @user.first_name = "a" * 51 }
it { should_not be_valid }
end
describe "when last name is too long" do
before { @user.last_name = "a" * 51 }
it { should_not be_valid }
end