Merge branch 'tag_stream'
This commit is contained in:
commit
c9523d49ac
16 changed files with 261 additions and 124 deletions
9
app/controllers/api/v0/users_controller.rb
Normal file
9
app/controllers/api/v0/users_controller.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
class Api::V0::UsersController < ApplicationController
|
||||||
|
def show
|
||||||
|
if user = User.find_by_username(params[:username])
|
||||||
|
render :json => Api::V0::Serializers::User.new(user)
|
||||||
|
else
|
||||||
|
head :not_found
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -150,7 +150,7 @@ class ApplicationController < ActionController::Base
|
||||||
def default_stream_action(stream_klass)
|
def default_stream_action(stream_klass)
|
||||||
authenticate_user!
|
authenticate_user!
|
||||||
save_sort_order
|
save_sort_order
|
||||||
@stream = stream_klass.new(current_user, :max_time => params[:max_time], :order => sort_order)
|
@stream = stream_klass.new(current_user, :max_time => max_time, :order => sort_order)
|
||||||
|
|
||||||
if params[:only_posts]
|
if params[:only_posts]
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
require File.join(Rails.root, 'app', 'models', 'acts_as_taggable_on_tag')
|
require File.join(Rails.root, 'app', 'models', 'acts_as_taggable_on_tag')
|
||||||
|
require File.join(Rails.root, 'lib', 'stream', 'tag')
|
||||||
|
|
||||||
class TagsController < ApplicationController
|
class TagsController < ApplicationController
|
||||||
skip_before_filter :which_action_and_user
|
skip_before_filter :which_action_and_user
|
||||||
|
|
@ -34,34 +35,17 @@ class TagsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
params[:name].downcase!
|
@stream = Stream::Tag.new(current_user, params[:name], :max_time => max_time, :page => params[:page])
|
||||||
@aspect = :tag
|
|
||||||
@tag = ActsAsTaggableOn::Tag.find_by_name(params[:name])
|
|
||||||
@tag_follow_count = @tag.try(:followed_count).to_i
|
|
||||||
|
|
||||||
if current_user
|
|
||||||
@posts = StatusMessage.owned_or_visible_by_user(current_user)
|
|
||||||
else
|
|
||||||
@posts = StatusMessage.all_public
|
|
||||||
end
|
|
||||||
|
|
||||||
@posts = @posts.tagged_with(params[:name]).for_a_stream(max_time, 'created_at')
|
|
||||||
|
|
||||||
@commenting_disabled = true
|
|
||||||
params[:prefill] = "##{params[:name]} "
|
|
||||||
|
|
||||||
if params[:only_posts]
|
if params[:only_posts]
|
||||||
render :partial => 'shared/stream', :locals => {:posts => @posts}
|
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}
|
||||||
else
|
return
|
||||||
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}).paginate(:page => params[:page], :per_page => 15)
|
|
||||||
@people_count = Person.where(:id => profiles.map{|p| p.person_id}).count
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_followed?
|
def tag_followed?
|
||||||
if @tag_followed.nil?
|
if @tag_followed.nil?
|
||||||
@tag_followed = TagFollowing.joins(:tag).where(:tags => {:name => params[:name]}, :user_id => current_user.id).exists? #,
|
@tag_followed = TagFollowing.joins(:tag).where(:tags => {:name => params[:name]}, :user_id => current_user.id).exists?
|
||||||
end
|
end
|
||||||
@tag_followed
|
@tag_followed
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,4 @@ module CommentsHelper
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def commenting_disabled?(post)
|
|
||||||
return true unless user_signed_in?
|
|
||||||
if defined?(@commenting_disabled)
|
|
||||||
@commenting_disabled
|
|
||||||
elsif defined?(@stream)
|
|
||||||
!@stream.can_comment?(post)
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
22
app/helpers/interim_stream_hackiness_helper.rb
Normal file
22
app/helpers/interim_stream_hackiness_helper.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
module InterimStreamHackinessHelper
|
||||||
|
def commenting_disabled?(post)
|
||||||
|
return true unless user_signed_in?
|
||||||
|
if defined?(@commenting_disabled)
|
||||||
|
@commenting_disabled
|
||||||
|
elsif defined?(@stream)
|
||||||
|
!@stream.can_comment?(post)
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def publisher_prefill_text
|
||||||
|
if params[:prefill].present?
|
||||||
|
params[:prefill]
|
||||||
|
elsif defined?(@stream)
|
||||||
|
@stream.publisher_prefill_text
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
module StreamHelper
|
module StreamHelper
|
||||||
def next_page_path(opts ={})
|
def next_page_path(opts ={})
|
||||||
if controller.instance_of?(TagsController)
|
if controller.instance_of?(TagsController)
|
||||||
tag_path(:name => @tag.name, :max_time => @posts.last.created_at.to_i)
|
tag_path(:name => @stream.tag_name, :max_time => time_for_scroll(opts[:ajax_stream], @stream))
|
||||||
elsif controller.instance_of?(AppsController)
|
elsif controller.instance_of?(AppsController)
|
||||||
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
|
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
|
||||||
elsif controller.instance_of?(PeopleController)
|
elsif controller.instance_of?(PeopleController)
|
||||||
|
|
|
||||||
19
app/models/api/v0/serializers/user.rb
Normal file
19
app/models/api/v0/serializers/user.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
class Api::V0::Serializers::User
|
||||||
|
attr_accessor :user
|
||||||
|
|
||||||
|
def initialize(user)
|
||||||
|
@user = user
|
||||||
|
@person = user.person
|
||||||
|
@profile = @person.profile
|
||||||
|
end
|
||||||
|
|
||||||
|
def as_json(opts={})
|
||||||
|
{
|
||||||
|
"diaspora_id" => @person.diaspora_handle,
|
||||||
|
"first_name" => @profile.first_name,
|
||||||
|
"last_name" => @profile.last_name,
|
||||||
|
"image_url" => @profile.image_url,
|
||||||
|
"searchable" => @profile.searchable
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -58,6 +58,8 @@ class Person < ActiveRecord::Base
|
||||||
select("DISTINCT people.*")
|
select("DISTINCT people.*")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scope :profile_tagged_with, lambda{|tag_name| joins(:profile => :tags).where(:profile => {:tags => {:name => tag_name}}).where('profiles.searchable IS TRUE') }
|
||||||
|
|
||||||
def self.featured_users
|
def self.featured_users
|
||||||
AppConfig[:featured_users].present? ? Person.where(:diaspora_handle => AppConfig[:featured_users]) : []
|
AppConfig[:featured_users].present? ? Person.where(:diaspora_handle => AppConfig[:featured_users]) : []
|
||||||
end
|
end
|
||||||
|
|
@ -76,7 +78,6 @@ class Person < ActiveRecord::Base
|
||||||
self.profile ||= Profile.new unless profile_set
|
self.profile ||= Profile.new unless profile_set
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def self.find_from_id_or_username(params)
|
def self.find_from_id_or_username(params)
|
||||||
p = if params[:id].present?
|
p = if params[:id].present?
|
||||||
Person.where(:id => params[:id]).first
|
Person.where(:id => params[:id]).first
|
||||||
|
|
@ -273,6 +274,8 @@ class Person < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# @param person [Person]
|
# @param person [Person]
|
||||||
# @param url [String]
|
# @param url [String]
|
||||||
def update_url(url)
|
def update_url(url)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#publisher_textarea_wrapper
|
#publisher_textarea_wrapper
|
||||||
= link_to( image_tag('deletelabel.png'), "#", :id => "hide_publisher", :title => t('.discard_post'))
|
= link_to( image_tag('deletelabel.png'), "#", :id => "hide_publisher", :title => t('.discard_post'))
|
||||||
%ul#photodropzone
|
%ul#photodropzone
|
||||||
= status.text_area :fake_text, :rows => 2, :value => h(params[:prefill]), :tabindex => 1, :placeholder => t('.whats_on_your_mind')
|
= status.text_area :fake_text, :rows => 2, :value => h(publisher_prefill_text), :tabindex => 1, :placeholder => t('.whats_on_your_mind')
|
||||||
= status.hidden_field :text, :value => '', :class => 'clear_on_submit'
|
= status.hidden_field :text, :value => '', :class => 'clear_on_submit'
|
||||||
|
|
||||||
#file-upload{:title => t('.upload_photos')}
|
#file-upload{:title => t('.upload_photos')}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
|
|
||||||
- content_for :page_title do
|
- content_for :page_title do
|
||||||
- if params[:name]
|
- if @stream.tag_name
|
||||||
= "##{params[:name]}"
|
= @stream.display_tag_name
|
||||||
- else
|
- else
|
||||||
= t('.whatup', :pod => @pod_url)
|
= t('.whatup', :pod => @pod_url)
|
||||||
|
|
||||||
|
|
@ -17,12 +17,12 @@
|
||||||
$(".button.tag_following").hover(function(){
|
$(".button.tag_following").hover(function(){
|
||||||
$this = $(this);
|
$this = $(this);
|
||||||
$this.removeClass("in_aspects");
|
$this.removeClass("in_aspects");
|
||||||
$this.val("#{t('.stop_following', :tag => params[:name])}");
|
$this.val("#{t('.stop_following', :tag => @stream.tag_name)}");
|
||||||
},
|
},
|
||||||
function(){
|
function(){
|
||||||
$this = $(this);
|
$this = $(this);
|
||||||
$this.addClass("in_aspects");
|
$this.addClass("in_aspects");
|
||||||
$this.val("#{t('.following', :tag => params[:name])}");
|
$this.val("#{t('.following', :tag => @stream.tag_name)}");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$(".people_stream .pagination a").live("click", function() {
|
$(".people_stream .pagination a").live("click", function() {
|
||||||
|
|
@ -36,10 +36,10 @@
|
||||||
|
|
||||||
.span-6.tags_people
|
.span-6.tags_people
|
||||||
%h3
|
%h3
|
||||||
= t('people', :count => @people_count)
|
= t('people', :count => @stream.people_count)
|
||||||
|
|
||||||
.side_stream.stream
|
.side_stream.stream
|
||||||
= render :partial => 'people/index', :locals => {:people => @people}
|
= render :partial => 'people/index', :locals => {:people => @stream.people}
|
||||||
|
|
||||||
%br
|
%br
|
||||||
|
|
||||||
|
|
@ -49,28 +49,28 @@
|
||||||
.span-15.last
|
.span-15.last
|
||||||
.stream_container
|
.stream_container
|
||||||
#author_info
|
#author_info
|
||||||
- if user_signed_in? && current_user.person != @person
|
- if user_signed_in?
|
||||||
.right
|
.right
|
||||||
- unless tag_followed?
|
- unless tag_followed?
|
||||||
= button_to t('.follow', :tag => params[:name]), tag_tag_followings_path(:name => params[:name]), :method => :post, :class => 'button take_action'
|
= button_to t('.follow', :tag => @stream.tag_name), tag_tag_followings_path(:name => @stream.tag_name), :method => :post, :class => 'button take_action'
|
||||||
- else
|
- else
|
||||||
= button_to t('.following', :tag => params[:name]), tag_tag_followings_path(:name => params[:name]), :method => :delete, :class => 'button red_on_hover tag_following in_aspects take_action'
|
= button_to t('.following', :tag => @stream.tag_name), tag_tag_followings_path(:name => @stream.tag_name), :method => :delete, :class => 'button red_on_hover tag_following in_aspects take_action'
|
||||||
%h2
|
%h2
|
||||||
= "##{params[:name]}"
|
= @stream.display_tag_name
|
||||||
%small
|
%small
|
||||||
= t('.followed_by')
|
= t('.followed_by')
|
||||||
= t('people', :count => @tag_follow_count)
|
= t('people', :count => @stream.tag_follow_count)
|
||||||
|
|
||||||
- if current_user
|
- if current_user
|
||||||
= render 'shared/publisher', :selected_aspects => all_aspects.map{|a| a.id}, :aspect_ids => all_aspects.map{|a| a.id}, :for_all_aspects => true, :aspect => all_aspects.first
|
= render 'shared/publisher', :selected_aspects => @stream.aspect_ids, :aspect_ids => @stream.aspect_ids, :for_all_aspects => true, :aspect => @stream.aspect
|
||||||
|
|
||||||
%hr
|
%hr
|
||||||
|
|
||||||
#main_stream.stream
|
#main_stream.stream
|
||||||
- if @posts.length > 0
|
- if @stream.posts.length > 0
|
||||||
= render 'shared/stream', :posts => @posts
|
= render 'shared/stream', :posts => @stream.posts
|
||||||
#pagination
|
#pagination
|
||||||
=link_to(t('more'), next_page_path, :class => 'paginate')
|
=link_to(t('more'), next_page_path, :class => 'paginate')
|
||||||
- else
|
- else
|
||||||
= t('.nobody_talking', :tag => "##{params[:name]}")
|
= t('.nobody_talking', :tag => @stream.display_tag_name)
|
||||||
|
|
||||||
|
|
|
||||||
11
features/api.feature
Normal file
11
features/api.feature
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
Feature: API
|
||||||
|
In order to use a client application
|
||||||
|
as an epic developer
|
||||||
|
I need to get user's info
|
||||||
|
|
||||||
|
Scenario: Getting a users public profile
|
||||||
|
Given a user named "Maxwell S" with email "maxwell@example.com"
|
||||||
|
And I send and accept JSON
|
||||||
|
When I send a GET request to "/api/v0/users/maxwell_s"
|
||||||
|
Then the response status should be "200"
|
||||||
|
And the JSON response should have "first_name" with the text "Maxwell"
|
||||||
|
|
@ -39,6 +39,11 @@ class Stream::Base
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [String]
|
||||||
|
def publisher_prefill_text
|
||||||
|
''
|
||||||
|
end
|
||||||
|
|
||||||
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
|
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
|
||||||
def people
|
def people
|
||||||
people_ids = posts.map{|x| x.author_id}
|
people_ids = posts.map{|x| x.author_id}
|
||||||
|
|
|
||||||
53
lib/stream/tag.rb
Normal file
53
lib/stream/tag.rb
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
class Stream::Tag < Stream::Base
|
||||||
|
attr_accessor :tag_name, :people_page
|
||||||
|
|
||||||
|
def initialize(user, tag_name, opts={})
|
||||||
|
super(user, opts)
|
||||||
|
self.tag_name = tag_name
|
||||||
|
@people_page = opts[:page] || 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def tag
|
||||||
|
@tag ||= ActsAsTaggableOn::Tag.find_by_name(tag_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def tag_follow_count
|
||||||
|
@tag_follow_count ||= tag.try(:followed_count).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def display_tag_name
|
||||||
|
@display_tag_name ||= "##{tag_name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def people
|
||||||
|
@people ||= Person.profile_tagged_with(tag_name).paginate(:page => people_page, :per_page => 15)
|
||||||
|
end
|
||||||
|
|
||||||
|
def people_count
|
||||||
|
@people_count ||= Person.profile_tagged_with(tag_name).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def posts
|
||||||
|
@posts ||= construct_post_query
|
||||||
|
end
|
||||||
|
|
||||||
|
def publisher_prefill_text
|
||||||
|
display_tag_name + ' '
|
||||||
|
end
|
||||||
|
|
||||||
|
def tag_name=(tag_name)
|
||||||
|
@tag_name = tag_name.downcase.gsub('#', '')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def construct_post_query
|
||||||
|
posts = StatusMessage
|
||||||
|
if user.present?
|
||||||
|
posts = posts.owned_or_visible_by_user(user)
|
||||||
|
else
|
||||||
|
posts = posts.all_public
|
||||||
|
end
|
||||||
|
posts.tagged_with(tag_name).for_a_stream(max_time, 'created_at')
|
||||||
|
end
|
||||||
|
end
|
||||||
23
spec/controllers/api/v0/users_controller_spec.rb
Normal file
23
spec/controllers/api/v0/users_controller_spec.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
# 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 Api::V0::UsersController do
|
||||||
|
describe '#show' do
|
||||||
|
it 'succeeds' do
|
||||||
|
get :show, :username => 'alice'
|
||||||
|
response.should be_success
|
||||||
|
end
|
||||||
|
it "404s if there's no such user" do
|
||||||
|
get :show, :username => "*****"
|
||||||
|
response.should be_not_found
|
||||||
|
end
|
||||||
|
it "returns the public profile data" do
|
||||||
|
get :show, :username => 'alice'
|
||||||
|
parsed_json = JSON.parse(response.body)
|
||||||
|
parsed_json.keys.should =~ %w( diaspora_id first_name last_name image_url searchable )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -41,89 +41,26 @@ describe TagsController do
|
||||||
sign_in :user, alice
|
sign_in :user, alice
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'displays your own post' do
|
it 'assigns a Stream::Tag object with the current_user' do
|
||||||
my_post = alice.post(:status_message, :text => "#what", :to => 'all')
|
get :show, :name => 'yes'
|
||||||
get :show, :name => 'what'
|
assigns[:stream].user.should == alice
|
||||||
assigns(:posts).should == [my_post]
|
|
||||||
response.status.should == 200
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "displays a friend's post" do
|
it 'succeeds' do
|
||||||
other_post = bob.post(:status_message, :text => "#hello", :to => 'all')
|
|
||||||
get :show, :name => 'hello'
|
|
||||||
assigns(:posts).should == [other_post]
|
|
||||||
response.status.should == 200
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'displays a public post' do
|
|
||||||
other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
|
||||||
get :show, :name => 'hello'
|
|
||||||
assigns(:posts).should == [other_post]
|
|
||||||
response.status.should == 200
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'displays a public post that was sent to no one' do
|
|
||||||
stranger = Factory(:user_with_aspect)
|
|
||||||
stranger_post = stranger.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
|
||||||
get :show, :name => 'hello'
|
|
||||||
assigns(:posts).should == [stranger_post]
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'displays a post with a comment containing the tag search' do
|
|
||||||
pending "toooo slow"
|
|
||||||
bob.post(:status_message, :text => "other post y'all", :to => 'all')
|
|
||||||
other_post = bob.post(:status_message, :text => "sup y'all", :to => 'all')
|
|
||||||
Factory(:comment, :text => "#hello", :post => other_post)
|
|
||||||
get :show, :name => 'hello'
|
|
||||||
assigns(:posts).should == [other_post]
|
|
||||||
response.status.should == 200
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'succeeds without posts' do
|
|
||||||
get :show, :name => 'hellyes'
|
get :show, :name => 'hellyes'
|
||||||
response.status.should == 200
|
response.status.should == 200
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "not signed in" do
|
context "not signed in" do
|
||||||
context "when there are people to display" do
|
it 'assigns a Stream::Tag object with no user' do
|
||||||
before do
|
get :show, :name => 'yes'
|
||||||
alice.profile.tag_string = "#whatevs"
|
assigns[:stream].user.should be_nil
|
||||||
alice.profile.build_tags
|
|
||||||
alice.profile.save!
|
|
||||||
get :show, :name => "whatevs"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "succeeds" do
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
|
|
||||||
it "assigns the right set of people" do
|
|
||||||
assigns(:people).should == [alice.person]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there are posts to display" do
|
it 'succeeds' do
|
||||||
before do
|
get :show, :name => 'hellyes'
|
||||||
@post = alice.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
response.status.should == 200
|
||||||
alice.post(:status_message, :text => "#hello", :public => true, :to => 'all')
|
|
||||||
end
|
|
||||||
|
|
||||||
it "succeeds" do
|
|
||||||
get :show, :name => 'what'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
|
|
||||||
it "assigns the right set of posts" do
|
|
||||||
get :show, :name => 'what'
|
|
||||||
assigns[:posts].should == [@post]
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'succeeds with comments' do
|
|
||||||
alice.comment('what WHAT!', :post => @post)
|
|
||||||
get :show, :name => 'what'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
82
spec/lib/stream/tag_spec.rb
Normal file
82
spec/lib/stream/tag_spec.rb
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||||
|
|
||||||
|
describe Stream::Tag do
|
||||||
|
context 'with a user' do
|
||||||
|
before do
|
||||||
|
@stream = Stream::Tag.new(alice, "what")
|
||||||
|
bob.post(:status_message, :text => "#not_what", :to => 'all')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'displays your own post' do
|
||||||
|
my_post = alice.post(:status_message, :text => "#what", :to => 'all')
|
||||||
|
@stream.posts.should == [my_post]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "displays a friend's post" do
|
||||||
|
other_post = bob.post(:status_message, :text => "#what", :to => 'all')
|
||||||
|
@stream.posts.should == [other_post]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'displays a public post' do
|
||||||
|
other_post = eve.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||||
|
@stream.posts.should == [other_post]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'displays a public post that was sent to no one' do
|
||||||
|
stranger = Factory(:user_with_aspect)
|
||||||
|
stranger_post = stranger.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||||
|
@stream.posts.should == [stranger_post]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'displays a post with a comment containing the tag search' do
|
||||||
|
pending "toooo slow"
|
||||||
|
other_post = bob.post(:status_message, :text => "sup y'all", :to => 'all')
|
||||||
|
Factory(:comment, :text => "#what", :post => other_post)
|
||||||
|
@stream.posts.should == [other_post]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without a user' do
|
||||||
|
before do
|
||||||
|
@post = alice.post(:status_message, :text => "#what", :public => true, :to => 'all')
|
||||||
|
alice.post(:status_message, :text => "#tagwhat", :public => true, :to => 'all')
|
||||||
|
alice.post(:status_message, :text => "#what", :public => false, :to => 'all')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "displays only public posts with the tag" do
|
||||||
|
stream = Stream::Tag.new(nil, "what")
|
||||||
|
stream.posts.should == [@post]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'people' do
|
||||||
|
it "assigns the right set of people" do
|
||||||
|
stream = Stream::Tag.new(bob, "whatevs")
|
||||||
|
alice.profile.tag_string = "#whatevs"
|
||||||
|
alice.profile.build_tags
|
||||||
|
alice.profile.save!
|
||||||
|
stream.people.should == [alice.person]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'shared behaviors' do
|
||||||
|
before do
|
||||||
|
@stream = Stream::Tag.new(Factory(:user), "test")
|
||||||
|
end
|
||||||
|
it_should_behave_like 'it is a stream'
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#tag_name=' do
|
||||||
|
it 'downcases the tag' do
|
||||||
|
stream = Stream::Tag.new(nil, "WHAT")
|
||||||
|
stream.tag_name.should == 'what'
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'removes #es' do
|
||||||
|
stream = Stream::Tag.new(nil, "#WHAT")
|
||||||
|
stream.tag_name.should == 'what'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue