callbacks not running on photo save

This commit is contained in:
Raphael 2010-07-17 14:09:21 -07:00
parent 40435d6891
commit 7d7c39e3dc
5 changed files with 50 additions and 25 deletions

View file

@ -1,6 +1,8 @@
class Photo < Post
require 'carrierwave/orm/mongomapper'
include MongoMapper::Document
before_validation {puts "I'M GONNA VALIDATE"}
before_save {puts "I'M GONNA SAVE"}
before_create {puts "I'M GONNA CREATE"}
mount_uploader :image, ImageUploader
end

View file

@ -3,6 +3,7 @@
""
end
def verify_creator_signature
#creator_signature = sign if creator_signature.nil? && person == User.owner
verify_signature(creator_signature, person)
end
@ -10,21 +11,24 @@
return false unless signature && person.key_fingerprint
validity = nil
GPGME::verify(signature, signable_string,
{:armor => true, :always_trust => true}){ |sig|
validity = sig.status == GPGME::GPG_ERR_NO_ERROR &&
sig.fpr == person.key_fingerprint
{:armor => true, :always_trust => true}){ |signature_analysis|
puts signature_analysis
validity = signature_analysis.status == GPGME::GPG_ERR_NO_ERROR &&
signature_analysis.fpr == person.key_fingerprint
}
return validity
end
protected
def sign_if_mine
puts "In sign_if_mine"
if self.person == User.owner
self.creator_signature = sign
end
end
def sign
puts "signing"
sign_with_key(User.owner.key)
end

View file

@ -3,20 +3,38 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe Photo do
before do
@user = Factory.create(:user)
@fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
end
it 'should save a photo to GridFS' do
photo = Photo.new(:person => @user)
fixture_name = File.dirname(__FILE__) + '/../fixtures/bp.jpeg'
file = File.open(fixture_name)
file = File.open(@fixture_name)
photo.image = file
photo.save.should == true
binary = photo.image.read
fixture_binary = File.open(fixture_name).read
fixture_binary = File.open(@fixture_name).read
binary.should == fixture_binary
end
it 'should create thumbnails' do
pending('need to figure this out... tearing issue')
end
describe 'with encryption' do
before do
unstub_mocha_stubs
end
after do
stub_signature_verification
end
it 'should save a signed photo to GridFS' do
photo = Photo.new(:person => @user)
photo.image = File.open(@fixture_name)
#photo.creator_signature = photo.send(:sign)
photo.verify_creator_signature.should be true
photo.save.should == true
end
end
end

View file

@ -42,29 +42,30 @@ end
end
def stub_signature_verification
post_models = []
get_models.each{ |model|
puts model
constant_model = model.camelize.constantize
if constant_model == Post || constant_model.superclass == Post
post_models << constant_model
end
}
post_models.each{ | model|
model.any_instance.stubs(:verify_creator_signature).returns(true)
}
Post.any_instance.stubs(:verify_creator_signature).returns(true)
StatusMessage.any_instance.stubs(:verify_creator_signature).returns(true)
Blog.any_instance.stubs(:verify_creator_signature).returns(true)
Bookmark.any_instance.stubs(:verify_creator_signature).returns(true)
Comment.any_instance.stubs(:verify_creator_signature).returns(true)
Comment.any_instance.stubs(:verify_post_creator_signature).returns(true)
Photo.any_instance.stubs(:verify_creator_signature).returns(true)
Person.any_instance.stubs(:remove_key).returns(true)
User.any_instance.stubs(:remove_key).returns(true)
end
def unstub_mocha_stubs
Mocha::Mockery.instance.stubba.unstub_all
end
def get_models
models = []
Dir.glob( RAILS_ROOT + '/app/models/*' ).each do |f|
Dir.glob( File.dirname(__FILE__) + '/../app/models/*' ).each do |f|
models << File.basename( f ).gsub( /^(.+).rb/, '\1')
end
models