0
0
Fork 0

added specs for Renderer.transform

This commit is contained in:
Gibheer 2012-11-16 18:11:49 +01:00
parent 2f57c9965e
commit 41cf83c525
2 changed files with 34 additions and 2 deletions

View File

@ -76,8 +76,8 @@ module Zero
# @api private
# @param string [String] the original type name
# @return [String] the shorter representation or the original
def transform(string)
return map[string] if map.has_key?(string)
def self.transform(string)
return type_map[string] if type_map.has_key?(string)
string
end

View File

@ -0,0 +1,32 @@
require 'spec_helper'
describe Zero::Renderer, '.transform' do
subject { Zero::Renderer }
let(:map) {{ 'text/html' => 'html' }}
shared_examples_for 'a transformer' do
before :each do
Zero::Renderer.type_map = map
end
after :each do
Zero::Renderer.type_map = {}
end
it "transforms a string" do
subject.transform(original).should eq(result)
end
end
context "with a shortable type" do
let(:original) { 'text/html' }
let(:result) { 'html' }
it_behaves_like 'a transformer'
end
context "with an unshortable type" do
let(:original) { 'application/json' }
let(:result) { 'application/json' }
it_behaves_like 'a transformer'
end
end