IZ RS getting remote messages (not yet done)
This commit is contained in:
parent
4da68fc4b1
commit
c4b931c309
9 changed files with 92 additions and 12 deletions
|
|
@ -1,9 +1,17 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
class Friend
|
||||
include Mongoid::Document
|
||||
include ROXML
|
||||
|
||||
xml_accessor :username
|
||||
xml_accessor :url
|
||||
|
||||
field :username
|
||||
field :url
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ class StatusMessage
|
|||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
include ROXML
|
||||
include StatusMessagesHelper
|
||||
|
||||
xml_accessor :message
|
||||
xml_accessor :owner
|
||||
|
|
@ -22,9 +23,14 @@ class StatusMessage
|
|||
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
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue