FIX: user avatar urls need to be absolute in wordpress api

This commit is contained in:
Neil Lalonde 2014-05-29 17:19:49 -04:00
parent d69472c9fb
commit e6841d0849
4 changed files with 31 additions and 4 deletions

View File

@ -0,0 +1,14 @@
# The most basic attributes of a topic that we need to create a link for it.
class PostWordpressSerializer < BasicPostSerializer
include UrlHelper
def avatar_template
if object.user
absolute object.user.avatar_template
else
nil
end
end
end

View File

@ -6,8 +6,8 @@ class TopicViewWordpressSerializer < ApplicationSerializer
:filtered_posts_count, :filtered_posts_count,
:posts :posts
has_many :participants, serializer: BasicUserSerializer, embed: :objects has_many :participants, serializer: UserWordpressSerializer, embed: :objects
has_many :posts, serializer: BasicPostSerializer, embed: :objects has_many :posts, serializer: PostWordpressSerializer, embed: :objects
def id def id
object.topic.id object.topic.id

View File

@ -0,0 +1,13 @@
class UserWordpressSerializer < BasicUserSerializer
include UrlHelper
def avatar_template
if Hash === object
absolute User.avatar_template(user[:username], user[:uploaded_avatar_id])
else
absolute object.avatar_template
end
end
end

View File

@ -24,7 +24,7 @@ describe TopicsController do
post = json['posts'][0] post = json['posts'][0]
post['id'].should == p2.id post['id'].should == p2.id
post['username'].should == user.username post['username'].should == user.username
post['avatar_template'].should == user.avatar_template post['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}"
post['name'].should == user.name post['name'].should == user.name
post['created_at'].should be_present post['created_at'].should be_present
post['cooked'].should == p2.cooked post['cooked'].should == p2.cooked
@ -34,7 +34,7 @@ describe TopicsController do
participant = json['participants'][0] participant = json['participants'][0]
participant['id'].should == user.id participant['id'].should == user.id
participant['username'].should == user.username participant['username'].should == user.username
participant['avatar_template'].should == user.avatar_template participant['avatar_template'].should == "#{Discourse.base_url_no_prefix}#{user.avatar_template}"
end end
end end