Commit d6e9809b authored by Maxwell Salzberg's avatar Maxwell Salzberg

MS SM finished tag stream refactor

parent 2dda1609
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
...@@ -30,15 +30,4 @@ module CommentsHelper ...@@ -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
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
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
...@@ -18,7 +18,7 @@ ...@@ -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')}
......
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 ...@@ -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}
......
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
# 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 ...@@ -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
it "displays a friend's post" 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 end
it 'displays a public post that was sent to no one' do it 'succeeds' 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
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment