PostsController#index -> TagsController#show
This commit is contained in:
parent
8f9f24f383
commit
3db11cf38d
9 changed files with 80 additions and 98 deletions
|
|
@ -8,29 +8,6 @@ class PostsController < ApplicationController
|
|||
skip_before_filter :which_action_and_user
|
||||
skip_before_filter :set_grammatical_gender
|
||||
|
||||
def index
|
||||
if current_user
|
||||
@posts = StatusMessage.joins(:aspects).where(:pending => false
|
||||
).where(Aspect.arel_table[:user_id].eq(current_user.id).or(StatusMessage.arel_table[:public].eq(true))
|
||||
).select('DISTINCT `posts`.*')
|
||||
else
|
||||
@posts = StatusMessage.where(:public => true, :pending => false)
|
||||
end
|
||||
|
||||
params[:tag] ||= 'partytimeexcellent'
|
||||
|
||||
@posts = @posts.tagged_with(params[:tag])
|
||||
@posts = @posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC')
|
||||
|
||||
profiles = Profile.tagged_with(params[:tag]).where(:searchable => true).select('profiles.id, profiles.person_id')
|
||||
@people = Person.where(:id => profiles.map{|p| p.person_id}).limit(15)
|
||||
@people_count = Person.where(:id => profiles.map{|p| p.person_id}).count
|
||||
|
||||
@fakes = PostsFake.new(@posts)
|
||||
@commenting_disabled = true
|
||||
@pod_url = AppConfig[:pod_uri].host
|
||||
end
|
||||
|
||||
def show
|
||||
@post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first
|
||||
|
||||
|
|
|
|||
30
app/controllers/tags_controller.rb
Normal file
30
app/controllers/tags_controller.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
class TagsController < ApplicationController
|
||||
skip_before_filter :count_requests
|
||||
skip_before_filter :set_invites
|
||||
skip_before_filter :which_action_and_user
|
||||
skip_before_filter :set_grammatical_gender
|
||||
|
||||
def show
|
||||
if current_user
|
||||
@posts = StatusMessage.joins(:aspects).where(:pending => false
|
||||
).where(Aspect.arel_table[:user_id].eq(current_user.id).or(StatusMessage.arel_table[:public].eq(true))
|
||||
).select('DISTINCT `posts`.*')
|
||||
else
|
||||
@posts = StatusMessage.where(:public => true, :pending => false)
|
||||
end
|
||||
|
||||
@posts = @posts.tagged_with(params[:name])
|
||||
@posts = @posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC')
|
||||
|
||||
profiles = Profile.tagged_with(params[:name]).where(:searchable => true).select('profiles.id, profiles.person_id')
|
||||
@people = Person.where(:id => profiles.map{|p| p.person_id}).limit(15)
|
||||
@people_count = Person.where(:id => profiles.map{|p| p.person_id}).count
|
||||
|
||||
@fakes = PostsFake.new(@posts)
|
||||
@commenting_disabled = true
|
||||
end
|
||||
end
|
||||
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
|
||||
- content_for :page_title do
|
||||
- if params[:tag]
|
||||
= "##{params[:tag]}"
|
||||
- if params[:name]
|
||||
= "##{params[:name]}"
|
||||
|
||||
- else
|
||||
= t('.whatup', :pod => @pod_url)
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
.span-24.last
|
||||
%h1.tag
|
||||
= "##{params[:tag]}"
|
||||
= "##{params[:name]}"
|
||||
|
||||
.span-15
|
||||
#main_stream.stream
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
%a.paginate
|
||||
= t("more")
|
||||
- else
|
||||
= t('.nobody_talking', :tag => "##{params[:tag]}")
|
||||
= t('.nobody_talking', :tag => "##{params[:name]}")
|
||||
= will_paginate @posts
|
||||
|
||||
.prepend-2.span-7.last
|
||||
|
|
@ -405,8 +405,9 @@ en:
|
|||
|
||||
posts:
|
||||
doesnt_exist: "that post does not exist!"
|
||||
index:
|
||||
whatup: "What's happening on %{pod}"
|
||||
|
||||
tags:
|
||||
show:
|
||||
posts_tagged_with: "Posts tagged with #%{tag}"
|
||||
nobody_talking: "Nobody is talking about %{tag} yet."
|
||||
people_tagged_with: "People tagged with %{tag}"
|
||||
|
|
|
|||
|
|
@ -3,12 +3,13 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
Diaspora::Application.routes.draw do
|
||||
|
||||
|
||||
resources :status_messages, :only => [:new, :create, :destroy, :show]
|
||||
resources :comments, :only => [:create]
|
||||
resources :requests, :only => [:destroy, :create]
|
||||
|
||||
match 'tags/:name' => 'tags#show'
|
||||
resources :tags, :only => [:show]
|
||||
|
||||
resource :profile
|
||||
match 'services/inviter/:provider' => 'services#inviter', :as => 'service_inviter'
|
||||
match 'services/finder/:provider' => 'services#finder', :as => 'friend_finder'
|
||||
|
|
@ -19,7 +20,7 @@ Diaspora::Application.routes.draw do
|
|||
|
||||
match 'notifications/read_all' => 'notifications#read_all'
|
||||
resources :notifications, :only => [:index, :update]
|
||||
resources :posts, :only => [:show, :index], :path => '/p/'
|
||||
resources :posts, :only => [:show], :path => '/p/'
|
||||
|
||||
resources :contacts
|
||||
resources :aspect_memberships, :only => [:destroy, :create]
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ module Diaspora
|
|||
return text if opts[:plain_text]
|
||||
regex = /(^|\s)#(\w+)/
|
||||
form_message = text.gsub(regex) do |matched_string|
|
||||
"#{$~[1]}<a href=\"/p?tag=#{$~[2]}\" class=\"tag\">##{$~[2]}</a>"
|
||||
"#{$~[1]}<a href=\"/tags/#{$~[2]}\" class=\"tag\">##{$~[2]}</a>"
|
||||
end
|
||||
form_message.html_safe
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,70 +10,6 @@ describe PostsController do
|
|||
before do
|
||||
@user = alice
|
||||
end
|
||||
describe '#index' do
|
||||
context 'signed in' do
|
||||
before do
|
||||
sign_in :user, @user
|
||||
end
|
||||
it 'works' do
|
||||
get :index
|
||||
response.status.should == 200
|
||||
end
|
||||
it "shows the signed in user's posts" do
|
||||
pending
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :text => "#what", :to => 'all')
|
||||
end
|
||||
eve.post(:status_message, :text => "#what", :to => 'all')
|
||||
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
it "shows any posts that the user can see" do
|
||||
pending
|
||||
posts = []
|
||||
2.times do
|
||||
posts << bob.post(:status_message, :text => "#what", :to => 'all')
|
||||
end
|
||||
eve.post(:status_message, :text => "#what", :to => 'all')
|
||||
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
end
|
||||
it 'restricts the posts by tag' do
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||
end
|
||||
2.times do
|
||||
@user.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
||||
end
|
||||
|
||||
get :index, :tag => 'what'
|
||||
assigns[:posts].should =~ posts
|
||||
|
||||
end
|
||||
it 'shows the most recent public posts' do
|
||||
pending
|
||||
posts = []
|
||||
3.times do
|
||||
posts << @user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
end
|
||||
get :index
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
it' shows only local posts' do
|
||||
pending
|
||||
3.times do
|
||||
@user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
end
|
||||
@user.person.update_attributes(:owner_id => nil)
|
||||
get :index
|
||||
assigns[:posts].should == []
|
||||
end
|
||||
end
|
||||
describe '#show' do
|
||||
it 'shows a public post' do
|
||||
status = @user.post(:status_message, :text => "hello", :public => true, :to => 'all')
|
||||
|
|
|
|||
37
spec/controllers/tags_controller_spec.rb
Normal file
37
spec/controllers/tags_controller_spec.rb
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe TagsController do
|
||||
render_views
|
||||
|
||||
before do
|
||||
@user = alice
|
||||
end
|
||||
describe '#show' do
|
||||
context 'signed in' do
|
||||
before do
|
||||
sign_in :user, @user
|
||||
end
|
||||
it 'works' do
|
||||
get :show, :name => 'testing'
|
||||
response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
||||
it 'restricts the posts by tag' do
|
||||
posts = []
|
||||
2.times do
|
||||
posts << @user.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||
end
|
||||
2.times do
|
||||
@user.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
||||
end
|
||||
|
||||
get :show, :name => 'what'
|
||||
assigns[:posts].should =~ posts
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -19,7 +19,7 @@ describe Diaspora::Taggable do
|
|||
@object.save!
|
||||
end
|
||||
it 'links the tag to /p' do
|
||||
link = link_to('#what', posts_path(:tag => 'what'), :class => 'tag')
|
||||
link = link_to('#what', '/tags/what', :class => 'tag')
|
||||
@object.format_tags(@str).should include(link)
|
||||
end
|
||||
it 'responds to plain_text' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue