From 586e23727cf4231bb5faa73d0460cc2b5e55507b Mon Sep 17 00:00:00 2001 From: David McMullin <david.mcmullin@gmail.com> Date: Sun, 30 Sep 2012 13:27:39 +0100 Subject: [PATCH] add specs for chromeframe fix typo in ChromeFrame itself remove unneccessary chromeframe meta tags from layouts --- app/views/layouts/application.html.haml | 1 - app/views/layouts/blank.haml | 1 - app/views/layouts/post.haml | 1 - lib/rack/chrome_frame.rb | 2 +- spec/helper_methods.rb | 7 ++++ spec/lib/rack/chrome_frame_spec.rb | 47 +++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 spec/lib/rack/chrome_frame_spec.rb diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 61b6d61614..af2d720fc6 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -6,7 +6,6 @@ %html{:lang => I18n.locale.to_s, :dir => (rtl?) ? 'rtl' : 'ltr'} %head %meta{:charset => 'utf-8'} - %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'} %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"} %meta{:name => "description", :content => "Diaspora*"} diff --git a/app/views/layouts/blank.haml b/app/views/layouts/blank.haml index b9e7d816da..0ed9927abc 100644 --- a/app/views/layouts/blank.haml +++ b/app/views/layouts/blank.haml @@ -6,7 +6,6 @@ %html{:lang => I18n.locale.to_s, :dir => (rtl?) ? 'rtl' : 'ltr'} %head %meta{:charset => 'utf-8'} - %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'} %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"} = csrf_meta_tag diff --git a/app/views/layouts/post.haml b/app/views/layouts/post.haml index f0ef05e044..4d10bb287d 100644 --- a/app/views/layouts/post.haml +++ b/app/views/layouts/post.haml @@ -6,7 +6,6 @@ %html{:lang => I18n.locale.to_s, :dir => (rtl?) ? 'rtl' : 'ltr'} %head %meta{:charset => 'utf-8'} - %meta{'http-equiv' => 'X-UA-Compatible', :content => 'IE=edge,chrome=1'} %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"} %meta{:name => "description", :content => "Diaspora*"} diff --git a/lib/rack/chrome_frame.rb b/lib/rack/chrome_frame.rb index 81f438d6d5..de7234dd11 100644 --- a/lib/rack/chrome_frame.rb +++ b/lib/rack/chrome_frame.rb @@ -29,7 +29,7 @@ module Rack <body> <div id="cf-placeholder"></div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script> - <script>CFInstall.check({ node: "cf-placx eholder" #{', destination: "' + @options[:destination] + '" ' if @options[:destination]}});</script> + <script>CFInstall.check({ node: "cf-placeholder" #{', destination: "' + @options[:destination] + '" ' if @options[:destination]}});</script> </body> </html> HTML diff --git a/spec/helper_methods.rb b/spec/helper_methods.rb index 4715264520..494f15407a 100644 --- a/spec/helper_methods.rb +++ b/spec/helper_methods.rb @@ -72,4 +72,11 @@ module HelperMethods Conversation.create!(create_hash) end + + def get_response_for_user_agent(app, userAgent) + env = Rack::MockRequest.env_for('/', "HTTP_USER_AGENT" => userAgent) + status, headers, body = app.call(env) + body.close if body.respond_to?(:close) # avoids deadlock after 3 tests + ActionDispatch::TestResponse.new(status, headers, body) + end end diff --git a/spec/lib/rack/chrome_frame_spec.rb b/spec/lib/rack/chrome_frame_spec.rb new file mode 100644 index 0000000000..12643a95c3 --- /dev/null +++ b/spec/lib/rack/chrome_frame_spec.rb @@ -0,0 +1,47 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. +require 'spec_helper' + +describe Rack::ChromeFrame do + + before :all do + @app = Rack::Builder.parse_file(Rails.root.join('config.ru').to_s).first + end + + before :each do + @response = get_response_for_user_agent(@app, ua_string); + end + + subject { @response } + + context "non-IE browser" do + let(:ua_string) { "another browser chromeframe" } + + its(:body) { should_not =~ /chrome=1/ } + its(:body) { should_not =~ /Diaspora doesn't support your version of Internet Explorer/ } + end + + context "IE8 without chromeframe" do + let(:ua_string) { "MSIE 8" } + + its(:body) { should_not =~ /chrome=1/ } + its(:body) { should_not =~ /Diaspora doesn't support your version of Internet Explorer/ } + end + + context "IE7 without chromeframe" do + let(:ua_string) { "MSIE 7" } + + its(:body) { should_not =~ /chrome=1/ } + its(:body) { should =~ /Diaspora doesn't support your version of Internet Explorer/ } + specify {@response.headers["Content-Length"].should == @response.body.length.to_s} + end + + context "any IE with chromeframe" do + let(:ua_string) { "MSIE number chromeframe" } + + its(:body) { should =~ /chrome=1/ } + its(:body) { should_not =~ /Diaspora doesn't support your version of Internet Explorer/ } + specify {@response.headers["Content-Length"].should == @response.body.length.to_s} + end +end -- GitLab