diff options
Diffstat (limited to 'spec/lib/peek/views/bullet_detailed_spec.rb')
-rw-r--r-- | spec/lib/peek/views/bullet_detailed_spec.rb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/lib/peek/views/bullet_detailed_spec.rb b/spec/lib/peek/views/bullet_detailed_spec.rb new file mode 100644 index 00000000000..a482cadc7db --- /dev/null +++ b/spec/lib/peek/views/bullet_detailed_spec.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Peek::Views::BulletDetailed do + subject { described_class.new } + + before do + allow(Bullet).to receive(:enable?).and_return(bullet_enabled) + end + + context 'bullet disabled' do + let(:bullet_enabled) { false } + + it 'returns empty results' do + expect(subject.results).to eq({}) + end + end + + context 'bullet enabled' do + let(:bullet_enabled) { true } + + before do + allow(Bullet).to receive_message_chain(:notification_collector, :collection).and_return(notifications) + end + + context 'where there are no notifications' do + let(:notifications) { [] } + + it 'returns empty results' do + expect(subject.results).to eq({}) + end + end + + context 'when notifications exist' do + let(:notifications) do + [ + double(title: 'Title 1', body: 'Body 1', body_with_caller: "first\nsecond\n"), + double(title: 'Title 2', body: 'Body 2', body_with_caller: "first\nsecond\n") + ] + end + + it 'returns empty results' do + expect(subject.key).to eq('bullet') + expect(subject.results[:calls]).to eq(2) + expect(subject.results[:warnings]).to eq([Peek::Views::BulletDetailed::WARNING_MESSAGE]) + expect(subject.results[:details]).to eq([ + { notification: 'Title 1: Body 1', backtrace: "first\nsecond\n" }, + { notification: 'Title 2: Body 2', backtrace: "first\nsecond\n" } + ]) + end + end + end +end |