Skip to content

Commit

Permalink
Fix to content tagging filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
cykod committed Oct 22, 2010
1 parent dba7982 commit f2fdf48
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/models/content_publication.rb
Expand Up @@ -297,9 +297,9 @@ def filter_conditions(options={},form_options={})

tags = (options[:tags]||[]).find_all() { |elm| !elm.blank? }
if tags.length > 0
filter[:conditions] << 'content_tags.id IN (?)'
filter[:conditions] << 'content_tag_tags.content_tag_id IN (?)'
filter[:values] << tags
filter[:joins] << "INNER JOIN content_tags ON (`#{content_model.table_name}`.id = content_tags.id)"
filter[:joins] << "INNER JOIN content_tag_tags ON (`#{content_model.table_name}`.id = content_tag_tags.content_id AND content_tag_tags.content_type = #{content_model.connection.quote(content_model.table_name.classify)})"
end
end

Expand Down
32 changes: 28 additions & 4 deletions spec/models/content_publication_spec.rb
Expand Up @@ -5,7 +5,7 @@

include ContentSpecHelper

reset_domain_tables :content_publications,:content_publication_fields, :content_model_features
reset_domain_tables :content_publications,:content_publication_fields, :content_model_features, :content_tags,:content_tag_tags


before(:all) do
Expand Down Expand Up @@ -175,7 +175,31 @@
end

end





it "should filter items by content tags correctly" do
@cm.update_attributes(:show_tags => true)

@cm.reload
cls = @cm.model_class(true)

@entry0 = cls.create(:string_field => 'a', :text_field => 'Yay!', :tag_names => 'Yes, No, Maybe')
@entry1 = cls.create(:string_field => 'b', :text_field => 'Nay!', :tag_names => 'Yes, Go Go, TaDa')
@entry2 = cls.create(:string_field => 'c', :text_field => 'Yay!', :tag_names => 'Go Go')
@entry3 = cls.create(:string_field => 'd', :text_field => 'Nay!', :tag_names => 'No, Maybe, TaDa')

@publication = @cm.content_publications.create(:name => 'List',:publication_type => 'list',:publication_module => 'content/core_publication')


@tag = ContentTag.find_by_name('Go Go')

@paging, @data = @publication.get_list_data(1, { :tags => [ @tag.id ] } )
@data.length.should == 2 # Should only return first

@data.include?(@entry0).should be_false
@data.include?(@entry1).should be_true
@data.include?(@entry2).should be_true

end

end

0 comments on commit f2fdf48

Please sign in to comment.