Sha256: 5139b0e8761824466ccb006fb7fdd8e46c8e3567932459a85feea41a7e2f21e4

Contents?: true

Size: 780 Bytes

Versions: 3

Compression:

Stored size: 780 Bytes

Contents

class RailsExtras
  module RSpec
    module Support
      module Common

        def self.upload_file(path, options={})
          filename = path.split('/').last.to_s.force_encoding("UTF-8")
          tempfile = File.new(Rails.root.join('spec', 'files', path))
          hash = {tempfile: tempfile, filename: filename}
          hash[:original_filename] = options[:original_filename] if options[:original_filename]
          hash[:content_type] = options[:content_type] || 'text/plain'
          hash[:headers] = options[:headers] if options[:headers]

          ::ActionDispatch::Http::UploadedFile.new(hash)
        end

        def upload_file(path, options={})
          ::RailsExtras::RSpec::Support::Common.upload_file(path, options)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rails_extras-0.1.5 lib/rails_extras/rspec/support/common.rb
rails_extras-0.1.4 lib/rails_extras/rspec/support/common.rb
rails_extras-0.1.3 lib/rails_extras/rspec/support/common.rb