use fixtures in request spec; collapsed xml specs
This commit is contained in:
parent
bef8377610
commit
c800b0bfef
4 changed files with 42 additions and 74 deletions
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
class Request < ActiveRecord::Base
|
||||
require File.join(Rails.root, 'lib/diaspora/webhooks')
|
||||
|
||||
require File.join(Rails.root, 'lib/postzord/dispatch')
|
||||
|
||||
include Diaspora::Webhooks
|
||||
include ROXML
|
||||
|
||||
xml_accessor :sender_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 :aspect
|
||||
|
||||
|
|
@ -34,10 +34,13 @@ class Request < ActiveRecord::Base
|
|||
)
|
||||
end
|
||||
|
||||
def diaspora_handle
|
||||
sender_handle
|
||||
end
|
||||
|
||||
def sender_handle
|
||||
sender.diaspora_handle
|
||||
end
|
||||
|
||||
def sender_handle= sender_handle
|
||||
self.sender = Person.where(:diaspora_handle => sender_handle).first
|
||||
end
|
||||
|
|
@ -45,17 +48,12 @@ class Request < ActiveRecord::Base
|
|||
def recipient_handle
|
||||
recipient.diaspora_handle
|
||||
end
|
||||
|
||||
def recipient_handle= recipient_handle
|
||||
self.recipient = Person.where(:diaspora_handle => recipient_handle).first
|
||||
end
|
||||
|
||||
def diaspora_handle
|
||||
sender_handle
|
||||
end
|
||||
|
||||
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
|
||||
else
|
||||
Notifications::NewRequest
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# 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|
|
||||
t.integer "aspect_id", :null => false
|
||||
|
|
@ -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"], :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"], :name => "index_posts_on_type"
|
||||
|
||||
create_table "profiles", :force => true do |t|
|
||||
t.string "diaspora_handle"
|
||||
|
|
|
|||
|
|
@ -6,11 +6,11 @@ require 'spec_helper'
|
|||
|
||||
describe Request do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@user2 = Factory.create(:user)
|
||||
@user = alice
|
||||
@user2 = eve
|
||||
@person = Factory :person
|
||||
@aspect = @user.aspects.create(:name => "dudes")
|
||||
@aspect2 = @user2.aspects.create(:name => "Snoozers")
|
||||
@aspect = @user.aspects.first
|
||||
@aspect2 = @user2.aspects.first
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
|
|
@ -54,13 +54,14 @@ describe Request do
|
|||
before do
|
||||
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||
end
|
||||
it "returns 'request_accepted' if there is a pending contact" do
|
||||
Contact.create(:user_id => @user.id, :person_id => @person.id)
|
||||
@request.notification_type(@user, @person).should == Notifications::RequestAccepted
|
||||
|
||||
it 'returns request_accepted' do
|
||||
@user.contacts.create(:person_id => @person.id, :pending => true)
|
||||
@request.notification_type(@user, @person).should == Notifications::RequestAccepted
|
||||
end
|
||||
|
||||
it 'returns new_request if there is not a pending contact' do
|
||||
@request.notification_type(@user, @person).should == Notifications::NewRequest
|
||||
it 'returns new_request' do
|
||||
@request.notification_type(@user, @person).should == Notifications::NewRequest
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -71,56 +72,37 @@ describe Request do
|
|||
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
|
||||
@request = Request.new(:sender => @user.person, :recipient => @user2.person, :aspect => @aspect)
|
||||
@xml = @request.to_xml.to_s
|
||||
end
|
||||
|
||||
describe 'serialization' do
|
||||
it 'does not generate xml for the User as a Person' do
|
||||
it 'produces valid xml' do
|
||||
@xml.should include @user.person.diaspora_handle
|
||||
@xml.should include @user2.person.diaspora_handle
|
||||
@xml.should_not include @user.person.exported_key
|
||||
@xml.should_not include @user.person.profile.first_name
|
||||
end
|
||||
|
||||
it 'serializes the handle and not the sender' do
|
||||
@xml.should include @user.person.diaspora_handle
|
||||
end
|
||||
|
||||
it 'serializes the intended recipient handle' do
|
||||
@xml.should include @user2.person.diaspora_handle
|
||||
end
|
||||
|
||||
it 'does not serialize the exported key' do
|
||||
@xml.should_not include @user.person.exported_key
|
||||
end
|
||||
end
|
||||
|
||||
describe 'marshalling' do
|
||||
before do
|
||||
@marshalled = Request.from_xml @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
|
||||
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
|
||||
context 'marshalling' do
|
||||
it 'produces a request object' do
|
||||
marshalled = Request.from_xml @xml
|
||||
|
||||
marshalled.sender.should == @user.person
|
||||
marshalled.recipient.should == @user2.person
|
||||
marshalled.aspect.should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -65,12 +65,6 @@ describe Diaspora::UserModules::Connecting do
|
|||
received_req = @r.receive(user, person_one)
|
||||
}.should_not change(Contact, :count)
|
||||
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
|
||||
|
||||
describe '#receive_request_acceptance' do
|
||||
|
|
@ -79,18 +73,13 @@ describe Diaspora::UserModules::Connecting do
|
|||
@acceptance = @original_request.reverse_for(user2)
|
||||
end
|
||||
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
|
||||
end
|
||||
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
|
||||
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
|
||||
|
||||
context 'received a contact request' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue