acts-as-taggable-on 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/acts-as-taggable-on.rb +1 -0
- data/lib/acts_as_taggable_on/acts_as_taggable_on.rb +5 -11
- data/lib/acts_as_taggable_on/group_helper.rb +12 -0
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +0 -8
- data/spec/acts_as_taggable_on/group_helper_spec.rb +18 -0
- metadata +5 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.12
|
data/lib/acts-as-taggable-on.rb
CHANGED
@@ -109,6 +109,7 @@ module ActiveRecord
|
|
109
109
|
end
|
110
110
|
|
111
111
|
module SingletonMethods
|
112
|
+
include ActiveRecord::Acts::TaggableOn::GroupHelper
|
112
113
|
# Pass either a tag string, or an array of strings or tags
|
113
114
|
#
|
114
115
|
# Options:
|
@@ -177,7 +178,7 @@ module ActiveRecord
|
|
177
178
|
" ON #{taggings_alias}.taggable_id = #{table_name}.#{primary_key}" +
|
178
179
|
" AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)}"
|
179
180
|
|
180
|
-
group = "#{
|
181
|
+
group = "#{grouped_column_names_for(self)} HAVING COUNT(#{taggings_alias}.taggable_id) = #{tags.size}"
|
181
182
|
end
|
182
183
|
|
183
184
|
{ :joins => joins.join(" "),
|
@@ -232,7 +233,7 @@ module ActiveRecord
|
|
232
233
|
at_least = sanitize_sql(['COUNT(*) >= ?', options.delete(:at_least)]) if options[:at_least]
|
233
234
|
at_most = sanitize_sql(['COUNT(*) <= ?', options.delete(:at_most)]) if options[:at_most]
|
234
235
|
having = [at_least, at_most].compact.join(' AND ')
|
235
|
-
group_by = "#{
|
236
|
+
group_by = "#{grouped_column_names_for(Tag)} HAVING COUNT(*) > 0"
|
236
237
|
group_by << " AND #{having}" unless having.blank?
|
237
238
|
|
238
239
|
{ :select => "#{Tag.table_name}.*, COUNT(*) AS count",
|
@@ -247,17 +248,10 @@ module ActiveRecord
|
|
247
248
|
def is_taggable?
|
248
249
|
true
|
249
250
|
end
|
250
|
-
|
251
|
-
def column_names_for_tag_group
|
252
|
-
Tag.column_names.map { |column| "#{Tag.table_name}.#{column}" }.join(", ")
|
253
|
-
end
|
254
|
-
|
255
|
-
def column_names_for_tagging_group
|
256
|
-
column_names.map { |column| "#{table_name}.#{column}" }.join(", ")
|
257
|
-
end
|
258
251
|
end
|
259
252
|
|
260
253
|
module InstanceMethods
|
254
|
+
include ActiveRecord::Acts::TaggableOn::GroupHelper
|
261
255
|
|
262
256
|
def tag_types
|
263
257
|
self.class.tag_types
|
@@ -324,7 +318,7 @@ module ActiveRecord
|
|
324
318
|
{ :select => "#{klass.table_name}.*, COUNT(#{Tag.table_name}.id) AS count",
|
325
319
|
:from => "#{klass.table_name}, #{Tag.table_name}, #{Tagging.table_name}",
|
326
320
|
:conditions => ["#{exclude_self} #{klass.table_name}.id = #{Tagging.table_name}.taggable_id AND #{Tagging.table_name}.taggable_type = '#{klass.to_s}' AND #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND #{Tag.table_name}.name IN (?)", tags_to_find],
|
327
|
-
:group =>
|
321
|
+
:group => grouped_column_names_for(klass),
|
328
322
|
:order => "count DESC"
|
329
323
|
}.update(options)
|
330
324
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Acts
|
3
|
+
module TaggableOn
|
4
|
+
module GroupHelper
|
5
|
+
# all column names are necessary for PostgreSQL group clause
|
6
|
+
def grouped_column_names_for(object)
|
7
|
+
object.column_names.map { |column| "#{object.table_name}.#{column}" }.join(", ")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -40,14 +40,6 @@ describe "Acts As Taggable On" do
|
|
40
40
|
@taggable.should respond_to(:tag_list, :skill_list, :language_list)
|
41
41
|
@taggable.should respond_to(:tag_list=, :skill_list=, :language_list=)
|
42
42
|
end
|
43
|
-
|
44
|
-
it "should return all column names joined for Tag GROUP clause" do
|
45
|
-
TaggableModel.column_names_for_tag_group.should == "tags.id, tags.name"
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should return all column names joined for TaggableModel GROUP clause" do
|
49
|
-
TaggableModel.column_names_for_tagging_group.should == "taggable_models.id, taggable_models.name, taggable_models.type"
|
50
|
-
end
|
51
43
|
end
|
52
44
|
|
53
45
|
describe "Single Table Inheritance" do
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe "Group Helper" do
|
4
|
+
|
5
|
+
describe "grouped_column_names_for method" do
|
6
|
+
before(:each) do
|
7
|
+
@taggable = TaggableModel.new(:name => "Bob Jones")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should return all column names joined for Tag GROUP clause" do
|
11
|
+
@taggable.grouped_column_names_for(Tag).should == "tags.id, tags.name"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return all column names joined for TaggableModel GROUP clause" do
|
15
|
+
@taggable.grouped_column_names_for(TaggableModel).should == "taggable_models.id, taggable_models.name, taggable_models.type"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
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.
|
4
|
+
version: 1.0.12
|
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-12-
|
12
|
+
date: 2009-12-07 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/acts-as-taggable-on.rb
|
31
31
|
- lib/acts_as_taggable_on/acts_as_taggable_on.rb
|
32
32
|
- lib/acts_as_taggable_on/acts_as_tagger.rb
|
33
|
+
- lib/acts_as_taggable_on/group_helper.rb
|
33
34
|
- lib/acts_as_taggable_on/tag.rb
|
34
35
|
- lib/acts_as_taggable_on/tag_list.rb
|
35
36
|
- lib/acts_as_taggable_on/tagging.rb
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- rails/init.rb
|
38
39
|
- spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
|
39
40
|
- spec/acts_as_taggable_on/acts_as_tagger_spec.rb
|
41
|
+
- spec/acts_as_taggable_on/group_helper_spec.rb
|
40
42
|
- spec/acts_as_taggable_on/tag_list_spec.rb
|
41
43
|
- spec/acts_as_taggable_on/tag_spec.rb
|
42
44
|
- spec/acts_as_taggable_on/taggable_spec.rb
|
@@ -76,6 +78,7 @@ summary: ActsAsTaggableOn is a tagging plugin for Rails that provides multiple t
|
|
76
78
|
test_files:
|
77
79
|
- spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
|
78
80
|
- spec/acts_as_taggable_on/acts_as_tagger_spec.rb
|
81
|
+
- spec/acts_as_taggable_on/group_helper_spec.rb
|
79
82
|
- spec/acts_as_taggable_on/tag_list_spec.rb
|
80
83
|
- spec/acts_as_taggable_on/tag_spec.rb
|
81
84
|
- spec/acts_as_taggable_on/taggable_spec.rb
|