about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
authorMatt Jankowski <mjankowski@thoughtbot.com>2017-05-05 22:00:21 -0400
committerEugen Rochko <eugen@zeonfederated.com>2017-05-06 04:00:21 +0200
commit3f5b994ff0674fa8e0e5676ca22f0c347f9d7712 (patch)
treed1d4578daac486b3f5b6a360066919b3cccbfaee /spec
parentdacdfec9734a99577658c34c46bbcbd431dc148d (diff)
Stream entry specs and refactor to use delegate (#2827)
* Add coverage for stream entry delegated methods

* Use delegate with allow_nil to clean up stream entry
Diffstat (limited to 'spec')
-rw-r--r--spec/models/stream_entry_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/models/stream_entry_spec.rb b/spec/models/stream_entry_spec.rb
index 45bf26899..3b7ff5143 100644
--- a/spec/models/stream_entry_spec.rb
+++ b/spec/models/stream_entry_spec.rb
@@ -26,4 +26,52 @@ RSpec.describe StreamEntry, type: :model do
       expect(status.stream_entry.threaded?).to be false
     end
   end
+
+  describe 'delegated methods' do
+    context 'with a nil status' do
+      subject { described_class.new(status: nil) }
+
+      it 'returns nil for target' do
+        expect(subject.target).to be_nil
+      end
+
+      it 'returns nil for title' do
+        expect(subject.title).to be_nil
+      end
+
+      it 'returns nil for content' do
+        expect(subject.content).to be_nil
+      end
+
+      it 'returns nil for thread' do
+        expect(subject.thread).to be_nil
+      end
+    end
+
+    context 'with a real status' do
+      let(:original) { Fabricate(:status, text: 'Test status') }
+      let(:status) { Fabricate(:status, reblog: original, thread: original) }
+      subject { described_class.new(status: status) }
+
+      it 'delegates target' do
+        expect(status.target).not_to be_nil
+        expect(subject.target).to eq(status.target)
+      end
+
+      it 'delegates title' do
+        expect(status.title).not_to be_nil
+        expect(subject.title).to eq(status.title)
+      end
+
+      it 'delegates content' do
+        expect(status.content).not_to be_nil
+        expect(subject.content).to eq(status.content)
+      end
+
+      it 'delegates thread' do
+        expect(status.thread).not_to be_nil
+        expect(subject.thread).to eq(status.thread)
+      end
+    end
+  end
 end