Class: Webrat::FileField

Inherits:
Field show all
Defined in:
lib/webrat/core/elements/field.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Field

#value

Attributes inherited from Element

#element

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Field

#disabled?, field_class, field_classes, #id, inherited, #initialize, #label_text, load, #raise_error_if_disabled, #unset, xpath_search_excluding_hidden

Methods inherited from Element

#initialize, #inspect, load, load_all, #path

Constructor Details

This class inherits a constructor from Webrat::Field

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type


331
332
333
# File 'lib/webrat/core/elements/field.rb', line 331

def content_type
  @content_type
end

Class Method Details

.xpath_searchObject


327
328
329
# File 'lib/webrat/core/elements/field.rb', line 327

def self.xpath_search
  ".//input[@type = 'file']"
end

Instance Method Details

#digest_valueObject


339
340
341
# File 'lib/webrat/core/elements/field.rb', line 339

def digest_value
  @value ? Digest::MD5.hexdigest(self.object_id.to_s) : ""
end

#set(value, content_type = nil) ⇒ Object


333
334
335
336
337
# File 'lib/webrat/core/elements/field.rb', line 333

def set(value, content_type = nil)
  @original_value = @value
  @content_type ||= content_type
  super(value)
end

#test_uploaded_fileObject


348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/webrat/core/elements/field.rb', line 348

def test_uploaded_file
  return "" if @original_value.blank?

  case Webrat.configuration.mode
  when :rails
    if content_type
      ActionController::TestUploadedFile.new(@original_value, content_type)
    else
      ActionController::TestUploadedFile.new(@original_value)
    end
  when :rack, :merb
    Rack::Test::UploadedFile.new(@original_value, content_type)
  end
end

#to_query_stringObject


343
344
345
346
# File 'lib/webrat/core/elements/field.rb', line 343

def to_query_string
  @value.nil? ? set("") : set(digest_value)
  super
end