acts-as-taggable-on 1.0.18 → 1.0.19
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.
|
1
|
+
1.0.19
|
@@ -117,6 +117,7 @@ module ActiveRecord
|
|
117
117
|
# Pass either a tag string, or an array of strings or tags
|
118
118
|
#
|
119
119
|
# Options:
|
120
|
+
# :any - find models that match any of the given tags
|
120
121
|
# :exclude - Find models that are not tagged with the given tags
|
121
122
|
# :match_all - Find models that match all of the given tags, not just one
|
122
123
|
# :conditions - A piece of SQL conditions to add to the query
|
@@ -153,6 +154,10 @@ module ActiveRecord
|
|
153
154
|
tags_conditions = tag_list.map { |t| sanitize_sql(["#{Tag.table_name}.name LIKE ?", t]) }.join(" OR ")
|
154
155
|
conditions << "#{table_name}.#{primary_key} NOT IN (SELECT #{Tagging.table_name}.taggable_id FROM #{Tagging.table_name} JOIN #{Tag.table_name} ON #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND (#{tags_conditions}) WHERE #{Tagging.table_name}.taggable_type = #{quote_value(base_class.name)})"
|
155
156
|
|
157
|
+
elsif options.delete(:any)
|
158
|
+
tags_conditions = tag_list.map { |t| sanitize_sql(["#{Tag.table_name}.name LIKE ?", t]) }.join(" OR ")
|
159
|
+
conditions << "#{table_name}.#{primary_key} IN (SELECT #{Tagging.table_name}.taggable_id FROM #{Tagging.table_name} JOIN #{Tag.table_name} ON #{Tagging.table_name}.tag_id = #{Tag.table_name}.id AND (#{tags_conditions}) WHERE #{Tagging.table_name}.taggable_type = #{quote_value(base_class.name)})"
|
160
|
+
|
156
161
|
else
|
157
162
|
tags = Tag.named_like_any(tag_list)
|
158
163
|
return { :conditions => "1 = 0" } unless tags.length == tag_list.length
|
@@ -41,9 +41,10 @@ class TagList < Array
|
|
41
41
|
# tag_list = TagList.new("Round", "Square,Cube")
|
42
42
|
# tag_list.to_s # 'Round, "Square,Cube"'
|
43
43
|
def to_s
|
44
|
-
|
44
|
+
tags = frozen? ? self.dup : self
|
45
|
+
tags.send(:clean!)
|
45
46
|
|
46
|
-
map do |name|
|
47
|
+
tags.map do |name|
|
47
48
|
name.include?(delimiter) ? "\"#{name}\"" : name
|
48
49
|
end.join(delimiter.ends_with?(" ") ? delimiter : "#{delimiter} ")
|
49
50
|
end
|
@@ -55,7 +56,7 @@ class TagList < Array
|
|
55
56
|
map!(&:strip)
|
56
57
|
uniq!
|
57
58
|
end
|
58
|
-
|
59
|
+
|
59
60
|
def extract_and_apply_options!(args)
|
60
61
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
61
62
|
options.assert_valid_keys :parse
|
@@ -61,4 +61,10 @@ describe TagList do
|
|
61
61
|
@tag_list.add("cool","rad,bodacious")
|
62
62
|
@tag_list.to_s.should == "awesome, radical, cool, \"rad,bodacious\""
|
63
63
|
end
|
64
|
+
|
65
|
+
it "should be able to call to_s on a frozen tag list" do
|
66
|
+
@tag_list.freeze
|
67
|
+
lambda { @tag_list.add("cool","rad,bodacious") }.should raise_error(TypeError)
|
68
|
+
lambda { @tag_list.to_s }.should_not raise_error(TypeError)
|
69
|
+
end
|
64
70
|
end
|
@@ -149,7 +149,17 @@ describe "Taggable" do
|
|
149
149
|
TaggableModel.find_tagged_with("ruby, rails", :order => 'taggable_models.name').should == [bob, frank]
|
150
150
|
TaggableModel.find_tagged_with(["ruby", "rails"], :order => 'taggable_models.name').should == [bob, frank]
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
|
+
it "should be able to find tagged with any tag" do
|
154
|
+
bob = TaggableModel.create(:name => "Bob", :tag_list => "fitter, happier, more productive", :skill_list => "ruby, rails, css")
|
155
|
+
frank = TaggableModel.create(:name => "Frank", :tag_list => "weaker, depressed, inefficient", :skill_list => "ruby, rails, css")
|
156
|
+
steve = TaggableModel.create(:name => 'Steve', :tag_list => 'fitter, happier, more productive', :skill_list => 'c++, java, ruby')
|
157
|
+
|
158
|
+
TaggableModel.find_tagged_with(["ruby", "java"], :order => 'taggable_models.name', :any => true).should == [bob, frank, steve]
|
159
|
+
TaggableModel.find_tagged_with(["c++", "fitter"], :order => 'taggable_models.name', :any => true).should == [bob, steve]
|
160
|
+
TaggableModel.find_tagged_with(["depressed", "css"], :order => 'taggable_models.name', :any => true).should == [bob, frank]
|
161
|
+
end
|
162
|
+
|
153
163
|
it "should be able to find tagged on a custom tag context" do
|
154
164
|
bob = TaggableModel.create(:name => "Bob")
|
155
165
|
bob.set_tag_list_on(:rotors, "spinning, jumping")
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
2
2
|
require 'rubygems'
|
3
|
-
require '
|
3
|
+
require 'active_record'
|
4
4
|
require 'spec'
|
5
5
|
|
6
6
|
module Spec::Example::ExampleGroupMethods
|
@@ -24,7 +24,10 @@ ActiveRecord::Base.establish_connection(
|
|
24
24
|
|
25
25
|
RAILS_DEFAULT_LOGGER = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
26
26
|
|
27
|
-
|
27
|
+
ActiveRecord::Base.silence do
|
28
|
+
ActiveRecord::Migration.verbose = false
|
29
|
+
load(File.dirname(__FILE__) + '/schema.rb')
|
30
|
+
end
|
28
31
|
|
29
32
|
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
30
33
|
require File.join(File.dirname(__FILE__), '..', 'init')
|
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.19
|
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: 2010-01-
|
12
|
+
date: 2010-01-21 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|