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

DG MS; added database_cleaner for spec runner. touched up common specs for...

DG MS; added database_cleaner for spec runner.  touched up common specs for webhooks; depirated old status message to xml
parent d4bf2f53
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -11,7 +11,6 @@ gem "haml" ...@@ -11,7 +11,6 @@ gem "haml"
gem "devise", :git => "git://github.com/plataformatec/devise.git" gem "devise", :git => "git://github.com/plataformatec/devise.git"
gem 'roxml', :git => "git://github.com/Empact/roxml.git" gem 'roxml', :git => "git://github.com/Empact/roxml.git"
gem 'dm-core' gem 'dm-core'
group :test do group :test do
...@@ -22,6 +21,7 @@ group :test do ...@@ -22,6 +21,7 @@ group :test do
gem 'redgreen' gem 'redgreen'
gem 'autotest' gem 'autotest'
gem 'factory_girl_rails' gem 'factory_girl_rails'
gem 'database_cleaner'
end end
group :development do group :development do
......
class StatusMessagesController < ApplicationController class StatusMessagesController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
include StatusMessagesHelper
def index def index
@status_messages = StatusMessage.criteria.all.order_by( [:created_at, :desc] ) @status_messages = StatusMessage.criteria.all.order_by( [:created_at, :desc] )
...@@ -8,7 +7,7 @@ class StatusMessagesController < ApplicationController ...@@ -8,7 +7,7 @@ class StatusMessagesController < ApplicationController
respond_to do |format| respond_to do |format|
format.html 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 } format.json { render :json => @status_messages }
end end
......
...@@ -9,14 +9,4 @@ module StatusMessagesHelper ...@@ -9,14 +9,4 @@ module StatusMessagesHelper
end end
end end
class StatusMessages
include ROXML
def initialize(messages=[])
@statusmessages = messages
end
xml_accessor :statusmessages, :as => [StatusMessage]
attr_accessor :statusmessages
end
end end
...@@ -29,4 +29,18 @@ Diaspora::Application.configure do ...@@ -29,4 +29,18 @@ Diaspora::Application.configure do
# This is necessary if your schema can't be completely dumped by the schema dumper, # 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 # like if you have constraints or database-specific column types
# config.active_record.schema_format = :sql # 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 end
...@@ -4,23 +4,18 @@ module Diaspora ...@@ -4,23 +4,18 @@ module Diaspora
def self.included(klass) def self.included(klass)
klass.class_eval do klass.class_eval do
after_save :notify_friends after_save :notify_friends
@@queue = MessageHandler.new @@queue = MessageHandler.new
def notify_friends def notify_friends
if self.owner == User.first.email if self.owner == User.first.email
xml = Post.build_xml_for(self) xml = Post.build_xml_for(self)
@@queue.add_post_request( friends_with_permissions, xml ) @@queue.add_post_request( friends_with_permissions, xml )
@@queue.process @@queue.process
end end
end end
def prep_webhook
self.to_xml.to_s
end
def prep_many def prep_webhook
"<post>#{self.prep_webhook}</post>" "<post>#{self.to_xml.to_s}</post>"
end end
def friends_with_permissions def friends_with_permissions
...@@ -29,7 +24,7 @@ module Diaspora ...@@ -29,7 +24,7 @@ module Diaspora
def self.build_xml_for(posts) def self.build_xml_for(posts)
xml = "<posts>" xml = "<posts>"
posts.each {|x| xml << x.prep_many} posts.each {|x| xml << x.prep_webhook}
xml = xml + "</posts>" xml = xml + "</posts>"
end end
end end
......
...@@ -8,7 +8,7 @@ describe Diaspora do ...@@ -8,7 +8,7 @@ describe Diaspora do
describe Webhooks do describe Webhooks do
before do before do
@user = Factory.create(:user) @user = Factory.create(:user)
@post = Factory.build(:post) @post = Factory.create(:post)
end end
it "should add the following methods to Post on inclusion" do it "should add the following methods to Post on inclusion" do
...@@ -18,7 +18,7 @@ describe Diaspora do ...@@ -18,7 +18,7 @@ describe Diaspora do
end end
it "should convert an object to a proper webhook" do 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 end
it "should retrieve all valid friend endpoints" do it "should retrieve all valid friend endpoints" do
...@@ -31,25 +31,21 @@ describe Diaspora do ...@@ -31,25 +31,21 @@ describe Diaspora do
@post.friends_with_permissions.should include("http://www.jane.com/receive/") @post.friends_with_permissions.should include("http://www.jane.com/receive/")
end end
it "should send all prepped webhooks to be processed" do it "should send an owners post to their friends" do
MessageHandler.any_instance.stubs(:add_post_request).returns true Post.stub(:build_xml_for).and_return(true)
MessageHandler.any_instance.stubs(:process).returns true Post.should_receive(:build_xml_for).and_return true
@post.notify_friends.should be true @post.save
end end
it "should check that it only sends a user's posts to their friends" do it "should check that it does not send a friends post to an owners friends" do
Factory.create(:friend, :url => "http://www.bob.com") Post.stub(:build_xml_for).and_return(true)
Factory.create(:friend, :url => "http://www.alice.com") Post.should_not_receive(:build_xml_for)
Factory.create(:status_message) Factory.create(:post, :owner => "nottheowner@post.com")
Factory.create(:bookmark)
# this is a messagequeue thing; out of scope for webhooks action
end end
it "should ensure no duplicate url posts" do it "should ensure one url is created for every friend" do
pending 5.times {Factory.create(:friend)}
# this is a messagequeue thing; out of scope for webhooks action @post.friends_with_permissions.size.should == 5
end end
it "should build an xml object containing multiple Post types" do it "should build an xml object containing multiple Post types" do
......
...@@ -13,4 +13,22 @@ describe Bookmark do ...@@ -13,4 +13,22 @@ describe Bookmark do
n = Factory.create(:bookmark) n = Factory.create(:bookmark)
n.owner.should == "bob@aol.com" n.owner.should == "bob@aol.com"
end 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 end
require File.dirname(__FILE__) + '/../spec_helper' require File.dirname(__FILE__) + '/../spec_helper'
include StatusMessagesHelper
describe StatusMessage do describe StatusMessage do
before do before do
...@@ -40,53 +39,12 @@ describe StatusMessage do ...@@ -40,53 +39,12 @@ describe StatusMessage do
end end
it 'should marshal serialized XML to object' do 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 = StatusMessage.from_xml(xml)
parsed.message.should == "I hate WALRUSES!" parsed.message.should == "I hate WALRUSES!"
parsed.owner.should == "Bob@rob.ert" parsed.owner.should == "Bob@rob.ert"
parsed.valid?.should be_true parsed.valid?.should be_true
end end
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 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 @@ ...@@ -3,6 +3,7 @@
ENV["RAILS_ENV"] ||= 'test' ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails) require File.dirname(__FILE__) + "/../config/environment" unless defined?(Rails)
require 'rspec/rails' require 'rspec/rails'
require 'database_cleaner'
#require File.dirname(__FILE__) + "/factories" #require File.dirname(__FILE__) + "/factories"
include Devise::TestHelpers include Devise::TestHelpers
...@@ -20,12 +21,21 @@ Rspec.configure do |config| ...@@ -20,12 +21,21 @@ Rspec.configure do |config|
# config.mock_with :rr # config.mock_with :rr
config.mock_with :rspec config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures" DatabaseCleaner.strategy = :truncation
config.before(:each) do DatabaseCleaner.orm = "mongoid"
Mongoid.master.collections.select { |c| c.name != 'system.indexes' }.each(&:drop)
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 # If you're not using ActiveRecord, or you'd prefer not to run each of your
......
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