Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request mbleigh#743 from emerson-h/master
Browse files Browse the repository at this point in the history
Remove existing selects from relation
  • Loading branch information
seuros authored Jul 1, 2016
2 parents 12e9968 + 26fd98d commit 33052d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/acts_as_taggable_on/taggable/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def generate_tagging_scope_in_clause(tagging_scope, table_name, primary_key)
scoped_ids = pluck(table_name_pkey)
tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN (?)", scoped_ids)
else
tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{safe_to_sql(select(table_name_pkey))})")
tagging_scope = tagging_scope.where("#{ActsAsTaggableOn::Tagging.table_name}.taggable_id IN(#{safe_to_sql(except(:select).select(table_name_pkey))})")
end

tagging_scope
Expand Down
15 changes: 15 additions & 0 deletions spec/acts_as_taggable_on/taggable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@
expect(@taggable.tag_counts_on(:tags).length).to eq(2)
end

context 'tag_counts on a collection' do
context 'a select clause is specified on the collection' do
it 'should return tag counts without raising an error' do
expect(TaggableModel.tag_counts_on(:tags)).to be_empty

@taggable.tag_list = %w(awesome epic)
@taggable.save

expect {
expect(TaggableModel.select(:name).tag_counts_on(:tags).length).to eq(2)
}.not_to raise_error
end
end
end

it 'should have tags_on' do
expect(TaggableModel.tags_on(:tags)).to be_empty

Expand Down

0 comments on commit 33052d9

Please sign in to comment.