Skip to content
Extraits de code Groupes Projets
Valider c4b931c3 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

IZ RS getting remote messages (not yet done)

parent 4da68fc4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class StatusMessagesController < ApplicationController
before_filter :authenticate_user!
#before_filter :authenticate_user!
include StatusMessagesHelper
def index
@status_messages = StatusMessage.all
@friends = Friend.all
respond_to do |format|
format.html
format.xml {render :xml => StatusMessages.new(@status_messages).to_xml }
format.json { render :json => @status_messages }
end
end
def create
......
module StatusMessagesHelper
def my_latest_message
message = StatusMessage.my_newest
unless message.nil?
......@@ -7,4 +8,15 @@ module StatusMessagesHelper
return "No message to display."
end
end
class StatusMessages
include ROXML
def initialize(messages=[])
@statusmessages = messages
end
xml_accessor :statusmessages, :as => [StatusMessage]
attr_accessor :statusmessages
end
end
......@@ -17,4 +17,4 @@ class Bookmark
def set_default_owner
self.owner ||= User.first.email
end
end
\ No newline at end of file
end
class Friend
include Mongoid::Document
include ROXML
xml_accessor :username
xml_accessor :url
field :username
field :url
validates_presence_of :username, :url
end
\ No newline at end of file
validates_presence_of :username, :url
end
......@@ -2,7 +2,8 @@ class StatusMessage
include Mongoid::Document
include Mongoid::Timestamps
include ROXML
include StatusMessagesHelper
xml_accessor :message
xml_accessor :owner
......@@ -21,10 +22,15 @@ class StatusMessage
def self.my_newest
StatusMessage.newest(User.first.email)
end
def self.retrieve_from_friend(friend)
StatusMessages.from_xml `curl #{friend.url}status_messages.xml --user a@a.com:aaaaaa`
end
protected
def set_default_owner
self.owner ||= User.first.email
self.owner ||= User.first.email
end
end
......@@ -47,10 +47,21 @@ describe StatusMessagesController do
response.should render_template(:show)
end
it "should return xml on the show type if the meme type exsits" do
it "should return xml on show type if the MIME type exists" do
request.env["HTTP_ACCEPT"] = "application/xml"
message = StatusMessage.first
get :show, :id => message.id
response.body.include?(message.to_xml.to_s).should be true
end
it "should return xml on index if the MIME type exists" do
Factory.create(:status_message)
request.env["HTTP_ACCEPT"] = "application/xml"
get :index
StatusMessage.all.each do |message|
response.body.include?(message.message).should be true
response.body.include?(message.owner).should be true
end
end
end
......@@ -9,7 +9,6 @@ describe Bookmark do
end
it "should add an owner if none is present" do
#User.create(:email => "bob@aol.com", :password => "big bux")
Factory.create(:user, :email => "bob@aol.com")
n = Factory.create(:bookmark)
n.owner.should == "bob@aol.com"
......
......@@ -8,4 +8,23 @@ describe Friend do
n.url = "http://max.com/"
n.valid?.should be true
end
describe "XML" do
before do
@f = Factory.build(:friend)
@xml = "<friend>\n <username>#{@f.username}</username>\n <url>#{@f.url}</url>\n</friend>"
end
it 'should serialize to XML' do
@f.to_xml.to_s.should == @xml
end
it 'should marshal serialized XML to object' do
parsed = Friend.from_xml(@xml)
parsed.username.should == @f.username
parsed.url.should == @f.url
parsed.valid?.should be_true
end
end
end
......@@ -46,6 +46,27 @@ describe StatusMessage do
parsed = StatusMessage.from_xml(@xml)
parsed.message.should == "I hate WALRUSES!"
parsed.owner.should == "Bob"
parsed.valid?.should be_true
end
end
describe "retrieving" do
before do
@remote = Factory.create(:friend, :url => "http://localhost:1254/")
@remote_xml = (0..5).collect{Factory.create(:status_message).to_xml}
StatusMessages = StatusMessagesHelper::StatusMessages
#@remote_messages = (0..5).collect {|a| Factory.build(:status_message)}
#stub with response of @remote_msg.xml
end
it "should marshal xml and serialize it" do
messages = StatusMessages.new(@remote_xml)
unreadable_xml = messages.to_xml.to_s.sub("\t\t","\t")
unreadable_xml.include?(remote_xml.first.to_s).should be true
end
it "marshal retrieved xml" do
StatusMessage.retrieve_from_friend(@remote).to_xml.should == StatusMessages.from_xml(@remote_xml).to_xml
# .from_xml == @remote_messages
end
end
end
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