Make pending specs green, I think there are still some to_jsons where there should be as_json
This commit is contained in:
parent
5dbbc79f65
commit
c0ce0d71b8
5 changed files with 42 additions and 51 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
class ApisController < ApplicationController
|
class ApisController < ApplicationController #We should start with this versioned, V0ApisController BEES
|
||||||
before_filter :authenticate_user!, :only => [:home_timeline, :user_timeline]
|
before_filter :authenticate_user!, :only => [:home_timeline, :user_timeline]
|
||||||
respond_to :json
|
respond_to :json
|
||||||
|
|
||||||
|
|
@ -11,19 +11,18 @@ class ApisController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_timeline
|
def user_timeline #No public timeline for a user? - R
|
||||||
set_defaults
|
set_defaults
|
||||||
|
|
||||||
person_id = params[:user_id] || current_user.person.id
|
person_id = params[:user_id] || current_user.person.guid # I wouldn't put implicit params in anything meant to be programatically accessed - R
|
||||||
|
|
||||||
if person = Person.find(person_id)
|
if person = Person.where(:guid => person_id).first
|
||||||
timeline = current_user.posts_from(person)
|
timeline = current_user.posts_from(person)
|
||||||
|
respond_with timeline do |format|
|
||||||
|
format.json{ render :json => timeline.to_json(:format => :twitter) }
|
||||||
|
end
|
||||||
else
|
else
|
||||||
timeline = []
|
render :json => {:status => 'failed', :reason => 'user not found'}, :status => 404
|
||||||
end
|
|
||||||
|
|
||||||
respond_with timeline do |format|
|
|
||||||
format.json{ render :json => timeline.to_json(:format => :twitter) }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -54,7 +53,7 @@ class ApisController < ApplicationController
|
||||||
#people
|
#people
|
||||||
def users
|
def users
|
||||||
if params[:user_id]
|
if params[:user_id]
|
||||||
person = Person.where(:id => params[:user_id]).first
|
person = Person.where(:guid => params[:user_id]).first
|
||||||
elsif params[:screen_name]
|
elsif params[:screen_name]
|
||||||
person = Person.where(:diaspora_handle => params[:screen_name]).first
|
person = Person.where(:diaspora_handle => params[:screen_name]).first
|
||||||
end
|
end
|
||||||
|
|
@ -98,20 +97,20 @@ class ApisController < ApplicationController
|
||||||
posts = StatusMessage.where(:public => true, :pending => false)
|
posts = StatusMessage.where(:public => true, :pending => false)
|
||||||
posts = posts.tagged_with(params[:tag])
|
posts = posts.tagged_with(params[:tag])
|
||||||
posts = posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
|
posts = posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
|
||||||
render :json => posts.as_json
|
render :json => posts.as_json(:format => :twitter)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_people
|
def tag_people
|
||||||
set_defaults
|
set_defaults
|
||||||
profiles = Profile.tagged_with(params[:tag]).where(:searchable => true).select('profiles.id, profiles.person_id')
|
profiles = Profile.tagged_with(params[:tag]).where(:searchable => true).select('profiles.id, profiles.person_id')
|
||||||
people = Person.where(:id => profiles.map{|p| p.person_id}).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
|
people = Person.where(:id => profiles.map{|p| p.person_id}).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
|
||||||
render :json => people.as_json
|
render :json => people.as_json(:format => :twitter)
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def set_defaults
|
def set_defaults
|
||||||
params[:per_page] ||= 20
|
params[:per_page] ||= 20
|
||||||
params[:order] ||= 'created_at'
|
params[:order] = 'created_at' unless ['created_at', 'updated_at'].include?(params[:order])
|
||||||
params[:page] ||= 1
|
params[:page] ||= 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -189,11 +189,12 @@ class Person < ActiveRecord::Base
|
||||||
opts ||= {}
|
opts ||= {}
|
||||||
if(opts[:format] == :twitter)
|
if(opts[:format] == :twitter)
|
||||||
{
|
{
|
||||||
:id => self.id,
|
:id => self.guid,
|
||||||
:screen_name => self.diaspora_handle,
|
:screen_name => self.diaspora_handle,
|
||||||
:name => self.name,
|
:name => self.name,
|
||||||
:created_at => self.created_at,
|
:created_at => self.created_at,
|
||||||
:profile_image_url => self.profile.image_url(:thumb_small)
|
:profile_image_url => self.profile.image_url(:thumb_small),
|
||||||
|
:profile => self.profile.as_json(opts)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
super(:include => [:profile], :except => [:mongo_id, :owner_id, :serialized_public_key])
|
super(:include => [:profile], :except => [:mongo_id, :owner_id, :serialized_public_key])
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ class Post < ActiveRecord::Base
|
||||||
def as_json(opts={})
|
def as_json(opts={})
|
||||||
{
|
{
|
||||||
:post => {
|
:post => {
|
||||||
:id => self.id,
|
:id => self.guid,
|
||||||
:author => self.author.as_json,
|
:author => self.author.as_json,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,17 +96,6 @@ class StatusMessage < Post
|
||||||
identifiers.empty? ? [] : Person.where(:diaspora_handle => identifiers)
|
identifiers.empty? ? [] : Person.where(:diaspora_handle => identifiers)
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(opts={})
|
|
||||||
{:guid => self.guid,
|
|
||||||
:id => self.id,
|
|
||||||
:author => self.author.as_json,
|
|
||||||
:photos => self.photos.as_json,
|
|
||||||
:created_at => self.created_at,
|
|
||||||
:updated_at => self.updated_at,
|
|
||||||
:raw_message => self.raw_message,
|
|
||||||
:text => self.text, }
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_activity
|
def to_activity
|
||||||
<<-XML
|
<<-XML
|
||||||
<entry>
|
<entry>
|
||||||
|
|
@ -135,7 +124,7 @@ class StatusMessage < Post
|
||||||
},
|
},
|
||||||
:source => 'diaspora',
|
:source => 'diaspora',
|
||||||
:created_at => self.created_at,
|
:created_at => self.created_at,
|
||||||
:user => self.author.to_json(opts)
|
:user => self.author.as_json(opts)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
super(opts)
|
super(opts)
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,11 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
class ApisController
|
|
||||||
include ActionController::UrlFor
|
|
||||||
include ActionController::Testing
|
|
||||||
include Rails.application.routes.url_helpers
|
|
||||||
include ActionController::Compatibility
|
|
||||||
end
|
|
||||||
|
|
||||||
describe ApisController do
|
describe ApisController do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@status_message1 = Factory(:status_message, :text => '#bobby #flay #sux', :public => true)
|
@status_message1 = Factory(:status_message, :text => '#bobby #flay #sux', :public => true, :updated_at => Time.now + 20)
|
||||||
|
|
||||||
@status_message2 = Factory(:status_message, :public => true)
|
@status_message2 = Factory(:status_message, :text => '#aobby', :public => true, :created_at => Time.now + 10)
|
||||||
@status_message3 = Factory(:status_message)
|
@status_message3 = Factory(:status_message, :created_at => Time.now + 15)
|
||||||
@person = Factory(:person, :profile => Factory.build(:profile,:first_name => 'bobby', :searchable => true, :tag_string => '#zord'))
|
@person = Factory(:person, :profile => Factory.build(:profile,:first_name => 'bobby', :searchable => true, :tag_string => '#zord'))
|
||||||
@person.profile.save
|
@person.profile.save
|
||||||
end
|
end
|
||||||
|
|
@ -21,15 +14,25 @@ describe ApisController do
|
||||||
it 'returns all of the public posts' do
|
it 'returns all of the public posts' do
|
||||||
get :public_timeline, :format => :json
|
get :public_timeline, :format => :json
|
||||||
@posts = JSON.parse(response.body)
|
@posts = JSON.parse(response.body)
|
||||||
|
@posts.map{|p| p['id']}.should == [@status_message2.guid, @status_message1.guid]
|
||||||
@posts.count.should == 2
|
@posts.count.should == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accepts an order paramater' do
|
it 'accepts an order paramater' do
|
||||||
pending
|
get :public_timeline, :format => :json, :order => 'updated_at'
|
||||||
|
@posts = JSON.parse(response.body)
|
||||||
|
@posts.map{|p| p['id']}.should == [@status_message1.guid, @status_message2.guid]
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accpets a page paramater' do
|
it 'does not allow arbitrary orders' do
|
||||||
pending
|
get :public_timeline, :format => :json, :order => 'text'
|
||||||
|
@posts = JSON.parse(response.body)
|
||||||
|
@posts.map{|p| p['id']}.should == [@status_message2.guid, @status_message1.guid]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'accepts a page paramater' do
|
||||||
|
get :public_timeline, :format => :json, :per_page=> 1, :page => 2
|
||||||
|
JSON.parse(response.body).first['id'].should == @status_message1.guid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'accepts a per_page param' do
|
it 'accepts a per_page param' do
|
||||||
|
|
@ -101,7 +104,7 @@ describe ApisController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows alice' do
|
it 'shows alice' do
|
||||||
get :user_timeline, :format => :json, :user_id => alice.person.id
|
get :user_timeline, :format => :json, :user_id => alice.person.guid
|
||||||
p = JSON.parse(response.body)
|
p = JSON.parse(response.body)
|
||||||
|
|
||||||
p.length.should == 1
|
p.length.should == 1
|
||||||
|
|
@ -109,7 +112,7 @@ describe ApisController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows eve' do
|
it 'shows eve' do
|
||||||
get :user_timeline, :format => :json, :user_id => eve.person.id
|
get :user_timeline, :format => :json, :user_id => eve.person.guid
|
||||||
p = JSON.parse(response.body)
|
p = JSON.parse(response.body)
|
||||||
|
|
||||||
p.length.should == 1
|
p.length.should == 1
|
||||||
|
|
@ -130,7 +133,7 @@ describe ApisController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows alice' do
|
it 'shows alice' do
|
||||||
get :user_timeline, :format => :json, :user_id => alice.person.id
|
get :user_timeline, :format => :json, :user_id => alice.person.guid
|
||||||
p = JSON.parse(response.body)
|
p = JSON.parse(response.body)
|
||||||
|
|
||||||
p.length.should == 1
|
p.length.should == 1
|
||||||
|
|
@ -138,7 +141,7 @@ describe ApisController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'shows eve' do
|
it 'shows eve' do
|
||||||
get :user_timeline, :format => :json, :user_id => eve.person.id
|
get :user_timeline, :format => :json, :user_id => eve.person.guid
|
||||||
p = JSON.parse(response.body)
|
p = JSON.parse(response.body)
|
||||||
p.length.should == 0
|
p.length.should == 0
|
||||||
end
|
end
|
||||||
|
|
@ -161,7 +164,7 @@ describe ApisController do
|
||||||
p['text'].should == @status_message1.formatted_message(:plain_text => true)
|
p['text'].should == @status_message1.formatted_message(:plain_text => true)
|
||||||
p['entities'].class.should == Hash
|
p['entities'].class.should == Hash
|
||||||
p['source'].should == 'diaspora'
|
p['source'].should == 'diaspora'
|
||||||
p['user'].should == @status_message1.author.to_json(:format => :twitter)
|
p['user'].should == JSON.parse(@status_message1.author.to_json(:format => :twitter))
|
||||||
p['created_at'].should_not be_nil
|
p['created_at'].should_not be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -173,9 +176,9 @@ describe ApisController do
|
||||||
|
|
||||||
describe '#users' do
|
describe '#users' do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
get :users, :user_id => @person.id, :format => :json
|
get :users, :user_id => @person.guid, :format => :json
|
||||||
p = JSON.parse(response.body)
|
p = JSON.parse(response.body)
|
||||||
p['id'].should == @person.id
|
p['id'].should == @person.guid
|
||||||
p['name'].should == @person.name
|
p['name'].should == @person.name
|
||||||
p['screen_name'].should == @person.diaspora_handle
|
p['screen_name'].should == @person.diaspora_handle
|
||||||
p['profile_image_url'].should == @person.profile.image_url(:thumb_small)
|
p['profile_image_url'].should == @person.profile.image_url(:thumb_small)
|
||||||
|
|
@ -193,19 +196,18 @@ describe ApisController do
|
||||||
|
|
||||||
describe '#tag_posts' do
|
describe '#tag_posts' do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
pending
|
|
||||||
get :tag_posts, :tag => 'flay'
|
get :tag_posts, :tag => 'flay'
|
||||||
p = JSON.parse(response.body).first
|
p = JSON.parse(response.body).first
|
||||||
p['id'].should == @status_message1.guid
|
p['id'].should == @status_message1.guid
|
||||||
|
p['user']['id'].should == @status_message1.author.guid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#tag_people' do
|
describe '#tag_people' do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
pending
|
|
||||||
get :tag_people, :tag => 'zord'
|
get :tag_people, :tag => 'zord'
|
||||||
p = JSON.parse(response.body).first
|
p = JSON.parse(response.body).first
|
||||||
p['person']['id'].should == @person.id
|
p['id'].should == @person.guid
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue