Merge branch 'master' of github.com:diaspora/diaspora_rails into encryption

This commit is contained in:
ilya 2010-07-09 18:15:22 -04:00
commit 7eec041846
15 changed files with 84 additions and 40 deletions

View file

@ -15,11 +15,11 @@ class ApplicationController < ActionController::Base
end
def set_friends
@friends = Person.friends.all
@friends = Person.friends.all if current_user
end
def count_requests
@request_count = Request.for_user(current_user).size
@request_count = Request.for_user(current_user).size if current_user
end
end

View file

@ -7,10 +7,15 @@ class RequestsController < ApplicationController
end
def destroy
@request = Request.where(:id => params[:id]).first
@request.destroy
flash[:notice] = "Successfully destroyed person request."
if params[:accept]
current_user.accept_friend_request params[:id]
flash[:notice] = "you are now friends with #{@request.person.real_name}"
else
current_user.ignore_friend_request params[:id]
flash[:notice] = "ignored friend request"
end
redirect_to requests_url
end
def new
@ -27,4 +32,6 @@ class RequestsController < ApplicationController
render :action => 'new'
end
end
end

View file

@ -5,7 +5,8 @@ class Person
xml_accessor :email
xml_accessor :url
xml_accessor :profile, :as => Profile
xml_accessor :_id
key :email, String
key :url, String
key :active, Boolean, :default => false
@ -23,7 +24,7 @@ class Person
#validates_uniqueness_of :url
validates_true_for :url, :logic => lambda { self.url_unique?}
scope :friends, where(:_type => "Person")
scope :friends, where(:_type => "Person", :active => true)
validates_presence_of :email
before_validation :clean_url

View file

@ -4,7 +4,7 @@ class User < Person
:recoverable, :rememberable, :trackable, :validatable
before_create :assign_key
#before_create :assign_key
validates_presence_of :profile
before_validation :do_bad_things
@ -27,10 +27,12 @@ class User < Person
######### Friend Requesting
def send_friend_request_to(friend_url)
p = Request.instantiate(:to => friend_url, :from => self)
if p.save
p.push_to_url friend_url
p
unless Person.where(:url => friend_url).first
p = Request.instantiate(:to => friend_url, :from => self)
if p.save
p.push_to_url friend_url
p
end
end
end
@ -48,16 +50,22 @@ class User < Person
request.destroy
end
def ignore_friend_request(friend_request_id)
request = Request.where(:id => friend_request_id).first
person = request.person
person.destroy unless person.active
request.destroy
end
def receive_friend_request(friend_request)
if Request.where(:callback_url => friend_request.callback_url).first
friend_request.activate_friend
friend_request.destroy
else
#does this actually save as the same id?
friend_request.save
end
end
def mine?(post)
self == post.person

View file

@ -4,4 +4,6 @@
= "#{request.destination_url}"
.destroy_link
= link_to 'Accept', request_path(request, :accept => true), :confirm => 'Are you sure?', :method => :delete
|
= link_to 'Ignore', request_path(request), :confirm => 'Are you sure?', :method => :delete

View file

@ -4,6 +4,6 @@
%h3= "currently #{@request_count} requests"
%ul#stream
- for request in @remote_requests
= render "request", :request => request
- for request in @remote_requests
= render "request", :request => request

View file

@ -55,12 +55,12 @@ def create(backer_number, password)
user = User.create( :email => "#{email}@joindiaspora.com", :password => "#{email+backer_info[backer_number][0].to_s}", :profile => Profile.create( :first_name => backer_info[backer_number][1], :last_name => backer_info[backer_number][2] ))
# Make connection with Diaspora Tom
Person.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :profile => Profile.create(:first_name => "Alexander", :last_name => "Hamiltom"))
Person.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :active => true, :profile => Profile.create(:first_name => "Alexander", :last_name => "Hamiltom"))
# Make people
(0..10).each { |n|
email = backer_info[n][2].gsub(/ /,'').downcase
Person.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :profile => Profile.create(:first_name => backer_info[n][1], :last_name => backer_info[n][2])) unless n == backer_number
Person.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :active => true, :profile => Profile.create(:first_name => backer_info[n][1], :last_name => backer_info[n][2])) unless n == backer_number
}
end

View file

@ -52,7 +52,7 @@ names = [ ["George", "Washington"],
# Make people
(0..10).each { |n|
email = names[n][1].gsub(/ /,'').downcase
Person.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n][0], :last_name => names[n][1]))
Person.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :active => true, :profile => Profile.create(:first_name => names[n][0], :last_name => names[n][1]))
}

View file

@ -52,7 +52,7 @@ names = [ ["George", "Washington"],
# Make people
(0..10).each { |n|
email = names[n][1].gsub(/ /,'').downcase
Person.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :profile => Profile.create(:first_name => names[n][0], :last_name => names[n][1]))
Person.create( :email => "#{email}@joindiaspora.com", :url => "http://#{email}.joindiaspora.com/", :active => true, :profile => Profile.create(:first_name => names[n][0], :last_name => names[n][1]))
}

View file

@ -5,18 +5,14 @@ describe DashboardsController do
before do
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
Factory.create(:user, :profile => Profile.create( :first_name => "bob", :last_name => "smith"))
@user = Factory.create(:user, :profile => Profile.create( :first_name => "bob", :last_name => "smith"))
end
it "index action should render index template" do
get :index
response.should render_template(:index)
end
it "on index sets a person's variable" do
it "on index sets a variable containing all a user's friends when a user is signed in" do
sign_in :user, @user
Factory.create :person
get :index
assigns[:people].should == Person.friends.all
assigns[:friends].should == Person.friends.all
end
end

View file

@ -112,14 +112,18 @@ describe "parser in application helper" do
it "should create a new person upon getting a person request" do
request = Request.instantiate(:to =>"http://www.google.com/", :from => @person)
original_person_id = @person.id
xml = Request.build_xml_for [request]
@person.destroy
Person.friends.all.count.should be 0
Person.all.count.should be 1
store_objects_from_xml(xml)
Person.friends.all.count.should be 1
Person.all.count.should be 2
Person.where(:url => request.callback_url).first.id.should == original_person_id
end
it "should activate the Person if I initiated a request to that url" do
request = Request.instantiate(:to => @person.url, :from => @user).save

View file

@ -24,4 +24,14 @@ describe Person do
xml = person.to_xml.to_s
(xml.include? "first_name").should == true
end
it 'should only return active friends' do
Factory.create(:person, :active => true)
Factory.create(:person)
Factory.create(:person)
Person.friends.all.count.should == 1
end
end

View file

@ -22,10 +22,6 @@ describe Request do
xml = request.to_xml.to_s
puts xml
puts user.profile.first_name
puts user.profile.last_name
xml.include?(user.email).should be true
xml.include?(user.url).should be true
xml.include?(user.profile.first_name).should be true

View file

@ -10,16 +10,35 @@ describe User do
it "should be able to accept a pending friend request" do
@user = Factory.create(:user)
@friend = Factory.create(:person)
r = Request.instantiate(:to => @user.url, :from => @friend)
r.save
Person.all.count.should == 2
Request.for_user(@user).all.count.should == 1
@user.accept_friend_request(r.id)
Request.for_user(@user).all.count.should == 0
Person.where(:id => @friend.id).first.active.should == true
end
it 'should be able to ignore a pending friend request' do
@user = Factory.create(:user)
@friend = Factory.create(:person)
r = Request.instantiate(:to => @user.url, :from => @friend)
r.save
Person.count.should == 2
@friend.active.should == false
@user.ignore_friend_request(r.id)
Person.count.should == 1
Request.count.should == 0
end
it 'should not be able to friend request an existing friend' do
@user = Factory.create(:user)
@friend = Factory.create(:person, :active => true)
@user.send_friend_request_to( @friend.url ).should be nil
end
end

View file

@ -12,6 +12,7 @@ describe 'user encryption' do
@u.url = "www.example.com"
@u.profile = Profile.new( :first_name => "Bob", :last_name => "Smith" )
@u.profile.save
@u.send(:assign_key)
@u.save
end