From 47f7e1086039e31337fa8345d8311ddc7fc38a64 Mon Sep 17 00:00:00 2001 From: Diaspora Europe Date: Wed, 8 Feb 2012 18:36:58 +0100 Subject: [PATCH 1/2] tags should be case insensitive --- app/controllers/tags_controller.rb | 2 +- spec/controllers/tags_controller_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 8128c03d2..c5a679393 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -41,7 +41,7 @@ class TagsController < ApplicationController def tag_followed? if @tag_followed.nil? - @tag_followed = TagFollowing.joins(:tag).where(:tags => {:name => params[:name]}, :user_id => current_user.id).exists? + @tag_followed = TagFollowing.joins(:tag).where(:tags => {:name => params[:name].downcase}, :user_id => current_user.id).exists? end @tag_followed end diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index fcce6b312..b08a8602d 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -76,10 +76,10 @@ describe TagsController do sign_in bob @tag = ActsAsTaggableOn::Tag.create!(:name => "partytimeexcellent") @controller.stub(:current_user).and_return(bob) - @controller.stub(:params).and_return({:name => "partytimeexcellent"}) + @controller.stub(:params).and_return({:name => "PARTYTIMEexcellent"}) end - it 'returns true if the following already exists' do + it 'returns true if the following already exists and should be case insensitive' do TagFollowing.create!(:tag => @tag, :user => bob ) @controller.tag_followed?.should be_true end From 8eda9aaf52286b38efc80f3a91fc8bb8adb5ac4e Mon Sep 17 00:00:00 2001 From: Diaspora Europe Date: Thu, 9 Feb 2012 14:16:57 +0100 Subject: [PATCH 2/2] added user_is_following method, added 2 model specs --- app/controllers/tags_controller.rb | 5 +---- app/models/tag_following.rb | 5 +++++ spec/models/tag_following_spec.rb | 9 +++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index c5a679393..091e14be8 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -40,10 +40,7 @@ class TagsController < ApplicationController end def tag_followed? - if @tag_followed.nil? - @tag_followed = TagFollowing.joins(:tag).where(:tags => {:name => params[:name].downcase}, :user_id => current_user.id).exists? - end - @tag_followed + TagFollowing.user_is_following?(current_user, params[:name]) end def prep_tags_for_javascript diff --git a/app/models/tag_following.rb b/app/models/tag_following.rb index 6fd07c0ef..8705f185f 100644 --- a/app/models/tag_following.rb +++ b/app/models/tag_following.rb @@ -3,4 +3,9 @@ class TagFollowing < ActiveRecord::Base belongs_to :tag, :class_name => "ActsAsTaggableOn::Tag" validates_uniqueness_of :tag_id, :scope => :user_id + + def self.user_is_following?(user, tagname) + tagname.nil? ? false : joins(:tag).where(:tags => {:name => tagname.downcase}, :user_id => user.id).exists? + end + end diff --git a/spec/models/tag_following_spec.rb b/spec/models/tag_following_spec.rb index 71163c680..a5dada8ac 100644 --- a/spec/models/tag_following_spec.rb +++ b/spec/models/tag_following_spec.rb @@ -13,4 +13,13 @@ describe TagFollowing do it 'allows multiple tag followings for different users' do TagFollowing.new(:tag => @tag, :user => bob).valid?.should be_true end + + it 'user is following a tag' do + TagFollowing.user_is_following?(alice, @tag.name).should be_true + end + + it 'user not following a tag' do + TagFollowing.user_is_following?(bob, @tag.name).should be_false + end + end