Merge pull request #6816 from cmrd-senya/publisher-refactor
A minor refactor of the Publisher
This commit is contained in:
commit
209cd783c8
5 changed files with 17 additions and 43 deletions
|
|
@ -39,27 +39,19 @@ module InterimStreamHackinessHelper
|
|||
end
|
||||
end
|
||||
|
||||
def publisher_method(method)
|
||||
@stream.try(:publisher).try(method) == true
|
||||
end
|
||||
|
||||
def publisher_open
|
||||
if defined?(@stream)
|
||||
@stream.publisher.open?
|
||||
else
|
||||
false
|
||||
end
|
||||
publisher_method(:open)
|
||||
end
|
||||
|
||||
def publisher_public
|
||||
if defined?(@stream)
|
||||
@stream.publisher.public?
|
||||
else
|
||||
false
|
||||
end
|
||||
publisher_method(:public)
|
||||
end
|
||||
|
||||
def publisher_explain
|
||||
if defined?(@stream)
|
||||
@stream.publisher.public?
|
||||
else
|
||||
false
|
||||
end
|
||||
publisher_method(:explain)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,26 +10,10 @@ class Publisher
|
|||
end
|
||||
|
||||
def text
|
||||
formatted_message
|
||||
end
|
||||
|
||||
def open?
|
||||
self.open
|
||||
end
|
||||
|
||||
def public?
|
||||
self.public
|
||||
end
|
||||
|
||||
def explain?
|
||||
self.explain
|
||||
end
|
||||
|
||||
private
|
||||
def formatted_message
|
||||
if self.prefill.present?
|
||||
sm = StatusMessage.new(:text => self.prefill)
|
||||
Diaspora::Mentionable.format(sm.raw_message, sm.mentioned_people, plain_text: true)
|
||||
end
|
||||
return unless prefill.present?
|
||||
Diaspora::MessageRenderer.new(
|
||||
prefill,
|
||||
mentioned_people: Diaspora::Mentionable.people_from_string(prefill)
|
||||
).plain_text
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class Stream::Multi < Stream::Base
|
|||
private
|
||||
def publisher_opts
|
||||
if welcome?
|
||||
{:open => true, :prefill => publisher_prefill, :public => true}
|
||||
{open: true, prefill: publisher_prefill, public: true, explain: true}
|
||||
else
|
||||
super
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ describe Publisher do
|
|||
end
|
||||
|
||||
["open", "public", "explain"].each do |property|
|
||||
describe "##{property}?" do
|
||||
describe "##{property}" do
|
||||
it 'defaults to closed' do
|
||||
expect(@publisher.send("#{property}?".to_sym)).to be_falsey
|
||||
expect(@publisher.send("#{property}".to_sym)).to be_falsey
|
||||
end
|
||||
|
||||
it 'listens to the opts' do
|
||||
expect(Publisher.new(alice, {property.to_sym => true}).send("#{property}?".to_sym)).to be true
|
||||
expect(Publisher.new(alice, property.to_sym => true).send("#{property}".to_sym)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ describe Stream::Multi do
|
|||
prefill_text = "sup?"
|
||||
allow(@stream).to receive(:welcome?).and_return(true)
|
||||
allow(@stream).to receive(:publisher_prefill).and_return(prefill_text)
|
||||
expect(@stream.send(:publisher_opts)).to eq({:open => true,
|
||||
:prefill => prefill_text,
|
||||
:public => true})
|
||||
expect(@stream.send(:publisher_opts)).to eq(open: true, prefill: prefill_text, public: true, explain: true)
|
||||
end
|
||||
|
||||
it 'provides no opts if welcome? is not set' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue