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
|
class SocketController < ApplicationController
|
||||||
|
include ApplicationHelper
|
||||||
|
include SocketHelper
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
|
def default_url_options()
|
||||||
|
{:host=> 'example.com'}
|
||||||
|
end
|
||||||
|
|
||||||
def incoming(msg)
|
def incoming(msg)
|
||||||
puts msg
|
puts msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def new_subscriber
|
def new_subscriber
|
||||||
WebSocket.subscribe
|
WebSocket.subscribe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def outgoing(object)
|
def outgoing(object)
|
||||||
puts "made it sucka"
|
puts "made it sucka"
|
||||||
WebSocket.push_to_clients(action_hash(object))
|
WebSocket.push_to_clients(action_hash(object))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def delete_subscriber(sid)
|
def delete_subscriber(sid)
|
||||||
WebSocket.unsubscribe(sid)
|
WebSocket.unsubscribe(sid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# need a data strucutre to keep track of who is where
|
# need a data strucutre to keep track of who is where
|
||||||
|
|
||||||
#the way this is set up now, we have users on pages
|
#the way this is set up now, we have users on pages
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
module SocketHelper
|
module SocketHelper
|
||||||
|
include ApplicationHelper
|
||||||
def obj_id(object)
|
def obj_id(object)
|
||||||
object.is_a? Post ? object.id : object.post_id
|
(object.is_a? Post) ? object.id : object.post_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url_options
|
||||||
|
{:host => "", :only_path => true}
|
||||||
|
end
|
||||||
|
|
||||||
def action_hash(object)
|
def action_hash(object)
|
||||||
|
|
||||||
begin
|
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
|
rescue Exception => e
|
||||||
puts "in failzord " + v.inspect
|
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)}
|
{:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||||
%span.from
|
%span.from
|
||||||
= link_to_person post.person
|
= link_to post.person.real_name, post.person
|
||||||
= auto_link post.message
|
= auto_link post.message
|
||||||
|
|
||||||
%div.time
|
%div.time
|
||||||
|
|
@ -11,4 +11,4 @@
|
||||||
|
|
||||||
- if mine?(post)
|
- if mine?(post)
|
||||||
.destroy_link
|
.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'
|
#require 'em-spec/rspec'
|
||||||
describe SocketController do
|
describe SocketController do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Factory.create(:user)
|
@user = Factory.create(:user)
|
||||||
WebSocket.unstub!(:push_to_clients)
|
WebSocket.unstub!(:push_to_clients)
|
||||||
WebSocket.unstub!(:unsubscribe)
|
WebSocket.unstub!(:unsubscribe)
|
||||||
WebSocket.unstub!(:subscribe)
|
WebSocket.unstub!(:subscribe)
|
||||||
|
|
@ -19,11 +21,25 @@ describe SocketController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should add a new subscriber to the websocket channel' do
|
it 'should add a new subscriber to the websocket channel' do
|
||||||
|
|
||||||
puts "balls"
|
|
||||||
WebSocket.initialize_channel
|
WebSocket.initialize_channel
|
||||||
puts "foobar"
|
|
||||||
@controller.new_subscriber.should == 1
|
@controller.new_subscriber.should == 1
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ Factory.define :user do |u|
|
||||||
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
u.sequence(:email) {|n| "bob#{n}@aol.com"}
|
||||||
u.password "bluepin7"
|
u.password "bluepin7"
|
||||||
u.password_confirmation "bluepin7"
|
u.password_confirmation "bluepin7"
|
||||||
|
u.url "www.example.com"
|
||||||
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
u.profile Profile.new( :first_name => "Bob", :last_name => "Smith" )
|
||||||
end
|
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