From 58d496e1461bb8d711cc6cef0b3cb5280d45365b Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sat, 15 Oct 2011 22:11:23 -0700 Subject: [PATCH 1/4] MS SM WIP --- .travis.yml | 1 - config/routes.rb | 1 + lib/stream/base.rb | 2 +- spec/lib/stream/base_spec.rb | 8 ++++---- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index d43ddbb42..0b826c315 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ branches: only: - 'master' - rvm: - 1.8.7 - ree diff --git a/config/routes.rb b/config/routes.rb index 0c3e44237..f0abaf08c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/stream/base.rb b/lib/stream/base.rb index 81f78e39e..5717ea329 100644 --- a/lib/stream/base.rb +++ b/lib/stream/base.rb @@ -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 diff --git a/spec/lib/stream/base_spec.rb b/spec/lib/stream/base_spec.rb index f901a8d2b..182627708 100644 --- a/spec/lib/stream/base_spec.rb +++ b/spec/lib/stream/base_spec.rb @@ -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 From f2c16bec85da5a43f79d70cff8bf80f345adbf4f Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Sat, 15 Oct 2011 22:38:21 -0700 Subject: [PATCH 2/4] add files --- app/controllers/api/v0/tags_controller.rb | 5 +++++ .../api/v0/tags_controller_spec.rb | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 app/controllers/api/v0/tags_controller.rb create mode 100644 spec/controllers/api/v0/tags_controller_spec.rb diff --git a/app/controllers/api/v0/tags_controller.rb b/app/controllers/api/v0/tags_controller.rb new file mode 100644 index 000000000..15a6bed51 --- /dev/null +++ b/app/controllers/api/v0/tags_controller.rb @@ -0,0 +1,5 @@ +class Api::V0::TagsController < ApplicationController + def show + + end +end diff --git a/spec/controllers/api/v0/tags_controller_spec.rb b/spec/controllers/api/v0/tags_controller_spec.rb new file mode 100644 index 000000000..1fd9867a4 --- /dev/null +++ b/spec/controllers/api/v0/tags_controller_spec.rb @@ -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 From 42e061dfa000b07d418d04e8e427915e0c8df9ba Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Sun, 16 Oct 2011 13:43:21 -0700 Subject: [PATCH 3/4] Fix one tag api spec --- app/controllers/api/v0/tags_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v0/tags_controller.rb b/app/controllers/api/v0/tags_controller.rb index 15a6bed51..4bb084286 100644 --- a/app/controllers/api/v0/tags_controller.rb +++ b/app/controllers/api/v0/tags_controller.rb @@ -1,5 +1,5 @@ class Api::V0::TagsController < ApplicationController def show - + head :ok end end From 80821c9cc5e8c8470cecdd7004a1506c912b38ef Mon Sep 17 00:00:00 2001 From: Sarah Mei Date: Sun, 16 Oct 2011 15:25:11 -0700 Subject: [PATCH 4/4] Basic tag metadata returned. Now what to do about posts?... --- app/controllers/api/v0/tags_controller.rb | 6 +++++- app/controllers/api/v0/users_controller.rb | 4 ++++ app/models/api/v0/serializers/tag.rb | 19 +++++++++++++++++++ app/models/api/v0/serializers/user.rb | 7 ++++--- lib/stream/tag.rb | 4 ++++ spec/lib/stream/tag_spec.rb | 4 ++++ 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 app/models/api/v0/serializers/tag.rb diff --git a/app/controllers/api/v0/tags_controller.rb b/app/controllers/api/v0/tags_controller.rb index 4bb084286..1ce401b1c 100644 --- a/app/controllers/api/v0/tags_controller.rb +++ b/app/controllers/api/v0/tags_controller.rb @@ -1,5 +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 - head :ok + render :json => Api::V0::Serializers::Tag.new(params[:name]) end end diff --git a/app/controllers/api/v0/users_controller.rb b/app/controllers/api/v0/users_controller.rb index 882a46162..5328a63c3 100644 --- a/app/controllers/api/v0/users_controller.rb +++ b/app/controllers/api/v0/users_controller.rb @@ -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]) diff --git a/app/models/api/v0/serializers/tag.rb b/app/models/api/v0/serializers/tag.rb new file mode 100644 index 000000000..73ef055d8 --- /dev/null +++ b/app/models/api/v0/serializers/tag.rb @@ -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 diff --git a/app/models/api/v0/serializers/user.rb b/app/models/api/v0/serializers/user.rb index 7bbaa259d..2dc94fc07 100644 --- a/app/models/api/v0/serializers/user.rb +++ b/app/models/api/v0/serializers/user.rb @@ -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 diff --git a/lib/stream/tag.rb b/lib/stream/tag.rb index 312a3b58f..97d7a7936 100644 --- a/lib/stream/tag.rb +++ b/lib/stream/tag.rb @@ -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 diff --git a/spec/lib/stream/tag_spec.rb b/spec/lib/stream/tag_spec.rb index edc9d4e7e..3c12d55f0 100644 --- a/spec/lib/stream/tag_spec.rb +++ b/spec/lib/stream/tag_spec.rb @@ -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')