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.
require 'spec_helper'
describe PhotosController do
Raphael Sofaer
a validé
@alices_photo = alice.post(:photo, :user_file => uploaded_photo, :to => alice.aspects.first.id)
@bobs_photo = bob.post(:photo, :user_file => uploaded_photo, :to => bob.aspects.first.id, :public => true)
Raphael Sofaer
a validé
@controller.stub!(:current_user).and_return(alice)
sign_in :user, alice
maxwell
a validé
request.env["HTTP_REFERER"] = ''
@controller.stub!(:file_handler).and_return(uploaded_photo)
@params = {:photo => {:user_file => uploaded_photo, :aspect_ids => "all"} }
post :create, @params
}.should change(Photo, :count).by(1)
end
it 'can set the photo as the profile photo' do
Raphael Sofaer
a validé
old_url = alice.person.profile.image_url
@params[:photo][:set_profile_photo] = true
post :create, @params
Raphael Sofaer
a validé
alice.reload.person.profile.image_url.should_not == old_url
Raphael Sofaer
a validé
get :index, :person_id => alice.person.id.to_s
assigns[:person].should == alice.person
Raphael Sofaer
a validé
get :index, :person_id => bob.person.id.to_s
assigns[:person].should == bob.person
context "user's own photo" do
before do
get :show, :id => @alices_photo.id
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @alices_photo
context "private photo user can see" do
before do
get :show, :id => @bobs_photo.id
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @bobs_photo
context "private photo user cannot see" do
before do
user3 = Factory(:user_with_aspect)
@photo = user3.post(:photo, :user_file => uploaded_photo, :to => user3.aspects.first.id)
end
it "redirects to the referrer" do
request.env["HTTP_REFERER"] = "http://google.com"
get :show, :id => @photo.to_param
response.should redirect_to("http://google.com")
end
it "redirects to the aspects page if there's no referrer" do
request.env.delete("HTTP_REFERER")
get :show, :id => @photo.to_param
response.should redirect_to(aspects_path)
end
end
context "public photo" do
before do
user3 = Factory(:user_with_aspect)
@photo = user3.post(:photo, :user_file => uploaded_photo, :to => user3.aspects.first.id, :public => true)
get :show, :id => @photo.to_param
end
it "succeeds" do
response.should be_success
end
it "assigns the photo" do
assigns[:photo].should == @photo
maxwell
a validé
end
it "succeeds when user owns the photo" do
get :edit, :id => @alices_photo.id
response.should be_success
it "redirects when the user does not own the photo" do
get :edit, :id => @bobs_photo.id
Raphael Sofaer
a validé
response.should redirect_to(:action => :index, :person_id => alice.person.id.to_s)
Raphael Sofaer
a validé
it 'let a user delete his message' do
delete :destroy, :id => @alices_photo.id
Photo.find_by_id(@alices_photo.id).should be_nil
Raphael Sofaer
a validé
it 'sends a retraction on delete' do
alice.should_receive(:retract).with(@alices_photo)
delete :destroy, :id => @alices_photo.id
end
it 'will not let you destroy posts visible to you' do
delete :destroy, :id => @bobs_photo.id
Photo.find_by_id(@bobs_photo.id).should be_true
Raphael Sofaer
a validé
it 'will not let you destory posts you do not own' do
eves_photo = eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
delete :destroy, :id => eves_photo.id
Photo.find_by_id(eves_photo.id).should be_true
end
it "updates the caption of a photo" do
put :update, :id => @alices_photo.id, :photo => { :text => "now with lasers!" }
@alices_photo.reload.text.should == "now with lasers!"
Michael Sofaer
a validé
it "doesn't overwrite random attributes" do
new_user = Factory.create(:user)
params = { :text => "now with lasers!", :author_id => new_user.id }
put :update, :id => @alices_photo.id, :photo => params
Raphael Sofaer
a validé
@alices_photo.reload.author_id.should == alice.person.id
it 'redirects if you do not have access to the post' do
params = { :text => "now with lasers!" }
put :update, :id => @bobs_photo.id, :photo => params
Raphael Sofaer
a validé
response.should redirect_to(:action => :index, :person_id => alice.person.id.to_s)
danielvincent
a validé
describe "#make_profile_photo" do
it 'should return a 201 on a js success' do
get :make_profile_photo, :photo_id => @alices_photo.id, :format => 'js'
danielvincent
a validé
response.code.should == "201"
end
MrZYX
a validé
it 'should return a 422 on failure' do
get :make_profile_photo, :photo_id => @bobs_photo.id
MrZYX
a validé
response.code.should == "422"
danielvincent
a validé
end
end
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
describe 'data helpers' do
describe '.object_aspect_ids' do
it 'on show, assigns object aspect ids' do
get :show, :id => @alices_photo.id
@controller.object_aspect_ids.should == [alice.aspects.first.id]
end
it 'on index, it is empty' do
get :index, :person_id => alice.person.id
@controller.object_aspect_ids.should == []
end
end
describe '.ownership' do
it 'is true if current user owns the photo' do
get :show, :id => @alices_photo.id
@controller.ownership.should be_true
end
it 'is true if current user owns the photo' do
get :show, :id => @bobs_photo.id
@controller.ownership.should be_false
end
end
describe 'parent' do
it 'grabs the status message of the photo if a parent exsists' do
sm = alice.post(:status_message, :text => 'yes', :to => alice.aspects.first)
@alices_photo.status_message = sm
@alices_photo.save
get :show, :id => @alices_photo.id
@controller.parent.id.should == sm.id
end
it 'uses the photo if no status_message exsists' do
get :show, :id => @alices_photo.id
@controller.parent.id.should == @alices_photo.id
end
end
describe '.photo' do
it 'returns a visible photo, based on the :id param' do
get :show, :id => @alices_photo.id
@controller.photo.id.should == @alices_photo.id
end
end
describe '.additonal_photos' do
it 'finds all of a parent status messages photos' do
sm = alice.post(:status_message, :text => 'yes', :to => alice.aspects.first)
@alices_photo.status_message = sm
@alices_photo.save
get :show, :id => @alices_photo.id
@controller.additional_photos.should include(@alices_photo)
end
end
describe '.next_photo' do
end
describe '.previous_photo' do
end
end
end