added specs for Renderer.transform
This commit is contained in:
parent
2f57c9965e
commit
41cf83c525
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue