about summary refs log tree commit diff
path: root/app/models/stream_entry.rb
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 /app/models/stream_entry.rb
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 'app/models/stream_entry.rb')
-rw-r--r--app/models/stream_entry.rb21
1 files changed, 5 insertions, 16 deletions
diff --git a/app/models/stream_entry.rb b/app/models/stream_entry.rb
index c173e6257..d451e0dde 100644
--- a/app/models/stream_entry.rb
+++ b/app/models/stream_entry.rb
@@ -1,4 +1,5 @@
 # frozen_string_literal: true
+
 # == Schema Information
 #
 # Table name: stream_entries
@@ -26,6 +27,10 @@ class StreamEntry < ApplicationRecord
   default_scope { where(activity_type: 'Status') }
   scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES) }
 
+  delegate :target, :title, :content, :thread,
+           to: :status,
+           allow_nil: true
+
   def object_type
     orphaned? || targeted? ? :activity : status.object_type
   end
@@ -38,26 +43,10 @@ class StreamEntry < ApplicationRecord
     [:follow, :request_friend, :authorize, :reject, :unfollow, :block, :unblock, :share, :favorite].include? verb
   end
 
-  def target
-    orphaned? ? nil : status.target
-  end
-
-  def title
-    orphaned? ? nil : status.title
-  end
-
-  def content
-    orphaned? ? nil : status.content
-  end
-
   def threaded?
     (verb == :favorite || object_type == :comment) && !thread.nil?
   end
 
-  def thread
-    orphaned? ? nil : status.thread
-  end
-
   def mentions
     orphaned? ? [] : status.mentions.map(&:account)
   end