Skip to content
Extraits de code Groupes Projets
Valider 8cf0fa84 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Don't get tags in the publisher

parent 254d83b2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter