Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:mbleigh/acts-as-taggable-on

Conflicts:
	Gemfile
	lib/acts_as_taggable_on/compatibility/Gemfile
	spec/database.yml.sample
  • Loading branch information...
commit d7d938874043261e075bf55e03ba217285e1a490 2 parents 968cfa2 + 67fdfee
@tomeric tomeric authored
View
4 Gemfile
@@ -4,7 +4,7 @@ source :gemcutter
gem 'rails', '3.0.0.beta3'
gem 'rspec', '2.0.0.beta.8'
gem 'sqlite3-ruby', :require => 'sqlite3'
-gem 'mysql', :require => 'mysql'
-gem 'pg', :require => 'pg'
+gem 'mysql'
+gem 'pg'
gem 'jeweler'
gem 'rcov'
View
2  README.rdoc
@@ -139,7 +139,7 @@ to allow for dynamic tag contexts (this could be user generated tag contexts!)
@user.save
@user.tags_on(:customs) # => [<Tag name='same'>,...]
@user.tag_counts_on(:customs)
- User.find_tagged_with("same", :on => :customs) # => [@user]
+ User.tagged_with("same", :on => :customs) # => [@user]
=== Tag Ownership
View
4 lib/acts_as_taggable_on/acts_as_taggable_on/collection.rb
@@ -87,7 +87,9 @@ def all_tag_counts(options = {})
tagging_join,
taggable_join,
scope[:joins]
- ].compact.reverse
+ ].compact
+
+ joins = joins.reverse if ActiveRecord::VERSION::MAJOR < 3
## Generate scope:
View
8 lib/acts_as_taggable_on/acts_as_taggable_on/core.rb
@@ -117,6 +117,7 @@ def tagged_with(tags, options = {})
scoped(:joins => joins.join(" "),
:group => group,
:conditions => conditions.join(" AND "),
+ :order => options[:order],
:readonly => false)
end
@@ -172,8 +173,11 @@ def all_tags_list_on(context)
##
# Returns all tags of a given context
def all_tags_on(context)
- opts = ["#{ActsAsTaggableOn::Tagging.table_name}.context = ?", context.to_s]
- base_tags.where(opts).order("#{ActsAsTaggableOn::Tagging.table_name}.created_at").group("#{ActsAsTaggableOn::Tagging.table_name}.tag_id").all
+ tag_table_name = ActsAsTaggableOn::Tag.table_name
+ tagging_table_name = ActsAsTaggableOn::Tagging.table_name
+
+ opts = ["#{tagging_table_name}.context = ?", context.to_s]
+ base_tags.where(opts).order("max(#{tagging_table_name}.created_at)").group("#{tag_table_name}.id, #{tag_table_name}.name").all
end
##
View
4 lib/acts_as_taggable_on/compatibility/Gemfile
@@ -4,5 +4,5 @@ source :gemcutter
gem 'rails', '2.3.5'
gem 'rspec', '1.3.0', :require => 'spec'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
-gem 'mysql', :require => 'mysql'
-gem 'pg', :require => 'pg'
+gem 'pg'
View
44 lib/acts_as_taggable_on/compatibility/postgresql.rb
@@ -0,0 +1,44 @@
+module ActsAsTaggableOn
+ module Taggable
+ module PostgreSQL
+ def self.included(base)
+ base.send :include, ActsAsTaggableOn::Taggable::PostgreSQL::InstanceMethods
+ base.extend ActsAsTaggableOn::Taggable::PostgreSQL::ClassMethods
+
+ ActsAsTaggableOn::Tag.class_eval do
+ def self.named(name)
+ where(["name ILIKE ?", name])
+ end
+
+ def self.named_any(list)
+ where(list.map { |tag| sanitize_sql(["name ILIKE ?", tag.to_s]) }.join(" OR "))
+ end
+
+ def self.named_like(name)
+ where(["name ILIKE ?", "%#{name}%"])
+ end
+
+ def self.named_like_any(list)
+ where(list.map { |tag| sanitize_sql(["name ILIKE ?", "%#{tag.to_s}%"]) }.join(" OR "))
+ end
+ end
+ end
+
+ module InstanceMethods
+ end
+
+ module ClassMethods
+ # all column names are necessary for PostgreSQL group clause
+ def grouped_column_names_for(*objects)
+ object = objects.shift
+ columns = object.column_names.map { |column| "#{object.table_name}.#{column}" }
+ columns << objects.map do |object|
+ "#{object.table_name}.created_at"
+ end.flatten
+
+ columns.flatten.join(", ")
+ end
+ end
+ end
+ end
+end
View
15 lib/acts_as_taggable_on/tag.rb
@@ -16,19 +16,19 @@ class Tag < ::ActiveRecord::Base
### SCOPES:
def self.named(name)
- where(["name LIKE ?", name])
+ where(["name #{like_operator} ?", name])
end
def self.named_any(list)
- where(list.map { |tag| sanitize_sql(["name LIKE ?", tag.to_s]) }.join(" OR "))
+ where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", tag.to_s]) }.join(" OR "))
end
def self.named_like(name)
- where(["name LIKE ?", "%#{name}%"])
+ where(["name #{like_operator} ?", "%#{name}%"])
end
def self.named_like_any(list)
- where(list.map { |tag| sanitize_sql(["name LIKE ?", "%#{tag.to_s}%"]) }.join(" OR "))
+ where(list.map { |tag| sanitize_sql(["name #{like_operator} ?", "%#{tag.to_s}%"]) }.join(" OR "))
end
### CLASS METHODS:
@@ -63,5 +63,12 @@ def count
read_attribute(:count).to_i
end
+ class << self
+ private
+ def like_operator
+ connection.adapter_name == 'PostgreSQL' ? 'ILIKE' : 'LIKE'
+ end
+ end
+
end
end
View
2  spec/acts_as_taggable_on/acts_as_taggable_on_spec.rb
@@ -12,6 +12,8 @@
describe "Taggable Method Generation" do
before(:each) do
clean_database!
+ TaggableModel.write_inheritable_attribute(:tag_types, [])
+ TaggableModel.acts_as_taggable_on(:tags, :languages, :skills, :needs, :offerings)
@taggable = TaggableModel.new(:name => "Bob Jones")
end
View
12 spec/acts_as_taggable_on/taggable_spec.rb
@@ -108,7 +108,7 @@
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
TaggableModel.all_tag_counts.all.should_not be_empty
- TaggableModel.all_tag_counts.first.count.should == 3 # ruby
+ TaggableModel.all_tag_counts(:order => 'tags.id').first.count.should == 3 # ruby
end
if ActiveRecord::VERSION::MAJOR >= 3
@@ -132,7 +132,7 @@
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
- TaggableModel.tagged_with("ruby").tag_counts.first.count.should == 2 # ruby
+ TaggableModel.tagged_with("ruby").tag_counts(:order => 'tags.id').first.count.should == 2 # ruby
TaggableModel.tagged_with("ruby").skill_counts.first.count.should == 1 # ruby
end
@@ -141,7 +141,7 @@
frank = TaggableModel.create(:name => "Frank", :tag_list => "ruby, rails")
charlie = TaggableModel.create(:name => "Charlie", :skill_list => "ruby")
- TaggableModel.tagged_with("ruby").all_tag_counts.first.count.should == 3 # ruby
+ TaggableModel.tagged_with("ruby").all_tag_counts(:order => 'tags.id').first.count.should == 3 # ruby
end
it 'should only return tag counts for the available scope' do
@@ -298,9 +298,9 @@
@inherited_different.tag_list = "fork, spoon"
@inherited_different.save!
- InheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso)
- AlteredInheritingTaggableModel.tag_counts_on(:tags).map(&:name).should == %w(fork spoon)
- TaggableModel.tag_counts_on(:tags).map(&:name).should == %w(bob kelso fork spoon)
+ InheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso)
+ AlteredInheritingTaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(fork spoon)
+ TaggableModel.tag_counts_on(:tags, :order => 'tags.id').map(&:name).should == %w(bob kelso fork spoon)
end
it 'should store same tag without validation conflict' do
View
4 spec/database.yml.sample
@@ -9,9 +9,9 @@ mysql:
password:
database: acts_as_taggable_on
-postgres:
+postgresql:
adapter: postgresql
hostname: localhost
username: postgres
password:
- database: acts_as_taggable_on
+ database: acts_as_taggable_on
Please sign in to comment.
Something went wrong with that request. Please try again.