RS MS added url for for the socket controller
This commit is contained in:
parent
bf0afeede0
commit
947f1a60e7
6 changed files with 47 additions and 16 deletions
|
|
@ -1,27 +1,31 @@
|
|||
class SocketController < ApplicationController
|
||||
include ApplicationHelper
|
||||
include SocketHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
def default_url_options()
|
||||
{:host=> 'example.com'}
|
||||
end
|
||||
|
||||
def incoming(msg)
|
||||
puts msg
|
||||
end
|
||||
|
||||
|
||||
def new_subscriber
|
||||
WebSocket.subscribe
|
||||
end
|
||||
|
||||
|
||||
|
||||
def outgoing(object)
|
||||
puts "made it sucka"
|
||||
WebSocket.push_to_clients(action_hash(object))
|
||||
end
|
||||
|
||||
|
||||
def delete_subscriber(sid)
|
||||
WebSocket.unsubscribe(sid)
|
||||
end
|
||||
|
||||
|
||||
|
||||
# need a data strucutre to keep track of who is where
|
||||
|
||||
#the way this is set up now, we have users on pages
|
||||
|
|
|
|||
|
|
@ -1,13 +1,17 @@
|
|||
module SocketHelper
|
||||
|
||||
include ApplicationHelper
|
||||
def obj_id(object)
|
||||
object.is_a? Post ? object.id : object.post_id
|
||||
(object.is_a? Post) ? object.id : object.post_id
|
||||
end
|
||||
|
||||
def url_options
|
||||
{:host => "", :only_path => true}
|
||||
end
|
||||
|
||||
def action_hash(object)
|
||||
|
||||
begin
|
||||
v = render_to_string(type_partial(object), :post => object) unless object.is_a? Retraction
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object}) unless object.is_a? Retraction
|
||||
|
||||
rescue Exception => e
|
||||
puts "in failzord " + v.inspect
|
||||
|
|
@ -19,4 +23,6 @@ module SocketHelper
|
|||
{:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||
%span.from
|
||||
= link_to_person post.person
|
||||
= link_to post.person.real_name, post.person
|
||||
= auto_link post.message
|
||||
|
||||
%div.time
|
||||
= link_to(how_long_ago(post), status_message_path(post))
|
||||
\--
|
||||
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
|
||||
= render "comments/comments", :post => post
|
||||
= render "comments/comments", :post => post
|
||||
|
||||
- if mine?(post)
|
||||
.destroy_link
|
||||
= link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true
|
||||
= link_to 'Delete', status_message_url(post), :confirm => 'Are you sure?', :method => :delete, :remote => true
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|||
|
||||
#require 'em-spec/rspec'
|
||||
describe SocketController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
Factory.create(:user)
|
||||
@user = Factory.create(:user)
|
||||
WebSocket.unstub!(:push_to_clients)
|
||||
WebSocket.unstub!(:unsubscribe)
|
||||
WebSocket.unstub!(:subscribe)
|
||||
|
|
@ -19,11 +21,25 @@ describe SocketController do
|
|||
end
|
||||
|
||||
it 'should add a new subscriber to the websocket channel' do
|
||||
|
||||
puts "balls"
|
||||
WebSocket.initialize_channel
|
||||
puts "foobar"
|
||||
@controller.new_subscriber.should == 1
|
||||
end
|
||||
describe 'actionhash' do
|
||||
before do
|
||||
@message = Factory.create(:status_message, :person => @user)
|
||||
end
|
||||
|
||||
it 'should actionhash posts' do
|
||||
hash = @controller.action_hash(@message)
|
||||
hash[:html].include?(@message.message).should be_true
|
||||
hash[:class].include?('status_message').should be_true
|
||||
end
|
||||
|
||||
it 'should actionhash retractions' do
|
||||
retraction = Retraction.for @message
|
||||
hash = @controller.action_hash(retraction)
|
||||
hash[:class].include?('retraction').should be_true
|
||||
hash[:html].should be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ Factory.define :user do |u|
|
|||
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
||||
u.password "bluepin7"
|
||||
u.password_confirmation "bluepin7"
|
||||
u.url "www.example.com"
|
||||
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
||||
end
|
||||
|
||||
|
|
|
|||
4
spec/helpers/socket_helper_spec.rb
Normal file
4
spec/helpers/socket_helper_spec.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
require File.dirname(__FILE__) + '/../spec_helper'
|
||||
describe SocketHelper do
|
||||
|
||||
end
|
||||
Loading…
Reference in a new issue