acts-as-taggable-on 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.8
1
+ 1.0.9
@@ -129,6 +129,10 @@ module ActiveRecord
129
129
  Tag.find(:all, find_options_for_tag_counts(options.merge({:on => context.to_s})))
130
130
  end
131
131
 
132
+ def all_tag_counts(options = {})
133
+ Tag.find(:all, find_options_for_tag_counts(options))
134
+ end
135
+
132
136
  def find_options_for_find_tagged_with(tags, options = {})
133
137
  tags = TagList.from(tags)
134
138
 
@@ -228,10 +232,10 @@ module ActiveRecord
228
232
  at_least = sanitize_sql(['COUNT(*) >= ?', options.delete(:at_least)]) if options[:at_least]
229
233
  at_most = sanitize_sql(['COUNT(*) <= ?', options.delete(:at_most)]) if options[:at_most]
230
234
  having = [at_least, at_most].compact.join(' AND ')
231
- group_by = "#{Tag.table_name}.id, #{Tag.table_name}.name HAVING COUNT(*) > 0"
235
+ group_by = "#{Tag.table_name}.id HAVING COUNT(*) > 0"
232
236
  group_by << " AND #{having}" unless having.blank?
233
237
 
234
- { :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",
238
+ { :select => "#{Tag.table_name}.*, COUNT(*) AS count",
235
239
  :joins => joins.join(" "),
236
240
  :conditions => conditions,
237
241
  :group => group_by,
@@ -82,12 +82,30 @@ describe "Taggable" do
82
82
  TaggableModel.skill_counts.should_not be_empty
83
83
  end
84
84
 
85
- it "should be able to get tag counts on an association" do
85
+ it "should be able to get all tag counts on model as whole" do
86
86
  bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
87
87
  frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
88
88
  charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
89
- bob.tag_counts.first.count.should == 2
90
- charlie.skill_counts.first.count.should == 1
89
+
90
+ TaggableModel.all_tag_counts.should_not be_empty
91
+ TaggableModel.all_tag_counts.first.count.should == 3 # ruby
92
+ end
93
+
94
+ it "should be able to get scoped tag counts" do
95
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
96
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
97
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
98
+
99
+ TaggableModel.tagged_with("ruby").tag_counts.first.count.should == 2 # ruby
100
+ TaggableModel.tagged_with("ruby").skill_counts.first.count.should == 1 # ruby
101
+ end
102
+
103
+ it "should be able to get all scoped tag counts" do
104
+ bob = TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
105
+ frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
106
+ charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
107
+
108
+ TaggableModel.tagged_with("ruby").all_tag_counts.first.count.should == 3 # ruby
91
109
  end
92
110
 
93
111
  it "should be able to set a custom tag context list" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts-as-taggable-on
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-13 00:00:00 +01:00
12
+ date: 2009-11-17 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15