From 673e5c850833ac18edc9767dd144364e798cc356 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Wed, 14 Nov 2012 21:38:45 +0100 Subject: added specs for #preferred --- spec/unit/request/accept/preferred_spec.rb | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spec/unit/request/accept/preferred_spec.rb (limited to 'spec/unit/request') diff --git a/spec/unit/request/accept/preferred_spec.rb b/spec/unit/request/accept/preferred_spec.rb new file mode 100644 index 0000000..5d11799 --- /dev/null +++ b/spec/unit/request/accept/preferred_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Zero::Request::Accept, '#preferred' do + subject { Zero::Request::Accept } + 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(: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 + before :each do + # reset the mapping to nothing + Zero::Request::Accept.map = {} + end + + it { subject.new(html).preferred.should == html } + it { subject.new(json).preferred.should == json } + 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 } + end + + context 'with mapping' do + before :all do + Zero::Request::Accept.map = {'text/html' => 'html'} + end + + it { subject.new(html).preferred.should == 'html' } + end +end -- cgit v1.2.3-70-g09d2