diff --git a/app/controllers/socket_controller.rb b/app/controllers/socket_controller.rb index 65f9518a0..a5c91f89f 100644 --- a/app/controllers/socket_controller.rb +++ b/app/controllers/socket_controller.rb @@ -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 diff --git a/app/helpers/socket_helper.rb b/app/helpers/socket_helper.rb index 485b053b9..fa996d811 100644 --- a/app/helpers/socket_helper.rb +++ b/app/helpers/socket_helper.rb @@ -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 @@ -18,5 +22,7 @@ module SocketHelper {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)} end + -end \ No newline at end of file + +end diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index f3e94c09d..1333640f9 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -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 diff --git a/spec/controllers/socket_controller_spec.rb b/spec/controllers/socket_controller_spec.rb index 053175f97..8f3f47e76 100644 --- a/spec/controllers/socket_controller_spec.rb +++ b/spec/controllers/socket_controller_spec.rb @@ -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 diff --git a/spec/factories.rb b/spec/factories.rb index 37032592f..fa525a9a4 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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 diff --git a/spec/helpers/socket_helper_spec.rb b/spec/helpers/socket_helper_spec.rb new file mode 100644 index 000000000..45c77f564 --- /dev/null +++ b/spec/helpers/socket_helper_spec.rb @@ -0,0 +1,4 @@ +require File.dirname(__FILE__) + '/../spec_helper' +describe SocketHelper do + +end