From d2e26f6937c435e682029d2de1d25419e2000f1e Mon Sep 17 00:00:00 2001
From: danielgrippi <danielgrippi@gmail.com>
Date: Thu, 7 Jul 2011 13:39:15 -0700
Subject: [PATCH] Revert "Merge branch 'hashtags-in-comments'"

This reverts commit f85d5ad6d46d1b89a2647c57b91e4ae648d696ab, reversing
changes made to b8d70393f4a54f4bfbf20b32a41f2fcdd15438c7.
---
 app/controllers/tags_controller.rb       | 15 ++++-----------
 app/models/comment.rb                    |  5 -----
 app/models/status_message.rb             |  2 +-
 app/views/comments/_comment.html.haml    |  2 +-
 app/views/people/_person.html.haml       |  2 +-
 app/views/people/contacts.haml           |  2 +-
 app/views/people/show.html.haml          |  2 +-
 lib/diaspora/taggable.rb                 |  2 +-
 spec/controllers/tags_controller_spec.rb | 14 --------------
 spec/models/comment_spec.rb              |  7 -------
 spec/shared_behaviors/taggable.rb        |  6 +++---
 11 files changed, 13 insertions(+), 46 deletions(-)

diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 9aa9616d90..5bf799cfe8 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -56,18 +56,11 @@ class TagsController < ApplicationController
       @posts = StatusMessage.where(:public => true, :pending => false)
     end
 
-    @tag = ActsAsTaggableOn::Tag.where(:name => params[:name]).first
-    if @tag
-      @posts = @posts.joins("LEFT OUTER JOIN comments ON comments.post_id = posts.id").
-                      joins("INNER JOIN taggings ON (taggings.tag_id = #{@tag.id} AND 
-                             ((taggable_id = posts.id AND taggable_type = 'Post') OR (taggings.taggable_type = 'Comment' AND taggings.taggable_id = comments.id)))")
+    @posts = @posts.tagged_with(params[:name])
 
-      max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
-      @posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time))
-      @posts = @posts.includes({:comments => {:author => :profile}}, :photos).order('posts.created_at DESC').limit(15)
-    else
-      @posts = []
-    end
+    max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
+    @posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time))
+    @posts = @posts.includes({:comments => {:author => :profile}}, :photos).order('posts.created_at DESC').limit(15)
 
     @posts = PostsFake.new(@posts)
     @commenting_disabled = true
diff --git a/app/models/comment.rb b/app/models/comment.rb
index fd416b370d..f0d829dd4a 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -13,11 +13,6 @@ class Comment < ActiveRecord::Base
   include Diaspora::Relayable
 
   include Diaspora::Socketable
-  include Diaspora::Taggable
-
-  acts_as_taggable_on :tags
-  extract_tags_from :text
-  before_create :build_tags
 
   xml_attr :text
   xml_attr :diaspora_handle
diff --git a/app/models/status_message.rb b/app/models/status_message.rb
index d037ec7d7f..a5aed41b34 100644
--- a/app/models/status_message.rb
+++ b/app/models/status_message.rb
@@ -43,7 +43,7 @@ class StatusMessage < Post
 
     escaped_message = opts[:plain_text] ? self.raw_message: ERB::Util.h(self.raw_message)
     mentioned_message = self.format_mentions(escaped_message, opts)
-    Diaspora::Taggable.format_tags(mentioned_message, opts)
+    self.format_tags(mentioned_message, opts)
   end
 
   def format_mentions(text, opts = {})
diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml
index 19e54da98c..0809a407b0 100644
--- a/app/views/comments/_comment.html.haml
+++ b/app/views/comments/_comment.html.haml
@@ -12,7 +12,7 @@
       = person_link(comment.author, :class => "hovercardable")
 
     %span{:class => direction_for(comment.text)}
-      = markdownify(Diaspora::Taggable.format_tags(comment.text), :youtube_maps => comment.youtube_titles)
+      = markdownify(comment.text, :youtube_maps => comment.youtube_titles)
 
       %br
       %time.timeago{:datetime => comment.created_at}
diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml
index fb8e759aea..b01b479dff 100644
--- a/app/views/people/_person.html.haml
+++ b/app/views/people/_person.html.haml
@@ -15,5 +15,5 @@
       =person_link(person)
 
     .info
-      = Diaspora::Taggable.format_tags(person.profile.tag_string)
+      = person.profile.format_tags(person.profile.tag_string)
 
diff --git a/app/views/people/contacts.haml b/app/views/people/contacts.haml
index d3a8b47b22..0c704398da 100644
--- a/app/views/people/contacts.haml
+++ b/app/views/people/contacts.haml
@@ -47,7 +47,7 @@
         = @person.diaspora_handle
       .description
         - if !@person.profile.tag_string.blank?
-          = Diapsora::Taggable.format_tags(@person.profile.tag_string)
+          = @person.profile.format_tags(@person.profile.tag_string)
           - if user_signed_in? && @person == current_user.person
             %span.hover_edit
               = link_to t('people.show.edit'), edit_profile_path
diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml
index 32e429da4b..f163c814d8 100644
--- a/app/views/people/show.html.haml
+++ b/app/views/people/show.html.haml
@@ -38,7 +38,7 @@
 
         .description
           - if !@person.profile.tag_string.blank? && user_signed_in? && (@contact.persisted? || @person == current_user.person || @incoming_request)
-            = Diaspora::Taggable.format_tags(@person.profile.tag_string)
+            = @person.profile.format_tags(@person.profile.tag_string)
             - if user_signed_in? && @person == current_user.person
               %span.hover_edit
                 = link_to t('.edit'), edit_profile_path
diff --git a/lib/diaspora/taggable.rb b/lib/diaspora/taggable.rb
index 7c3ab66bd2..2eff354428 100644
--- a/lib/diaspora/taggable.rb
+++ b/lib/diaspora/taggable.rb
@@ -36,7 +36,7 @@ module Diaspora
       unique_matches.values
     end
 
-    def self.format_tags(text, opts={})
+    def format_tags(text, opts={})
       return text if opts[:plain_text]
       regex = /(^|\s)#(#{VALID_TAG_BODY})/
       form_message = text.gsub(regex) do |matched_string|
diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb
index c412313d01..34d892e5f2 100644
--- a/spec/controllers/tags_controller_spec.rb
+++ b/spec/controllers/tags_controller_spec.rb
@@ -69,20 +69,6 @@ describe TagsController do
         get :show, :name => 'hello'
         assigns(:posts).models.should == [stranger_post]
       end
-
-      it 'displays a post with a comment containing the tag search' do
-        bob.post(:status_message, :text => "other post y'all", :to => 'all')
-        other_post = bob.post(:status_message, :text => "sup y'all", :to => 'all')
-        Factory(:comment, :text => "#hello", :post => other_post)
-        get :show, :name => 'hello'
-        assigns(:posts).models.should == [other_post]
-        response.status.should == 200
-      end
-
-      it 'succeeds without posts' do
-        get :show, :name => 'hellyes'
-        response.status.should == 200
-      end
     end
 
     context "not signed in" do
diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb
index f815a2c644..74f6d78714 100644
--- a/spec/models/comment_spec.rb
+++ b/spec/models/comment_spec.rb
@@ -126,11 +126,4 @@ describe Comment do
     it_should_behave_like 'it is relayable'
   end
 
-  describe 'tags' do
-    before do
-      @object = Factory.build(:comment)
-    end
-    it_should_behave_like 'it is taggable'
-  end
-
 end
diff --git a/spec/shared_behaviors/taggable.rb b/spec/shared_behaviors/taggable.rb
index cb47fe0386..0b1bd95f0e 100644
--- a/spec/shared_behaviors/taggable.rb
+++ b/spec/shared_behaviors/taggable.rb
@@ -12,7 +12,7 @@ describe Diaspora::Taggable do
     def controller
     end
 
-    describe '.format_tags' do
+    describe '#format_tags' do
       before do
         @str = '#what #hey #vöglein'
         @object.send(@object.class.field_with_tags_setter, @str)
@@ -21,10 +21,10 @@ describe Diaspora::Taggable do
       end
       it 'links the tag to /p' do
         link = link_to('#vöglein', '/tags/vöglein', :class => 'tag')
-        Diaspora::Taggable.format_tags(@str).should include(link)
+        @object.format_tags(@str).should include(link)
       end
       it 'responds to plain_text' do
-        Diaspora::Taggable.format_tags(@str, :plain_text => true).should == @str
+        @object.format_tags(@str, :plain_text => true).should == @str
       end
     end
     describe '#build_tags' do
-- 
GitLab