Newer
Older
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
danielgrippi
a validé
@status_message1 = Factory(:status_message, :text => '#bobby #flay #sux', :public => true, :updated_at => Time.now + 20)
danielgrippi
a validé
@status_message2 = Factory(:status_message, :text => '#aobby', :public => true, :created_at => Time.now + 10)
@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.profile.save
end
danielgrippi
a validé
@posts.map{|p| p['id']}.should == [@status_message2.guid, @status_message1.guid]
@posts.count.should == 2
end
it 'accepts an order paramater' do
danielgrippi
a validé
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
it 'does not allow arbitrary orders' do
get :public_timeline, :format => :json, :order => 'text'
@posts = JSON.parse(response.body)
@posts.map{|p| p['id']}.should == [@status_message2.guid, @status_message1.guid]
danielgrippi
a validé
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
get :public_timeline, :format => :json, :per_page=> 1
JSON.parse(response.body).count.should == 1
end
end
context 'protected timelines' do
let(:authenticate){
@controller.stub(:current_user).and_return(@user)
}
before do
@message1 = alice.post(:status_message, :text=> "hello", :to => alice.aspects.first)
@message2 = eve.post(:status_message, :text=> "hello", :to => eve.aspects.first)
end
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
describe '#home_timeline' do
it 'authenticates' do
get :home_timeline, :format => :json
response.code.should == '401'
end
it 'shows posts for alice' do
@user = alice
authenticate
get :home_timeline, :format => :json
p = JSON.parse(response.body)
p.length.should == 1
p[0]['id'].should == @message1.guid
end
it 'shows posts for eve' do
@user = eve
authenticate
get :home_timeline, :format => :json
p = JSON.parse(response.body)
p.length.should == 1
p[0]['id'].should == @message2.guid
end
it 'shows posts for bob' do
@user = bob
authenticate
get :home_timeline, :format => :json
p = JSON.parse(response.body)
p.length.should == 2
end
end
describe '#user_timeline' do
context 'unauthenticated' do
it 'shows public posts' do
get :user_timeline, :format => :json, :user_id => @status_message1.author.guid
posts = JSON.parse(response.body)
posts.first['id'].should == @status_message1.guid
posts.length.should == 1
it 'does not show non-public posts' do
danielgrippi
a validé
get :user_timeline, :format => :json, :user_id => alice.person.guid
posts = JSON.parse(response.body)
posts.should be_empty
end
end
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
context 'authenticated' do
context 'with bob logged in' do
before do
@user = bob
authenticate
end
it 'shows alice' do
get :user_timeline, :format => :json, :user_id => alice.person.guid
p = JSON.parse(response.body)
p.length.should == 1
p[0]['id'].should == @message1.guid
end
it 'shows eve' do
get :user_timeline, :format => :json, :user_id => eve.person.guid
p = JSON.parse(response.body)
p.length.should == 1
p[0]['id'].should == @message2.guid
end
it 'shows bob' do
get :user_timeline, :format => :json, :user_id => bob.person.guid
p = JSON.parse(response.body)
p.length.should == 0
end
context 'with alice logged in' do
before do
@user = alice
authenticate
end
it 'shows alice' do
get :user_timeline, :format => :json, :user_id => alice.person.guid
p = JSON.parse(response.body)
p.length.should == 1
p[0]['id'].should == @message1.guid
end
it 'shows eve' do
get :user_timeline, :format => :json, :user_id => eve.person.guid
p = JSON.parse(response.body)
p.length.should == 0
end
end
end
end
end
describe '#users_profile_image' do
it 'redirects on success' do
get :users_profile_image, :screen_name => bob.diaspora_handle, :format => :json
response.should redirect_to(bob.person.profile.image_url)
end
end
get :statuses, :guid => @status_message1.guid, :format => :json
p['id'].should == @status_message1.guid
p['text'].should == @status_message1.formatted_message(:plain_text => true)
p['entities'].class.should == Hash
p['source'].should == 'diaspora'
danielgrippi
a validé
p['user'].should == JSON.parse(@status_message1.author.to_json(:format => :twitter))
get :users, :user_id => alice.person.guid, :format => :json
p['id'].should == alice.person.guid
p['name'].should == alice.person.name
p['screen_name'].should == alice.person.diaspora_handle
p['profile_image_url'].should == alice.person.profile.image_url(:thumb_small)
p['created_at'].should_not be_nil
end
end
describe '#users_search' do
it 'searches' do
get :users_search, :q => @person.name, :format => :json
p = JSON.parse(response.body)
response.code.should == '200'
end
end
describe '#tag_posts' do
it 'succeeds' do
get :tag_posts, :tag => 'flay'
p = JSON.parse(response.body).first
danielgrippi
a validé
p['user']['id'].should == @status_message1.author.guid
end
end
describe '#tag_people' do
it 'succeeds' do
get :tag_people, :tag => 'zord'
p = JSON.parse(response.body).first
danielgrippi
a validé
p['id'].should == @person.guid