Merge commit 'pd/master'

This commit is contained in:
Bryan Helmkamp 2008-07-25 17:59:27 -04:00
commit 03308b942f
4 changed files with 41 additions and 6 deletions

View File

@ -43,7 +43,8 @@ module Webrat
end end
def to_param def to_param
param_parser.parse_query_parameters("#{name}=#{@value}") value = @value.to_s.gsub('&', '%26')
param_parser.parse_query_parameters("#{name}=#{value}")
end end
def set(value) def set(value)
@ -239,11 +240,19 @@ module Webrat
class FileField < Field class FileField < Field
attr_accessor :content_type
def set(value, content_type = nil)
super(value)
@content_type = content_type
end
def to_param def to_param
if @value.nil? if @value.nil?
super super
else else
replace_param_value(super, @value, ActionController::TestUploadedFile.new(@value)) file = content_type ? ActionController::TestUploadedFile.new(@value, content_type) : ActionController::TestUploadedFile.new(@value)
replace_param_value(super, @value, file)
end end
end end

View File

@ -101,13 +101,14 @@ module Webrat
# Verifies that an input file field exists on the current page and sets # Verifies that an input file field exists on the current page and sets
# its value to the given +file+, so that the file will be uploaded # its value to the given +file+, so that the file will be uploaded
# along with the form. # along with the form. An optional <tt>content_type</tt> may be given.
# #
# Example: # Example:
# attaches_file "Photo", "/path/to/the/photo.jpg" # attaches_file "Resume", "/path/to/the/resume.txt"
def attaches_file(id_or_name_or_label, path) # attaches_file "Photo", "/path/to/the/image.png", "image/png"
def attaches_file(id_or_name_or_label, path, content_type = nil)
field = find_field(id_or_name_or_label, FileField) field = find_field(id_or_name_or_label, FileField)
field.set(path) field.set(path, content_type)
end end
alias_method :attach_file, :attaches_file alias_method :attach_file, :attaches_file

View File

@ -56,4 +56,17 @@ describe "attaches_file" do
@session.attaches_file "Spreadsheet", @filename @session.attaches_file "Spreadsheet", @filename
@session.clicks_button @session.clicks_button
end end
it "should allow the content type to be specified" do
@session.response_body = <<-EOS
<form method="post" action="/widgets">
<label for="person_picture">Picture</label>
<input type="file" id="person_picture" name="person[picture]" />
<input type="submit" />
</form>
EOS
ActionController::TestUploadedFile.expects(:new).with(@filename, "image/png").returns(@uploaded_file)
@session.attaches_file "Picture", @filename, "image/png"
@session.clicks_button
end
end end

View File

@ -48,6 +48,18 @@ describe "selects" do
@session.clicks_button @session.clicks_button
end end
it "should send values with HTML encoded ampersands" do
@session.response_body = <<-EOS
<form method="post" action="/login">
<select name="encoded"><option value="A &amp; B">Encoded</option></select>
<input type="submit" />
</form>
EOS
@session.expects(:post).with("/login", "encoded" => "A & B")
@session.selects "Encoded", :from => "encoded"
@session.clicks_button
end
it "should work with empty select lists" do it "should work with empty select lists" do
@session.response_body = <<-EOS @session.response_body = <<-EOS
<form method="post" action="/login"> <form method="post" action="/login">