Merge commit 'sr/mime' into sr-mime
Conflicts: Rakefile lib/webrat.rb
This commit is contained in:
commit
27a773e6b0
1
Rakefile
1
Rakefile
|
@ -21,6 +21,7 @@ Most Ruby web frameworks and testing frameworks are supported.
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
s.add_dependency "nokogiri", ">= 1.2.0"
|
s.add_dependency "nokogiri", ">= 1.2.0"
|
||||||
|
s.add_dependency "rack", ">= 1.0"
|
||||||
|
|
||||||
# TODO: Add development dependencies
|
# TODO: Add development dependencies
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,7 @@ module Webrat
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
require "rack"
|
||||||
require "nokogiri"
|
require "nokogiri"
|
||||||
require "webrat/core/xml/nokogiri"
|
require "webrat/core/xml/nokogiri"
|
||||||
require "webrat/core"
|
require "webrat/core"
|
||||||
|
|
|
@ -1,29 +1,18 @@
|
||||||
module Webrat #:nodoc:
|
module Webrat #:nodoc:
|
||||||
module MIME #:nodoc:
|
module MIME #:nodoc:
|
||||||
|
MIME_TYPES = Rack::Mime::MIME_TYPES.dup.merge(
|
||||||
|
".multipart_form" => "multipart/form-data",
|
||||||
|
".url_encoded_form" => "application/x-www-form-urlencoded"
|
||||||
|
).freeze
|
||||||
|
|
||||||
def self.mime_type(string_or_symbol) #:nodoc:
|
def mime_type(type)
|
||||||
if string_or_symbol.is_a?(String)
|
return type if type.nil? || type.to_s.include?("/")
|
||||||
string_or_symbol
|
type = ".#{type}" unless type.to_s[0] == ?.
|
||||||
else
|
MIME_TYPES.fetch(type) { |type|
|
||||||
case string_or_symbol
|
raise ArgumentError.new("Invalid Mime type: #{type}")
|
||||||
when :text then "text/plain"
|
}
|
||||||
when :html then "text/html"
|
|
||||||
when :js then "text/javascript"
|
|
||||||
when :css then "text/css"
|
|
||||||
when :ics then "text/calendar"
|
|
||||||
when :csv then "text/csv"
|
|
||||||
when :xml then "application/xml"
|
|
||||||
when :rss then "application/rss+xml"
|
|
||||||
when :atom then "application/atom+xml"
|
|
||||||
when :yaml then "application/x-yaml"
|
|
||||||
when :multipart_form then "multipart/form-data"
|
|
||||||
when :url_encoded_form then "application/x-www-form-urlencoded"
|
|
||||||
when :json then "application/json"
|
|
||||||
else
|
|
||||||
raise ArgumentError.new("Invalid Mime type: #{string_or_symbol.inspect}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module_function :mime_type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,6 +62,11 @@ describe Webrat::Session do
|
||||||
it "should raise an error if a symbol Mime type is passed that does not exist" do
|
it "should raise an error if a symbol Mime type is passed that does not exist" do
|
||||||
lambda { webrat_session.http_accept(:oogabooga) }.should raise_error(ArgumentError)
|
lambda { webrat_session.http_accept(:oogabooga) }.should raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should recognize a couple of webrat-specific formats" do
|
||||||
|
webrat_session.http_accept(:multipart_form).should == "multipart/form-data"
|
||||||
|
webrat_session.http_accept(:url_encoded_form).should == "application/x-www-form-urlencoded"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#request_page" do
|
describe "#request_page" do
|
||||||
|
|
Loading…
Reference in New Issue