Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
Dan Hansen & Sarah Mei 2010-12-15 14:29:33 -05:00
commit 82e2f23f91
8 changed files with 86 additions and 89 deletions

View file

@ -17,9 +17,8 @@ class Request
belongs_to :to, :class => Person belongs_to :to, :class => Person
validates_presence_of :from, :to validates_presence_of :from, :to
validate :not_already_connected_if_sent validates_uniqueness_of :from_id, :scope => :to_id
validate :not_already_connected_if_not_sent validate :not_already_connected
validate :no_pending_request, :if => :sent
validate :not_friending_yourself validate :not_friending_yourself
scope :from, lambda { |person| scope :from, lambda { |person|
@ -36,8 +35,7 @@ class Request
def self.instantiate(opts = {}) def self.instantiate(opts = {})
self.new(:from => opts[:from], self.new(:from => opts[:from],
:to => opts[:to], :to => opts[:to],
:into => opts[:into], :into => opts[:into])
:sent => true)
end end
def reverse_for accepting_user def reverse_for accepting_user
@ -75,27 +73,12 @@ class Request
requests.map{|r| {:request => r, :sender => senders_hash[r.from_id]}} requests.map{|r| {:request => r, :sender => senders_hash[r.from_id]}}
end end
private private
def no_pending_request
if Request.first(:from_id => from_id, :to_id => to_id)
errors[:base] << 'You have already sent a request to that person'
end
end
def not_already_connected_if_sent def not_already_connected
if self.sent
if Contact.first(:user_id => self.from.owner_id, :person_id => self.to.id)
errors[:base] << 'You have already connected to this person'
end
end
end
def not_already_connected_if_not_sent
unless self.sent
if Contact.first(:user_id => self.to.owner_id, :person_id => self.from.id) if Contact.first(:user_id => self.to.owner_id, :person_id => self.from.id)
errors[:base] << 'You have already connected to this person' errors[:base] << 'You have already connected to this person'
end end
end end
end
def not_friending_yourself def not_friending_yourself
if self.to == self.from if self.to == self.from

View file

@ -35,7 +35,7 @@
%br %br
%hr{:style=>"width:300px;"} %hr{:style=>"width:300px;"}
-if contact || person == current_user.person -if (contact && !contact.pending?) || person == current_user.person
%ul#profile_information %ul#profile_information
%li %li
%h3 #{t('.bio')} %h3 #{t('.bio')}

View file

@ -44,19 +44,23 @@ en:
user: user:
attributes: attributes:
person: person:
invalid: "is invalid" invalid: "is invalid."
username: username:
taken: "is already taken" taken: "is already taken."
email: email:
taken: "is already taken" taken: "is already taken."
person: person:
attributes: attributes:
diaspora_handle: diaspora_handle:
taken: "is already taken" taken: "is already taken."
contact: contact:
attributes: attributes:
person_id: person_id:
taken: "must be unique among this user's contacts" taken: "must be unique among this user's contacts."
request:
attributes:
from_id:
taken: "is a duplicate of a pre-existing request."
application: application:
helper: helper:
unknown_person: "unknown person" unknown_person: "unknown person"

View file

@ -10,5 +10,5 @@
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => citie # Mayor.create(:name => 'Daley', :city => citie
require File.join(File.dirname(__FILE__), "..", "..", "config", "environment") require File.join(File.dirname(__FILE__), "..", "config", "environment")

View file

@ -5,7 +5,6 @@
require File.join(File.dirname(__FILE__), "..", "..", "config", "environment") require File.join(File.dirname(__FILE__), "..", "..", "config", "environment")
require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods") require File.join(File.dirname(__FILE__), "..", "..", "spec", "helper_methods")
def set_app_config username def set_app_config username
current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example'))) current_config = YAML.load(File.read(Rails.root.join('config', 'app_config.yml.example')))
current_config[Rails.env.to_s] ||= {} current_config[Rails.env.to_s] ||= {}
@ -21,6 +20,15 @@ set_app_config username unless File.exists?(Rails.root.join('config', 'app_confi
require Rails.root.join('config', "initializers", "_load_app_config.rb") require Rails.root.join('config', "initializers", "_load_app_config.rb")
include HelperMethods include HelperMethods
module Resque
def enqueue(klass, *args)
if $process_queue
klass.send(:perform, *args)
else
true
end
end
end
# Create seed user # Create seed user
user = User.build( :email => "tom@tom.joindiaspora.com", user = User.build( :email => "tom@tom.joindiaspora.com",
:username => "tom", :username => "tom",
@ -30,7 +38,7 @@ user = User.build( :email => "tom@tom.joindiaspora.com",
:profile => { :first_name => "Alexander", :last_name => "Hamiltom", :profile => { :first_name => "Alexander", :last_name => "Hamiltom",
:image_url => "/images/user/tom.jpg"}}) :image_url => "/images/user/tom.jpg"}})
user.save user.save!
user.person.save! user.person.save!
user.seed_aspects user.seed_aspects
@ -42,12 +50,9 @@ user2 = User.build( :email => "korth@tom.joindiaspora.com",
:image_url => "/images/user/korth.jpg"}}) :image_url => "/images/user/korth.jpg"}})
user2.save user2.save!
user2.person.save! user2.person.save!
user2.seed_aspects user2.seed_aspects
# connecting users # connecting users
aspect = user.aspects.create(:name => "other dudes")
aspect2 = user2.aspects.create(:name => "presidents")
connect_users(user, aspect, user2, aspect2) connect_users(user, user.aspects.first, user2, user2.aspects.first)
user.aspects.create(:name => "Presidents")

View file

@ -53,7 +53,7 @@
<body> <body>
<!-- This file lives in public/500.html --> <!-- This file lives in public/500.html -->
<header> <header>
<img id="diaspora_logo" src="images/diaspora_logo_large.png"/> <img id="diaspora_logo" src="images/logo_large.png"/>
</header> </header>
<h1> <h1>
@ -65,17 +65,21 @@
<div id="satisfaction"> <div id="satisfaction">
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
if(window.location.hostname == 'joindiaspora.com'){
var is_ssl = ("https:" == document.location.protocol); var is_ssl = ("https:" == document.location.protocol);
var asset_host = is_ssl ? "https://s3.amazonaws.com/getsatisfaction.com/" : "http://s3.amazonaws.com/getsatisfaction.com/"; var asset_host = is_ssl ? "https://s3.amazonaws.com/getsatisfaction.com/" : "http://s3.amazonaws.com/getsatisfaction.com/";
document.write(unescape("%3Cscript src='" + asset_host + "javascripts/feedback-v2.js' type='text/javascript'%3E%3C/script%3E")); document.write(unescape("%3Cscript src='" + asset_host + "javascripts/feedback-v2.js' type='text/javascript'%3E%3C/script%3E"));
}
</script> </script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
if(window.location.hostname == 'joindiaspora.com'){
var feedback_widget_options = {}; var feedback_widget_options = {};
feedback_widget_options.display = "inline"; feedback_widget_options.display = "inline";
feedback_widget_options.company = "diaspora"; feedback_widget_options.company = "diaspora";
feedback_widget_options.style = 'problem'; feedback_widget_options.style = 'problem';
var feedback_widget = new GSFN.feedback_widget(feedback_widget_options); var feedback_widget = new GSFN.feedback_widget(feedback_widget_options);
}
</script> </script>
</div> </div>

View file

@ -5,21 +5,23 @@
require 'spec_helper' require 'spec_helper'
describe Request do describe Request do
let(:user) { make_user } before do
let(:user2) { make_user } @user = make_user
let(:person) { Factory :person } @user2 = make_user
let(:aspect) { user.aspects.create(:name => "dudes") } @person = Factory :person
let(:request){ user.send_contact_request_to user2.person, aspect } @aspect = @user.aspects.create(:name => "dudes")
@aspect2 = @user2.aspects.create(:name => "Snoozers")
end
describe 'validations' do describe 'validations' do
before do before do
@request = Request.instantiate(:from => user.person, :to => user2.person, :into => aspect) @request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
end end
it 'is valid' do it 'is valid' do
@request.should be_valid @request.should be_valid
@request.from.should == user.person @request.from.should == @user.person
@request.to.should == user2.person @request.to.should == @user2.person
@request.into.should == aspect @request.into.should == @aspect
end end
it 'is from a person' do it 'is from a person' do
@request.from = nil @request.from = nil
@ -33,49 +35,49 @@ describe Request do
@request.into = nil @request.into = nil
@request.should be_valid @request.should be_valid
end end
it 'is not from an existing friend' do
Contact.create(:user => @user2, :person => @user.person, :aspects => [@aspect2])
@request.should_not be_valid
end
it 'is not a duplicate of an existing pending request' do it 'is not a duplicate of an existing pending request' do
request @request.save
@request.should_not be_valid duplicate_request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
duplicate_request.should_not be_valid
end end
it 'is not to an existing friend' do
connect_users(user, aspect, user2, user2.aspects.create(:name => 'new aspect'))
@request.should_not be_valid
end
it 'is not to yourself' do it 'is not to yourself' do
@request = Request.instantiate(:from => user.person, :to => user.person, :into => aspect) @request = Request.instantiate(:from => @user.person, :to => @user.person, :into => @aspect)
@request.should_not be_valid @request.should_not be_valid
end end
end end
describe 'scopes' do describe 'scopes' do
before do before do
@request = Request.instantiate(:from => user.person, :to => user2.person, :into => aspect) @request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
@request.save @request.save
end end
describe '.from' do describe '.from' do
it 'returns requests from a person' do it 'returns requests from a person' do
query = Request.from(user.person) query = Request.from(@user.person)
query.first.should == @request query.first.should == @request
end end
it 'returns requests from a user' do it 'returns requests from a user' do
query = Request.from(user) query = Request.from(@user)
query.first.should == @request query.first.should == @request
end end
end end
describe '.to' do describe '.to' do
it 'returns requests to a person' do it 'returns requests to a person' do
query = Request.to(user2.person) query = Request.to(@user2.person)
query.first.should == @request query.first.should == @request
end end
it 'returns requests to a user' do it 'returns requests to a user' do
query = Request.to(user2) query = Request.to(@user2)
query.first.should == @request query.first.should == @request
end end
end end
it 'chains' do it 'chains' do
Request.from(user).to(user2.person).first.should == @request Request.from(@user).to(@user2.person).first.should == @request
end end
end end
@ -90,7 +92,7 @@ describe Request do
@hash = @hashes.first @hash = @hashes.first
end end
it 'gives back requests' do it 'gives back requests' do
@hash[:request].should == Request.from(@user2).to(@user).first(:sent => false) @hash[:request].should == Request.from(@user2).to(@user).first
end end
it 'gives back people' do it 'gives back people' do
@hash[:sender].should == @user2.person @hash[:sender].should == @user2.person
@ -101,24 +103,24 @@ describe Request do
end end
describe 'xml' do describe 'xml' do
before do before do
@request = Request.new(:from => user.person, :to => user2.person, :into => aspect) @request = Request.new(:from => @user.person, :to => @user2.person, :into => @aspect)
@xml = @request.to_xml.to_s @xml = @request.to_xml.to_s
end end
describe 'serialization' do describe 'serialization' do
it 'should not generate xml for the User as a Person' do it 'should not generate xml for the User as a Person' do
@xml.should_not include user.person.profile.first_name @xml.should_not include @user.person.profile.first_name
end end
it 'should serialize the handle and not the sender' do it 'should serialize the handle and not the sender' do
@xml.should include user.person.diaspora_handle @xml.should include @user.person.diaspora_handle
end end
it 'serializes the intended recipient handle' do it 'serializes the intended recipient handle' do
@xml.should include user2.person.diaspora_handle @xml.should include @user2.person.diaspora_handle
end end
it 'should not serialize the exported key' do it 'should not serialize the exported key' do
@xml.should_not include user.person.exported_key @xml.should_not include @user.person.exported_key
end end
it 'does not serialize the id' do it 'does not serialize the id' do
@ -131,10 +133,10 @@ describe Request do
@marshalled = Request.from_xml @xml @marshalled = Request.from_xml @xml
end end
it 'marshals the sender' do it 'marshals the sender' do
@marshalled.from.should == user.person @marshalled.from.should == @user.person
end end
it 'marshals the recipient' do it 'marshals the recipient' do
@marshalled.to.should == user2.person @marshalled.to.should == @user2.person
end end
it 'knows nothing about the aspect' do it 'knows nothing about the aspect' do
@marshalled.into.should be_nil @marshalled.into.should be_nil
@ -146,10 +148,10 @@ describe Request do
@marshalled = Diaspora::Parser.from_xml @d_xml @marshalled = Diaspora::Parser.from_xml @d_xml
end end
it 'marshals the sender' do it 'marshals the sender' do
@marshalled.from.should == user.person @marshalled.from.should == @user.person
end end
it 'marshals the recipient' do it 'marshals the recipient' do
@marshalled.to.should == user2.person @marshalled.to.should == @user2.person
end end
it 'knows nothing about the aspect' do it 'knows nothing about the aspect' do
@marshalled.into.should be_nil @marshalled.into.should be_nil

View file

@ -93,11 +93,10 @@ describe Diaspora::UserModules::Connecting do
let(:request2_for_user) {Request.instantiate(:to => user.person, :from => person_one)} let(:request2_for_user) {Request.instantiate(:to => user.person, :from => person_one)}
let(:request_from_myself) {Request.instantiate(:to => user.person, :from => user.person)} let(:request_from_myself) {Request.instantiate(:to => user.person, :from => user.person)}
before do before do
request_for_user.save
user.receive(request_for_user.to_diaspora_xml, person) user.receive(request_for_user.to_diaspora_xml, person)
@received_request = Request.from(person).to(user.person).first(:sent => false) @received_request = Request.from(person).to(user.person).first
user.receive(request2_for_user.to_diaspora_xml, person_one) user.receive(request2_for_user.to_diaspora_xml, person_one)
@received_request2 = Request.from(person_one).to(user.person).first(:sent => false) @received_request2 = Request.from(person_one).to(user.person).first
user.reload user.reload
end end