From bfe0b7129c57e177e5b4767fc9d497638e788f11 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 16 Jan 2012 19:33:47 -0800 Subject: [PATCH 1/2] move all stream actions into PostController --- app/controllers/application_controller.rb | 4 +- app/controllers/aspects_controller.rb | 28 ------- app/controllers/comment_stream_controller.rb | 19 ----- app/controllers/home_controller.rb | 2 +- app/controllers/like_stream_controller.rb | 19 ----- app/controllers/mentions_controller.rb | 19 ----- app/controllers/multis_controller.rb | 20 ----- app/controllers/notifications_controller.rb | 2 +- app/controllers/posts_controller.rb | 74 +++++++++++++++++-- app/controllers/status_messages_controller.rb | 2 +- app/controllers/tag_followings_controller.rb | 12 +-- app/controllers/users_controller.rb | 10 +-- app/controllers/vanna_controller.rb | 2 +- app/helpers/stream_helper.rb | 22 ++---- app/views/aspects/index.html.haml | 8 +- app/views/layouts/application.mobile.haml | 2 +- app/views/tags/_followed_tags_listings.haml | 2 +- app/views/users/logged_out.haml | 7 +- config/routes.rb | 31 ++++---- features/accepts_invitation.feature | 4 +- features/change_password.feature | 2 +- features/follows_tags.feature | 4 +- features/logs_in_and_out.feature | 4 +- features/signs_up.feature | 6 +- features/support/paths.rb | 2 +- lib/stream/multi.rb | 2 +- public/javascripts/app/router.js | 6 +- spec/controllers/admins_controller_spec.rb | 4 +- spec/controllers/aspects_controller_spec.rb | 68 +---------------- spec/controllers/home_controller_spec.rb | 2 +- .../jasmine_fixtures/aspects_spec.rb | 22 +++--- .../jasmine_fixtures/stream_spec.rb | 6 +- .../like_stream_controller_spec.rb | 23 ------ spec/controllers/posts_controller_spec.rb | 66 ++++++++++++++--- .../registrations_controller_spec.rb | 2 +- spec/controllers/sessions_controller_spec.rb | 4 +- 36 files changed, 200 insertions(+), 312 deletions(-) delete mode 100644 app/controllers/comment_stream_controller.rb delete mode 100644 app/controllers/like_stream_controller.rb delete mode 100644 app/controllers/mentions_controller.rb delete mode 100644 app/controllers/multis_controller.rb delete mode 100644 spec/controllers/like_stream_controller_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c46581f80..52bda40bc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -83,7 +83,7 @@ class ApplicationController < ActionController::Base def redirect_unless_admin unless current_user.admin? - redirect_to multi_url, :notice => 'you need to be an admin to do that' + redirect_to multi_stream_url, :notice => 'you need to be an admin to do that' return end end @@ -111,7 +111,7 @@ class ApplicationController < ActionController::Base end def after_sign_in_path_for(resource) - stored_location_for(:user) || (current_user.getting_started? ? getting_started_path : multi_path) + stored_location_for(:user) || (current_user.getting_started? ? getting_started_path : multi_stream_path) end def tag_followings diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 2fcc10c31..1873cd635 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -2,29 +2,13 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(Rails.root, "lib", 'stream', "aspect") - class AspectsController < ApplicationController before_filter :authenticate_user! - before_filter :save_selected_aspects, :only => :index - before_filter :ensure_page, :only => :index respond_to :html, :js, :json - def index - stream_klass = Stream::Aspect - aspect_ids = (session[:a_ids] ? session[:a_ids] : []) - @stream = Stream::Aspect.new(current_user, aspect_ids, - :max_time => params[:max_time].to_i) - - respond_with do |format| - format.html { render 'aspects/index' } - format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } - end - end - def create @aspect = current_user.aspects.create(params[:aspect]) @@ -132,16 +116,4 @@ class AspectsController < ApplicationController end @aspect.save end - - def ensure_page - params[:max_time] ||= Time.now + 1 - end - - private - - def save_selected_aspects - if params[:a_ids].present? - session[:a_ids] = params[:a_ids] - end - end end diff --git a/app/controllers/comment_stream_controller.rb b/app/controllers/comment_stream_controller.rb deleted file mode 100644 index f478a6d20..000000000 --- a/app/controllers/comment_stream_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib','stream', 'comments') - -class CommentStreamController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Comments - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 5376bc8ab..e33d51656 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -6,7 +6,7 @@ class HomeController < ApplicationController def show if current_user - redirect_to multi_path if current_user + redirect_to multi_stream_path if current_user elsif is_mobile_device? redirect_to user_session_path else diff --git a/app/controllers/like_stream_controller.rb b/app/controllers/like_stream_controller.rb deleted file mode 100644 index 5fd8fc631..000000000 --- a/app/controllers/like_stream_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib','stream', 'likes') - -class LikeStreamController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Likes - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/mentions_controller.rb b/app/controllers/mentions_controller.rb deleted file mode 100644 index 87e2f37f7..000000000 --- a/app/controllers/mentions_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib','stream', 'mention') - -class MentionsController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Mention - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/multis_controller.rb b/app/controllers/multis_controller.rb deleted file mode 100644 index 9eb042503..000000000 --- a/app/controllers/multis_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib', 'stream', 'multi') - -class MultisController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Multi - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.mobile{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index c27df96c7..b51d7e470 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -50,7 +50,7 @@ class NotificationsController < VannaController post_process :html do def post_read_all(json) - Response.new(:status => 302, :location => multi_path) + Response.new(:status => 302, :location => multi_stream_path) end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 1a44a8f26..c58f3944b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,12 +2,21 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(Rails.root, 'lib', 'stream', 'public') +require File.join(Rails.root, "lib", "stream", "aspect") +require File.join(Rails.root, "lib", "stream", "multi") +require File.join(Rails.root, "lib", "stream", "comments") +require File.join(Rails.root, "lib", "stream", "likes") +require File.join(Rails.root, "lib", "stream", "mention") +require File.join(Rails.root, "lib", "stream", "followed_tag") class PostsController < ApplicationController before_filter :authenticate_user!, :except => :show before_filter :set_format_if_malformed_from_status_net, :only => :show - before_filter :redirect_unless_admin, :only => :index + + before_filter :redirect_unless_admin, :only => :public + + before_filter :save_selected_aspects, :only => :aspects + before_filter :ensure_page, :only => :aspects respond_to :html, :mobile, @@ -54,7 +63,7 @@ class PostsController < ApplicationController respond_to do |format| format.js {render 'destroy'} format.json { render :nothing => true, :status => 204 } - format.all {redirect_to multi_path} + format.all {redirect_to multi_stream_path} end else Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'" @@ -62,16 +71,57 @@ class PostsController < ApplicationController end end - def index - default_stream_action(Stream::Public) + # streams + def aspects + stream_klass = Stream::Aspect + aspect_ids = (session[:a_ids] ? session[:a_ids] : []) + @stream = Stream::Aspect.new(current_user, aspect_ids, + :max_time => params[:max_time].to_i) + + respond_with do |format| + format.html { render 'aspects/index' } + format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } + end + end + + def public + stream_responder(Stream::Public) + end + + def multi + stream_responder(Stream::Multi) + end + + def commented + stream_responder(Stream::Comments) + end + + def liked + stream_responder(Stream::Likes) + end + + def mentioned + stream_responder(Stream::Mention) + end + + def followed_tags + stream_responder(Stream::FollowedTag) + end + + private + + def stream_responder(stream_klass) + respond_with do |format| + format.html{ default_stream_action(stream_klass) } + format.mobile{ default_stream_action(stream_klass) } + format.json{ stream_json(stream_klass) } + end end def set_format_if_malformed_from_status_net request.format = :html if request.format == 'application/html+xml' end - private - def user_can_not_comment_on_post? if @post.public && @post.author.local? false @@ -83,4 +133,14 @@ class PostsController < ApplicationController true end end + + def save_selected_aspects + if params[:a_ids].present? + session[:a_ids] = params[:a_ids] + end + end + + def ensure_page + params[:max_time] ||= Time.now + 1 + end end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 3717cd472..726835961 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -70,7 +70,7 @@ class StatusMessagesController < ApplicationController respond_to do |format| format.html { redirect_to :back} - format.mobile{ redirect_to multi_path} + format.mobile{ redirect_to multi_stream_path} format.json{ render :json => @status_message.as_api_response(:backbone), :status => 201 } end else diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index b99e00a22..f9a0e7b63 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -2,22 +2,12 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. # -require File.join(Rails.root, 'lib', 'stream', 'followed_tag') class TagFollowingsController < ApplicationController before_filter :authenticate_user! respond_to :html, :json - def index - stream_klass = Stream::FollowedTag - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end - # POST /tag_followings # POST /tag_followings.xml def create @@ -73,6 +63,6 @@ class TagFollowingsController < ApplicationController @tag_following = current_user.tag_followings.create(:tag_id => @tag.id) end end - redirect_to multi_path + redirect_to multi_stream_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 56a26bab8..72c1ccbd7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -87,7 +87,7 @@ class UsersController < ApplicationController if params[:user] && params[:user][:current_password] && current_user.valid_password?(params[:user][:current_password]) current_user.close_account! sign_out current_user - redirect_to(multi_path, :notice => I18n.t('users.destroy.success')) + redirect_to(multi_stream_path, :notice => I18n.t('users.destroy.success')) else if params[:user].present? && params[:user][:current_password].present? flash[:error] = t 'users.destroy.wrong_password' @@ -111,7 +111,7 @@ class UsersController < ApplicationController format.any { redirect_to person_path(user.person.id) } end else - redirect_to multi_path, :error => I18n.t('users.public.does_not_exist', :username => params[:username]) + redirect_to multi_stream_path, :error => I18n.t('users.public.does_not_exist', :username => params[:username]) end end @@ -127,14 +127,14 @@ class UsersController < ApplicationController def logged_out @page = :logged_out if user_signed_in? - redirect_to multi_path + redirect_to multi_stream_path end end def getting_started_completed user = current_user user.update_attributes(:getting_started => false) - redirect_to multi_path + redirect_to multi_stream_path end def export @@ -150,7 +150,7 @@ class UsersController < ApplicationController def user_photo username = params[:username].split('@')[0] user = User.find_by_username(username) - if user.present? + if user.present? redirect_to user.profile.image_url else render :nothing => true, :status => 404 diff --git a/app/controllers/vanna_controller.rb b/app/controllers/vanna_controller.rb index 3ae86330c..693f10dc9 100644 --- a/app/controllers/vanna_controller.rb +++ b/app/controllers/vanna_controller.rb @@ -83,7 +83,7 @@ class VannaController < Vanna::Base def redirect_unless_admin unless current_user.admin? - redirect_to multi_path, :notice => 'you need to be an admin to do that' + redirect_to multi_stream_path, :notice => 'you need to be an admin to do that' return end end diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index 44b882380..f18654525 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -10,25 +10,19 @@ module StreamHelper "/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}" elsif controller.instance_of?(PeopleController) local_or_remote_person_path(@person, :max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(TagFollowingsController) - tag_followings_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(MentionsController) - mentions_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(MultisController) - multi_path(:max_time => time_for_scroll(@stream)) elsif controller.instance_of?(PostsController) public_stream_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(AspectsController) - aspects_path(:max_time => time_for_scroll(@stream), :a_ids => @stream.aspect_ids) - elsif controller.instance_of?(LikeStreamController) - like_stream_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(CommentStreamController) - comment_stream_path(:max_time => time_for_scroll(@stream)) else raise 'in order to use pagination for this new controller, update next_page_path in stream helper' end end + def reshare?(post) + post.instance_of?(Reshare) + end + + private + def time_for_scroll(stream) if stream.stream_posts.empty? (Time.now() + 1).to_i @@ -36,8 +30,4 @@ module StreamHelper stream.stream_posts.last.send(stream.order.to_sym).to_i end end - - def reshare?(post) - post.instance_of?(Reshare) - end end diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index bd1039821..313e83e8b 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -31,21 +31,21 @@ .section %ul.left_nav %li - = link_to t("streams.multi.title"), multi_path, :class => 'home_selector', :rel => 'backbone' + = link_to t("streams.multi.title"), multi_stream_path, :class => 'home_selector', :rel => 'backbone' = render 'aspects/aspect_listings', :stream => @stream %ul.left_nav %li - = link_to t('streams.mentions.title'), mentions_path, :class => 'home_selector', :rel => 'backbone' + = link_to t('streams.mentions.title'), mentioned_stream_path, :class => 'home_selector', :rel => 'backbone' %ul.left_nav %li - = link_to t('streams.comment_stream.title'), comment_stream_path, :class => 'home_selector', :rel => 'backbone' + = link_to t('streams.comment_stream.title'), commented_stream_path, :class => 'home_selector', :rel => 'backbone' %ul.left_nav %li - = link_to t('streams.like_stream.title'), like_stream_path, :class => 'home_selector', :rel => 'backbone' + = link_to t('streams.like_stream.title'), liked_stream_path, :class => 'home_selector', :rel => 'backbone' #followed_tags_listing = render 'tags/followed_tags_listings' diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index 89601a4c5..b574203bd 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -50,7 +50,7 @@ = yield %header - = link_to(image_tag('white@2x.png', :height => 20, :width => 127, :id => 'header_title'), multi_path) + = link_to(image_tag('white@2x.png', :height => 20, :width => 127, :id => 'header_title'), multi_stream_path) - if user_signed_in? - if yield(:header_action).present? = yield(:header_action) diff --git a/app/views/tags/_followed_tags_listings.haml b/app/views/tags/_followed_tags_listings.haml index 30bed3e9f..3ed55ada3 100644 --- a/app/views/tags/_followed_tags_listings.haml +++ b/app/views/tags/_followed_tags_listings.haml @@ -5,7 +5,7 @@ - if user_signed_in? %ul.left_nav %li - %b=link_to t('streams.followed_tag.title'), tag_followings_path, :class => 'home_selector' + %b=link_to t('streams.followed_tag.title'), followed_tags_stream_path, :class => 'home_selector' - if @stream.is_a?(Stream::FollowedTag) %ul.sub_nav diff --git a/app/views/users/logged_out.haml b/app/views/users/logged_out.haml index b0ae96e93..9ca4a458b 100644 --- a/app/views/users/logged_out.haml +++ b/app/views/users/logged_out.haml @@ -4,10 +4,7 @@ - content_for :head do :css - body { - margin-top: 220px; - } - + body { margin-top: 220px; } #grey_header .row @@ -25,7 +22,7 @@ %h4 = t('.simply_visit') %strong - = link_to AppConfig[:pod_url], multi_path + = link_to AppConfig[:pod_url], multi_stream_path = t('.on_your_mobile_device') %p.dull diff --git a/config/routes.rb b/config/routes.rb index e85117ea5..4ce940862 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,15 +4,10 @@ Diaspora::Application.routes.draw do - # Posting and Reading resources :reshares - resources :aspects do - put :toggle_contact_visibility - end - resources :status_messages, :only => [:new, :create] resources :posts, :only => [:show, :destroy] do @@ -20,12 +15,23 @@ Diaspora::Application.routes.draw do resources :comments, :only => [:new, :create, :destroy, :index] end get 'p/:id' => 'posts#show', :as => 'short_post' - get 'public_stream' => 'posts#index', :as => 'public_stream' # roll up likes into a nested resource above resources :comments, :only => [:create, :destroy] do resources :likes, :only => [:create, :destroy, :index] end + # Streams + get "public" => "posts#public", :as => "public_stream" + get "stream" => "posts#multi", :as => "multi_stream" + get "followed_tags" => "posts#followed_tags", :as => "followed_tags_stream" + get "mentions" => "posts#mentioned", :as => "mentioned_stream" + get "liked" => "posts#liked", :as => "liked_stream" + get "commented" => "posts#commented", :as => "commented_stream" + get "aspects" => "posts#aspects", :as => "aspects_stream" + + resources :aspects do + put :toggle_contact_visibility + end get 'bookmarklet' => 'status_messages#bookmarklet' @@ -50,26 +56,19 @@ Diaspora::Application.routes.draw do resources :tags, :only => [:index] scope "tags/:name" do post "tag_followings" => "tag_followings#create", :as => 'tag_tag_followings' - delete "tag_followings" => "tag_followings#destroy" + delete "tag_followings" => "tag_followings#destroy", :as => 'tag_tag_followings' end post "multiple_tag_followings" => "tag_followings#create_multiple", :as => 'multiple_tag_followings' - - get "tag_followings" => "tag_followings#index", :as => 'tag_followings' - resources :mentions, :only => [:index] resources "tag_followings", :only => [:create] - get 'comment_stream' => 'comment_stream#index', :as => 'comment_stream' - - get 'like_stream' => 'like_stream#index', :as => 'like_stream' - get 'tags/:name' => 'tags#show', :as => 'tag' resources :apps, :only => [:show] #Cubbies info page - resource :token, :only => :show + resource :token, :only => :show # Users and people @@ -120,8 +119,6 @@ Diaspora::Application.routes.draw do get 'community_spotlight' => "contacts#spotlight", :as => 'community_spotlight' - get 'stream' => "multis#index", :as => 'multi' - resources :people, :except => [:edit, :update] do resources :status_messages resources :photos diff --git a/features/accepts_invitation.feature b/features/accepts_invitation.feature index d675f1c00..3971078ce 100644 --- a/features/accepts_invitation.feature +++ b/features/accepts_invitation.feature @@ -16,7 +16,7 @@ Feature: invitation acceptance And I preemptively confirm the alert And I follow "awesome_button" - Then I should be on the multi page + Then I should be on the multi stream page Scenario: accept invitation from user Given I have been invited by a user @@ -34,7 +34,7 @@ Feature: invitation acceptance And I preemptively confirm the alert And I follow "awesome_button" - Then I should be on the multi page + Then I should be on the multi stream page Scenario: sends an invitation Given a user with email "bob@bob.bob" diff --git a/features/change_password.feature b/features/change_password.feature index 1115741f9..6bb646c91 100644 --- a/features/change_password.feature +++ b/features/change_password.feature @@ -11,7 +11,7 @@ Feature: Change password Then I should see "Password changed" Then I should be on the new user session page When I sign in with password "newsecret" - Then I should be on the multi page + Then I should be on the multi stream page Scenario: Reset my password Given a user with email "forgetful@users.net" diff --git a/features/follows_tags.feature b/features/follows_tags.feature index 01f09e88f..f305e32d7 100644 --- a/features/follows_tags.feature +++ b/features/follows_tags.feature @@ -29,11 +29,11 @@ Feature: posting Scenario: can stop following a tag from the tag page When I press "Following #boss" - And I go to the tag_followings page + And I go to the followed tags stream page Then I should not see "#boss" within ".left_nav" Scenario: can stop following a tag from the homepage - When I go to the tag_followings page + When I go to the followed tags stream page And I preemptively confirm the alert And I hover over the "li.unfollow#tag-following-boss" And I follow "unfollow_boss" diff --git a/features/logs_in_and_out.feature b/features/logs_in_and_out.feature index f5017bdcd..cc01930c1 100644 --- a/features/logs_in_and_out.feature +++ b/features/logs_in_and_out.feature @@ -6,7 +6,7 @@ Feature: user authentication And I fill in "Username" with "ohai" And I fill in "Password" with "secret" And I press "Sign in" - Then I should be on the multi page + Then I should be on the multi stream page @javascript Scenario: user logs out @@ -19,5 +19,5 @@ Feature: user authentication Scenario: user uses token auth Given a user with username "ohai" and password "secret" When I post a photo with a token - And I go to the multi page + And I go to the multi stream page Then I should be on the new user session page diff --git a/features/signs_up.feature b/features/signs_up.feature index cd0e9e24e..8cdd51e87 100644 --- a/features/signs_up.feature +++ b/features/signs_up.feature @@ -19,18 +19,18 @@ Feature: new user registration And I preemptively confirm the alert And I follow "awesome_button" - Then I should be on the multi page + Then I should be on the multi stream page And I should not see "awesome_button" Scenario: new user skips the setup wizard When I preemptively confirm the alert And I follow "awesome_button" - Then I should be on the multi page + Then I should be on the multi stream page Scenario: closing a popover clears getting started When I preemptively confirm the alert And I follow "awesome_button" - Then I should be on the multi page + Then I should be on the multi stream page And I have turned off jQuery effects And I wait for the popovers to appear And I click close on all the popovers diff --git a/features/support/paths.rb b/features/support/paths.rb index cf0166ca1..ce6ccb3dc 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -2,7 +2,7 @@ module NavigationHelpers def path_to(page_name) case page_name when /^the home(?: )?page$/ - multi_path + multi_stream_path when /^step (\d)$/ if $1.to_i == 1 getting_started_path diff --git a/lib/stream/multi.rb b/lib/stream/multi.rb index 8e6e62cde..0dc9efaa1 100644 --- a/lib/stream/multi.rb +++ b/lib/stream/multi.rb @@ -2,7 +2,7 @@ class Stream::Multi < Stream::Base # @return [String] URL def link(opts) - Rails.application.routes.url_helpers.multi_path(opts) + Rails.application.routes.url_helpers.multi_stream_path(opts) end # @return [String] diff --git a/public/javascripts/app/router.js b/public/javascripts/app/router.js index dde392e68..ab7234f59 100644 --- a/public/javascripts/app/router.js +++ b/public/javascripts/app/router.js @@ -2,12 +2,12 @@ app.Router = Backbone.Router.extend({ routes: { "stream": "stream", "aspects:query": "stream", - "comment_stream": "stream", - "like_stream": "stream", + "commented": "stream", + "liked": "stream", "mentions": "stream", "people/:id": "stream", "u/:name": "stream", - "tag_followings": "stream", + "followed_tags": "stream", "tags/:name": "stream", "posts/:id": "stream" }, diff --git a/spec/controllers/admins_controller_spec.rb b/spec/controllers/admins_controller_spec.rb index 776a54e80..165103df0 100644 --- a/spec/controllers/admins_controller_spec.rb +++ b/spec/controllers/admins_controller_spec.rb @@ -14,7 +14,7 @@ describe AdminsController do context 'admin not signed in' do it 'is behind redirect_unless_admin' do get :user_search - response.should redirect_to multi_path + response.should redirect_to multi_stream_path end end @@ -64,7 +64,7 @@ describe AdminsController do context 'admin not signed in' do it 'is behind redirect_unless_admin' do get :admin_inviter - response.should redirect_to multi_path + response.should redirect_to multi_stream_path end end diff --git a/spec/controllers/aspects_controller_spec.rb b/spec/controllers/aspects_controller_spec.rb index 97e3cabf5..697670fc4 100644 --- a/spec/controllers/aspects_controller_spec.rb +++ b/spec/controllers/aspects_controller_spec.rb @@ -35,52 +35,6 @@ describe AspectsController do end end - describe "#index" do - it 'assigns an Stream::Aspect' do - get :index - assigns(:stream).class.should == Stream::Aspect - end - - describe 'filtering by aspect' do - before do - @aspect1 = alice.aspects.create(:name => "test aspect") - @stream = Stream::Aspect.new(alice, []) - @stream.stub(:posts).and_return([]) - end - - it 'respects a single aspect' do - Stream::Aspect.should_receive(:new).with(alice, [@aspect1.id], anything).and_return(@stream) - get :index, :a_ids => [@aspect1.id] - end - - it 'respects multiple aspects' do - aspect2 = alice.aspects.create(:name => "test aspect two") - Stream::Aspect.should_receive(:new).with(alice, [@aspect1.id, aspect2.id], anything).and_return(@stream) - get :index, :a_ids => [@aspect1.id, aspect2.id] - end - end - - describe 'performance', :performance => true do - before do - require 'benchmark' - 8.times do |n| - user = Factory.create(:user) - aspect = user.aspects.create(:name => 'people') - connect_users(alice, @alices_aspect_1, user, aspect) - post = alice.post(:status_message, :text => "hello#{n}", :to => @alices_aspect_2.id) - 8.times do |n| - user.comment "yo#{post.text}", :post => post - end - end - end - it 'takes time' do - Benchmark.realtime { - get :index - }.should < 1.5 - end - end - end - describe "#show" do it "succeeds" do get :show, 'id' => @alices_aspect_1.id.to_s @@ -124,6 +78,7 @@ describe AspectsController do end end end + context "with invalid params" do it "does not create an aspect" do alice.aspects.count.should == 2 @@ -232,25 +187,4 @@ describe AspectsController do end end end - - describe "mobile site" do - before do - ap = alice.person - posts = [] - posts << alice.post(:reshare, :root_guid => Factory(:status_message, :public => true).guid, :to => 'all') - posts << alice.post(:status_message, :text => 'foo', :to => alice.aspects) - photo = Factory(:activity_streams_photo, :public => true, :author => ap) - posts << photo - posts.each do |p| - alice.build_like(:positive => true, :target => p).save - end - alice.add_to_streams(photo, alice.aspects) - sign_in alice - end - - it 'should not 500' do - get :index, :format => :mobile - response.should be_success - end - end end diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index 0ef0f07aa..f9e950357 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -14,7 +14,7 @@ describe HomeController do it 'redirects to multis index if user is logged in' do sign_in alice get :show, :home => true - response.should redirect_to(multi_path) + response.should redirect_to(multi_stream_path) end end end diff --git a/spec/controllers/jasmine_fixtures/aspects_spec.rb b/spec/controllers/jasmine_fixtures/aspects_spec.rb index 0092b431e..32811ed3c 100644 --- a/spec/controllers/jasmine_fixtures/aspects_spec.rb +++ b/spec/controllers/jasmine_fixtures/aspects_spec.rb @@ -4,8 +4,8 @@ require 'spec_helper' -describe AspectsController do - describe '#index' do +describe PostsController do + describe '#aspects' do before do sign_in :user, alice @alices_aspect_2 = alice.aspects.create(:name => "another aspect") @@ -19,19 +19,19 @@ describe AspectsController do end it "generates a jasmine fixture", :fixture => true do - get :index + get :aspects save_fixture(html_for("body"), "aspects_index") end it "generates a jasmine fixture with a prefill", :fixture => true do - get :index, :prefill => "reshare things" + get :aspects, :prefill => "reshare things" save_fixture(html_for("body"), "aspects_index_prefill") end it 'generates a jasmine fixture with services', :fixture => true do alice.services << Services::Facebook.create(:user_id => alice.id) alice.services << Services::Twitter.create(:user_id => alice.id) - get :index, :prefill => "reshare things" + get :aspects, :prefill => "reshare things" save_fixture(html_for("body"), "aspects_index_services") end @@ -39,14 +39,14 @@ describe AspectsController do bob.post(:status_message, :text => "Is anyone out there?", :to => @bob.aspects.where(:name => "generic").first.id) message = alice.post(:status_message, :text => "hello "*800, :to => @alices_aspect_2.id) 5.times { bob.comment("what", :post => message) } - get :index + get :aspects save_fixture(html_for("body"), "aspects_index_with_posts") end it 'generates a jasmine fixture with only posts', :fixture => true do 2.times { bob.post(:status_message, :text => "Is anyone out there?", :to => @bob.aspects.where(:name => "generic").first.id) } - get :index, :only_posts => true + get :aspects, :only_posts => true save_fixture(response.body, "aspects_index_only_posts") end @@ -54,14 +54,14 @@ describe AspectsController do it "generates a jasmine fixture with a post with comments", :fixture => true do message = bob.post(:status_message, :text => "HALO WHIRLED", :to => @bob.aspects.where(:name => "generic").first.id) 5.times { bob.comment("what", :post => message) } - get :index + get :aspects save_fixture(html_for("body"), "aspects_index_post_with_comments") end it 'generates a jasmine fixture with a followed tag', :fixture => true do @tag = ActsAsTaggableOn::Tag.create!(:name => "partytimeexcellent") TagFollowing.create!(:tag => @tag, :user => alice) - get :index + get :aspects save_fixture(html_for("body"), "aspects_index_with_one_followed_tag") end @@ -89,7 +89,7 @@ describe AspectsController do ) alice.post(:status_message, :text => "http://www.youtube.com/watch?v=UYrkQL1bX4A", :to => @alices_aspect_2.id) - get :index + get :aspects save_fixture(html_for("body"), "aspects_index_with_video_post") end @@ -98,7 +98,7 @@ describe AspectsController do alice.build_like(:positive => true, :target => message).save bob.build_like(:positive => true, :target => message).save - get :index + get :aspects save_fixture(html_for("body"), "aspects_index_with_a_post_with_likes") end end diff --git a/spec/controllers/jasmine_fixtures/stream_spec.rb b/spec/controllers/jasmine_fixtures/stream_spec.rb index 27f71b9c6..fd9fa7d13 100644 --- a/spec/controllers/jasmine_fixtures/stream_spec.rb +++ b/spec/controllers/jasmine_fixtures/stream_spec.rb @@ -4,8 +4,8 @@ require 'spec_helper' -describe MultisController do - describe '#index' do +describe PostsController do + describe '#multi' do before do sign_in :user, alice end @@ -27,7 +27,7 @@ describe MultisController do end end - get :index, :format => :json + get :multi, :format => :json response.should be_success save_fixture(response.body, "multi_stream_json") diff --git a/spec/controllers/like_stream_controller_spec.rb b/spec/controllers/like_stream_controller_spec.rb deleted file mode 100644 index 9dfddce4d..000000000 --- a/spec/controllers/like_stream_controller_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' - -describe LikeStreamController do - before do - sign_in :user, alice - end - - describe 'index' do - it 'succeeds' do - get :index - response.should be_success - end - - it 'assigns a stream' do - get :index - assigns[:stream].should be_a Stream::Likes - end - end -end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 5141ee383..42fc96bce 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -138,22 +138,70 @@ describe PostsController do end end - describe '#index' do + context 'streams' do before do sign_in alice end - it 'will succeed if admin' do - AppConfig[:admins] = [alice.username] - get :index - response.should be_success + describe "#public" do + it 'will succeed if admin' do + AppConfig[:admins] = [alice.username] + get :public + response.should be_success + end + + it 'will redirect if not' do + AppConfig[:admins] = [] + get :public + response.should be_redirect + end end - it 'will redirect if not' do - AppConfig[:admins] = [] - get :index - response.should be_redirect + describe '#multi' do + before do + @old_spotlight_value = AppConfig[:community_spotlight] + end + + after do + AppConfig[:community_spotlight] = @old_spotlight_value + end + + it 'succeeds' do + AppConfig[:community_spotlight] = [bob.person.diaspora_handle] + get :multi + response.should be_success + end + + it 'succeeds without AppConfig[:community_spotlight]' do + AppConfig[:community_spotlight] = nil + get :multi + response.should be_success + end + + it 'succeeds on mobile' do + get :multi, :format => :mobile + response.should be_success + end end + streams = [ + {:path => :liked, :type => Stream::Likes}, + {:path => :mentioned, :type => Stream::Mention}, + {:path => :followed_tags, :type => Stream::FollowedTag} + ] + + streams.each do |s| + describe "##{s[:path]}" do + it 'succeeds' do + get s[:path] + response.should be_success + end + + it 'assigns a stream' do + get s[:path] + assigns[:stream].should be_a s[:type] + end + end + end end end diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index b647895fd..b7338ce4a 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -67,7 +67,7 @@ describe RegistrationsController do it "redirects to the home path" do get :create, @valid_params response.should be_redirect - response.location.should match /^#{multi_url}\??$/ + response.location.should match /^#{multi_stream_url}\??$/ end end diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb index cabf39664..38c203e6e 100644 --- a/spec/controllers/sessions_controller_spec.rb +++ b/spec/controllers/sessions_controller_spec.rb @@ -27,14 +27,14 @@ describe SessionsController do it "redirects to /stream for a non-mobile user" do post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} response.should be_redirect - response.location.should match /^#{multi_url}\??$/ + response.location.should match /^#{multi_stream_url}\??$/ end it "redirects to /stream for a mobile user" do @request.env['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7' post :create, {"user" => {"remember_me" => "0", "username" => @user.username, "password" => "evankorth"}} response.should be_redirect - response.location.should match /^#{multi_url}\??$/ + response.location.should match /^#{multi_stream_url}\??$/ end it 'queues up an update job' do From 339c47d7821a577f901f509ba5976ae30434044d Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 17 Jan 2012 15:52:15 -0800 Subject: [PATCH 2/2] moved stream logic into its own controller (StreamsController) --- app/controllers/application_controller.rb | 16 -- app/controllers/posts_controller.rb | 67 ------ app/controllers/streams_controller.rb | 71 +++++++ .../main_stream.html.haml} | 4 +- app/views/layouts/main_stream.mobile.haml | 18 ++ config/routes.rb | 14 +- features/oembed.feature | 1 + features/photo_lightbox.feature | 1 - features/posts_from_main_page.feature | 2 + .../jasmine_fixtures/aspects_spec.rb | 2 +- .../{stream_spec.rb => streams_spec.rb} | 2 +- spec/controllers/multis_controller_spec.rb | 35 ---- spec/controllers/posts_controller_spec.rb | 67 ------ spec/controllers/streams_controller_spec.rb | 72 +++++++ .../tag_followings_controller_spec.rb | 195 ------------------ 15 files changed, 175 insertions(+), 392 deletions(-) create mode 100644 app/controllers/streams_controller.rb rename app/views/{aspects/index.html.haml => layouts/main_stream.html.haml} (92%) create mode 100644 app/views/layouts/main_stream.mobile.haml rename spec/controllers/jasmine_fixtures/{stream_spec.rb => streams_spec.rb} (97%) delete mode 100644 spec/controllers/multis_controller_spec.rb create mode 100644 spec/controllers/streams_controller_spec.rb delete mode 100644 spec/controllers/tag_followings_controller_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 52bda40bc..3afefd3c2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -127,22 +127,6 @@ class ApplicationController < ActionController::Base @tags ||= current_user.followed_tags end - # @param stream_klass [Constant] - # @return [String] JSON representation of posts given a [Stream] constant. - def stream_json(stream_klass) - render_for_api :backbone, :json => stream(stream_klass).stream_posts, :root => :posts - end - - def stream(stream_klass) - authenticate_user! - stream_klass.new(current_user, :max_time => max_time) - end - - def default_stream_action(stream_klass) - @stream = stream(stream_klass) - render 'aspects/index' - end - def max_time params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index c58f3944b..856dcc104 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,22 +2,10 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(Rails.root, "lib", "stream", "aspect") -require File.join(Rails.root, "lib", "stream", "multi") -require File.join(Rails.root, "lib", "stream", "comments") -require File.join(Rails.root, "lib", "stream", "likes") -require File.join(Rails.root, "lib", "stream", "mention") -require File.join(Rails.root, "lib", "stream", "followed_tag") - class PostsController < ApplicationController before_filter :authenticate_user!, :except => :show before_filter :set_format_if_malformed_from_status_net, :only => :show - before_filter :redirect_unless_admin, :only => :public - - before_filter :save_selected_aspects, :only => :aspects - before_filter :ensure_page, :only => :aspects - respond_to :html, :mobile, :json, @@ -71,53 +59,8 @@ class PostsController < ApplicationController end end - # streams - def aspects - stream_klass = Stream::Aspect - aspect_ids = (session[:a_ids] ? session[:a_ids] : []) - @stream = Stream::Aspect.new(current_user, aspect_ids, - :max_time => params[:max_time].to_i) - - respond_with do |format| - format.html { render 'aspects/index' } - format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } - end - end - - def public - stream_responder(Stream::Public) - end - - def multi - stream_responder(Stream::Multi) - end - - def commented - stream_responder(Stream::Comments) - end - - def liked - stream_responder(Stream::Likes) - end - - def mentioned - stream_responder(Stream::Mention) - end - - def followed_tags - stream_responder(Stream::FollowedTag) - end - private - def stream_responder(stream_klass) - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.mobile{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end - def set_format_if_malformed_from_status_net request.format = :html if request.format == 'application/html+xml' end @@ -133,14 +76,4 @@ class PostsController < ApplicationController true end end - - def save_selected_aspects - if params[:a_ids].present? - session[:a_ids] = params[:a_ids] - end - end - - def ensure_page - params[:max_time] ||= Time.now + 1 - end end diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb new file mode 100644 index 000000000..50a240f37 --- /dev/null +++ b/app/controllers/streams_controller.rb @@ -0,0 +1,71 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require File.join(Rails.root, "lib", "stream", "aspect") +require File.join(Rails.root, "lib", "stream", "multi") +require File.join(Rails.root, "lib", "stream", "comments") +require File.join(Rails.root, "lib", "stream", "likes") +require File.join(Rails.root, "lib", "stream", "mention") +require File.join(Rails.root, "lib", "stream", "followed_tag") + +class StreamsController < ApplicationController + before_filter :authenticate_user! + before_filter :save_selected_aspects, :only => :aspects + before_filter :redirect_unless_admin, :only => :public + + respond_to :html, + :mobile, + :json + + def aspects + aspect_ids = (session[:a_ids] ? session[:a_ids] : []) + @stream = Stream::Aspect.new(current_user, aspect_ids, + :max_time => max_time) + stream_responder + end + + def public + stream_responder(Stream::Public) + end + + def multi + stream_responder(Stream::Multi) + end + + def commented + stream_responder(Stream::Comments) + end + + def liked + stream_responder(Stream::Likes) + end + + def mentioned + stream_responder(Stream::Mention) + end + + def followed_tags + stream_responder(Stream::FollowedTag) + end + + private + + def stream_responder(stream_klass=nil) + if stream_klass.present? + @stream ||= stream_klass.new(current_user, :max_time => max_time) + end + + respond_with do |format| + format.html { render 'layouts/main_stream' } + format.mobile { render 'layouts/main_stream' } + format.json { render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } + end + end + + def save_selected_aspects + if params[:a_ids].present? + session[:a_ids] = params[:a_ids] + end + end +end diff --git a/app/views/aspects/index.html.haml b/app/views/layouts/main_stream.html.haml similarity index 92% rename from app/views/aspects/index.html.haml rename to app/views/layouts/main_stream.html.haml index 313e83e8b..fad1427e9 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/layouts/main_stream.html.haml @@ -13,9 +13,9 @@ = link_to image_tag('close_label.png'), getting_started_completed_path, :id => "gs-skip-x" .span-23 %h1 - = t('.welcome_to_diaspora', :name => current_user.first_name) + = t('aspects.index.welcome_to_diaspora', :name => current_user.first_name) %h3 - = t('.introduce_yourself') + = t('aspects.index.introduce_yourself') %br %br %br diff --git a/app/views/layouts/main_stream.mobile.haml b/app/views/layouts/main_stream.mobile.haml new file mode 100644 index 000000000..4c5ab0cb9 --- /dev/null +++ b/app/views/layouts/main_stream.mobile.haml @@ -0,0 +1,18 @@ +-# Copyright (c) 2010-2011, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +%h2{:style => "padding:0 10px;display:none;"} + - if @stream.for_all_aspects? + = t('all_aspects') + - else + = @stream.aspect + +#main_stream.stream + = render 'shared/stream', :posts => @stream.stream_posts + -if @stream.stream_posts.length > 0 + #pagination + %a.more-link.paginate{:href => next_page_path} + %h1 + = t("more") + diff --git a/config/routes.rb b/config/routes.rb index 4ce940862..de5a45cfa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,13 +21,13 @@ Diaspora::Application.routes.draw do end # Streams - get "public" => "posts#public", :as => "public_stream" - get "stream" => "posts#multi", :as => "multi_stream" - get "followed_tags" => "posts#followed_tags", :as => "followed_tags_stream" - get "mentions" => "posts#mentioned", :as => "mentioned_stream" - get "liked" => "posts#liked", :as => "liked_stream" - get "commented" => "posts#commented", :as => "commented_stream" - get "aspects" => "posts#aspects", :as => "aspects_stream" + get "public" => "streams#public", :as => "public_stream" + get "stream" => "streams#multi", :as => "multi_stream" + get "followed_tags" => "streams#followed_tags", :as => "followed_tags_stream" + get "mentions" => "streams#mentioned", :as => "mentioned_stream" + get "liked" => "streams#liked", :as => "liked_stream" + get "commented" => "streams#commented", :as => "commented_stream" + get "aspects" => "streams#aspects", :as => "aspects_stream" resources :aspects do put :toggle_contact_visibility diff --git a/features/oembed.feature b/features/oembed.feature index 6aefc2a18..9fdf31c9b 100644 --- a/features/oembed.feature +++ b/features/oembed.feature @@ -22,6 +22,7 @@ Feature: oembed Given I expand the publisher When I fill in "status_message_fake_text" with "http://mytube.com/watch?v=M3r2XDceM6A&format=json" And I press "Share" + And I wait for the ajax to finish And I follow "Your Aspects" Then I should not see a video player diff --git a/features/photo_lightbox.feature b/features/photo_lightbox.feature index de908ec35..1b13de22d 100644 --- a/features/photo_lightbox.feature +++ b/features/photo_lightbox.feature @@ -12,7 +12,6 @@ Feature: viewing the photo lightbox And I fill in "status_message_fake_text" with "Look at this dog" And I press "Share" And I wait for the ajax to finish - And I am on the aspects page Scenario: viewing a photo Then I should see an image attached to the post diff --git a/features/posts_from_main_page.feature b/features/posts_from_main_page.feature index 251b782aa..fffe3073c 100644 --- a/features/posts_from_main_page.feature +++ b/features/posts_from_main_page.feature @@ -19,6 +19,8 @@ Feature: posting from the main page Given I expand the publisher When I fill in "status_message_fake_text" with "I am eating a yogurt" And I press "Share" + And I wait for the ajax to finish + And I go to the aspects page Then I should see "I am eating a yogurt" within ".stream_element" diff --git a/spec/controllers/jasmine_fixtures/aspects_spec.rb b/spec/controllers/jasmine_fixtures/aspects_spec.rb index 32811ed3c..2dace2747 100644 --- a/spec/controllers/jasmine_fixtures/aspects_spec.rb +++ b/spec/controllers/jasmine_fixtures/aspects_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PostsController do +describe StreamsController do describe '#aspects' do before do sign_in :user, alice diff --git a/spec/controllers/jasmine_fixtures/stream_spec.rb b/spec/controllers/jasmine_fixtures/streams_spec.rb similarity index 97% rename from spec/controllers/jasmine_fixtures/stream_spec.rb rename to spec/controllers/jasmine_fixtures/streams_spec.rb index fd9fa7d13..95f3ed476 100644 --- a/spec/controllers/jasmine_fixtures/stream_spec.rb +++ b/spec/controllers/jasmine_fixtures/streams_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' -describe PostsController do +describe StreamsController do describe '#multi' do before do sign_in :user, alice diff --git a/spec/controllers/multis_controller_spec.rb b/spec/controllers/multis_controller_spec.rb deleted file mode 100644 index 874b18608..000000000 --- a/spec/controllers/multis_controller_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' - -describe MultisController do - describe '#index' do - before do - @old_spotlight_value = AppConfig[:community_spotlight] - sign_in :user, alice - end - - after do - AppConfig[:community_spotlight] = @old_spotlight_value - end - - it 'succeeds' do - AppConfig[:community_spotlight] = [bob.person.diaspora_handle] - get :index - response.should be_success - end - - it 'succeeds without AppConfig[:community_spotlight]' do - AppConfig[:community_spotlight] = nil - get :index - response.should be_success - end - - it 'succeeds on mobile' do - get :index, :format => :mobile - response.should be_success - end - end -end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 42fc96bce..ffe8e6d65 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -137,71 +137,4 @@ describe PostsController do StatusMessage.exists?(message.id).should be_true end end - - context 'streams' do - before do - sign_in alice - end - - describe "#public" do - it 'will succeed if admin' do - AppConfig[:admins] = [alice.username] - get :public - response.should be_success - end - - it 'will redirect if not' do - AppConfig[:admins] = [] - get :public - response.should be_redirect - end - end - - describe '#multi' do - before do - @old_spotlight_value = AppConfig[:community_spotlight] - end - - after do - AppConfig[:community_spotlight] = @old_spotlight_value - end - - it 'succeeds' do - AppConfig[:community_spotlight] = [bob.person.diaspora_handle] - get :multi - response.should be_success - end - - it 'succeeds without AppConfig[:community_spotlight]' do - AppConfig[:community_spotlight] = nil - get :multi - response.should be_success - end - - it 'succeeds on mobile' do - get :multi, :format => :mobile - response.should be_success - end - end - - streams = [ - {:path => :liked, :type => Stream::Likes}, - {:path => :mentioned, :type => Stream::Mention}, - {:path => :followed_tags, :type => Stream::FollowedTag} - ] - - streams.each do |s| - describe "##{s[:path]}" do - it 'succeeds' do - get s[:path] - response.should be_success - end - - it 'assigns a stream' do - get s[:path] - assigns[:stream].should be_a s[:type] - end - end - end - end end diff --git a/spec/controllers/streams_controller_spec.rb b/spec/controllers/streams_controller_spec.rb new file mode 100644 index 000000000..6b713e06d --- /dev/null +++ b/spec/controllers/streams_controller_spec.rb @@ -0,0 +1,72 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require 'spec_helper' + +describe StreamsController do + before do + sign_in alice + end + + describe "#public" do + it 'will succeed if admin' do + AppConfig[:admins] = [alice.username] + get :public + response.should be_success + end + + it 'will redirect if not' do + AppConfig[:admins] = [] + get :public + response.should be_redirect + end + end + + describe '#multi' do + before do + @old_spotlight_value = AppConfig[:community_spotlight] + end + + after do + AppConfig[:community_spotlight] = @old_spotlight_value + end + + it 'succeeds' do + AppConfig[:community_spotlight] = [bob.person.diaspora_handle] + get :multi + response.should be_success + end + + it 'succeeds without AppConfig[:community_spotlight]' do + AppConfig[:community_spotlight] = nil + get :multi + response.should be_success + end + + it 'succeeds on mobile' do + get :multi, :format => :mobile + response.should be_success + end + end + + streams = [ + {:path => :liked, :type => Stream::Likes}, + {:path => :mentioned, :type => Stream::Mention}, + {:path => :followed_tags, :type => Stream::FollowedTag} + ] + + streams.each do |s| + describe "##{s[:path]}" do + it 'succeeds' do + get s[:path] + response.should be_success + end + + it 'assigns a stream' do + get s[:path] + assigns[:stream].should be_a s[:type] + end + end + end +end diff --git a/spec/controllers/tag_followings_controller_spec.rb b/spec/controllers/tag_followings_controller_spec.rb deleted file mode 100644 index 9717aa9a1..000000000 --- a/spec/controllers/tag_followings_controller_spec.rb +++ /dev/null @@ -1,195 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require 'spec_helper' - -describe TagFollowingsController do - - def valid_attributes - {:name => "partytimeexcellent"} - end - - before do - @tag = ActsAsTaggableOn::Tag.create!(:name => "partytimeexcellent") - sign_in :user, bob - bob.followed_tags.create(:name => "testing") - end - - describe 'index' do - it 'succeeds' do - get :index - response.should be_success - end - - it 'assigns a stream' do - get :index - assigns[:stream].should be_a Stream::FollowedTag - end - - describe 'if empty' do - it 'succeeds' do - bob.followed_tags.delete_all - get :index - response.should be_success - end - - it 'assigns a stream' do - bob.followed_tags.delete_all - get :index - assigns[:stream].should be_a Stream::FollowedTag - end - end - end - - - describe "create" do - describe "successfully" do - it "creates a new TagFollowing" do - expect { - post :create, valid_attributes - response.should be_redirect - }.to change(TagFollowing, :count).by(1) - end - - it "associates the tag following with the currently-signed-in user" do - expect { - post :create, valid_attributes - response.should be_redirect - }.to change(bob.tag_followings, :count).by(1) - end - - it "assigns a newly created tag_following as @tag_following" do - post :create, valid_attributes - response.should be_redirect - assigns(:tag_following).should be_a(TagFollowing) - assigns(:tag_following).should be_persisted - end - - it "creates the tag IFF it doesn't already exist" do - ActsAsTaggableOn::Tag.find_by_name('tomcruisecontrol').should be_nil - expect { - post :create, :name => "tomcruisecontrol" - }.to change(ActsAsTaggableOn::Tag, :count).by(1) - end - - it "flashes success to the tag page" do - post :create, valid_attributes - flash[:notice].should include(valid_attributes[:name]) - end - - it "flashes error if you already have a tag" do - TagFollowing.any_instance.stub(:save).and_return(false) - post :create, valid_attributes - flash[:error].should include(valid_attributes[:name]) - end - - it 'squashes the tag' do - ActsAsTaggableOn::Tag.find_by_name('somestuff').should be_nil - post :create, :name => "some stuff" - assigns[:tag].name.should == "somestuff" - ActsAsTaggableOn::Tag.find_by_name('somestuff').should_not be_nil - end - - it 'downcases the tag name' do - ActsAsTaggableOn::Tag.find_by_name('somestuff').should be_nil - post :create, :name => "SOMESTUFF" - response.should be_redirect - assigns[:tag].name.should == "somestuff" - ActsAsTaggableOn::Tag.find_by_name('somestuff').should_not be_nil - end - - it "normalizes the tag name" do - ActsAsTaggableOn::Tag.find_by_name('foobar').should be_nil - post :create, :name => "foo:bar" - assigns[:tag].name.should == "foobar" - ActsAsTaggableOn::Tag.find_by_name('foobar').should_not be_nil - end - end - - describe 'fails to' do - it "create the tag if it already exists" do - ActsAsTaggableOn::Tag.find_by_name('tomcruisecontrol').should be_nil - expect { - post :create, :name => "tomcruisecontrol" - }.to change(ActsAsTaggableOn::Tag, :count).by(1) - ActsAsTaggableOn::Tag.find_by_name('tomcruisecontrol').should_not be_nil - - expect { - post :create, :name => "tomcruisecontrol" - }.to change(ActsAsTaggableOn::Tag, :count).by(0) - expect { - post :create, :name => "tom cruise control" - }.to change(ActsAsTaggableOn::Tag, :count).by(0) - expect { - post :create, :name => "TomCruiseControl" - }.to change(ActsAsTaggableOn::Tag, :count).by(0) - expect { - post :create, :name => "tom:cruise:control" - }.to change(ActsAsTaggableOn::Tag, :count).by(0) - end - - it "create a tag following for a user other than the currently signed in user" do - expect { - expect { - post :create, valid_attributes.merge(:user_id => alice.id) - }.not_to change(alice.tag_followings, :count).by(1) - }.to change(bob.tag_followings, :count).by(1) - end - end - end - - describe "DELETE destroy" do - before do - TagFollowing.create!(:tag => @tag, :user => bob ) - TagFollowing.create!(:tag => @tag, :user => alice ) - end - - it "destroys the requested tag_following" do - expect { - delete :destroy, valid_attributes - }.to change(TagFollowing, :count).by(-1) - end - - it "redirects and flashes error if you already don't follow the tag" do - delete :destroy, valid_attributes - - response.should redirect_to(tag_path(:name => valid_attributes[:name])) - flash[:notice].should include(valid_attributes[:name]) - end - - it "redirects and flashes error if you already don't follow the tag" do - TagFollowing.any_instance.stub(:destroy).and_return(false) - delete :destroy, valid_attributes - - response.should redirect_to(tag_path(:name => valid_attributes[:name])) - flash[:error].should include(valid_attributes[:name]) - end - end - - describe "#create_multiple" do - it "redirects" do - post :create_multiple, :tags => "#foo,#bar" - response.should be_redirect - end - - it "handles no tags parameter" do - expect { post :create_multiple, :name => 'not tags' }.to_not raise_exception - end - - it "adds multiple tags" do - expect { post :create_multiple, :tags => "#tags,#cats,#bats," }.to change{ bob.followed_tags.count }.by(3) - end - - it "adds non-followed tags" do - TagFollowing.create!(:tag => @tag, :user => bob ) - expect { post :create_multiple, :tags => "#partytimeexcellent,#a,#b," }.to change{ bob.followed_tags.count }.by(2) - end - - it "normalizes the tag names" do - bob.followed_tags.delete_all - post :create_multiple, :tags => "#foo:bar,#bar#foo" - bob.followed_tags(true).map(&:name).should =~ ["foobar", "barfoo"] - end - end -end