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#417 from okgrow/fix-group-by
Browse files Browse the repository at this point in the history
Fix: Let '.count' work when tagged_with is accompanied by a group clause
  • Loading branch information
seuros committed Jan 27, 2014
2 parents ad6b492 + d0255fd commit 18c8b32
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch.
* [@rafael #406 Dirty attributes not correctly derived](https://github.com/mbleigh/acts-as-taggable-on/pull/406)
* [@bzbnhang #440 Did not respect strict_case_match](https://github.com/mbleigh/acts-as-taggable-on/pull/440)
* [@znz #456 Fix breaking encoding of tag](https://github.com/mbleigh/acts-as-taggable-on/pull/456)
* [@rgould #417 Let '.count' work when tagged_with is accompanied by a group clause](https://github.com/mbleigh/acts-as-taggable-on/pull/417)
* Misc
* [@billychan #463 Thread safe support](https://github.com/mbleigh/acts-as-taggable-on/pull/463)
* [@billychan #386 Add parse:true instructions to README](https://github.com/mbleigh/acts-as-taggable-on/pull/386)
Expand Down
1 change: 1 addition & 0 deletions lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def tagged_with(tags, options = {})
end
end

group = [] # Rails interprets this as a no-op in the group() call below
if options.delete(:order_by_matching_tag_count)
select_clause = "#{table_name}.*, COUNT(#{taggings_alias}.tag_id) AS #{taggings_alias}_count"
group_columns = ActsAsTaggableOn::Tag.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}"
Expand Down
7 changes: 7 additions & 0 deletions spec/acts_as_taggable_on/taggable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@
TaggableModel.tagged_with("ruby").first.should == @taggable
end

it "should be able to get a count with find by tag when using a group by" do
@taggable.skill_list = "ruby"
@taggable.save

expect(TaggableModel.tagged_with("ruby").group(:created_at).count.count).to eq(1)
end

it "should be able to find by tag with context" do
@taggable.skill_list = "ruby, rails, css"
@taggable.tag_list = "bob, charlie"
Expand Down

0 comments on commit 18c8b32

Please sign in to comment.