diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index fc47ca9..0292a08 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -227,7 +227,7 @@ class SearchController < PublicController def tag @tag = environment.tags.find_by_name(params[:tag]) - @tagged = @tag.taggings.map(&:taggable) + @tagged = environment.articles.find_tagged_with(@tag) end ####################################################### diff --git a/app/models/article.rb b/app/models/article.rb index ccb274c..9e2495e 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -276,6 +276,10 @@ class Article < ActiveRecord::Base $1 end + def self.find_tagged_with(tag) + self.find(:all, :include => :taggings, :conditions => ['taggings.tag_id = ?', tag.id]) + end + private def sanitize_tag_list diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 84340b4..8e17434 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -721,4 +721,24 @@ class ArticleTest < Test::Unit::TestCase assert !a.highlighted end + should 'get tagged with tag' do + a = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') + t = a.tags[0] + as = Article.find_tagged_with(t) + + assert_includes as, a + end + + should 'not get tagged with tag from other environment' do + a1 = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') + e = Environment.create!(:name => 'other env') + p = create_user('other_user', :environment => e).person + a2 = Article.create!(:name => 'Published at', :profile => p, :tag_list => 'bli') + t = a2.tags[0] + as = e.articles.find_tagged_with(t) + + assert_includes as, a2 + assert_not_includes as, a1 + end + end -- libgit2 0.21.2