Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

publisher lib, prefill, open, still need to do public first message f…

…or new users
  • Loading branch information...
commit 1ccf965194530962f7640d4351cbc4a98a02d413 1 parent ee74948
@zhitomirskiyi zhitomirskiyi authored danielgrippi committed
View
12 app/helpers/interim_stream_hackiness_helper.rb
@@ -14,7 +14,7 @@ def publisher_prefill_text
if params[:prefill].present?
params[:prefill]
elsif defined?(@stream)
- @stream.publisher_prefill_text
+ @stream.publisher.prefill
else
nil
end
@@ -24,7 +24,7 @@ def from_group(post)
if defined?(@stream) && params[:controller] == 'multis'
@stream.post_from_group(post)
else
- []
+ []
end
end
@@ -35,4 +35,12 @@ def what_stream_sentence(post)
def stream_settings_link(post)
link_to "", "#{edit_user_path}#stream-preferences"
end
+
+ def publisher_open
+ if defined?(@stream)
+ @stream.publisher.open?
+ else
+ false
+ end
+ end
end
View
7 app/views/shared/_publisher.html.haml
@@ -9,6 +9,13 @@
$(".public_icon").tipsy({trigger: 'hover', gravity: 'n'});
});
+- if publisher_open
+ :javascript
+ $(document).ready(function()
+ {
+ Publisher.open();
+ });
+
#publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )}
.content_creation
= form_for(StatusMessage.new, :remote => remote?, :html => {"data-type" => "json"}) do |status|
View
4 lib/publisher.rb
@@ -1,10 +1,10 @@
class Publisher
- attr_accessor :user, :open, :prefill_text, :public
+ attr_accessor :user, :open, :prefill, :public
def initialize(user, opts={})
self.user = user
self.open = (opts[:open] == true)? true : false
- self.prefill_text = opts[:prefill_text]
+ self.prefill = opts[:prefill]
self.public = (opts[:public] == true)? true : false
end
View
28 lib/stream/aspect.rb
@@ -126,4 +126,32 @@ def contacts_link
def can_comment?(post)
true
end
+
+ def publisher
+ if welcome?
+ @publisher ||= Publisher.new(self.user, :open => true, :prefill => publisher_prefill,
+ :public => true)
+ else
+ super
+ end
+ end
+
+ private
+ # Generates the prefill for the publisher
+ #
+ # @return [String]
+ def publisher_prefill
+ prefill = "Hi, I'm #newhere."
+
+ if self.user.followed_tags.size > 0
+ tag_string = self.user.followed_tags.map{|t| "##{t.name}"}.join(", ")
+ prefill << "I like #{tag_string}."
+ end
+
+ prefill
+ end
+
+ def welcome?
+ self.user.getting_started
+ end
end
View
6 lib/stream/base.rb
@@ -44,11 +44,6 @@ def posts
[]
end
- # @return [String]
- def publisher_prefill_text
- ''
- end
-
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
people_ids = posts.map{|x| x.author_id}
@@ -107,6 +102,7 @@ def order=(order_string)
@order ||= 'created_at'
end
+ # @return [Publisher]
def publisher
@publisher ||= Publisher.new(self.user)
end
View
8 lib/stream/tag.rb
@@ -35,14 +35,14 @@ def posts
@posts ||= construct_post_query
end
- def publisher_prefill_text
- display_tag_name + ' '
- end
-
def tag_name=(tag_name)
@tag_name = tag_name.downcase.gsub('#', '')
end
+ def publisher
+ @publisher ||= Publisher.new(self.user, :prefill => "#{display_tag_name} ")
+ end
+
private
def construct_post_query
View
4 spec/lib/publisher_spec.rb
@@ -21,11 +21,11 @@
describe "#prefill" do
it 'defaults to nothing' do
- @publisher.prefill_text.should be_blank
+ @publisher.prefill.should be_blank
end
it 'is settable' do
- Publisher.new(alice, :prefill_text => "party!").prefill_text.should == "party!"
+ Publisher.new(alice, :prefill => "party!").prefill.should == "party!"
end
end
View
63 spec/lib/stream/aspect_spec.rb
@@ -172,4 +172,67 @@ class Person ; end
end
it_should_behave_like 'it is a stream'
end
+
+ describe "#publisher" do
+ before do
+ @stream = Stream::Aspect.new(alice, alice.aspects.map(&:id))
+ @stream.stub(:welcome?).and_return(false)
+ end
+
+ it 'does not use prefill text by default' do
+ @stream.should_not_receive(:publisher_prefill)
+
+ @stream.publisher
+ end
+
+ it 'checks welcome?' do
+ @stream.should_receive(:welcome?).and_return(true)
+
+ @stream.publisher
+ end
+
+ it 'creates a welcome publisher for new user' do
+ @stream.stub(:welcome?).and_return(true)
+ @stream.should_receive(:publisher_prefill).and_return("abc")
+
+ Publisher.should_receive(:new).with(alice, hash_including(:open => true, :prefill => "abc", :public => true))
+ @stream.publisher
+ end
+
+ it 'creates a default publisher for returning users' do
+ Publisher.should_receive(:new).with(alice)
+ @stream.publisher
+ end
+ end
+
+ describe "#publisher_prefill" do
+ before do
+ @tag = ActsAsTaggableOn::Tag.find_or_create_by_name("cats")
+ @tag_following = alice.tag_followings.create(:tag_id => @tag.id)
+
+ @stream = Stream::Aspect.new(alice, alice.aspects.map(&:id))
+ end
+
+ it 'returns includes new user hashtag' do
+ @stream.send(:publisher_prefill).include?("#newhere").should be_true
+ end
+
+ it 'includes followed hashtags' do
+ @stream.send(:publisher_prefill).include?("#cats").should be_true
+ end
+ end
+
+ describe "#welcome?" do
+ it 'returns true if user is getting started' do
+ alice.getting_started = true
+
+ Stream::Aspect.new(alice, alice.aspects.map(&:id)).send(:welcome?).should be_true
+ end
+
+ it 'returns false if user is getting started' do
+ alice.getting_started = false
+
+ Stream::Aspect.new(alice, alice.aspects.map(&:id)).send(:welcome?).should be_false
+ end
+ end
end
View
8 spec/lib/stream/tag_spec.rb
@@ -91,4 +91,12 @@
stream.tag_name.should == 'what'
end
end
+
+ describe "#publisher" do
+ it 'creates a publisher with the tag prefill' do
+ Publisher.should_receive(:new).with(anything(), hash_including(:prefill => "#what "))
+ @stream = Stream::Tag.new(alice, "what")
+ @stream.publisher
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.