Added photo file validation spec
This commit is contained in:
parent
de3a08d031
commit
d8cbbcf6c8
2 changed files with 25 additions and 18 deletions
|
|
@ -8,7 +8,6 @@ class PhotosController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@photo = Photo.new(params[:photo])
|
@photo = Photo.new(params[:photo])
|
||||||
@photo.person = current_user
|
@photo.person = current_user
|
||||||
|
|
||||||
if @photo.save
|
if @photo.save
|
||||||
flash[:notice] = "Successfully uploaded photo."
|
flash[:notice] = "Successfully uploaded photo."
|
||||||
redirect_to photos_url
|
redirect_to photos_url
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,34 @@ describe Photo do
|
||||||
@user = Factory.create(:user)
|
@user = Factory.create(:user)
|
||||||
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
|
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
|
||||||
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml'
|
@fail_fixture_name = File.dirname(__FILE__) + '/../fixtures/msg.xml'
|
||||||
|
@photo = Photo.new(:person => @user)
|
||||||
end
|
end
|
||||||
it 'should save a photo to GridFS' do
|
it 'should save a @photo to GridFS' do
|
||||||
photo = Photo.new(:person => @user)
|
|
||||||
file = File.open(@fixture_name)
|
file = File.open(@fixture_name)
|
||||||
photo.image = file
|
@photo.image = file
|
||||||
photo.save.should == true
|
@photo.save.should == true
|
||||||
binary = photo.image.read
|
binary = @photo.image.read
|
||||||
fixture_binary = File.open(@fixture_name).read
|
fixture_binary = File.open(@fixture_name).read
|
||||||
binary.should == fixture_binary
|
binary.should == fixture_binary
|
||||||
end
|
end
|
||||||
|
describe 'non-image files' do
|
||||||
|
it 'should not store' do
|
||||||
|
file = File.open(@fail_fixture_name)
|
||||||
|
@photo.image.should_receive(:check_whitelist!)
|
||||||
|
lambda {
|
||||||
|
@photo.image.store! file
|
||||||
|
}.should raise_error
|
||||||
|
end
|
||||||
|
|
||||||
it 'should not accept files of non-image types' do
|
it 'should not save' do
|
||||||
photo = Photo.new(:person => @user)
|
pending "We need to figure out the difference between us and the example app"
|
||||||
file = File.open(@fail_fixture_name)
|
file = File.open(@fail_fixture_name)
|
||||||
photo.image = file
|
@photo.image.should_receive(:check_whitelist!)
|
||||||
photo.save.should == false
|
@photo.image = file
|
||||||
|
@photo.save.should == false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'with encryption' do
|
describe 'with encryption' do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
@ -34,11 +43,10 @@ describe Photo do
|
||||||
stub_signature_verification
|
stub_signature_verification
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should save a signed photo to GridFS' do
|
it 'should save a signed @photo to GridFS' do
|
||||||
photo = Photo.new(:person => @user)
|
@photo.image = File.open(@fixture_name)
|
||||||
photo.image = File.open(@fixture_name)
|
@photo.save.should == true
|
||||||
photo.save.should == true
|
@photo.verify_creator_signature.should be true
|
||||||
photo.verify_creator_signature.should be true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue