From eb65074360238b3adb79de86fd17525ce9ad6e4d Mon Sep 17 00:00:00 2001 From: Johannes Hackel Date: Tue, 22 Nov 2011 12:16:00 +0100 Subject: [PATCH 1/5] Fix Bug 2274, empty tag --- app/controllers/people_controller.rb | 3 +++ app/controllers/tag_followings_controller.rb | 17 +++++++++++------ config/locales/diaspora/en.yml | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 623618ebb..e645ecb14 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -22,6 +22,9 @@ class PeopleController < ApplicationController if (params[:q][0] == 35 || params[:q][0] == '#') && params[:q].length > 1 redirect_to tag_path(:name => params[:q].gsub(/[#\.]/, ''), :q => params[:q]) return + elsif (params[:q][0] == 35 || params[:q][0] == '#') && params[:q].length == 1 + flash[:error] = I18n.t('tags.show.none', :name => params[:q]) + redirect_to multi_path() end limit = params[:limit] ? params[:limit].to_i : 15 diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index 84c2766b3..c86cbcb92 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -15,13 +15,18 @@ class TagFollowingsController < ApplicationController # POST /tag_followings.xml def create name_normalized = ActsAsTaggableOn::Tag.normalize(params['name']) - @tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized) - @tag_following = current_user.tag_followings.new(:tag_id => @tag.id) - - if @tag_following.save - flash[:notice] = I18n.t('tag_followings.create.success', :name => name_normalized) + + if name_normalized.nil? || name_normalized.empty? + flash[:error] = I18n.t('tag_followings.create.none', :name => name_normalized) else - flash[:error] = I18n.t('tag_followings.create.failure', :name => name_normalized) + @tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized) + @tag_following = current_user.tag_followings.new(:tag_id => @tag.id) + + if @tag_following.save + flash[:notice] = I18n.t('tag_followings.create.success', :name => name_normalized) + else + flash[:error] = I18n.t('tag_followings.create.failure', :name => name_normalized) + end end redirect_to :back diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 56ea705f2..0fb909ebe 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -846,10 +846,12 @@ en: following: "Following #%{tag}" stop_following: "Stop Following #%{tag}" followed_by: 'followed by' + none: "The empty tag don't exists!" tag_followings: create: success: "Hooray! You're now following #%{name}." failure: "Failed to follow #%{name}. Are you already following it?" + none: "You can't follow the empty tag!" destroy: success: "Alas! You aren't following #%{name} anymore." failure: "Failed to stop following #%{name}. Maybe you already stopped following it?" From 66acd7db14378e387dca149aa799d74e0910863d Mon Sep 17 00:00:00 2001 From: Johannes Hackel Date: Tue, 22 Nov 2011 12:54:19 +0100 Subject: [PATCH 2/5] specs, stay on page --- app/controllers/people_controller.rb | 2 +- spec/controllers/people_controller_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index e645ecb14..a23c69735 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -24,7 +24,7 @@ class PeopleController < ApplicationController return elsif (params[:q][0] == 35 || params[:q][0] == '#') && params[:q].length == 1 flash[:error] = I18n.t('tags.show.none', :name => params[:q]) - redirect_to multi_path() + redirect_to :back end limit = params[:limit] ? params[:limit].to_i : 15 diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 62305276a..fb9db299d 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -91,6 +91,10 @@ describe PeopleController do get :index, :q => '#babi.es' response.should redirect_to(tag_path('babies', :q => '#babi.es')) end + + it 'stay on the page if you search for the empty hash' do + get :index, :q => '#' + response.should redirect_to(:back) end describe '#tag_index' do From 0c1be5002d4be1f7ff7cbf4983f2b2ba6200e33d Mon Sep 17 00:00:00 2001 From: Johannes Hackel Date: Wed, 23 Nov 2011 08:00:08 +0100 Subject: [PATCH 3/5] end --- spec/controllers/people_controller_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index fb9db299d..57760971e 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -95,6 +95,7 @@ describe PeopleController do it 'stay on the page if you search for the empty hash' do get :index, :q => '#' response.should redirect_to(:back) + end end describe '#tag_index' do From ef28e8980936160c469b4b306b4e00df9613cc34 Mon Sep 17 00:00:00 2001 From: Johannes Hackel Date: Wed, 23 Nov 2011 23:45:09 +0100 Subject: [PATCH 4/5] people_controller_spec --- app/controllers/tag_followings_controller.rb | 2 +- spec/controllers/people_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index c86cbcb92..4a98720fb 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -17,7 +17,7 @@ class TagFollowingsController < ApplicationController name_normalized = ActsAsTaggableOn::Tag.normalize(params['name']) if name_normalized.nil? || name_normalized.empty? - flash[:error] = I18n.t('tag_followings.create.none', :name => name_normalized) + flash[:error] = I18n.t('tag_followings.create.none') else @tag = ActsAsTaggableOn::Tag.find_or_create_by_name(name_normalized) @tag_following = current_user.tag_followings.new(:tag_id => @tag.id) diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 57760971e..9a646cd66 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -94,7 +94,7 @@ describe PeopleController do it 'stay on the page if you search for the empty hash' do get :index, :q => '#' - response.should redirect_to(:back) + flash[:error].should be_present end end From e16e28a7ebc5a392093a92cff1567c8126cc4f3b Mon Sep 17 00:00:00 2001 From: Johannes Hackel Date: Tue, 29 Nov 2011 08:36:48 +0100 Subject: [PATCH 5/5] better english --- config/locales/diaspora/en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 0fb909ebe..4c7dc18e5 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -846,12 +846,12 @@ en: following: "Following #%{tag}" stop_following: "Stop Following #%{tag}" followed_by: 'followed by' - none: "The empty tag don't exists!" + none: "The empty tag does not exist!" tag_followings: create: success: "Hooray! You're now following #%{name}." failure: "Failed to follow #%{name}. Are you already following it?" - none: "You can't follow the empty tag!" + none: "You cannot follow a blank tag!" destroy: success: "Alas! You aren't following #%{name} anymore." failure: "Failed to stop following #%{name}. Maybe you already stopped following it?"