acts-as-taggable-on 3.2.6 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/db/migrate/4_add_missing_taggable_index.rb +9 -0
- data/lib/acts_as_taggable_on/taggable/core.rb +26 -11
- data/lib/acts_as_taggable_on/tagging.rb +1 -1
- data/lib/acts_as_taggable_on/tags_helper.rb +2 -2
- data/lib/acts_as_taggable_on/version.rb +1 -1
- data/spec/acts_as_taggable_on/taggable_spec.rb +14 -0
- data/spec/acts_as_taggable_on/tagger_spec.rb +0 -1
- data/spec/acts_as_taggable_on/tagging_spec.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c20928991764b079db87d3d1ba32846d0a3e01f
|
4
|
+
data.tar.gz: 94cae20632e6d61d21cd55921cb7ee284cb6f766
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29cfdac7542aed8bb4f8f55a0c7d33f592739ae1f887a5399e0bd34fd686a5824b3e5335f5037a0ada5928001b4a8b3ca124d21771d5af648fc6f55735bf31da
|
7
|
+
data.tar.gz: 535aa2433b00889491d6aaf7f488b372ebc1ac2e60f8d9cd2337ae07a19ce2ce1bce3438a1f2db48c77b52a3a57c56648c8c31ddf1b4f0c2447bebae27d67fe0
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# ActsAsTaggableOn
|
2
2
|
[![Build Status](https://secure.travis-ci.org/mbleigh/acts-as-taggable-on.png)](http://travis-ci.org/mbleigh/acts-as-taggable-on)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/mbleigh/acts-as-taggable-on.png)](https://codeclimate.com/github/mbleigh/acts-as-taggable-on)
|
4
|
-
[![Inline docs](http://inch-
|
4
|
+
[![Inline docs](http://inch-ci.org/github/mbleigh/acts-as-taggable-on.png)](http://inch-ci.org/github/mbleigh/acts-as-taggable-on)
|
5
5
|
|
6
6
|
This plugin was originally based on Acts as Taggable on Steroids by Jonathan Viney.
|
7
7
|
It has evolved substantially since that point, but all credit goes to him for the
|
@@ -73,6 +73,8 @@ module ActsAsTaggableOn::Taggable
|
|
73
73
|
# * <tt>:order_by_matching_tag_count</tt> - if set to true and used with :any, sort by objects matching the most tags, descending
|
74
74
|
# * <tt>:match_all</tt> - if set to true, return objects that are *ONLY* tagged with the specified tags
|
75
75
|
# * <tt>:owned_by</tt> - return objects that are *ONLY* owned by the owner
|
76
|
+
# * <tt>:start_at</tt> - Restrict the tags to those created after a certain time
|
77
|
+
# * <tt>:end_at</tt> - Restrict the tags to those created before a certain time
|
76
78
|
#
|
77
79
|
# Example:
|
78
80
|
# User.tagged_with("awesome", "cool") # Users that are tagged with awesome and cool
|
@@ -81,6 +83,7 @@ module ActsAsTaggableOn::Taggable
|
|
81
83
|
# User.tagged_with("awesome", "cool", :any => true, :order_by_matching_tag_count => true) # Sort by users who match the most tags, descending
|
82
84
|
# User.tagged_with("awesome", "cool", :match_all => true) # Users that are tagged with just awesome and cool
|
83
85
|
# User.tagged_with("awesome", "cool", :owned_by => foo ) # Users that are tagged with just awesome and cool by 'foo'
|
86
|
+
# User.tagged_with("awesome", "cool", :owned_by => foo, :start_at => Date.today ) # Users that are tagged with just awesome, cool by 'foo' and starting today
|
84
87
|
def tagged_with(tags, options = {})
|
85
88
|
tag_list = ActsAsTaggableOn::TagListParser.parse(tags)
|
86
89
|
options = options.dup
|
@@ -109,11 +112,14 @@ module ActsAsTaggableOn::Taggable
|
|
109
112
|
conditions << "#{table_name}.#{primary_key} NOT IN (SELECT #{ActsAsTaggableOn::Tagging.table_name}.taggable_id FROM #{ActsAsTaggableOn::Tagging.table_name} JOIN #{ActsAsTaggableOn::Tag.table_name} ON #{ActsAsTaggableOn::Tagging.table_name}.tag_id = #{ActsAsTaggableOn::Tag.table_name}.#{ActsAsTaggableOn::Tag.primary_key} AND (#{tags_conditions}) WHERE #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = #{quote_value(base_class.name, nil)})"
|
110
113
|
|
111
114
|
if owned_by
|
112
|
-
joins <<
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
115
|
+
joins << "JOIN #{ActsAsTaggableOn::Tagging.table_name}" +
|
116
|
+
" ON #{ActsAsTaggableOn::Tagging.table_name}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
|
117
|
+
" AND #{ActsAsTaggableOn::Tagging.table_name}.taggable_type = #{quote_value(base_class.name, nil)}" +
|
118
|
+
" AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_id = #{quote_value(owned_by.id, nil)}" +
|
119
|
+
" AND #{ActsAsTaggableOn::Tagging.table_name}.tagger_type = #{quote_value(owned_by.class.base_class.to_s, nil)}"
|
120
|
+
|
121
|
+
joins << " AND " + sanitize_sql(["#{ActsAsTaggableOn::Tagging.table_name}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
|
122
|
+
joins << " AND " + sanitize_sql(["#{ActsAsTaggableOn::Tagging.table_name}.created_at <= ?", options.delete(:end_at)]) if options[:end_at]
|
117
123
|
end
|
118
124
|
|
119
125
|
elsif any = options.delete(:any)
|
@@ -134,10 +140,14 @@ module ActsAsTaggableOn::Taggable
|
|
134
140
|
"#{alias_base_name[0..4]}#{taggings_context[0..6]}_taggings_#{ActsAsTaggableOn::Utils.sha_prefix(tags.map(&:name).join('_'))}"
|
135
141
|
)
|
136
142
|
|
137
|
-
tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}"
|
138
|
-
|
139
|
-
|
140
|
-
|
143
|
+
tagging_join = "JOIN #{ActsAsTaggableOn::Tagging.table_name} #{taggings_alias}" +
|
144
|
+
" ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" +
|
145
|
+
" AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name, nil)}"
|
146
|
+
|
147
|
+
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
|
148
|
+
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.created_at <= ?", options.delete(:end_at)]) if options[:end_at]
|
149
|
+
|
150
|
+
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context
|
141
151
|
|
142
152
|
# don't need to sanitize sql, map all ids and join with OR logic
|
143
153
|
conditions << tags.map { |t| "#{taggings_alias}.tag_id = #{quote_value(t.id, nil)}" }.join(' OR ')
|
@@ -169,7 +179,10 @@ module ActsAsTaggableOn::Taggable
|
|
169
179
|
" AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name, nil)}" +
|
170
180
|
" AND #{taggings_alias}.tag_id = #{quote_value(tag.id, nil)}"
|
171
181
|
|
172
|
-
tagging_join <<
|
182
|
+
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
|
183
|
+
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.created_at <= ?", options.delete(:end_at)]) if options[:end_at]
|
184
|
+
|
185
|
+
tagging_join << " AND " + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context
|
173
186
|
|
174
187
|
if owned_by
|
175
188
|
tagging_join << ' AND ' +
|
@@ -197,7 +210,9 @@ module ActsAsTaggableOn::Taggable
|
|
197
210
|
" ON #{taggings_alias}.taggable_id = #{quote}#{table_name}#{quote}.#{primary_key}" \
|
198
211
|
" AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name, nil)}"
|
199
212
|
|
200
|
-
joins <<
|
213
|
+
joins << " AND " + sanitize_sql(["#{taggings_alias}.context = ?", context.to_s]) if context
|
214
|
+
joins << " AND " + sanitize_sql(["#{ActsAsTaggableOn::Tagging.table_name}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
|
215
|
+
joins << " AND " + sanitize_sql(["#{ActsAsTaggableOn::Tagging.table_name}.created_at <= ?", options.delete(:end_at)]) if options[:end_at]
|
201
216
|
|
202
217
|
group_columns = ActsAsTaggableOn::Utils.using_postgresql? ? grouped_column_names_for(self) : "#{table_name}.#{primary_key}"
|
203
218
|
group = group_columns
|
@@ -4,10 +4,10 @@ module ActsAsTaggableOn
|
|
4
4
|
def tag_cloud(tags, classes)
|
5
5
|
return [] if tags.empty?
|
6
6
|
|
7
|
-
max_count = tags.sort_by(&:
|
7
|
+
max_count = tags.sort_by(&:taggings_count).last.taggings_count.to_f
|
8
8
|
|
9
9
|
tags.each do |tag|
|
10
|
-
index = ((tag.
|
10
|
+
index = ((tag.taggings_count / max_count) * (classes.size - 1))
|
11
11
|
yield tag, classes[index.nan? ? 0 : index.round]
|
12
12
|
end
|
13
13
|
end
|
@@ -223,6 +223,20 @@ describe 'Taggable' do
|
|
223
223
|
expect(TaggableModel.tagged_with('ruby').to_sql).to_not match /DISTINCT/
|
224
224
|
end
|
225
225
|
|
226
|
+
it "should be able to find a tag using dates" do
|
227
|
+
@taggable.skill_list = "ruby"
|
228
|
+
@taggable.save
|
229
|
+
|
230
|
+
expect(TaggableModel.tagged_with("ruby", :start_at => Date.today, :end_at => Date.tomorrow).count).to eq(1)
|
231
|
+
end
|
232
|
+
|
233
|
+
it "shouldn't be able to find a tag outside date range" do
|
234
|
+
@taggable.skill_list = "ruby"
|
235
|
+
@taggable.save
|
236
|
+
|
237
|
+
expect(TaggableModel.tagged_with("ruby", :start_at => Date.today - 2.days, :end_at => Date.today - 1.day).count).to eq(0)
|
238
|
+
end
|
239
|
+
|
226
240
|
it 'should be able to find by tag with context' do
|
227
241
|
@taggable.skill_list = 'ruby, rails, css'
|
228
242
|
@taggable.tag_list = 'bob, charlie'
|
@@ -44,7 +44,6 @@ describe 'Tagger' do
|
|
44
44
|
tags = TaggableModel.tagged_with(%w(ruby java), owned_by: @user, any: true)
|
45
45
|
expect(tags).to include(@taggable, @taggable2)
|
46
46
|
expect(tags.size).to eq(2)
|
47
|
-
|
48
47
|
end
|
49
48
|
|
50
49
|
it 'only returns objects tagged by owned_by when exclude is true' do
|
@@ -38,6 +38,17 @@ describe ActsAsTaggableOn::Tagging do
|
|
38
38
|
expect(another_taggable.tag_list.sort).to eq(%w(very serious bug).sort)
|
39
39
|
end
|
40
40
|
|
41
|
+
it 'should destroy unused tags after tagging destroyed' do
|
42
|
+
previous_setting = ActsAsTaggableOn.remove_unused_tags
|
43
|
+
ActsAsTaggableOn.remove_unused_tags = true
|
44
|
+
ActsAsTaggableOn::Tag.destroy_all
|
45
|
+
@taggable = TaggableModel.create(name: 'Bob Jones')
|
46
|
+
@taggable.update_attribute :tag_list, 'aaa,bbb,ccc'
|
47
|
+
@taggable.update_attribute :tag_list, ''
|
48
|
+
expect(ActsAsTaggableOn::Tag.count).to eql(0)
|
49
|
+
ActsAsTaggableOn.remove_unused_tags = previous_setting
|
50
|
+
end
|
51
|
+
|
41
52
|
pending 'context scopes' do
|
42
53
|
describe '.by_context'
|
43
54
|
|
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: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- db/migrate/1_acts_as_taggable_on_migration.rb
|
169
169
|
- db/migrate/2_add_missing_unique_indices.rb
|
170
170
|
- db/migrate/3_add_taggings_counter_cache_to_tags.rb
|
171
|
+
- db/migrate/4_add_missing_taggable_index.rb
|
171
172
|
- gemfiles/activerecord_3.2.gemfile
|
172
173
|
- gemfiles/activerecord_4.0.gemfile
|
173
174
|
- gemfiles/activerecord_4.1.gemfile
|