Skip to content
Extraits de code Groupes Projets
Valider c800b0bf rédigé par danielgrippi's avatar danielgrippi
Parcourir les fichiers

use fixtures in request spec; collapsed xml specs

parent bef83776
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
class Request < ActiveRecord::Base class Request < ActiveRecord::Base
require File.join(Rails.root, 'lib/diaspora/webhooks') require File.join(Rails.root, 'lib/diaspora/webhooks')
require File.join(Rails.root, 'lib/postzord/dispatch') require File.join(Rails.root, 'lib/postzord/dispatch')
include Diaspora::Webhooks include Diaspora::Webhooks
include ROXML include ROXML
xml_accessor :sender_handle xml_accessor :sender_handle
xml_accessor :recipient_handle xml_accessor :recipient_handle
belongs_to :sender, :class_name => 'Person' belongs_to :sender, :class_name => 'Person'
belongs_to :recipient, :class_name => 'Person' belongs_to :recipient, :class_name => 'Person'
belongs_to :aspect belongs_to :aspect
...@@ -34,10 +34,13 @@ class Request < ActiveRecord::Base ...@@ -34,10 +34,13 @@ class Request < ActiveRecord::Base
) )
end end
def diaspora_handle
sender_handle
end
def sender_handle def sender_handle
sender.diaspora_handle sender.diaspora_handle
end end
def sender_handle= sender_handle def sender_handle= sender_handle
self.sender = Person.where(:diaspora_handle => sender_handle).first self.sender = Person.where(:diaspora_handle => sender_handle).first
end end
...@@ -45,17 +48,12 @@ class Request < ActiveRecord::Base ...@@ -45,17 +48,12 @@ class Request < ActiveRecord::Base
def recipient_handle def recipient_handle
recipient.diaspora_handle recipient.diaspora_handle
end end
def recipient_handle= recipient_handle def recipient_handle= recipient_handle
self.recipient = Person.where(:diaspora_handle => recipient_handle).first self.recipient = Person.where(:diaspora_handle => recipient_handle).first
end end
def diaspora_handle
sender_handle
end
def notification_type(user, person) def notification_type(user, person)
if Contact.where(:user_id => user.id, :person_id => person.id).first if Contact.unscoped.where(:user_id => user.id, :person_id => person.id).first
Notifications::RequestAccepted Notifications::RequestAccepted
else else
Notifications::NewRequest Notifications::NewRequest
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110331004720) do ActiveRecord::Schema.define(:version => 20110331222629) do
create_table "aspect_memberships", :force => true do |t| create_table "aspect_memberships", :force => true do |t|
t.integer "aspect_id", :null => false t.integer "aspect_id", :null => false
...@@ -250,7 +250,6 @@ ActiveRecord::Schema.define(:version => 20110331004720) do ...@@ -250,7 +250,6 @@ ActiveRecord::Schema.define(:version => 20110331004720) do
add_index "posts", ["status_message_id", "pending"], :name => "index_posts_on_status_message_id_and_pending" add_index "posts", ["status_message_id", "pending"], :name => "index_posts_on_status_message_id_and_pending"
add_index "posts", ["status_message_id"], :name => "index_posts_on_status_message_id" add_index "posts", ["status_message_id"], :name => "index_posts_on_status_message_id"
add_index "posts", ["type", "pending", "id"], :name => "index_posts_on_type_and_pending_and_id" add_index "posts", ["type", "pending", "id"], :name => "index_posts_on_type_and_pending_and_id"
add_index "posts", ["type"], :name => "index_posts_on_type"
create_table "profiles", :force => true do |t| create_table "profiles", :force => true do |t|
t.string "diaspora_handle" t.string "diaspora_handle"
......
...@@ -6,11 +6,11 @@ require 'spec_helper' ...@@ -6,11 +6,11 @@ require 'spec_helper'
describe Request do describe Request do
before do before do
@user = Factory.create(:user) @user = alice
@user2 = Factory.create(:user) @user2 = eve
@person = Factory :person @person = Factory :person
@aspect = @user.aspects.create(:name => "dudes") @aspect = @user.aspects.first
@aspect2 = @user2.aspects.create(:name => "Snoozers") @aspect2 = @user2.aspects.first
end end
describe 'validations' do describe 'validations' do
...@@ -54,13 +54,14 @@ describe Request do ...@@ -54,13 +54,14 @@ describe Request do
before do before do
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect) @request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
end end
it "returns 'request_accepted' if there is a pending contact" do
Contact.create(:user_id => @user.id, :person_id => @person.id) it 'returns request_accepted' do
@request.notification_type(@user, @person).should == Notifications::RequestAccepted @user.contacts.create(:person_id => @person.id, :pending => true)
@request.notification_type(@user, @person).should == Notifications::RequestAccepted
end end
it 'returns new_request if there is not a pending contact' do it 'returns new_request' do
@request.notification_type(@user, @person).should == Notifications::NewRequest @request.notification_type(@user, @person).should == Notifications::NewRequest
end end
end end
...@@ -71,56 +72,37 @@ describe Request do ...@@ -71,56 +72,37 @@ describe Request do
end end
end end
describe 'xml' do describe '#receive' do
it 'calls receive_contact_request on user' do
request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
@user2.should_receive(:receive_contact_request).with(request)
request.receive(@user2, @user.person)
end
end
context 'xml' do
before do before do
@request = Request.new(:sender => @user.person, :recipient => @user2.person, :aspect => @aspect) @request = Request.new(:sender => @user.person, :recipient => @user2.person, :aspect => @aspect)
@xml = @request.to_xml.to_s @xml = @request.to_xml.to_s
end end
describe 'serialization' do
it 'does not generate xml for the User as a Person' do
@xml.should_not include @user.person.profile.first_name
end
it 'serializes the handle and not the sender' do describe 'serialization' do
it 'produces valid xml' do
@xml.should include @user.person.diaspora_handle @xml.should include @user.person.diaspora_handle
end
it 'serializes the intended recipient handle' do
@xml.should include @user2.person.diaspora_handle @xml.should include @user2.person.diaspora_handle
end
it 'does not serialize the exported key' do
@xml.should_not include @user.person.exported_key @xml.should_not include @user.person.exported_key
@xml.should_not include @user.person.profile.first_name
end end
end end
describe 'marshalling' do context 'marshalling' do
before do it 'produces a request object' do
@marshalled = Request.from_xml @xml marshalled = Request.from_xml @xml
end
it 'marshals the sender' do marshalled.sender.should == @user.person
@marshalled.sender.should == @user.person marshalled.recipient.should == @user2.person
end marshalled.aspect.should be_nil
it 'marshals the recipient' do
@marshalled.recipient.should == @user2.person
end
it 'knows nothing about the aspect' do
@marshalled.aspect.should be_nil
end
end
describe 'marshalling with diaspora wrapper' do
before do
@d_xml = @request.to_diaspora_xml
@marshalled = Diaspora::Parser.from_xml @d_xml
end
it 'marshals the sender' do
@marshalled.sender.should == @user.person
end
it 'marshals the recipient' do
@marshalled.recipient.should == @user2.person
end
it 'knows nothing about the aspect' do
@marshalled.aspect.should be_nil
end end
end end
end end
......
...@@ -65,12 +65,6 @@ describe Diaspora::UserModules::Connecting do ...@@ -65,12 +65,6 @@ describe Diaspora::UserModules::Connecting do
received_req = @r.receive(user, person_one) received_req = @r.receive(user, person_one)
}.should_not change(Contact, :count) }.should_not change(Contact, :count)
end end
it 'enqueues a mail job' do
Resque.should_receive(:enqueue).with(Job::MailRequestReceived, user.id, person.id, anything)
zord = Postzord::Receiver.new(user, :object => @r, :person => person)
zord.receive_object
end
end end
describe '#receive_request_acceptance' do describe '#receive_request_acceptance' do
...@@ -79,18 +73,13 @@ describe Diaspora::UserModules::Connecting do ...@@ -79,18 +73,13 @@ describe Diaspora::UserModules::Connecting do
@acceptance = @original_request.reverse_for(user2) @acceptance = @original_request.reverse_for(user2)
end end
it 'connects to the acceptor' do it 'connects to the acceptor' do
@acceptance.receive(user, user2.person) user.receive_contact_request(@acceptance)
user.contact_for(user2.person).should_not be_nil user.contact_for(user2.person).should_not be_nil
end end
it 'deletes the acceptance' do it 'deletes the acceptance' do
@acceptance.receive(user, user2.person) user.receive_contact_request(@acceptance)
Request.where(:sender_id => user2.person.id, :recipient_id => user.person.id).should be_empty Request.where(:sender_id => user2.person.id, :recipient_id => user.person.id).should be_empty
end end
it 'enqueues a mail job' do
Resque.should_receive(:enqueue).with(Job::MailRequestAcceptance, user.id, user2.person.id, nil).once
zord = Postzord::Receiver.new(user, :object => @acceptance, :person => user2.person)
zord.receive_object
end
end end
context 'received a contact request' do context 'received a contact request' do
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter