diff --git a/app/models/profile.rb b/app/models/profile.rb
index c3d196843..56a8ee28e 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -101,6 +101,10 @@ class Profile < ActiveRecord::Base
end
end
+ def tag_string
+ @tag_string || self.tags.map{|t| '#' << t.to_s }.join(' ')
+ end
+
protected
def strip_names
diff --git a/app/models/user.rb b/app/models/user.rb
index cc9ec2609..eaacca3ae 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -204,6 +204,11 @@ class User < ActiveRecord::Base
params[:image_url_medium] = photo.url(:thumb_medium)
params[:image_url_small] = photo.url(:thumb_small)
end
+ if tag_string = params.delete(:tags)
+ self.person.profile.tag_string = tag_string
+ self.person.profile.build_tags
+ self.person.profile.save
+ end
if self.person.profile.update_attributes(params)
Postzord::Dispatch.new(self, profile).post
true
diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml
index 7643365b9..8e4e84f01 100644
--- a/app/views/people/_profile_sidebar.html.haml
+++ b/app/views/people/_profile_sidebar.html.haml
@@ -37,8 +37,15 @@
-if user_signed_in? && ((contact.persisted? && !contact.pending?) || person == current_user.person || @incoming_request)
%ul#profile_information
- %li
- - unless person.profile.bio.blank?
+ - unless person.profile.tags.blank?
+ %li
+ %h4
+ tags
+ = person.profile.format_tags(person.profile.tag_string)
+
+
+ - unless person.profile.bio.blank?
+ %li
%h4
=t('.bio')
= markdownify(person.profile.bio, :newlines => true)
diff --git a/app/views/profiles/_edit.html.haml b/app/views/profiles/_edit.html.haml
index c7d9f1f39..909b0d29c 100644
--- a/app/views/profiles/_edit.html.haml
+++ b/app/views/profiles/_edit.html.haml
@@ -31,7 +31,7 @@
%h4
= t('profiles.edit.your_tags')
- = text_field_tag 'profile[tags]', profile.tags, :placeholder => t('.your_tags_placeholder')
+ = text_field_tag 'profile[tags]', profile.tag_string, :placeholder => t('.your_tags_placeholder')
%h4
= t('profiles.edit.your_bio')
diff --git a/lib/diaspora/taggable.rb b/lib/diaspora/taggable.rb
index cf5c955d2..999da53be 100644
--- a/lib/diaspora/taggable.rb
+++ b/lib/diaspora/taggable.rb
@@ -6,16 +6,14 @@ module Diaspora
module Taggable
def self.included(model)
model.class_eval do
-
- cattr_reader :field_with_tags
-
- def self.extract_tags_from sym
- puts "extract_tags_from"
- pp self
- @field_with_tags = sym
+ cattr_accessor :field_with_tags
+ end
+ model.instance_eval do
+ def extract_tags_from sym
+ self.field_with_tags = sym
end
- def self.field_with_tags_setter
- @field_with_tags_setter = "#{@field_with_tags}=".to_sym
+ def field_with_tags_setter
+ "#{self.field_with_tags}=".to_sym
end
end
end
@@ -26,8 +24,6 @@ module Diaspora
def tag_strings
regex = /(?:^|\s)#(\w+)/
- puts "tag strings"
- pp self
matches = self.send(self.class.field_with_tags).scan(regex).map do |match|
match.last
end
@@ -42,9 +38,9 @@ module Diaspora
return text if opts[:plain_text]
regex = /(^|\s)#(\w+)/
form_message = text.gsub(regex) do |matched_string|
- "#{$~[1]}##{ERB::Util.h($~[2])}"
+ "#{$~[1]}##{$~[2]}"
end
- form_message
+ form_message.html_safe
end
end
end
diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb
index 2fae00b1e..241170215 100644
--- a/spec/controllers/profiles_controller_spec.rb
+++ b/spec/controllers/profiles_controller_spec.rb
@@ -50,7 +50,7 @@ describe ProfilesController do
{ :tags => '#apples #oranges'}}
put :update, params
- @user.person(true).profile.tags.should =~ ['apples', 'oranges']
+ @user.person(true).profile.tag_list.to_set.should == ['apples', 'oranges'].to_set
end
context 'with a profile photo set' do
diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb
index 372a98694..0e70e8991 100644
--- a/spec/models/profile_spec.rb
+++ b/spec/models/profile_spec.rb
@@ -148,7 +148,8 @@ describe Profile do
describe 'tags' do
before do
- @object = Factory.build(:profile)
+ person = Factory.create(:person)
+ @object = person.profile
end
it_should_behave_like 'it is taggable'
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 3c9f9f82d..836b32d27 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -253,6 +253,13 @@ describe User do
:last_name => 'billytown',
}
end
+ it 'dispatches the profile when tags are set' do
+ @params = {:tags => '#what #hey'}
+ mailman = Postzord::Dispatch.new(alice, Profile.new)
+ Postzord::Dispatch.should_receive(:new).and_return(mailman)
+ mailman.should_receive(:deliver_to_local)
+ alice.update_profile(@params).should be_true
+ end
it 'sends a profile to their contacts' do
mailman = Postzord::Dispatch.new(alice, Profile.new)
Postzord::Dispatch.should_receive(:new).and_return(mailman)
diff --git a/spec/shared_behaviors/taggable.rb b/spec/shared_behaviors/taggable.rb
index 9c7248fd5..c1b48a9b1 100644
--- a/spec/shared_behaviors/taggable.rb
+++ b/spec/shared_behaviors/taggable.rb
@@ -6,13 +6,17 @@ require 'spec_helper'
describe Diaspora::Taggable do
shared_examples_for "it is taggable" do
+ include ActionView::Helpers::UrlHelper
+ include Rails.application.routes.url_helpers
+ def controller
+ end
+
describe '#format_tags' do
before do
@str = '#what #hey'
@object.send(@object.class.field_with_tags_setter, @str)
@object.build_tags
- @object.save
- @object.reload
+ @object.save!
end
it 'links the tag to /p' do
link = link_to('#what', posts_path(:tag => 'what'), :class => 'tag')