Sha256: 7582d302fcc5ca2d067569d618fcd4be08316fab1cb4b59ba768168b5e9624f3

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

require "paperclip/matchers"

include ActionDispatch::TestProcess

test_files_path = ":rails_root/test_files/:class/:attachment/:id_partition/:filename"
Paperclip::Attachment.default_options[:path] = test_files_path

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/assets"

  config.include Paperclip::Shoulda::Matchers

  config.after(:suite) do
    FileUtils.rm_rf("#{Rails.root}/test_files")
    FileUtils.rm_rf("#{Rails.root}/public/uploads")
  end
end

def fixture_asset(file_name, mime)
  file_path = Rails.root.to_s + "/spec/assets/" + file_name
  fixture_file_upload(file_path, mime)
rescue
  fixture_file_upload(file_name, mime)
end

# GENERAL CONFIG
# On test environment, paperclip attachments will be generated under /test_files directory.
# After running all the specs, the test_files folder will be deleted.
#
# SHOULDA MATCHERS
# Including Paperclip::Shoulda::Matchers will allow you to use special matchers
# to work with paperclip. For example:
#
# describe User do
#   it { should have_attached_file(:avatar) }
#   it { should validate_attachment_presence(:avatar) }
#   it { should validate_attachment_content_type(:avatar).
#                 allowing('image/png', 'image/gif').
#                 rejecting('text/plain', 'text/xml') }
#   it { should validate_attachment_size(:avatar).
#                 less_than(2.megabytes) }
# end
#
# ASSETS
# Your attachments go into /spec/assets directory. You can access them...
#
# From your factories:
#
# FactoryGirl.define do
#   factory :ticket do
#     attachment { fixture_asset("platanus.png", "image/png") }
#   end
# end
#
# From your specs:
#
# it "gets file name" do
#   expect(fixture_asset("platanus.png", "image/png").original_filename).to eq("platanus.png")
# end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
potassium-5.1.4 lib/potassium/assets/testing/paperclip.rb
potassium-5.1.3 lib/potassium/assets/testing/paperclip.rb
potassium-5.1.2 lib/potassium/assets/testing/paperclip.rb
potassium-5.1.1 lib/potassium/assets/testing/paperclip.rb
potassium-3.0.0 lib/potassium/assets/testing/paperclip.rb
potassium-2.3.0 lib/potassium/assets/testing/paperclip.rb