added controller test; put wallpaper into separate wallpaper/ directory

This commit is contained in:
danielgrippi 2012-05-06 12:34:45 -07:00
parent 46d4a957fe
commit 92230383a7
3 changed files with 70 additions and 40 deletions

View file

@ -78,6 +78,13 @@ class ProfilesController < ApplicationController
end end
def upload_wallpaper_image def upload_wallpaper_image
unless params[:photo].present?
respond_to do |format|
format.json { render :json => {"success" => false} }
end
return
end
if remotipart_submitted? if remotipart_submitted?
profile = current_user.person.profile profile = current_user.person.profile
@ -86,6 +93,10 @@ class ProfilesController < ApplicationController
respond_to do |format| respond_to do |format|
format.json { render :json => {"success" => true, "data" => {"wallpaper" => profile.wallpaper.url}} } format.json { render :json => {"success" => true, "data" => {"wallpaper" => profile.wallpaper.url}} }
end end
else
respond_to do |format|
format.json { render :json => {"success" => false} }
end
end end
end end
end end

View file

@ -2,7 +2,7 @@ class WallpaperUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick include CarrierWave::MiniMagick
def store_dir def store_dir
"uploads/images" "uploads/images/wallpaper"
end end
def extension_white_list def extension_white_list

View file

@ -6,37 +6,36 @@ require 'spec_helper'
describe ProfilesController do describe ProfilesController do
before do before do
@user = eve sign_in :user, eve
sign_in :user, @user
end end
describe '#show' do describe '#show' do
it "returns the user as json" do it "returns the user as json" do
get :show, :id => @user.person.guid, :format => :json get :show, :id => eve.person.guid, :format => :json
JSON.parse(response.body).should include(JSON.parse(@user.person.as_api_response(:backbone).to_json)) JSON.parse(response.body).should include(JSON.parse(eve.person.as_api_response(:backbone).to_json))
end end
it "returns the user's public information if a user is not logged in" do it "returns the user's public information if a user is not logged in" do
sign_out :user sign_out :user
get :show, :id => @user.person.guid, :format => :json get :show, :id => eve.person.guid, :format => :json
JSON.parse(response.body).should include(JSON.parse(@user.person.as_api_response(:backbone).to_json)) JSON.parse(response.body).should include(JSON.parse(eve.person.as_api_response(:backbone).to_json))
end end
it "returns the user's public information if a user is logged in and the visiting user is not receiving" do it "returns the user's public information if a user is logged in and the visiting user is not receiving" do
sign_in :user, alice sign_in :user, alice
get :show, :id => @user.person.guid, :format => :json get :show, :id => eve.person.guid, :format => :json
response.body.should_not match(/.location./) response.body.should_not match(/.location./)
end end
it "returns the user's private information if a user is logged in and the visiting user is receiving" do it "returns the user's private information if a user is logged in and the visiting user is receiving" do
sign_in :user, bob sign_in :user, bob
get :show, :id => @user.person.guid, :format => :json get :show, :id => eve.person.guid, :format => :json
response.body.should match(/.location./) response.body.should match(/.location./)
end end
it "returns the user's private information if a user is logged in as herself" do it "returns the user's private information if a user is logged in as herself" do
sign_in :user, eve sign_in :user, eve
get :show, :id => @user.person.guid, :format => :json get :show, :id => eve.person.guid, :format => :json
response.body.should match(/.location./) response.body.should match(/.location./)
end end
end end
@ -49,7 +48,7 @@ describe ProfilesController do
it 'sets the profile to the current users profile' do it 'sets the profile to the current users profile' do
get :edit get :edit
assigns[:profile].should == @user.person.profile assigns[:profile].should == eve.person.profile
end end
it 'sets the aspect to "person_edit" ' do it 'sets the aspect to "person_edit" ' do
@ -59,7 +58,7 @@ describe ProfilesController do
it 'sets the person to the current users person' do it 'sets the person to the current users person' do
get :edit get :edit
assigns[:person].should == @user.person assigns[:person].should == eve.person
end end
end end
@ -74,48 +73,48 @@ describe ProfilesController do
end end
it "sets nsfw" do it "sets nsfw" do
@user.person(true).profile.nsfw.should == false eve.person(true).profile.nsfw.should == false
put :update, :profile => { :id => @user.person.id, :nsfw => "1" } put :update, :profile => { :id => eve.person.id, :nsfw => "1" }
@user.person(true).profile.nsfw.should == true eve.person(true).profile.nsfw.should == true
end end
it "unsets nsfw" do it "unsets nsfw" do
@user.person.profile.nsfw = true eve.person.profile.nsfw = true
@user.person.profile.save eve.person.profile.save
@user.person(true).profile.nsfw.should == true eve.person(true).profile.nsfw.should == true
put :update, :profile => { :id => @user.person.id } put :update, :profile => { :id => eve.person.id }
@user.person(true).profile.nsfw.should == false eve.person(true).profile.nsfw.should == false
end end
it 'sets tags' do it 'sets tags' do
params = { :id => @user.person.id, params = { :id => eve.person.id,
:tags => '#apples #oranges'} :tags => '#apples #oranges'}
put :update, params put :update, params
@user.person(true).profile.tag_list.to_set.should == ['apples', 'oranges'].to_set eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges'].to_set
end end
it 'sets plaintext tags' do it 'sets plaintext tags' do
params = { :id => @user.person.id, params = { :id => eve.person.id,
:tags => ',#apples,#oranges,', :tags => ',#apples,#oranges,',
:profile => {:tag_string => '#pears'} } :profile => {:tag_string => '#pears'} }
put :update, params put :update, params
@user.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'pears'].to_set eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'pears'].to_set
end end
it 'sets plaintext tags without #' do it 'sets plaintext tags without #' do
params = { :id => @user.person.id, params = { :id => eve.person.id,
:tags => ',#apples,#oranges,', :tags => ',#apples,#oranges,',
:profile => {:tag_string => 'bananas'} } :profile => {:tag_string => 'bananas'} }
put :update, params put :update, params
@user.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'bananas'].to_set eve.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'bananas'].to_set
end end
it 'sets valid birthday' do it 'sets valid birthday' do
params = { :id => @user.person.id, params = { :id => eve.person.id,
:profile => { :profile => {
:date => { :date => {
:year => '2001', :year => '2001',
@ -123,13 +122,13 @@ describe ProfilesController do
:day => '28' } } } :day => '28' } } }
put :update, params put :update, params
@user.person(true).profile.birthday.year.should == 2001 eve.person(true).profile.birthday.year.should == 2001
@user.person(true).profile.birthday.month.should == 2 eve.person(true).profile.birthday.month.should == 2
@user.person(true).profile.birthday.day.should == 28 eve.person(true).profile.birthday.day.should == 28
end end
it 'displays error for invalid birthday' do it 'displays error for invalid birthday' do
params = { :id => @user.person.id, params = { :id => eve.person.id,
:profile => { :profile => {
:date => { :date => {
:year => '2001', :year => '2001',
@ -142,21 +141,21 @@ describe ProfilesController do
context 'with a profile photo set' do context 'with a profile photo set' do
before do before do
@params = { :id => @user.person.id, @params = { :id => eve.person.id,
:profile => :profile =>
{:image_url => "", {:image_url => "",
:last_name => @user.person.profile.last_name, :last_name => eve.person.profile.last_name,
:first_name => @user.person.profile.first_name }} :first_name => eve.person.profile.first_name }}
@user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" eve.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg"
@user.person.profile.save eve.person.profile.save
end end
it "doesn't overwrite the profile photo when an empty string is passed in" do it "doesn't overwrite the profile photo when an empty string is passed in" do
image_url = @user.person.profile.image_url image_url = eve.person.profile.image_url
put :update, @params put :update, @params
Person.find(@user.person.id).profile.image_url.should == image_url Person.find(eve.person.id).profile.image_url.should == image_url
end end
end end
@ -168,7 +167,7 @@ describe ProfilesController do
end end
it 'person_id' do it 'person_id' do
person = @user.person person = eve.person
profile = person.profile profile = person.profile
put :update, @profile_params put :update, @profile_params
profile.reload.person_id.should == person.id profile.reload.person_id.should == person.id
@ -176,8 +175,28 @@ describe ProfilesController do
it 'diaspora handle' do it 'diaspora handle' do
put :update, @profile_params put :update, @profile_params
Person.find(@user.person.id).profile[:diaspora_handle].should_not == 'abc@a.com' Person.find(eve.person.id).profile[:diaspora_handle].should_not == 'abc@a.com'
end end
end end
end end
describe '#upload_wallpaper_image' do
it 'returns a success=false response if the photo param is not present' do
post :upload_wallpaper_image, :format => :json
JSON.parse(response.body).should include("success" => false)
end
it 'stores the wallpaper for the current_user' do
# we should have another test here asserting that the wallpaper is set... i was having problems testing
# this behavior though :(
@controller.stub!(:current_user).and_return(eve)
@controller.stub!(:remotipart_submitted?).and_return(true)
@controller.stub!(:file_handler).and_return(uploaded_photo)
@params = {:photo => {:user_file => uploaded_photo} }
eve.person.profile.wallpaper.should_receive(:store!)
post :upload_wallpaper_image, @params.merge(:format => :json)
end
end
end end