Skip to content
Extraits de code Groupes Projets
Valider 98ef5212 rédigé par Sarah Mei's avatar Sarah Mei
Parcourir les fichiers

Merge branch 'tag_stream_api'

parents e63d29bc 80821c9c
Branches
Étiquettes
Aucune requête de fusion associée trouvée
...@@ -2,7 +2,6 @@ branches: ...@@ -2,7 +2,6 @@ branches:
only: only:
- 'master' - 'master'
rvm: rvm:
- 1.8.7 - 1.8.7
- ree - ree
......
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Api::V0::TagsController < ApplicationController
def show
render :json => Api::V0::Serializers::Tag.new(params[:name])
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.
class Api::V0::UsersController < ApplicationController class Api::V0::UsersController < ApplicationController
def show def show
if user = User.find_by_username(params[:username]) if user = User.find_by_username(params[:username])
......
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Api::V0::Serializers::Tag
def initialize(tag)
@stream = Stream::Tag.new(nil, tag)
end
def as_json(opts={})
{
"name" => @stream.tag_name,
"person_count" => @stream.people_count,
"followed_count" => @stream.tag_follow_count,
"posts" => []
}
end
end
class Api::V0::Serializers::User # Copyright (c) 2010-2011, Diaspora Inc. This file is
attr_accessor :user # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class Api::V0::Serializers::User
def initialize(user) def initialize(user)
@user = user
@person = user.person @person = user.person
@profile = @person.profile @profile = @person.profile
end end
......
...@@ -168,6 +168,7 @@ Diaspora::Application.routes.draw do ...@@ -168,6 +168,7 @@ Diaspora::Application.routes.draw do
namespace :api do namespace :api do
namespace :v0 do namespace :v0 do
get "/users/:username" => 'users#show', :as => 'user' get "/users/:username" => 'users#show', :as => 'user'
get "/tags/:name" => 'tags#show', :as => 'tag'
end end
end end
......
...@@ -120,7 +120,7 @@ class Stream::Base ...@@ -120,7 +120,7 @@ class Stream::Base
def post_is_from_contact?(post) def post_is_from_contact?(post)
@can_comment_cache ||= {} @can_comment_cache ||= {}
@can_comment_cache[post.id] ||= contacts_in_stream.find{|contact| contact.person_id == post.author.id}.present? @can_comment_cache[post.id] ||= contacts_in_stream.find{|contact| contact.person_id == post.author.id}.present?
@can_comment_cache[post.id] ||= user.person.id == post.author.id @can_comment_cache[post.id] ||= (user.person.id == post.author.id)
@can_comment_cache[post.id] @can_comment_cache[post.id]
end end
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.
class Stream::Tag < Stream::Base class Stream::Tag < Stream::Base
attr_accessor :tag_name, :people_page attr_accessor :tag_name, :people_page
......
# 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::TagsController do
describe '#show' do
it 'succeeds' do
get :show, :name => 'alice'
response.should be_success
end
it "returns the basic tag data" do
get :show, :name => 'alice'
parsed_json = JSON.parse(response.body)
parsed_json.keys.should =~ %w(name person_count followed_count posts)
end
end
end
...@@ -11,22 +11,22 @@ describe Stream::Base do ...@@ -11,22 +11,22 @@ describe Stream::Base do
@stream.stub(:people).and_return([bob.person, eve.person, @person]) @stream.stub(:people).and_return([bob.person, eve.person, @person])
end end
it 'returns true if user is a contact of the post author' do it 'allows me to comment on my local contacts post' do
post = Factory(:status_message, :author => bob.person) post = Factory(:status_message, :author => bob.person)
@stream.can_comment?(post).should be_true @stream.can_comment?(post).should be_true
end end
it 'returns true if a user is the author of the post' do it 'allows me to comment on my own post' do
post = Factory(:status_message, :author => alice.person) post = Factory(:status_message, :author => alice.person)
@stream.can_comment?(post).should be_true @stream.can_comment?(post).should be_true
end end
it 'returns true if the author of the post is local' do it 'allows me to comment on any local public post' do
post = Factory(:status_message, :author => eve.person) post = Factory(:status_message, :author => eve.person)
@stream.can_comment?(post).should be_true @stream.can_comment?(post).should be_true
end end
it 'returns true if person is remote and is a contact' do it 'allows me to comment on a remote contacts post' do
Contact.create!(:user => @stream.user, :person => @person) Contact.create!(:user => @stream.user, :person => @person)
post = Factory(:status_message, :author => @person) post = Factory(:status_message, :author => @person)
@stream.can_comment?(post).should be_true @stream.can_comment?(post).should be_true
......
# 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' require 'spec_helper'
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter