From f7abaab2763afd4574da1007fd1b2ebcef521aaf Mon Sep 17 00:00:00 2001 From: John Drummond Date: Sat, 25 Jun 2011 23:19:30 -0700 Subject: [PATCH 1/2] Issue 1049 fixed by pre-processing params[:profile][:tags_string] and adding # when required --- app/controllers/profiles_controller.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 25aa1f3bb..f2b97ac6b 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -20,7 +20,15 @@ class ProfilesController < ApplicationController def update # upload and set new profile photo params[:profile] ||= {} - params[:tags] << params[:profile][:tag_string] unless params[:profile][:tag_string].nil? + unless params[:profile][:tag_string].nil? + params[:profile][:tag_string].split( " " ).each do |extra_tag| + extra_tag.strip! + unless extra_tag == "" + extra_tag = "##{extra_tag}" unless extra_tag.start_with?( "#" ) + params[:tags] += ",##{extra_tag}" + end + end + end params[:profile][:tag_string] = (params[:tags]) ? params[:tags].gsub(',',' ') : "" params[:profile][:searchable] ||= false params[:profile][:photo] = Photo.where(:author_id => current_user.person.id, From cc6f82fbc1bd88f1804f94e4bc48c49286a93253 Mon Sep 17 00:00:00 2001 From: John Drummond Date: Sat, 25 Jun 2011 23:37:51 -0700 Subject: [PATCH 2/2] Added test for new plantext tag without a # symbol and fixed broken code. --- app/controllers/profiles_controller.rb | 2 +- spec/controllers/profiles_controller_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index f2b97ac6b..a7b10d7c6 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -25,7 +25,7 @@ class ProfilesController < ApplicationController extra_tag.strip! unless extra_tag == "" extra_tag = "##{extra_tag}" unless extra_tag.start_with?( "#" ) - params[:tags] += ",##{extra_tag}" + params[:tags] += " #{extra_tag}" end end end diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index 4d760e3f8..4f40af60c 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -59,6 +59,15 @@ describe ProfilesController do @user.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'pears'].to_set end + it 'sets plaintext tags without #' do + params = { :id => @user.person.id, + :tags => ',#apples,#oranges,', + :profile => {:tag_string => 'bananas'} } + + put :update, params + @user.person(true).profile.tag_list.to_set.should == ['apples', 'oranges', 'bananas'].to_set + end + context 'with a profile photo set' do before do @params = { :id => @user.person.id,