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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publisher_method(method)
|
||||||
|
@stream.try(:publisher).try(method) == true
|
||||||
|
end
|
||||||
|
|
||||||
def publisher_open
|
def publisher_open
|
||||||
if defined?(@stream)
|
publisher_method(:open)
|
||||||
@stream.publisher.open?
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def publisher_public
|
def publisher_public
|
||||||
if defined?(@stream)
|
publisher_method(:public)
|
||||||
@stream.publisher.public?
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def publisher_explain
|
def publisher_explain
|
||||||
if defined?(@stream)
|
publisher_method(:explain)
|
||||||
@stream.publisher.public?
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,26 +10,10 @@ class Publisher
|
||||||
end
|
end
|
||||||
|
|
||||||
def text
|
def text
|
||||||
formatted_message
|
return unless prefill.present?
|
||||||
end
|
Diaspora::MessageRenderer.new(
|
||||||
|
prefill,
|
||||||
def open?
|
mentioned_people: Diaspora::Mentionable.people_from_string(prefill)
|
||||||
self.open
|
).plain_text
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class Stream::Multi < Stream::Base
|
||||||
private
|
private
|
||||||
def publisher_opts
|
def publisher_opts
|
||||||
if welcome?
|
if welcome?
|
||||||
{:open => true, :prefill => publisher_prefill, :public => true}
|
{open: true, prefill: publisher_prefill, public: true, explain: true}
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,13 @@ describe Publisher do
|
||||||
end
|
end
|
||||||
|
|
||||||
["open", "public", "explain"].each do |property|
|
["open", "public", "explain"].each do |property|
|
||||||
describe "##{property}?" do
|
describe "##{property}" do
|
||||||
it 'defaults to closed' 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
|
end
|
||||||
|
|
||||||
it 'listens to the opts' do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,7 @@ describe Stream::Multi do
|
||||||
prefill_text = "sup?"
|
prefill_text = "sup?"
|
||||||
allow(@stream).to receive(:welcome?).and_return(true)
|
allow(@stream).to receive(:welcome?).and_return(true)
|
||||||
allow(@stream).to receive(:publisher_prefill).and_return(prefill_text)
|
allow(@stream).to receive(:publisher_prefill).and_return(prefill_text)
|
||||||
expect(@stream.send(:publisher_opts)).to eq({:open => true,
|
expect(@stream.send(:publisher_opts)).to eq(open: true, prefill: prefill_text, public: true, explain: true)
|
||||||
:prefill => prefill_text,
|
|
||||||
:public => true})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'provides no opts if welcome? is not set' do
|
it 'provides no opts if welcome? is not set' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue