From db1811eb6156068b43d4d6c695b0becd1fc1c6a3 Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 8 Jul 2010 14:12:18 -0700 Subject: [PATCH] DG MS; cleaned up views for person. Also, pluralized Dashboard and Socket --- ...controller.rb => dashboards_controller.rb} | 11 +------- app/controllers/people_controller.rb | 18 ------------- app/controllers/person_requests_controller.rb | 14 ++++------ ...et_controller.rb => sockets_controller.rb} | 4 +-- app/helpers/dashboard_helper.rb | 5 ---- app/helpers/dashboards_helper.rb | 5 ++++ app/helpers/person_requests_helper.rb | 2 ++ .../{socket_helper.rb => sockets_helper.rb} | 2 +- app/models/comment.rb | 2 +- app/models/person_request.rb | 3 ++- app/models/post.rb | 4 +-- app/views/dashboard/socket.erb | 26 ------------------- .../{dashboard => dashboards}/index.html.haml | 0 app/views/people/_sidebar.html.haml | 2 +- app/views/people/index.html.haml | 2 +- app/views/people/show.html.haml | 4 +-- .../{_form.html.haml => _form.haml} | 2 +- app/views/person_requests/show.html.haml | 2 +- config/initializers/inflections.rb | 1 - config/initializers/socket.rb | 6 ++--- config/routes.rb | 5 ++-- ..._spec.rb => dashboards_controller_spec.rb} | 2 +- ...ler_spec.rb => sockets_controller_spec.rb} | 14 +++++----- spec/helpers/socket_helper_spec.rb | 4 --- spec/spec_helper.rb | 16 ++++++------ 25 files changed, 48 insertions(+), 108 deletions(-) rename app/controllers/{dashboard_controller.rb => dashboards_controller.rb} (93%) rename app/controllers/{socket_controller.rb => sockets_controller.rb} (87%) delete mode 100644 app/helpers/dashboard_helper.rb create mode 100644 app/helpers/dashboards_helper.rb create mode 100644 app/helpers/person_requests_helper.rb rename app/helpers/{socket_helper.rb => sockets_helper.rb} (96%) delete mode 100644 app/views/dashboard/socket.erb rename app/views/{dashboard => dashboards}/index.html.haml (100%) rename app/views/person_requests/{_form.html.haml => _form.haml} (72%) rename spec/controllers/{dashboard_controller_spec.rb => dashboards_controller_spec.rb} (94%) rename spec/controllers/{socket_controller_spec.rb => sockets_controller_spec.rb} (74%) delete mode 100644 spec/helpers/socket_helper_spec.rb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboards_controller.rb similarity index 93% rename from app/controllers/dashboard_controller.rb rename to app/controllers/dashboards_controller.rb index 6c24e001a..33c2bd369 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -1,4 +1,4 @@ -class DashboardController < ApplicationController +class DashboardsController < ApplicationController before_filter :authenticate_user!, :except => :receive include ApplicationHelper @@ -7,20 +7,11 @@ class DashboardController < ApplicationController @posts = Post.paginate :page => params[:page], :order => 'created_at DESC' end - def receive - - puts "SOMEONE JUST SENT ME: #{params[:xml]}" - store_objects_from_xml CGI::escape( params[:xml] ) render :nothing => true end - def socket - #this is just for me to test teh sockets! - render "socket" - end - def warzombie render :nothing => true if User.first.email == "tom@joindiaspora.com" && StatusMessage.where(:message => "There's a bomb in the lasagna!?").first == nil diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index f55f9d0f9..d8769d448 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -18,22 +18,4 @@ class PeopleController < ApplicationController redirect_to people_url end - def new - @person = Person.new - @profile = Profile.new - end - - def create - - puts params.inspect - @person = Person.new(params[:person]) - - - if @person.save - flash[:notice] = "Successfully created person." - redirect_to @person - else - render :action => 'new' - end - end end diff --git a/app/controllers/person_requests_controller.rb b/app/controllers/person_requests_controller.rb index dfe23cd49..d6b22f993 100644 --- a/app/controllers/person_requests_controller.rb +++ b/app/controllers/person_requests_controller.rb @@ -1,14 +1,9 @@ class PersonRequestsController < ApplicationController before_filter :authenticate_user! - + include PersonRequestsHelper def index @person_requests = PersonRequest.paginate :page => params[:page], :order => 'created_at DESC' @person_request = PersonRequest.new - @person = Person.new - end - - def show - @person_request = PersonRequest.where(:id => params[:id]).first end def destroy @@ -20,17 +15,18 @@ class PersonRequestsController < ApplicationController def new @person_request = PersonRequest.new - @recipient = Person.new end def create - @person_request = PersonRequest.for(params[:person_request][:url]) + @person_request = PersonRequest.for params[:person_request][:url] if @person_request flash[:notice] = "Successfully created person request." - redirect_to @person_request + redirect_to person_requests_url else render :action => 'new' end end + + end diff --git a/app/controllers/socket_controller.rb b/app/controllers/sockets_controller.rb similarity index 87% rename from app/controllers/socket_controller.rb rename to app/controllers/sockets_controller.rb index 6046697b7..daea6466a 100644 --- a/app/controllers/socket_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -1,6 +1,6 @@ -class SocketController < ApplicationController +class SocketsController < ApplicationController include ApplicationHelper - include SocketHelper + include SocketsHelper include Rails.application.routes.url_helpers before_filter :authenticate_user! diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb deleted file mode 100644 index 4e26c74d8..000000000 --- a/app/helpers/dashboard_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module DashboardHelper - - - -end diff --git a/app/helpers/dashboards_helper.rb b/app/helpers/dashboards_helper.rb new file mode 100644 index 000000000..8673a62e8 --- /dev/null +++ b/app/helpers/dashboards_helper.rb @@ -0,0 +1,5 @@ +module DashboardsHelper + + + +end diff --git a/app/helpers/person_requests_helper.rb b/app/helpers/person_requests_helper.rb new file mode 100644 index 000000000..6dfc0a08e --- /dev/null +++ b/app/helpers/person_requests_helper.rb @@ -0,0 +1,2 @@ +module PersonRequestsHelper +end diff --git a/app/helpers/socket_helper.rb b/app/helpers/sockets_helper.rb similarity index 96% rename from app/helpers/socket_helper.rb rename to app/helpers/sockets_helper.rb index 36124a60d..5b84cbee3 100644 --- a/app/helpers/socket_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -1,4 +1,4 @@ -module SocketHelper +module SocketsHelper include ApplicationHelper def obj_id(object) diff --git a/app/models/comment.rb b/app/models/comment.rb index 55cfe7890..b8a682a94 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -36,6 +36,6 @@ class Comment def send_to_view - SocketController.new.outgoing(self) + SocketsController.new.outgoing(self) end end diff --git a/app/models/person_request.rb b/app/models/person_request.rb index 60e7a9267..3e3027886 100644 --- a/app/models/person_request.rb +++ b/app/models/person_request.rb @@ -20,8 +20,9 @@ class PersonRequest def self.for(url) request = PersonRequest.new(:url => url, :person => User.first) - request.save request.push_to_url + request.save + request end def check_for_person_requests diff --git a/app/models/post.rb b/app/models/post.rb index 266e16d0b..a0b69e08b 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -53,11 +53,11 @@ class Post end def send_to_view - SocketController.new.outgoing(self) + SocketsController.new.outgoing(self) end def remove_from_view - SocketController.new.outgoing(Retraction.for(self)) + SocketsController.new.outgoing(Retraction.for(self)) end end diff --git a/app/views/dashboard/socket.erb b/app/views/dashboard/socket.erb deleted file mode 100644 index ca397440b..000000000 --- a/app/views/dashboard/socket.erb +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - boner -
-
- - diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboards/index.html.haml similarity index 100% rename from app/views/dashboard/index.html.haml rename to app/views/dashboards/index.html.haml diff --git a/app/views/people/_sidebar.html.haml b/app/views/people/_sidebar.html.haml index dd8f68ff6..bee8cb4b3 100644 --- a/app/views/people/_sidebar.html.haml +++ b/app/views/people/_sidebar.html.haml @@ -2,4 +2,4 @@ %ul#friend_stream.nav - for person in @people %li= link_to person.real_name, person_path(person) -= link_to "add a new person", new_person_path += link_to "add a new person", new_person_request_path diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index 4d1d5a622..4d743a8f4 100644 --- a/app/views/people/index.html.haml +++ b/app/views/people/index.html.haml @@ -13,7 +13,7 @@ %td= link_to 'Show', person %td= link_to 'Destroy', person, :confirm => 'Are you sure?', :method => :delete -%p= link_to "New Person", new_person_path +%p= link_to "Add a friend", new_person_request_path #pagination = will_paginate @people diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index ca2e88566..ccdabacd3 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -1,4 +1,4 @@ -.span-18.last +.span-20.last %h1= "#{@person.real_name}" - if @person_profile %p @@ -14,7 +14,7 @@ %p = @person.url -.span-18 +.span-20 - if @person.posts %h3 stream %ul#stream diff --git a/app/views/person_requests/_form.html.haml b/app/views/person_requests/_form.haml similarity index 72% rename from app/views/person_requests/_form.html.haml rename to app/views/person_requests/_form.haml index 75603f405..8aa4eb008 100644 --- a/app/views/person_requests/_form.html.haml +++ b/app/views/person_requests/_form.haml @@ -1,4 +1,4 @@ -= form_for @person_request do |f| += form_for @person_request do |f| = f.error_messages %p diff --git a/app/views/person_requests/show.html.haml b/app/views/person_requests/show.html.haml index 207d347f1..1c6ce85d7 100644 --- a/app/views/person_requests/show.html.haml +++ b/app/views/person_requests/show.html.haml @@ -1,7 +1,7 @@ - title "Person Request" %p - = person_request.inspect + = @person_request.inspect %p = link_to "Edit", edit_person_request_path(@person_request) diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index bf760d087..fdca7d7b4 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -7,5 +7,4 @@ # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) - inflect.uncountable %w(dashboard socket) end diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index d1fcfc315..4651335a0 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -13,11 +13,11 @@ module WebSocket :debug =>APP_CONFIG[:debug]) do |ws| ws.onopen { @ws = ws - sid = SocketController.new.new_subscriber + sid = SocketsController.new.new_subscriber - ws.onmessage { |msg| SocketController.new.incoming(msg) }#@channel.push msg; puts msg} + ws.onmessage { |msg| SocketsController.new.incoming(msg) }#@channel.push msg; puts msg} - ws.onclose { SocketController.new.delete_subscriber(sid) } + ws.onclose { SocketsController.new.delete_subscriber(sid) } } end } diff --git a/config/routes.rb b/config/routes.rb index de1342247..914c5a08b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,9 +17,8 @@ Diaspora::Application.routes.draw do |map| resources :users - match 'receive', :to => 'dashboard#receive' - match "socket", :to => 'dashboard#socket' + match 'receive', :to => 'dashboards#receive' - root :to => 'dashboard#index' + root :to => 'dashboards#index' end diff --git a/spec/controllers/dashboard_controller_spec.rb b/spec/controllers/dashboards_controller_spec.rb similarity index 94% rename from spec/controllers/dashboard_controller_spec.rb rename to spec/controllers/dashboards_controller_spec.rb index 5efe9047c..34186d8df 100644 --- a/spec/controllers/dashboard_controller_spec.rb +++ b/spec/controllers/dashboards_controller_spec.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe DashboardController do +describe DashboardsController do render_views before do diff --git a/spec/controllers/socket_controller_spec.rb b/spec/controllers/sockets_controller_spec.rb similarity index 74% rename from spec/controllers/socket_controller_spec.rb rename to spec/controllers/sockets_controller_spec.rb index 5f5a8b70f..a5109e356 100644 --- a/spec/controllers/socket_controller_spec.rb +++ b/spec/controllers/sockets_controller_spec.rb @@ -1,21 +1,21 @@ require File.dirname(__FILE__) + '/../spec_helper' -describe 'SocketController' do +describe 'SocketsController' do render_views before do @user = Factory.create(:user) - SocketController.unstub!(:new) + SocketsController.unstub!(:new) #EventMachine::WebSocket.stub!(:start) - @controller = SocketController.new - stub_socket_controller + @controller = SocketsController.new + stub_sockets_controller end - it 'should unstub the websocket' do + it 'should unstub the websockets' do WebSocket.initialize_channel - @controller.class.should == SocketController + @controller.class.should == SocketsController end - it 'should add a new subscriber to the websocket channel' do + it 'should add a new subscriber to the websockets channel' do WebSocket.initialize_channel @controller.new_subscriber.should == 1 end diff --git a/spec/helpers/socket_helper_spec.rb b/spec/helpers/socket_helper_spec.rb deleted file mode 100644 index 45c77f564..000000000 --- a/spec/helpers/socket_helper_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require File.dirname(__FILE__) + '/../spec_helper' -describe SocketHelper do - -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a4d470af2..3983336f1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -24,7 +24,7 @@ RSpec.configure do |config| config.before(:each) do DatabaseCleaner.start - stub_socket_controller + stub_sockets_controller end config.after(:each) do @@ -32,11 +32,11 @@ RSpec.configure do |config| end end - def stub_socket_controller - mock_socket_controller = mock('socket mock') - mock_socket_controller.stub!(:incoming).and_return(true) - mock_socket_controller.stub!(:new_subscriber).and_return(true) - mock_socket_controller.stub!(:outgoing).and_return(true) - mock_socket_controller.stub!(:delete_subscriber).and_return(true) - SocketController.stub!(:new).and_return(mock_socket_controller) + def stub_sockets_controller + mock_sockets_controller = mock('sockets mock') + mock_sockets_controller.stub!(:incoming).and_return(true) + mock_sockets_controller.stub!(:new_subscriber).and_return(true) + mock_sockets_controller.stub!(:outgoing).and_return(true) + mock_sockets_controller.stub!(:delete_subscriber).and_return(true) + SocketsController.stub!(:new).and_return(mock_sockets_controller) end