DG MS; added database_cleaner for spec runner. touched up common specs for webhooks; depirated old status message to xml
This commit is contained in:
parent
d4bf2f539d
commit
c430aaff18
9 changed files with 69 additions and 89 deletions
2
Gemfile
2
Gemfile
|
|
@ -11,7 +11,6 @@ gem "haml"
|
|||
gem "devise", :git => "git://github.com/plataformatec/devise.git"
|
||||
gem 'roxml', :git => "git://github.com/Empact/roxml.git"
|
||||
|
||||
|
||||
gem 'dm-core'
|
||||
|
||||
group :test do
|
||||
|
|
@ -22,6 +21,7 @@ group :test do
|
|||
gem 'redgreen'
|
||||
gem 'autotest'
|
||||
gem 'factory_girl_rails'
|
||||
gem 'database_cleaner'
|
||||
end
|
||||
|
||||
group :development do
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
class StatusMessagesController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
include StatusMessagesHelper
|
||||
|
||||
def index
|
||||
@status_messages = StatusMessage.criteria.all.order_by( [:created_at, :desc] )
|
||||
|
|
@ -8,7 +7,7 @@ class StatusMessagesController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml {render :xml => StatusMessages.new(@status_messages).to_xml }
|
||||
format.xml {render :xml => Post.build_xml_for(@status_messages)}
|
||||
format.json { render :json => @status_messages }
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,14 +9,4 @@ module StatusMessagesHelper
|
|||
end
|
||||
end
|
||||
|
||||
class StatusMessages
|
||||
include ROXML
|
||||
|
||||
def initialize(messages=[])
|
||||
@statusmessages = messages
|
||||
end
|
||||
|
||||
xml_accessor :statusmessages, :as => [StatusMessage]
|
||||
attr_accessor :statusmessages
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,4 +29,18 @@ Diaspora::Application.configure do
|
|||
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
||||
# like if you have constraints or database-specific column types
|
||||
# config.active_record.schema_format = :sql
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
|
||||
begin
|
||||
require 'database_cleaner'
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
DatabaseCleaner.orm = "mongoid"
|
||||
rescue LoadError => ignore_if_database_cleaner_not_present
|
||||
puts "Error on cleaner"
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,23 +4,18 @@ module Diaspora
|
|||
def self.included(klass)
|
||||
klass.class_eval do
|
||||
after_save :notify_friends
|
||||
|
||||
@@queue = MessageHandler.new
|
||||
|
||||
def notify_friends
|
||||
if self.owner == User.first.email
|
||||
xml = Post.build_xml_for(self)
|
||||
@@queue.add_post_request( friends_with_permissions, xml )
|
||||
@@queue.process
|
||||
if self.owner == User.first.email
|
||||
xml = Post.build_xml_for(self)
|
||||
@@queue.add_post_request( friends_with_permissions, xml )
|
||||
@@queue.process
|
||||
end
|
||||
end
|
||||
|
||||
def prep_webhook
|
||||
self.to_xml.to_s
|
||||
end
|
||||
|
||||
def prep_many
|
||||
"<post>#{self.prep_webhook}</post>"
|
||||
def prep_webhook
|
||||
"<post>#{self.to_xml.to_s}</post>"
|
||||
end
|
||||
|
||||
def friends_with_permissions
|
||||
|
|
@ -29,7 +24,7 @@ module Diaspora
|
|||
|
||||
def self.build_xml_for(posts)
|
||||
xml = "<posts>"
|
||||
posts.each {|x| xml << x.prep_many}
|
||||
posts.each {|x| xml << x.prep_webhook}
|
||||
xml = xml + "</posts>"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ describe Diaspora do
|
|||
describe Webhooks do
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@post = Factory.build(:post)
|
||||
@post = Factory.create(:post)
|
||||
end
|
||||
|
||||
it "should add the following methods to Post on inclusion" do
|
||||
|
|
@ -18,7 +18,7 @@ describe Diaspora do
|
|||
end
|
||||
|
||||
it "should convert an object to a proper webhook" do
|
||||
@post.prep_webhook.should == @post.to_xml.to_s
|
||||
@post.prep_webhook.should == "<post>#{@post.to_xml.to_s}</post>"
|
||||
end
|
||||
|
||||
it "should retrieve all valid friend endpoints" do
|
||||
|
|
@ -31,25 +31,21 @@ describe Diaspora do
|
|||
@post.friends_with_permissions.should include("http://www.jane.com/receive/")
|
||||
end
|
||||
|
||||
it "should send all prepped webhooks to be processed" do
|
||||
MessageHandler.any_instance.stubs(:add_post_request).returns true
|
||||
MessageHandler.any_instance.stubs(:process).returns true
|
||||
@post.notify_friends.should be true
|
||||
it "should send an owners post to their friends" do
|
||||
Post.stub(:build_xml_for).and_return(true)
|
||||
Post.should_receive(:build_xml_for).and_return true
|
||||
@post.save
|
||||
end
|
||||
|
||||
it "should check that it only sends a user's posts to their friends" do
|
||||
Factory.create(:friend, :url => "http://www.bob.com")
|
||||
Factory.create(:friend, :url => "http://www.alice.com")
|
||||
Factory.create(:status_message)
|
||||
Factory.create(:bookmark)
|
||||
|
||||
# this is a messagequeue thing; out of scope for webhooks action
|
||||
it "should check that it does not send a friends post to an owners friends" do
|
||||
Post.stub(:build_xml_for).and_return(true)
|
||||
Post.should_not_receive(:build_xml_for)
|
||||
Factory.create(:post, :owner => "nottheowner@post.com")
|
||||
end
|
||||
|
||||
it "should ensure no duplicate url posts" do
|
||||
pending
|
||||
# this is a messagequeue thing; out of scope for webhooks action
|
||||
|
||||
it "should ensure one url is created for every friend" do
|
||||
5.times {Factory.create(:friend)}
|
||||
@post.friends_with_permissions.size.should == 5
|
||||
end
|
||||
|
||||
it "should build an xml object containing multiple Post types" do
|
||||
|
|
|
|||
|
|
@ -13,4 +13,22 @@ describe Bookmark do
|
|||
n = Factory.create(:bookmark)
|
||||
n.owner.should == "bob@aol.com"
|
||||
end
|
||||
|
||||
describe "XML" do
|
||||
it 'should serialize to XML' do
|
||||
Factory.create(:user)
|
||||
message = Factory.create(:bookmark, :title => "Reddit", :link => "http://reddit.com")
|
||||
message.to_xml.to_s.should include "<title>Reddit</title>"
|
||||
message.to_xml.to_s.should include "<link>http://reddit.com</link>"
|
||||
end
|
||||
|
||||
it 'should marshal serialized XML to object' do
|
||||
xml = "<bookmark><title>Reddit</message><link>http://reddit.com</link><owner>bob@aol.com</owner></bookmark>"
|
||||
parsed = Bookmark.from_xml(xml)
|
||||
parsed.title.should == "Reddit"
|
||||
parsed.link.should == "http://reddit.com"
|
||||
parsed.owner.should == "bob@aol.com"
|
||||
parsed.valid?.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
include StatusMessagesHelper
|
||||
|
||||
describe StatusMessage do
|
||||
before do
|
||||
|
|
@ -40,53 +39,12 @@ describe StatusMessage do
|
|||
end
|
||||
|
||||
it 'should marshal serialized XML to object' do
|
||||
xml = "<statusmessage>\n <message>I hate WALRUSES!</message><owner>Bob@rob.ert</owner></statusmessage>"
|
||||
xml = "<statusmessage><message>I hate WALRUSES!</message><owner>Bob@rob.ert</owner></statusmessage>"
|
||||
parsed = StatusMessage.from_xml(xml)
|
||||
parsed.message.should == "I hate WALRUSES!"
|
||||
parsed.owner.should == "Bob@rob.ert"
|
||||
parsed.valid?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe "retrieving" do
|
||||
before do
|
||||
@remote = Factory.create(:friend, :url => "fakeurl")#http://localhost:1254/")
|
||||
Curl.stub!(:get).and_return(@@remote_xml)
|
||||
end
|
||||
it "should marshal xml and serialize it without error" do
|
||||
StatusMessages.from_xml(@@remote_xml).to_xml.to_s.should == @@remote_xml
|
||||
end
|
||||
it "marshal retrieved xml" do
|
||||
remote_msgs = StatusMessage.retrieve_from_friend(@remote)
|
||||
local_msgs = StatusMessages.from_xml(@@remote_xml)
|
||||
|
||||
|
||||
remote_msgs.statusmessages.each{ |m| local_msgs.statusmessages.include?(m).should be_true}
|
||||
local_msgs.statusmessages.each{ |m| remote_msgs.statusmessages.include?(m).should be_true}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@remote_xml =
|
||||
"<statusmessages>
|
||||
<statusmessage>
|
||||
<message>jimmy's 22 whales</message>
|
||||
<owner>tester@yahoo.com</owner>
|
||||
</statusmessage>
|
||||
<statusmessage>
|
||||
<message>jimmy's 23 whales</message>
|
||||
<owner>tester@yahoo.com</owner>
|
||||
</statusmessage>
|
||||
<statusmessage>
|
||||
<message>jimmy's 24 whales</message>
|
||||
<owner>tester@yahoo.com</owner>
|
||||
</statusmessage>
|
||||
<statusmessage>
|
||||
<message>jimmy's 25 whales</message>
|
||||
<owner>tester@yahoo.com</owner>
|
||||
</statusmessage>
|
||||
<statusmessage>
|
||||
<message>jimmy's 26 whales</message>
|
||||
<owner>tester@yahoo.com</owner>
|
||||
</statusmessage>
|
||||
</statusmessages>"
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
ENV["RAILS_ENV"] ||= 'test'
|
||||
require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails)
|
||||
require 'rspec/rails'
|
||||
require 'database_cleaner'
|
||||
#require File.dirname(__FILE__) + "/factories"
|
||||
include Devise::TestHelpers
|
||||
|
||||
|
|
@ -20,12 +21,21 @@ Rspec.configure do |config|
|
|||
# config.mock_with :rr
|
||||
config.mock_with :rspec
|
||||
|
||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||
config.before(:each) do
|
||||
Mongoid.master.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)
|
||||
DatabaseCleaner.strategy = :truncation
|
||||
DatabaseCleaner.orm = "mongoid"
|
||||
|
||||
config.before(:suite) do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
DatabaseCleaner.clean_with(:truncation)
|
||||
end
|
||||
|
||||
end
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.start
|
||||
end
|
||||
|
||||
config.after(:each) do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
|
||||
|
||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||
|
|
|
|||
Loading…
Reference in a new issue