I am using paperclip-dropbox gem to store my assets. I want to create a test to ensure assets are properly destroyed if the destroy checkbox is checked. I can see on dropbox the image is uploaded and deleted but just after it's created again. Don't understand why.
Here is my test file:
require 'test_helper'
#
# == Admin namespace
#
module Admin
#
# == SettingsController test
#
class SettingsControllerTest < ActionController::TestCase
include Devise::TestHelpers
setup :initialize_test
#
# == Avatar
#
test 'should be able to upload logo' do
upload_dropbox_paperclip_attachment
setting = assigns(:setting)
assert setting.logo?
assert_equal 'bart.png', setting.logo_file_name
assert_equal 'image/png', setting.logo_content_type
end
test 'should be able to destroy logo' do
upload_dropbox_paperclip_attachment
remove_dropbox_paperclip_attachment
end
private
def initialize_test
@setting = settings(:one)
@administrator = users(:bob)
sign_in @administrator
end
def upload_dropbox_paperclip_attachment
puts '=== Uploading logo to Dropbox'
attachment = fixture_file_upload 'images/bart.png', 'image/png'
patch :update, id: @setting, setting: { logo: attachment }
end
def remove_dropbox_paperclip_attachment
puts '=== Removing logo from Dropbox'
patch :update, id: @setting, setting: { logo: nil, delete_logo: '1' }
assert_not assigns(:setting).logo?
end
end
end
Do someone know what is wrong with this test ? Thanks
My project:
- Rails 4.2.3
- Ruby 2.2.2
Aucun commentaire:
Enregistrer un commentaire