Merge branch 'master' of github.com:diaspora/diaspora_rails

This commit is contained in:
Raphael 2010-06-22 15:47:32 -07:00
commit 65f4a7f378
13 changed files with 45 additions and 18 deletions

View file

@ -32,4 +32,9 @@ module ApplicationHelper
def mine?(post) def mine?(post)
post.owner == User.first.email post.owner == User.first.email
end end
def type_partial(post)
class_name = post.class.name.to_s.underscore
"#{class_name.pluralize}/#{class_name}"
end
end end

View file

@ -1,8 +1,5 @@
module DashboardHelper module DashboardHelper
def type_partial(post)
class_name = post.class.name.to_s.underscore
"#{class_name.pluralize}/#{class_name}"
end
end end

View file

@ -41,7 +41,7 @@ class Post
protected protected
def send_to_view def send_to_view
WebSocket.update_clients (self.to_json) WebSocket.update_clients(self)
end end
def set_defaults def set_defaults

View file

@ -4,7 +4,10 @@
%b shared a link %b shared a link
%br %br
= post.title = post.title
= link_to post.link /- (foo = post.link.to_s)
/- (bar = post.link)
%a{:href => "#{post.link}"}
= post.link
%div.time= link_to "#{time_ago_in_words(post.updated_at)} ago", bookmark_path(post) %div.time= link_to "#{time_ago_in_words(post.updated_at)} ago", bookmark_path(post)
- if mine?(post) - if mine?(post)
= link_to 'Destroy', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete = link_to 'Destroy', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete

View file

@ -10,6 +10,15 @@
= javascript_include_tag 'jquery142' = javascript_include_tag 'jquery142'
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" /= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"
= javascript_include_tag 'rails' = javascript_include_tag 'rails'
- unless request.user_agent.include? "Safari" ||"Chrome"
= javascript_include_tag 'FABridge'
= javascript_include_tag 'swfobject'
= javascript_include_tag 'web_socket'
:javascript
WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf";
= javascript_include_tag 'socket' if user_signed_in? = javascript_include_tag 'socket' if user_signed_in?
= csrf_meta_tag = csrf_meta_tag
= yield(:head) = yield(:head)
@ -42,6 +51,7 @@
= link_to "login", new_user_session_path = link_to "login", new_user_session_path
#header_below #header_below
- if user_signed_in? - if user_signed_in?
%h1#user_name %h1#user_name
= link_to User.first.real_name, root_url = link_to User.first.real_name, root_url

View file

@ -26,8 +26,14 @@ module WebSocket
end end
} }
#this should get folded into message queue i think? #this should get folded into message queue i think?
def self.update_clients(json) def self.update_clients(object)
@channel.push(json) if @channel view = ActionView::Base.new(ActionController::Base.view_paths, {})
class << view
include ApplicationHelper
include Rails.application.routes.url_helpers
end
n = view.render(:partial =>view.type_partial(object), :locals => {:post => object})
@channel.push(n) if @channel
end end
end end

View file

@ -1,8 +1,10 @@
$(document).ready(function(){ $(document).ready(function(){
function debug(str){ $("#debug").append("<p>" + str); }; function debug(str){ $("#debug").append("<p>" + str); };
ws = new WebSocket("ws://localhost:8080/"); ws = new WebSocket("ws://localhost:8080/");
ws.onmessage = function(evt) { $(".msg").prepend("<p>"+evt.data+"</p>"); }; ws.onmessage = function(evt) {
$("#stream").prepend($(evt.data).fadeIn("fast"));
};
ws.onclose = function() { debug("socket closed"); }; ws.onclose = function() { debug("socket closed"); };
ws.onopen = function() { ws.onopen = function() {
debug("connected..."); debug("connected...");

View file

@ -125,14 +125,14 @@ ul#stream {
ul#stream > li { ul#stream > li {
list-style: none; list-style: none;
padding: 1em; padding: 1em;
border-bottom: 1px solid #f1f1f1; } border-bottom: 1px solid #f1f1f1;
margin-bottom: 5px; }
li.message { li.message {
line-height: 140%; line-height: 140%;
font-size: 120%; font-size: 120%;
font-family: "Lucida Grande"; font-family: "Lucida Grande";
color: #999999; color: #999999; }
margin-bottom: 5px; }
li.message span.from { li.message span.from {
color: black; color: black;
font-weight: bold; font-weight: bold;

View file

@ -151,6 +151,7 @@ ul#stream
:padding 1em :padding 1em
:border :border
:bottom 1px solid #f1f1f1 :bottom 1px solid #f1f1f1
:margin-bottom 5px
li.message li.message
:line-height 140% :line-height 140%
@ -158,7 +159,7 @@ li.message
:size 120% :size 120%
:family 'Lucida Grande' :family 'Lucida Grande'
:color #999 :color #999
:margin-bottom 5px
span.from span.from
:color #000 :color #000

View file

@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe BookmarksController do describe BookmarksController do
before do before do
#TODO(dan) Mocking Warden; this is a temp fix #TODO(dan) Mocking Warden; this is a temp fix
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user) request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user)
@bob = Factory.build(:user) @bob = Factory.build(:user)
@bookmark = Factory.build(:bookmark) @bookmark = Factory.build(:bookmark)
@ -31,7 +32,7 @@ describe BookmarksController do
it "update action should redirect when model is valid" do it "update action should redirect when model is valid" do
#TODO(dan) look into why we need to create a new bookmark object here #TODO(dan) look into why we need to create a new bookmark object here
Bookmark.any_instance.stubs(:valid?).returns(true) Bookmark.any_instance.stubs(:valid?).returns(true)
n = Factory.create(:bookmark, :link => "http://hotub.com") n = Factory.create(:bookmark, :link => "http://hotub.com/")
n.save n.save
put :update, :id => Bookmark.first.id put :update, :id => Bookmark.first.id
response.should redirect_to(bookmark_url(assigns[:bookmark])) response.should redirect_to(bookmark_url(assigns[:bookmark]))

View file

@ -39,7 +39,7 @@ describe Diaspora do
describe "body" do describe "body" do
before do before do
@post = Factory.create(:post) @post = Factory.create(:status_message)
end end
it "should add the following methods to Post on inclusion" do it "should add the following methods to Post on inclusion" do
@ -71,7 +71,7 @@ describe Diaspora do
it "should check that it does not send a friends post to an owners friends" do 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.stub(:build_xml_for).and_return(true)
Post.should_not_receive(:build_xml_for) Post.should_not_receive(:build_xml_for)
Factory.create(:post, :owner => "nottheowner@post.com") Factory.create(:status_message, :owner => "nottheowner@post.com")
end end
it "should ensure one url is created for every friend" do it "should ensure one url is created for every friend" do

View file

@ -10,7 +10,9 @@ describe Post do
describe 'defaults' do describe 'defaults' do
before do before do
WebSocket.stub!(:update_clients)
@post = Factory.create(:post, :owner => nil, :source => nil, :snippet => nil) @post = Factory.create(:post, :owner => nil, :source => nil, :snippet => nil)
end end
it "should add an owner if none is present" do it "should add an owner if none is present" do