Merge pull request #2846 from diasp/2398-fixed-following-tag-button

Tags should be case insensitive
This commit is contained in:
Maxwell Salzberg 2012-02-09 10:12:48 -08:00
commit 16b20905a5
4 changed files with 17 additions and 6 deletions

View file

@ -40,10 +40,7 @@ class TagsController < ApplicationController
end end
def tag_followed? def tag_followed?
if @tag_followed.nil? TagFollowing.user_is_following?(current_user, params[:name])
@tag_followed = TagFollowing.joins(:tag).where(:tags => {:name => params[:name]}, :user_id => current_user.id).exists?
end
@tag_followed
end end
def prep_tags_for_javascript def prep_tags_for_javascript

View file

@ -3,4 +3,9 @@ class TagFollowing < ActiveRecord::Base
belongs_to :tag, :class_name => "ActsAsTaggableOn::Tag" belongs_to :tag, :class_name => "ActsAsTaggableOn::Tag"
validates_uniqueness_of :tag_id, :scope => :user_id 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 end

View file

@ -76,10 +76,10 @@ describe TagsController do
sign_in bob sign_in bob
@tag = ActsAsTaggableOn::Tag.create!(:name => "partytimeexcellent") @tag = ActsAsTaggableOn::Tag.create!(:name => "partytimeexcellent")
@controller.stub(:current_user).and_return(bob) @controller.stub(:current_user).and_return(bob)
@controller.stub(:params).and_return({:name => "partytimeexcellent"}) @controller.stub(:params).and_return({:name => "PARTYTIMEexcellent"})
end 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 ) TagFollowing.create!(:tag => @tag, :user => bob )
@controller.tag_followed?.should be_true @controller.tag_followed?.should be_true
end end

View file

@ -13,4 +13,13 @@ describe TagFollowing do
it 'allows multiple tag followings for different users' do it 'allows multiple tag followings for different users' do
TagFollowing.new(:tag => @tag, :user => bob).valid?.should be_true TagFollowing.new(:tag => @tag, :user => bob).valid?.should be_true
end 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 end