I have 2 cucumber scenarios that simulate paperclip image upload. I want to remove those folders again once scenarios are complete.
I have the following attachment folder structure: :url => "/system/:attachment/:listing_id/:id/:style_:filename"
Paperclip automatically deletes the :id/:style_:filename folder but not the parent folder.
I have a the following in my listings controller (1 listing has many images) which works great to remove the image folder with the listing id when the listing is deleted. I need to simulate the same in Cucumber after the step is run.
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
I could a) tell cucumber to delete the :listing_id folder name after running through the scenario or b) tell cucumber to delete the listing as the final step?
I've tried adding this to my cucumber env.rb file:
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
But that causes problems because 1) I don't know how to get the @listing.id from that scenario, and 2) even when I hardcode it (as above) it doesn't remove it.
Any thoughts?