acts-as-taggable-on 2.0.5 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/README.rdoc +2 -2
- data/VERSION +1 -1
- data/lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb +3 -1
- data/lib/acts_as_taggable_on/acts_as_taggable_on/core.rb +6 -2
- data/lib/acts_as_taggable_on/compatibility/Gemfile +3 -1
- data/lib/acts_as_taggable_on/compatibility/postgresql.rb +44 -0
- data/lib/acts_as_taggable_on/tag.rb +11 -4
- data/spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb +2 -0
- data/spec/acts_as_taggable_on/taggable_spec.rb +6 -6
- data/spec/database.yml +17 -0
- data/spec/database.yml.sample +17 -0
- data/spec/spec_helper.rb +18 -15
- metadata +6 -3
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -139,7 +139,7 @@ to allow for dynamic tag contexts (this could be user generated tag contexts!)
|
|
139
139
|
@user.save
|
140
140
|
@user.tags_on(:customs) # => [<Tag name='same'>,...]
|
141
141
|
@user.tag_counts_on(:customs)
|
142
|
-
User.
|
142
|
+
User.tagged_with("same", :on => :customs) # => [@user]
|
143
143
|
|
144
144
|
=== Tag Ownership
|
145
145
|
|
@@ -174,7 +174,7 @@ Here is an example that generates a tag cloud.
|
|
174
174
|
Helper:
|
175
175
|
|
176
176
|
module PostsHelper
|
177
|
-
include TagsHelper
|
177
|
+
include ActsAsTaggableOn::TagsHelper
|
178
178
|
end
|
179
179
|
|
180
180
|
Controller:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.6
|
@@ -117,6 +117,7 @@ module ActsAsTaggableOn::Taggable
|
|
117
117
|
scoped(:joins => joins.join(" "),
|
118
118
|
:group => group,
|
119
119
|
:conditions => conditions.join(" AND "),
|
120
|
+
:order => options[:order],
|
120
121
|
:readonly => false)
|
121
122
|
end
|
122
123
|
|
@@ -172,8 +173,11 @@ module ActsAsTaggableOn::Taggable
|
|
172
173
|
##
|
173
174
|
# Returns all tags of a given context
|
174
175
|
def all_tags_on(context)
|
175
|
-
|
176
|
-
|
176
|
+
tag_table_name = ActsAsTaggableOn::Tag.table_name
|
177
|
+
tagging_table_name = ActsAsTaggableOn::Tagging.table_name
|
178
|
+
|
179
|
+
opts = ["#{tagging_table_name}.context = ?", context.to_s]
|
180
|
+
base_tags.where(opts).order("max(#{tagging_table_name}.created_at)").group("#{tag_table_name}.id, #{tag_table_name}.name").all
|
177
181
|
end
|
178
182
|
|
179
183
|
##
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ActsAsTaggableOn
|
2
|
+
module Taggable
|
3
|
+
module PostgreSQL
|
4
|
+
def self.included(base)
|
5
|
+
base.send :include, ActsAsTaggableOn::Taggable::PostgreSQL::InstanceMethods
|
6
|
+
base.extend ActsAsTaggableOn::Taggable::PostgreSQL::ClassMethods
|
7
|
+
|
8
|
+
ActsAsTaggableOn::Tag.class_eval do
|
9
|
+
def self.named(name)
|
10
|
+
where(["name ILIKE ?", name])
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.named_any(list)
|
14
|
+
where(list.map { |tag| sanitize_sql(["name ILIKE ?", tag.to_s]) }.join(" OR "))
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.named_like(name)
|
18
|
+
where(["name ILIKE ?", "%#{name}%"])
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.named_like_any(list)
|
22
|
+
where(list.map { |tag| sanitize_sql(["name ILIKE ?", "%#{tag.to_s}%"]) }.join(" OR "))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
end
|
29
|
+
|
30
|
+
module ClassMethods
|
31
|
+
# all column names are necessary for PostgreSQL group clause
|
32
|
+
def grouped_column_names_for(*objects)
|
33
|
+
object = objects.shift
|
34
|
+
columns = object.column_names.map { |column| "#{object.table_name}.#{column}" }
|
35
|
+
columns << objects.map do |object|
|
36
|
+
"#{object.table_name}.created_at"
|
37
|
+
end.flatten
|
38
|
+
|
39
|
+
columns.flatten.join(", ")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -16,19 +16,19 @@ module ActsAsTaggableOn
|
|
16
16
|
### SCOPES:
|
17
17
|
|
18
18
|
def self.named(name)
|
19
|
-
where(["name
|
19
|
+
where(["name #{like_operator} ?", name])
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.named_any(list)
|
23
|
-
where(list.map { |tag| sanitize_sql(["name
|
23
|
+
where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", tag.to_s]) }.join(" OR "))
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.named_like(name)
|
27
|
-
where(["name
|
27
|
+
where(["name #{like_operator} ?", "%#{name}%"])
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.named_like_any(list)
|
31
|
-
where(list.map { |tag| sanitize_sql(["name
|
31
|
+
where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", "%#{tag.to_s}%"]) }.join(" OR "))
|
32
32
|
end
|
33
33
|
|
34
34
|
### CLASS METHODS:
|
@@ -63,5 +63,12 @@ module ActsAsTaggableOn
|
|
63
63
|
read_attribute(:count).to_i
|
64
64
|
end
|
65
65
|
|
66
|
+
class << self
|
67
|
+
private
|
68
|
+
def like_operator
|
69
|
+
connection.adapter_name == 'PostgreSQL' ? 'ILIKE' : 'LIKE'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
66
73
|
end
|
67
74
|
end
|
@@ -12,6 +12,8 @@ describe "Acts As Taggable On" do
|
|
12
12
|
describe "Taggable Method Generation" do
|
13
13
|
before(:each) do
|
14
14
|
clean_database!
|
15
|
+
TaggableModel.write_inheritable_attribute(:tag_types, [])
|
16
|
+
TaggableModel.acts_as_taggable_on(:tags, :languages, :skills, :needs, :offerings)
|
15
17
|
@taggable = TaggableModel.new(:name => "Bob Jones")
|
16
18
|
end
|
17
19
|
|
@@ -108,7 +108,7 @@ describe "Taggable" do
|
|
108
108
|
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
109
109
|
|
110
110
|
TaggableModel.all_tag_counts.all.should_not be_empty
|
111
|
-
TaggableModel.all_tag_counts.first.count.should == 3 # ruby
|
111
|
+
TaggableModel.all_tag_counts(:order => 'tags.id').first.count.should == 3 # ruby
|
112
112
|
end
|
113
113
|
|
114
114
|
if ActiveRecord::VERSION::MAJOR >= 3
|
@@ -132,7 +132,7 @@ describe "Taggable" do
|
|
132
132
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
133
133
|
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
134
134
|
|
135
|
-
TaggableModel.tagged_with("ruby").tag_counts.first.count.should == 2 # ruby
|
135
|
+
TaggableModel.tagged_with("ruby").tag_counts(:order => 'tags.id').first.count.should == 2 # ruby
|
136
136
|
TaggableModel.tagged_with("ruby").skill_counts.first.count.should == 1 # ruby
|
137
137
|
end
|
138
138
|
|
@@ -141,7 +141,7 @@ describe "Taggable" do
|
|
141
141
|
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
|
142
142
|
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
|
143
143
|
|
144
|
-
TaggableModel.tagged_with("ruby").all_tag_counts.first.count.should == 3 # ruby
|
144
|
+
TaggableModel.tagged_with("ruby").all_tag_counts(:order => 'tags.id').first.count.should == 3 # ruby
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'should only return tag counts for the available scope' do
|
@@ -298,9 +298,9 @@ describe "Taggable" do
|
|
298
298
|
@inherited_different.tag_list = "fork, spoon"
|
299
299
|
@inherited_different.save!
|
300
300
|
|
301
|
-
InheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso)
|
302
|
-
AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
|
303
|
-
TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
|
301
|
+
InheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
|
302
|
+
AlteredInheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
|
303
|
+
TaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
|
304
304
|
end
|
305
305
|
|
306
306
|
it 'should store same tag without validation conflict' do
|
data/spec/database.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
sqlite3:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: acts_as_taggable_on.sqlite3
|
4
|
+
|
5
|
+
mysql:
|
6
|
+
adapter: mysql
|
7
|
+
hostname: localhost
|
8
|
+
username: root
|
9
|
+
password:
|
10
|
+
database: acts_as_taggable_on
|
11
|
+
|
12
|
+
postgresql:
|
13
|
+
adapter: postgresql
|
14
|
+
hostname: localhost
|
15
|
+
username: postgres
|
16
|
+
password:
|
17
|
+
database: acts_as_taggable_on
|
@@ -0,0 +1,17 @@
|
|
1
|
+
sqlite3:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: acts_as_taggable_on.sqlite3
|
4
|
+
|
5
|
+
mysql:
|
6
|
+
adapter: mysql
|
7
|
+
hostname: localhost
|
8
|
+
username: root
|
9
|
+
password:
|
10
|
+
database: acts_as_taggable_on
|
11
|
+
|
12
|
+
postgresql:
|
13
|
+
adapter: postgresql
|
14
|
+
hostname: localhost
|
15
|
+
username: postgres
|
16
|
+
password:
|
17
|
+
database: acts_as_taggable_on
|
data/spec/spec_helper.rb
CHANGED
@@ -29,21 +29,24 @@ unless [].respond_to?(:freq)
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
)
|
39
|
-
|
40
|
-
|
41
|
-
ActiveRecord::Base.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
32
|
+
ENV['DB'] ||= 'sqlite3'
|
33
|
+
|
34
|
+
database_yml = File.expand_path('../database.yml', __FILE__)
|
35
|
+
if File.exists?(database_yml)
|
36
|
+
active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
|
37
|
+
|
38
|
+
ActiveRecord::Base.establish_connection(active_record_configuration)
|
39
|
+
ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
|
40
|
+
|
41
|
+
ActiveRecord::Base.silence do
|
42
|
+
ActiveRecord::Migration.verbose = false
|
43
|
+
|
44
|
+
load(File.dirname(__FILE__) + '/schema.rb')
|
45
|
+
load(File.dirname(__FILE__) + '/models.rb')
|
46
|
+
end
|
47
|
+
|
48
|
+
else
|
49
|
+
raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
|
47
50
|
end
|
48
51
|
|
49
52
|
def clean_database!
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 2
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 2.0.
|
8
|
+
- 6
|
9
|
+
version: 2.0.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Bleigh
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-05-19 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/acts_as_taggable_on/acts_as_tagger.rb
|
46
46
|
- lib/acts_as_taggable_on/compatibility/Gemfile
|
47
47
|
- lib/acts_as_taggable_on/compatibility/active_record_backports.rb
|
48
|
+
- lib/acts_as_taggable_on/compatibility/postgresql.rb
|
48
49
|
- lib/acts_as_taggable_on/tag.rb
|
49
50
|
- lib/acts_as_taggable_on/tag_list.rb
|
50
51
|
- lib/acts_as_taggable_on/tagging.rb
|
@@ -61,6 +62,8 @@ files:
|
|
61
62
|
- spec/acts_as_taggable_on/tagging_spec.rb
|
62
63
|
- spec/acts_as_taggable_on/tags_helper_spec.rb
|
63
64
|
- spec/bm.rb
|
65
|
+
- spec/database.yml
|
66
|
+
- spec/database.yml.sample
|
64
67
|
- spec/models.rb
|
65
68
|
- spec/schema.rb
|
66
69
|
- spec/spec_helper.rb
|