私は次のモデルを使用しました。保存と更新に関するメソッドを実行したいのですが、フックが更新時に実行されていないという問題があります。更新フックがdm 1.0.2のDataMapperモデルで呼び出されない前に
it 'should call encrypt_password! on update' do
subject.save.should be_true
subject.should_receive(:encrypt_password!)
subject.update(:password => 'other-password', :password_confirmation => 'other-password').should be_true
end
をそして、これは渡します:
class User
include DataMapper::Resource
include BCrypt
property :id, Serial
property :email, String, :index => true
property :crypted_password, String, :accessor => :private
...
attr_accessor :password, :password_confirmation
before :save, :encrypt_password!
# also tried the following with no success:
# before :update, :encrypt_password!
# and tried this but hell was never raised
# before :update do
# raise 'hell'
# end
def encrypt_password!
self.crypted_password = Password.create password
end
end
このスペックは失敗していない成功を収めて保存します。後に加えてアップデート:私も後で試してみた
it 'should call encrypt_password! on create' do
subject.should_receive(:encrypt_password!)
subject.save.should be_true
end
。
何か不足していますか?