spec/bullet/rack_spec.rb in bullet-5.9.0 vs spec/bullet/rack_spec.rb in bullet-6.0.0

- old
+ new

@@ -43,13 +43,13 @@ it 'should be false if response is a string and not empty' do response = double(body: '<html><head></head><body></body></html>') expect(middleware).not_to be_empty(response) end - it 'should be true if response is not found' do + it 'should be false if response is not found' do response = ['Not Found'] - expect(middleware).to be_empty(response) + expect(middleware).not_to be_empty(response) end it 'should be true if response body is empty' do response = double(body: '') expect(middleware).to be_empty(response) @@ -66,10 +66,11 @@ end it 'should change response body if notification is active' do expect(Bullet).to receive(:notification?).and_return(true) expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>') + expect(middleware).to receive(:xhr_script).and_return('') expect(Bullet).to receive(:perform_out_of_channel_notifications) status, headers, response = middleware.call('Content-Type' => 'text/html') expect(headers['Content-Length']).to eq('56') expect(response).to eq(['<html><head></head><body><bullet></bullet></body></html>']) end @@ -79,20 +80,28 @@ response.body = '<html><head></head><body>é</body></html>' app.response = response expect(Bullet).to receive(:notification?).and_return(true) expect(Bullet).to receive(:gather_inline_notifications).and_return('<bullet></bullet>') status, headers, response = middleware.call('Content-Type' => 'text/html') - expect(headers['Content-Length']).to eq('58') + expect(headers['Content-Length']).to eq((58 + middleware.send(:xhr_script).length).to_s) end end context 'when Bullet is disabled' do before(:each) { allow(Bullet).to receive(:enable?).and_return(false) } it 'should not call Bullet.start_request' do expect(Bullet).not_to receive(:start_request) middleware.call({}) end + end + end + + context '#set_header' do + it 'should truncate headers to under 8kb' do + long_header = ['a' * 1024] * 10 + expected_res = (['a' * 1024] * 7).to_json + expect(middleware.set_header({}, 'Dummy-Header', long_header)).to eq(expected_res) end end describe '#response_body' do let(:response) { double }