Don't get tags in the publisher

This commit is contained in:
Raphael Sofaer 2011-07-07 10:48:07 -07:00
parent 254d83b278
commit 8cf0fa8446
5 changed files with 28 additions and 9 deletions

View file

@ -111,7 +111,7 @@ class PeopleController < ApplicationController
respond_to do |format|
format.all { respond_with @person, :locals => {:post_type => :all} }
format.json {
render :json => @person.to_json
render :json => @person.to_json(:includes => params[:includes])
}
end
end

View file

@ -219,15 +219,17 @@ class Person < ActiveRecord::Base
self.posts.where(:type => "Photo").exists?
end
def as_json(opts={})
def as_json( opts = {} )
opts ||= {}
json = {
:id => self.id,
:name => self.name,
:avatar => self.profile.image_url(:thumb_medium),
:handle => self.diaspora_handle,
:url => "/people/#{self.id}",
:hashtags => self.profile.tags.map{|t| "##{t.name}"}
}
json.merge!(:tags => self.profile.tags.map{|t| "##{t.name}"}) if opts[:includes] == "tags"
json
end
protected

View file

@ -7,7 +7,7 @@
this.start = function() {
self.personCache = new this.Cache();
self.dropdownCache = new this.Cache();
var card = $("#hovercard");
self.hoverCard = {
tip: $("#hovercard_container"),
@ -52,7 +52,7 @@
self.hoverCard.tip.hide();
self.hoverCard.tip.prependTo(self.target.parent());
self.personCache.get(self.target.attr("href") + ".json", function(person) {
self.personCache.get(self.target.attr("href") + ".json?includes=tags", function(person) {
self.populateHovercard(person);
});
};
@ -70,7 +70,7 @@
self.hoverCard.dropdown.attr("data-person-id", person.id);
self.hoverCard.hashtags.html("");
$.each(person.hashtags, function(index, hashtag) {
$.each(person.tags, function(index, hashtag) {
self.hoverCard.hashtags.append(
$("<a/>", {
href: "/tags/" + hashtag.substring(1)

View file

@ -57,7 +57,7 @@ describe PeopleController do
get :index, :q => "eugene@example.org"
assigns[:people].should =~ [eugene2]
end
it "does not redirect to person page if there is exactly one match" do
get :index, :q => "Korth"
response.should_not redirect_to @korth
@ -169,6 +169,12 @@ describe PeopleController do
get :show, :id => @user.person.id
response.should be_success
end
it 'passes through the includes option for json requests' do
json = @user.person.as_json
Person.any_instance.should_receive(:as_json).with(:includes => "horses").and_return(json)
get :show, :format => :json, :id => @user.person.id, :includes => "horses"
end
end
context "with no user signed in" do

View file

@ -364,7 +364,18 @@ describe Person do
end
describe '#as_json' do
it 'returns a hash representation of a person'
it 'return tags if asked'
it 'returns a hash representation of a person' do
@person.as_json.should == {
:id => @person.id,
:name => @person.name,
:avatar => @person.profile.image_url(:thumb_medium),
:handle => @person.diaspora_handle,
:url => "/people/#{@person.id}",
}
end
it 'return tags if asked' do
@person.as_json(:includes => :tags).
should == @person.as_json.merge(:tags => @person.profile.tags.map{|t| "##{t.name}"})
end
end
end