Skip to content

Commit

Permalink
media type support with charset
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Dec 12, 2009
1 parent 81a92ce commit 8df9853
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/restfulie/media_type.rb
Expand Up @@ -50,6 +50,7 @@ def self.register(name, who)

# TODO rename to type for mt
def self.media_type(name)
name = name[/[^;]*/]
raise UnsupportedContentType.new("unsupported content type '#{name}'") if media_types[name].nil?
media_types[name]
end
Expand Down
8 changes: 8 additions & 0 deletions spec/media_type_spec.rb
Expand Up @@ -11,6 +11,14 @@ class City
end
Restfulie::MediaType.media_type('vnd/caelum_city+xml').should eql(City)
end

it "should be able to locate with encoding" do
class City
extend Restfulie::MediaTypeControl
media_type 'vnd/caelum_city+xml'
end
Restfulie::MediaType.media_type('vnd/caelum_city+xml; charset=UTF-8').should eql(City)
end

it "should throw an exception if not found" do
lambda {Restfulie::MediaType.media_type('vnd/caelum_unknown_city+xml')}.should raise_error(Restfulie::UnsupportedContentType)
Expand Down

0 comments on commit 8df9853

Please sign in to comment.