fixed up stream/publisher logic; fixed cukes

This commit is contained in:
danielgrippi 2011-10-24 14:11:01 -07:00
parent 59e4955727
commit e63e8299b9
22 changed files with 117 additions and 157 deletions

View file

@ -3,18 +3,6 @@
# the COPYRIGHT file.
module GettingStartedHelper
# @return [Boolean] The user has filled out all profile fields
def has_completed_profile?
profile = current_user.person.profile
[:full_name, :image_url,
:birthday, :gender,
:bio, :location,
:tag_string].map! do |attr|
return false if profile.send(attr).blank?
end
true
end
# @return [Boolean] The user has connected at least one service
def has_connected_services?
AppConfig[:configured_services].blank? || current_user.services.size > 0
@ -29,7 +17,7 @@ module GettingStartedHelper
def has_few_followed_tags?
current_user.followed_tags.size > 2
end
# @return [Boolean] The user has connected to cubbi.es
def has_connected_cubbies?
current_user.authorizations.size > 0
@ -40,15 +28,6 @@ module GettingStartedHelper
current_user.getting_started == false
end
# @return [String] Welcome text with or without the current_user's first_name
def welcome_text
if current_user.person.profile.first_name.present?
t('users.getting_started.welcome_with_name', :name => current_user.first_name)
else
t('users.getting_started.welcome')
end
end
def tag_link(tag_name)
if tag_followed?(tag_name)
link_to "##{tag_name}", tag_followings_path(tag_name), :method => :delete, :class => "featured_tag followed"

View file

@ -155,7 +155,7 @@ class Person < ActiveRecord::Base
@first_name ||= if profile.nil? || profile.first_name.nil? || profile.first_name.blank?
self.diaspora_handle.split('@').first
else
profile.first_name.to_s
profile.first_name.to_s.split(/\s/).first
end
end

View file

@ -10,7 +10,11 @@
#welcome-to-diaspora
.container
%h1
Welcome to Diaspora, #{current_user.first_name}!
= t('.welcome_to_diaspora', :name => current_user.first_name)
%h3
= t('.time_to_introduce_yourself')
%br
%br
%br
%br
%br

View file

@ -23,8 +23,8 @@
- conv_opts[:title] = t('.many_people_are_you_sure', :suggested_limit => suggested_limit) if @contacts.size > suggested_limit
= link_to t('.start_a_conversation'), new_conversation_path(:aspect_id => @aspect.id, :name => @aspect.name), conv_opts
- if @contacts.size > suggested_limit
= link_to t('.add_to_aspect', :name => @aspect.name), edit_aspect_path(@aspect), :rel => "facebox"
- if @contacts.size
= link_to t('.add_to_aspect', :name => @aspect.name), edit_aspect_path(@aspect), :rel => "facebox"
- if @contacts.size > 0
- for contact in @contacts
@ -62,6 +62,6 @@
= link_to t('contacts.spotlight.community_spotlight'), community_spotlight_path
- if @aspect
or
= link_to t('.add_to_aspect', :name => @aspect.name).downcase, edit_aspect_path(@aspect), :rel => "facebox"
= link_to t('.add_to_aspect', :name => @aspect.name), edit_aspect_path(@aspect), :rel => "facebox"

View file

@ -10,7 +10,7 @@
%ul.left_nav
- if AppConfig[:community_spotlight]
%li{:class => ("active" if @spotlight)}
= link_to t('users.getting_started.community_spotlight'), community_spotlight_path, :class => "element_selector"
= link_to t('contacts.spotlight.community_spotlight'), community_spotlight_path, :class => "element_selector"
%li{:class => ("active" if @finder)}
= link_to "Facebook Friends", friend_finder_path('facebook'), :class => "element_selector"

View file

@ -43,6 +43,7 @@
$("#publisher .button.creation").bind("click", function(){
$("#publisher .dropdown").popover("hide");
$("#publisher #status_message_fake_text").popover("hide");
$("#gs-shim").popover("hide");
});
});

View file

@ -32,7 +32,7 @@
.row
.span6
= form_tag profile_path, :method => :put, :remote => true, :id => 'edit_profile' do |profile|
= form_tag profile_path, :method => :put, :remote => true, :id => 'edit_profile' do
%fieldset
.clearfix
= label_tag 'profile[first_name]', "Your name", :class => "bootstrapped"
@ -47,7 +47,6 @@
.clearfix
= label_tag :your_photo, "Your photo", :class => "bootstrapped"
.input{:style => "position:relative;"}
= render 'photos/new_profile_photo', :aspect => :getting_started, :person => current_user.person
%br
%br
@ -60,6 +59,8 @@
.row
%p
= t('.hashtag_explanation')
%i
= t('.hashtag_suggestions')
.row
.span13

View file

@ -163,6 +163,10 @@ en:
no_contacts: "No contacts"
post_a_message: "post a message >>"
people_sharing_with_you: "People sharing with you"
welcome_to_diaspora: "Welcome to Diaspora, %{name}!"
time_to_introduce_yourself: "Time to introduce yourself."
help:
need_help: "Need Help?"
here_to_help: "The Diaspora community is here!"
@ -237,7 +241,7 @@ en:
sharing:
people_sharing: "People sharing with you:"
index:
add_to_aspect: "Add contacts to %{name}"
add_to_aspect: "add contacts to %{name}"
start_a_conversation: "Start a conversation"
add_a_new_aspect: "Add a new aspect"
title: "Contacts"
@ -613,7 +617,9 @@ en:
your_gender: "Your gender"
your_birthday: "Your birthday"
your_tags: "Describe yourself in 5 words"
your_tags_placeholder: "like #movies #kittens #travel #teacher #newyork"
your_bio: "Your bio"
your_location: "Your location"
your_photo: "Your photo"
@ -916,6 +922,7 @@ en:
what_are_you_in_to: "What are you into?"
hashtag_explanation: "Hashtags allow you to talk about and follow your interests. They're also a great way to find new people on Diaspora."
hashtag_suggestions: "Try following tags like #art, #movies, #gif, etc."
saved: "Saved!"

View file

@ -10,7 +10,7 @@ Feature: invitation acceptance
| user_password_confirmation | secret |
And I press "Create my account"
Then I should be on the getting started page
And I should see "Welcome"
And I should see "Well, hello there!"
And I fill in the following:
| profile_first_name | O |
@ -27,7 +27,7 @@ Feature: invitation acceptance
| user_password_confirmation | secret |
And I press "Create my account"
Then I should be on the getting started page
And I should see "Welcome"
And I should see "Well, hello there!"
And I fill in the following:
| profile_first_name | O |

View file

@ -24,7 +24,7 @@ Feature: User manages contacts
And I have an aspect called "People"
When I am on the contacts page
And I follow "People"
And I follow "Add contacts to People"
And I follow "add contacts to People"
And I wait for the ajax to finish
And I preemptively confirm the alert
And I press "Delete" in the modal window
@ -48,7 +48,7 @@ Feature: User manages contacts
And I have an aspect called "Cat People"
When I am on the contacts page
And I follow "Cat People"
And I follow "Add contacts to Cat People"
And I follow "add contacts to Cat People"
And I wait for the ajax to finish
And I press the first ".contact_list .button"
And I wait for the ajax to finish

View file

@ -9,7 +9,7 @@ Feature: new user registration
And I fill in "user_password_confirmation" with "secret"
And I press "Create my account"
Then I should be on the getting started page
And I should see "Welcome"
And I should see "Well, hello there!"
And I should see "Who are you?"
And I should see "What are you into?"
@ -18,7 +18,7 @@ Feature: new user registration
| profile_first_name | O |
And I follow "awesome_button"
Then I should be on the aspects page
Then I should be on the multi page
And I should not see "awesome_button"
Scenario: new user skips the setup wizard

View file

@ -30,7 +30,7 @@ Feature: Unfollowing
And I click on my name in the header
And I follow "Contacts"
And I follow "Besties"
And I follow "Add contacts to Besties"
And I follow "add contacts to Besties"
And I wait for the ajax to finish
And I preemptively confirm the alert

View file

@ -1,12 +1,14 @@
require File.join(Rails.root, "lib", "publisher")
class Stream::Base
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
attr_accessor :max_time, :order, :user
attr_accessor :max_time, :order, :user, :publisher
def initialize(user, opts={})
self.user = user
self.max_time = opts[:max_time]
self.order = opts[:order]
self.publisher = Publisher.new(self.user, publisher_opts)
end
# @return [Person]
@ -76,7 +78,6 @@ class Stream::Base
true
end
#NOTE: MBS bad bad methods the fact we need these means our views are foobared. please kill them and make them
#private methods on the streams that need them
def aspects
@ -87,7 +88,7 @@ class Stream::Base
def aspect
aspects.first
end
def aspect_ids
aspects.map{|x| x.id}
end
@ -102,12 +103,11 @@ class Stream::Base
@order ||= 'created_at'
end
# @return [Publisher]
def publisher
@publisher ||= Publisher.new(self.user)
end
private
# @return [Hash]
def publisher_opts
{}
end
# Memoizes all Contacts present in the Stream
#

View file

@ -36,17 +36,15 @@ class Stream::Multi < Stream::Base
end.compact
end
# @return [Publisher]
def publisher
private
def publisher_opts
if welcome?
@publisher ||= Publisher.new(self.user, :open => true, :prefill => publisher_prefill,
:public => true)
{:open => true, :prefill => publisher_prefill, :public => true}
else
super
end
end
private
# Generates the prefill for the publisher
#
# @return [String]

View file

@ -5,10 +5,10 @@
class Stream::Tag < Stream::Base
attr_accessor :tag_name, :people_page
def initialize(user, tag_name, opts={})
super(user, opts)
def initialize(user, tag_name, opts={})
self.tag_name = tag_name
@people_page = opts[:page] || 1
self.people_page = opts[:page] || 1
super(user, opts)
end
def tag
@ -39,11 +39,11 @@ class Stream::Tag < Stream::Base
@tag_name = tag_name.downcase.gsub('#', '')
end
def publisher
@publisher ||= Publisher.new(self.user, :prefill => "#{display_tag_name} ")
end
private
# @return [Hash]
def publisher_opts
{:prefill => "#{display_tag_name} "}
end
def construct_post_query
posts = StatusMessage

View file

@ -3394,8 +3394,7 @@ a.toggle_selector
#welcome-to-diaspora
:-webkit-box-shadow inset 0 -2px 10px rgba(0,0,0,0.35)
:-moz-box-shadow inset 0 -2px 10px rgba(0,0,0,0.35)
:position absolute
:width 100%
@ -3410,4 +3409,4 @@ a.toggle_selector
#gs-shim
:position absolute
:top 340px
:top 380px

View file

@ -12,22 +12,6 @@ describe GettingStartedHelper do
@current_user
end
describe "#has_completed_profile?" do
it 'returns true if the current user has filled out all 7 suggested fields (from getting started)' do
profile = @current_user.person.profile
profile.update_attributes!(
{:first_name => "alice", :last_name => "smith", :image_url => "abcd.jpg", :birthday => Time.now,
:gender => "cow", :location => "san fran", :tag_string => "#sup", :bio => "holler" })
has_completed_profile?.should be_true
end
it 'returns false if the current user has not filled out all 7 suggested fields (from getting started)' do
@current_user.update_attributes(:person => {:profile =>
{:first_name => nil, :last_name => nil, :birthday => nil, :gender => nil }})
has_completed_profile?.should be_false
end
end
describe "#has_connected_services?" do
before do
AppConfig[:configured_services] = ['fake_service']
@ -102,19 +86,4 @@ describe GettingStartedHelper do
has_completed_getting_started?.should be_false
end
end
describe "#welcome_text" do
it 'returns "Welcome" without a name if first_name is not set' do
profile = @current_user.person.profile
profile.first_name = ""
profile.save
@current_user.person.instance_variable_set(:@first_name, nil)
welcome_text.should == "Welcome!"
end
it 'returns "Welcome, {first_name}" if first_name is set' do
welcome_text.should == "Welcome, #{current_user.first_name}!"
end
end
end

View file

@ -172,67 +172,4 @@ describe Stream::Aspect do
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 file

@ -18,4 +18,54 @@ describe Stream::Multi do
@stream.send(:is_in?, :aspects, p).should be_true
end
end
describe '#publisher_opts' do
it 'prefills, sets public, and autoexpands if welcome? is set' do
prefill_text = "sup?"
@stream.stub(:welcome?).and_return(true)
@stream.stub(:publisher_prefill).and_return(prefill_text)
@stream.send(:publisher_opts).should == {:open => true,
:prefill => prefill_text,
:public => true}
end
it 'provides no opts if welcome? is not set' do
prefill_text = "sup?"
@stream.stub(:welcome?).and_return(false)
@stream.send(:publisher_opts).should == {}
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::Multi.new(alice)
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
before do
@stream = Stream::Multi.new(alice)
end
it 'returns true if user is getting started' do
alice.getting_started = true
@stream.send(:welcome?).should be_true
end
it 'returns false if user is getting started' do
alice.getting_started = false
@stream.send(:welcome?).should be_false
end
end
end

View file

@ -94,9 +94,8 @@ describe Stream::Tag do
describe "#publisher" do
it 'creates a publisher with the tag prefill' do
Publisher.should_receive(:new).with(anything(), hash_including(:prefill => "#what "))
Publisher.should_receive(:new).with(anything(), {:prefill => "#what "})
@stream = Stream::Tag.new(alice, "what")
@stream.publisher
end
end
end

View file

@ -271,6 +271,18 @@ describe Person do
end
end
describe "#first_name" do
it 'returns username if first_name is not present in profile' do
alice.person.profile.update_attributes(:first_name => "")
alice.person.first_name.should == alice.username
end
it 'returns first word in first_name if first_name is present' do
alice.person.profile.update_attributes(:first_name => "Alice Smith")
alice.person.first_name.should == "Alice"
end
end
describe '.search' do
before do
Person.delete_all

View file

@ -15,6 +15,10 @@ describe 'Streams' do
@stream.people.should_not be_nil
end
it '#publisher_opts' do
@stream.send(:publisher_opts).should_not be_nil
end
it 'has a #contacts title' do
@stream.contacts_title.should_not be_nil
end