【发布时间】:2011-01-31 13:42:53
【问题描述】:
我有 2 个模拟回形针图像上传的黄瓜场景。一旦场景完成,我想再次删除这些文件夹。
我有以下附件文件夹结构: :url => "/system/:attachment/:listing_id/:id/:style_:filename"
Paperclip 会自动删除 :id/:style_:filename 文件夹,但不会删除父文件夹。
我的列表控制器中有以下内容(1 个列表有很多图像),当列表被删除时,它可以很好地删除带有列表 id 的图像文件夹。运行该步骤后,我需要在 Cucumber 中进行相同的模拟。
def destroy
@listing = Listing.find(params[:id])
# if destroy was a success, remove the listing image folder
if @listing.destroy
end
require 'fileutils'
dir = Rails.root + '/system/photos/' + @listing.id.to_s()
FileUtils.rm_rf(dir)
respond_to do |format|
format.html { redirect_to(listings_url) }
format.xml { head :ok }
end
end
我可以 a) 告诉 cucumber 在运行完场景后删除 :listing_id 文件夹名称,或者 b) 告诉 cucumber 作为最后一步删除列表?
我尝试将此添加到我的黄瓜 env.rb 文件中:
AfterStep('@paperclip') do
# This will only run before steps within scenarios tagged
# with @cucumis AND @sativus.
# delete folders that were created with paperclip during the test
require 'fileutils'
#@listing.id = 55
#dir = Rails.root + '/system/photos/' + @listing.id.to_s()
dir = Rails.root + '/system/photos/55' # NOT WORKING
FileUtils.rm_rf(dir)
end
但这会导致问题,因为 1) 我不知道如何从该场景中获取 @listing.id,并且 2) 即使我对其进行硬编码(如上所述)它也不会删除它。
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails cucumber paperclip