spec/bullet/rack_spec.rb in bullet-6.1.4 vs spec/bullet/rack_spec.rb in bullet-6.1.5

- old
+ new

@@ -103,23 +103,24 @@ expect(response).to eq(%w[<html><head></head><body>footer<bullet></bullet><script></script></body></html>]) end it 'should change response body for html safe string if add_footer is true' do expect(Bullet).to receive(:add_footer).exactly(3).times.and_return(true) - app.response = Support::ResponseDouble.new.tap do |response| - response.body = ActiveSupport::SafeBuffer.new('<html><head></head><body></body></html>') - end + app.response = + Support::ResponseDouble.new.tap do |response| + response.body = ActiveSupport::SafeBuffer.new('<html><head></head><body></body></html>') + end _, headers, response = middleware.call('Content-Type' => 'text/html') expect(headers['Content-Length']).to eq((73 + middleware.send(:footer_note).length).to_s) expect(response).to eq(%w[<html><head></head><body>footer<bullet></bullet><script></script></body></html>]) end it 'should add the footer-text header for non-html requests when add_footer is true' do allow(Bullet).to receive(:add_footer).at_least(:once).and_return(true) allow(Bullet).to receive(:footer_info).and_return(['footer text']) - app.headers = {'Content-Type' => 'application/json'} + app.headers = { 'Content-Type' => 'application/json' } _, headers, _response = middleware.call({}) expect(headers).to include('X-bullet-footer-text' => '["footer text"]') end it 'should change response body if console_enabled is true' do @@ -129,22 +130,23 @@ expect(response).to eq(%w[<html><head></head><body><bullet></bullet></body></html>]) end it 'should change response body for html safe string if console_enabled is true' do expect(Bullet).to receive(:console_enabled?).and_return(true) - app.response = Support::ResponseDouble.new.tap do |response| - response.body = ActiveSupport::SafeBuffer.new('<html><head></head><body></body></html>') - end + app.response = + Support::ResponseDouble.new.tap do |response| + response.body = ActiveSupport::SafeBuffer.new('<html><head></head><body></body></html>') + end _, headers, response = middleware.call('Content-Type' => 'text/html') expect(headers['Content-Length']).to eq('56') expect(response).to eq(%w[<html><head></head><body><bullet></bullet></body></html>]) end it 'should add headers for non-html requests when console_enabled is true' do allow(Bullet).to receive(:console_enabled?).at_least(:once).and_return(true) allow(Bullet).to receive(:text_notifications).and_return(['text notifications']) - app.headers = {'Content-Type' => 'application/json'} + app.headers = { 'Content-Type' => 'application/json' } _, headers, _response = middleware.call({}) expect(headers).to include('X-bullet-console-text' => '["text notifications"]') end it "shouldn't change response body unnecessarily" do @@ -153,17 +155,17 @@ _, _, response = middleware.call({}) expect(response).to eq(expected_response) end it "shouldn't add headers unnecessarily" do - app.headers = {'Content-Type' => 'application/json'} + app.headers = { 'Content-Type' => 'application/json' } _, headers, _response = middleware.call({}) expect(headers).not_to include('X-bullet-footer-text') expect(headers).not_to include('X-bullet-console-text') end - context "when skip_http_headers is enabled" do + context 'when skip_http_headers is enabled' do before do allow(Bullet).to receive(:skip_http_headers).and_return(true) end it 'should include the footer but not the xhr script tag if add_footer is true' do @@ -181,18 +183,18 @@ expect(response).to eq(%w[<html><head></head><body><bullet></bullet></body></html>]) end it 'should not add the footer-text header for non-html requests when add_footer is true' do allow(Bullet).to receive(:add_footer).at_least(:once).and_return(true) - app.headers = {'Content-Type' => 'application/json'} + app.headers = { 'Content-Type' => 'application/json' } _, headers, _response = middleware.call({}) expect(headers).not_to include('X-bullet-footer-text') end it 'should not add headers for non-html requests when console_enabled is true' do allow(Bullet).to receive(:console_enabled?).at_least(:once).and_return(true) - app.headers = {'Content-Type' => 'application/json'} + app.headers = { 'Content-Type' => 'application/json' } _, headers, _response = middleware.call({}) expect(headers).not_to include('X-bullet-console-text') end end end @@ -256,9 +258,23 @@ before { allow(response).to receive(:first).and_return(body_string) } it 'should return the plain body string' do expect(middleware.response_body(response)).to eq body_string end + end + + begin + require 'rack/files' + + context 'when `response` is a Rack::Files::Iterator' do + let(:response) { instance_double(::Rack::Files::Iterator) } + before { allow(response).to receive(:is_a?).with(::Rack::Files::Iterator) { true } } + + it 'should return nil' do + expect(middleware.response_body(response)).to be_nil + end + end + rescue LoadError end end end end