Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add some specs for Rack::Locale

  • Loading branch information...
commit 6e1c9c5c386813e48d2daa39802cd06c95973e58 1 parent b7e7c38
James A. Rosen authored
Showing with 45 additions and 0 deletions.
  1. +45 −0 test/spec_rack_locale.rb
View
45 test/spec_rack_locale.rb
@@ -0,0 +1,45 @@
+require 'test/spec'
+require 'rack/mock'
+
+context "Rack::Locale" do
+
+ setup do
+ begin
+ require 'rack/contrib/locale'
+ rescue LoadError
+ warn "I18n required for Rack::Locale specs"
+ end
+ end
+
+ def app
+ @app ||= Rack::Builder.new do
+ use Rack::Locale
+ run lambda { |env| [ 200, {}, [ I18n.locale.to_s ] ] }
+ end
+ end
+
+ def response_with_languages(accept_languages)
+ Rack::MockRequest.new(app).get('/', { 'HTTP_ACCEPT_LANGUAGE' => accept_languages } )
+ end
+
+ specify 'should use I18n.default_locale if no languages are requested' do
+ I18n.default_locale = :zh
+ response_with_languages(nil).body.should.equal('zh')
+ end
+
+ specify 'should treat an empty qvalue as 1.0' do
+ response_with_languages('en,es;q=0.95').body.should.equal('en')
+ end
+
+ specify 'should set the Content-Language response header' do
+ headers = response_with_languages('de;q=0.7,dk;q=0.9').headers
+ headers['Content-Language'].should.equal('dk')
+ end
+
+ specify 'should reset the I18n locale after the response' do
+ I18n.locale = 'es'
+ response_with_languages('en,de;q=0.8')
+ I18n.locale.should.equal(:es)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.