0
0
zero/spec/unit/request/accepttype/preferred_spec.rb

41 lines
1.5 KiB
Ruby
Raw Normal View History

2012-11-14 21:38:45 +01:00
require 'spec_helper'
2012-11-16 13:58:42 +01:00
describe Zero::Request::AcceptType, '#preferred' do
subject { Zero::Request::AcceptType }
2012-11-14 21:38:45 +01:00
let(:html) { 'text/html' }
let(:json) { 'application/json' }
let(:foo) { 'text/foo' }
let(:lower_quality) { foo + ';q=0.5' }
let(:default) { '*/*;q=0.1' }
let(:option) { [foo + ';b=23', html].join(',') }
2012-11-14 21:38:45 +01:00
let(:simple_accept) { [html, json].join(',') }
let(:quality_accept) { [html, lower_quality, default].join(',') }
let(:random_accept) { [lower_quality, default, html].join(',') }
let(:lower_accept) { [lower_quality, default].join(',') }
context 'without mapping' do
it { subject.new(html).preferred.should == html }
it { subject.new(json).preferred.should == json }
it { subject.new(option).preferred.should == foo }
it { subject.new(simple_accept).preferred.should == html }
it { subject.new(quality_accept).preferred.should == html }
it { subject.new(random_accept).preferred.should == html }
it { subject.new(lower_accept).preferred.should == foo }
it { subject.new(nil).preferred.should == '*/*' }
it { subject.new('').preferred.should == '*/*' }
it { subject.new('text / html').preferred.should == html }
2012-11-14 21:38:45 +01:00
end
2012-11-16 13:58:42 +01:00
# context 'with mapping' do
# before :all do
# Zero::Request::Accept.map = {'text/html' => 'html'}
# end
#
# after :all do
# Zero::Request::Accept.map = {}
# end
#
# it { subject.new(html).preferred.should == 'html' }
# end
2012-11-14 21:38:45 +01:00
end