From 05b1e2fc1960b1fdfe4f047555a39aa8eb796e5a Mon Sep 17 00:00:00 2001 From: Pistos Date: Sun, 13 Nov 2011 23:26:53 -0500 Subject: [PATCH] Fixed issue #2380 : No more 500 error when following an unnormalized version of an existing tag. e.g. if "test" exists and you try to follow "Test". --- app/models/acts_as_taggable_on/tag.rb | 2 +- .../tag_followings_controller_spec.rb | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/models/acts_as_taggable_on/tag.rb b/app/models/acts_as_taggable_on/tag.rb index 3eef9409c..1806262e7 100644 --- a/app/models/acts_as_taggable_on/tag.rb +++ b/app/models/acts_as_taggable_on/tag.rb @@ -17,7 +17,7 @@ class ActsAsTaggableOn::Tag # Special case for love, because the world needs more love. '<3' elsif name - name.gsub(/[^#{self.tag_text_regexp}]/, '') + name.gsub(/[^#{self.tag_text_regexp}]/, '').downcase end end end diff --git a/spec/controllers/tag_followings_controller_spec.rb b/spec/controllers/tag_followings_controller_spec.rb index 053c96916..bba65238f 100644 --- a/spec/controllers/tag_followings_controller_spec.rb +++ b/spec/controllers/tag_followings_controller_spec.rb @@ -33,17 +33,20 @@ describe TagFollowingsController do it "creates a new TagFollowing" do expect { post :create, valid_attributes + response.should be_redirect }.to change(TagFollowing, :count).by(1) end it "associates the tag following with the currently-signed-in user" do expect { post :create, valid_attributes + response.should be_redirect }.to change(bob.tag_followings, :count).by(1) end it "assigns a newly created tag_following as @tag_following" do post :create, valid_attributes + response.should be_redirect assigns(:tag_following).should be_a(TagFollowing) assigns(:tag_following).should be_persisted end @@ -67,32 +70,48 @@ describe TagFollowingsController do end it 'squashes the tag' do + ActsAsTaggableOn::Tag.find_by_name('somestuff').should be_nil post :create, :name => "some stuff" assigns[:tag].name.should == "somestuff" + ActsAsTaggableOn::Tag.find_by_name('somestuff').should_not be_nil end it 'downcases the tag name' do + ActsAsTaggableOn::Tag.find_by_name('somestuff').should be_nil post :create, :name => "SOMESTUFF" + response.should be_redirect assigns[:tag].name.should == "somestuff" + ActsAsTaggableOn::Tag.find_by_name('somestuff').should_not be_nil end it "normalizes the tag name" do + ActsAsTaggableOn::Tag.find_by_name('foobar').should be_nil post :create, :name => "foo:bar" assigns[:tag].name.should == "foobar" + ActsAsTaggableOn::Tag.find_by_name('foobar').should_not be_nil end end describe 'fails to' do - it "create the tag IFF already exists" do + it "create the tag if it already exists" do ActsAsTaggableOn::Tag.find_by_name('tomcruisecontrol').should be_nil expect { post :create, :name => "tomcruisecontrol" }.to change(ActsAsTaggableOn::Tag, :count).by(1) - ActsAsTaggableOn::Tag.find_by_name('tomcruisecontrol').should_not be_nil + expect { post :create, :name => "tomcruisecontrol" }.to change(ActsAsTaggableOn::Tag, :count).by(0) + expect { + post :create, :name => "tom cruise control" + }.to change(ActsAsTaggableOn::Tag, :count).by(0) + expect { + post :create, :name => "TomCruiseControl" + }.to change(ActsAsTaggableOn::Tag, :count).by(0) + expect { + post :create, :name => "tom:cruise:control" + }.to change(ActsAsTaggableOn::Tag, :count).by(0) end it "create a tag following for a user other than the currently signed in user" do