Merge branch 'tag_stream_api'
This commit is contained in:
commit
98ef5212f3
11 changed files with 70 additions and 9 deletions
|
|
@ -2,7 +2,6 @@ branches:
|
|||
only:
|
||||
- 'master'
|
||||
|
||||
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- ree
|
||||
|
|
|
|||
9
app/controllers/api/v0/tags_controller.rb
Normal file
9
app/controllers/api/v0/tags_controller.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# 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
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
# 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
|
||||
def show
|
||||
if user = User.find_by_username(params[:username])
|
||||
|
|
|
|||
19
app/models/api/v0/serializers/tag.rb
Normal file
19
app/models/api/v0/serializers/tag.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# 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
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
class Api::V0::Serializers::User
|
||||
attr_accessor :user
|
||||
# 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::User
|
||||
def initialize(user)
|
||||
@user = user
|
||||
@person = user.person
|
||||
@profile = @person.profile
|
||||
end
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ Diaspora::Application.routes.draw do
|
|||
namespace :api do
|
||||
namespace :v0 do
|
||||
get "/users/:username" => 'users#show', :as => 'user'
|
||||
get "/tags/:name" => 'tags#show', :as => 'tag'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ class Stream::Base
|
|||
def post_is_from_contact?(post)
|
||||
@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] ||= user.person.id == post.author.id
|
||||
@can_comment_cache[post.id] ||= (user.person.id == post.author.id)
|
||||
@can_comment_cache[post.id]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# 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
|
||||
attr_accessor :tag_name, :people_page
|
||||
|
||||
|
|
|
|||
20
spec/controllers/api/v0/tags_controller_spec.rb
Normal file
20
spec/controllers/api/v0/tags_controller_spec.rb
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# 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
|
|||
@stream.stub(:people).and_return([bob.person, eve.person, @person])
|
||||
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)
|
||||
@stream.can_comment?(post).should be_true
|
||||
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)
|
||||
@stream.can_comment?(post).should be_true
|
||||
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)
|
||||
@stream.can_comment?(post).should be_true
|
||||
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)
|
||||
post = Factory(:status_message, :author => @person)
|
||||
@stream.can_comment?(post).should be_true
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
# 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 File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue