私は誰かがオブジェクトを削除できるかどうかのパーミッションをチェックするためにbefore_filterを設定しようとしています。Ruby on Rails:2.3.8、カスタムフィルタが動作しない前に?
before_filter :test_hack, :only => :destroy
def test_hack
return false
end
ここに破棄方法::しかし、それは働いていません...最終的に私は、次の手順を実行し
def destroy
@content = Content.find(params[:id])
#will get rid of this when the before filter works...
# but this doesn't stop it from getting deleted either
if not has_permission_to_change?(@content)
puts "This content is not gonig to get deleted"
flash[:error] = 'You do not have permission to delete this content.'
else
@content.destroy
end
失敗テスト:アカウントbelongs_toの
should "not allow the deleting of #{plural_name} on different accounts" do
login_as(@user)
p = Factory(factory_name, :account => Factory(:account))
assert_difference("#{klass}.count", 0) do
begin
delete :destroy, :id => p.id
raise "program flow should not reach this message"
rescue ActiveRecord::RecordNotFound
assert true
end
end
コンテンツ
コンソール出力:
あなたのテストでLoaded suite test/functional/contents_controller_test
Started
This content is not gonig to get deleted
E
Finished in 0.649422 seconds.
1) Error:
test: destroy contents! should not allow the deleting of contents on different accounts. (ContentsControllerTest):
RuntimeError: program flow should not reach this message
便利です私は見an't誰かがあなたの他の質問に答えました:http://stackoverflow.com/questions/6683113/ruby-on-rails-2-3-8-freaking-destroy-behavior-ignores-before-filter – ryeguy
@ryeguy:ありがとう、私はやった;) – apneadiving