Merge branch 'master' of github.com:diaspora/diaspora_rails
This commit is contained in:
commit
39998db052
5 changed files with 83 additions and 12 deletions
|
|
@ -2,7 +2,13 @@ class PeopleController < ApplicationController
|
|||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
@people = Person.friends.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
unless params[:q]
|
||||
@people = Person.friends.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
render :index
|
||||
else
|
||||
@people = Person.search_for_friends(params[:q])
|
||||
render :json => @people.to_json(:only => :_id)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -30,9 +30,11 @@ class Person
|
|||
|
||||
after_destroy :remove_all_traces
|
||||
|
||||
scope :friends, where(:_type => "Person", :active => true)
|
||||
|
||||
|
||||
scope :friends, where(:_type => "Person", :active => true)
|
||||
|
||||
def self.search_for_friends(query)
|
||||
Person.all('$where' => "function() { return this.profile.first_name.match(/^#{query}/i) || this.profile.last_name.match(/^#{query}/i); }")
|
||||
end
|
||||
|
||||
def real_name
|
||||
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
= csrf_meta_tag
|
||||
= yield(:head)
|
||||
|
||||
= javascript_include_tag 'satisfaction' , 'satisfaction-display'
|
||||
/= javascript_include_tag 'satisfaction' , 'satisfaction-display'
|
||||
|
||||
= javascript_include_tag 'jquery.html5_upload'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
package :git, :provides => :scm do
|
||||
description 'Git Distributed Version Control'
|
||||
apt %w( git-core ) do
|
||||
pre :install, "mkdir -p /root/.ssh/"
|
||||
end
|
||||
apt %w( git-core )
|
||||
requires :pubkey
|
||||
requires :privkey
|
||||
requires :known_hosts
|
||||
|
||||
end
|
||||
|
||||
package :privkey do
|
||||
description 'checkout from github with it'
|
||||
transfer "#{File.dirname(__FILE__)}/../deploy_key/id_rsa", '/root/.ssh/id_rsa', :render => false
|
||||
transfer "#{File.dirname(__FILE__)}/../deploy_key/id_rsa", '/root/.ssh/id_rsa', :render => false do
|
||||
pre :install, "rm -rf /root/.ssh/ && mkdir -p /root/.ssh/"
|
||||
post :install, "chmod go-rwx /root/.ssh/id_rsa"
|
||||
end
|
||||
end
|
||||
|
||||
package :pubkey do
|
||||
transfer "#{File.dirname(__FILE__)}/../deploy_key/id_rsa.pub", '/root/.ssh/id_rsa.pub', :render => false
|
||||
transfer "#{File.dirname(__FILE__)}/../deploy_key/id_rsa.pub", '/root/.ssh/id_rsa.pub', :render => false
|
||||
requires :privkey
|
||||
requires :known_hosts
|
||||
end
|
||||
|
||||
package :known_hosts do
|
||||
|
|
|
|||
61
spec/controllers/people_controller_spec.rb
Normal file
61
spec/controllers/people_controller_spec.rb
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
|
||||
describe PeopleController do
|
||||
render_views
|
||||
before do
|
||||
@user = Factory.create(:user, :profile => Profile.new( :first_name => "bob", :last_name => "smith"))
|
||||
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user)
|
||||
|
||||
sign_in :user, @user
|
||||
end
|
||||
|
||||
it "index should yield search results for substring of person name" do
|
||||
friend_one = Factory.create(:person)
|
||||
friend_two = Factory.create(:person)
|
||||
friend_three = Factory.create(:person)
|
||||
friend_four = Factory.create(:person)
|
||||
|
||||
friend_one.profile.first_name = "Robert"
|
||||
friend_one.profile.last_name = "Grimm"
|
||||
friend_one.profile.save
|
||||
|
||||
friend_two.profile.first_name = "Eugene"
|
||||
friend_two.profile.last_name = "Weinstein"
|
||||
friend_two.save
|
||||
|
||||
friend_three.profile.first_name = "Yevgeniy"
|
||||
friend_three.profile.last_name = "Dodis"
|
||||
friend_three.save
|
||||
|
||||
friend_four.profile.first_name = "Casey"
|
||||
friend_four.profile.last_name = "Grippi"
|
||||
friend_four.save
|
||||
|
||||
|
||||
puts Person.friends.count
|
||||
|
||||
get :index, :q => "Eu"
|
||||
|
||||
|
||||
assigns[:people].include?(friend_two).should == true
|
||||
assigns[:people].include?(friend_one).should == false
|
||||
assigns[:people].include?(friend_three).should == false
|
||||
assigns[:people].include?(friend_four).should == false
|
||||
|
||||
get :index, :q => "Wei"
|
||||
assigns[:people].include?(friend_two).should == true
|
||||
assigns[:people].include?(friend_one).should == false
|
||||
assigns[:people].include?(friend_three).should == false
|
||||
assigns[:people].include?(friend_four).should == false
|
||||
|
||||
get :index, :q => "Gri"
|
||||
assigns[:people].include?(friend_one).should == true
|
||||
assigns[:people].include?(friend_four).should == true
|
||||
assigns[:people].include?(friend_two).should == false
|
||||
assigns[:people].include?(friend_three).should == false
|
||||
|
||||
get :index
|
||||
assigns[:people].should == Person.friends.all
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in a new issue