Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

git-svn-id: http://svn.viney.net.nz/things/rails/plugins/acts_as_tagg…

…able_on_steroids@350 20afb1e0-9c0e-0410-9884-91ed27886737
  • Loading branch information...
commit de1b46dad1c589eb3ab118aee7ad00f04eff73e8 1 parent 19a4aec
jonathan authored
View
4 CHANGELOG
@@ -1,5 +1,9 @@
[23 October 2007]
+* Make find_options_for_tag_counts and find_options_for_tagged_with dup their options.
+
+* Apply conditions properly in find_options_for_tag_counts.
+
* Fix tag_cloud when no tags are present.
[22 October 2007]
View
10 lib/acts_as_taggable.rb
@@ -42,6 +42,7 @@ def find_tagged_with(*args)
def find_options_for_find_tagged_with(tags, options = {})
tags = tags.is_a?(Array) ? TagList.new(tags.map(&:to_s)) : TagList.from(tags)
+ options = options.dup
return {} if tags.empty?
@@ -75,7 +76,7 @@ def find_options_for_find_tagged_with(tags, options = {})
:joins => "INNER JOIN #{Tagging.table_name} #{taggings_alias} ON #{taggings_alias}.taggable_id = #{table_name}.#{primary_key} AND #{taggings_alias}.taggable_type = #{quote_value(base_class.name)} " +
"INNER JOIN #{Tag.table_name} #{tags_alias} ON #{tags_alias}.id = #{taggings_alias}.tag_id",
:conditions => conditions.join(" AND ")
- }.update(options)
+ }.reverse_merge!(options)
end
# Calculate the tag counts for all tags.
@@ -94,6 +95,7 @@ def tag_counts(options = {})
def find_options_for_tag_counts(options = {})
options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit
+ options = options.dup
scope = scope(:find)
start_at = sanitize_sql(["#{Tagging.table_name}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
@@ -101,7 +103,7 @@ def find_options_for_tag_counts(options = {})
conditions = [
"#{Tagging.table_name}.taggable_type = #{quote_value(base_class.name)}",
- options[:conditions],
+ options.delete(:conditions),
scope && scope[:conditions],
start_at,
end_at
@@ -125,7 +127,7 @@ def find_options_for_tag_counts(options = {})
:joins => joins.join(" "),
:conditions => conditions,
:group => group_by
- }.update(options)
+ }.reverse_merge!(options)
end
def caching_tag_list?
@@ -181,7 +183,7 @@ def save_tags
#
# The possible options are the same as the tag_counts class method, excluding :conditions.
def tag_counts(options = {})
- self.class.tag_counts({ :conditions => ["#{Tag.table_name}.name IN (?)", tag_list] }.reverse_merge!(options))
+ self.class.tag_counts({ :conditions => self.class.send(:tags_condition, tag_list) }.reverse_merge!(options))
end
def reload_with_tag_list(*args) #:nodoc:
View
16 test/acts_as_taggable_test.rb
@@ -40,6 +40,11 @@ def test_find_tagged_with_conditions
assert_equal [], Post.find_tagged_with('"Very good", Nature', :conditions => '1=0')
end
+ def test_find_tagged_with_duplicates_options_hash
+ options = { :conditions => '1=1' }.freeze
+ assert_nothing_raised { Post.find_tagged_with("Nature", options) }
+ end
+
def test_find_tagged_with_exclusions
assert_equivalent [photos(:jonathan_questioning_dog), photos(:jonathan_bad_cat)], Photo.find_tagged_with("Nature", :exclude => true)
assert_equivalent [posts(:jonathan_grass), posts(:jonathan_rain), posts(:jonathan_cloudy), posts(:jonathan_still_cloudy)], Post.find_tagged_with("'Very good', Bad", :exclude => true)
@@ -97,6 +102,15 @@ def test_tag_counts_on_class_with_frequencies
assert_tag_counts Photo.tag_counts(:at_most => 2), :good => 1, :question => 1, :bad => 1
end
+ def test_tag_counts_on_class_with_frequencies_and_conditions
+ assert_tag_counts Photo.tag_counts(:at_least => 2, :conditions => '1=1'), :nature => 3, :animal => 3
+ end
+
+ def test_tag_counts_duplicates_options_hash
+ options = { :at_least => 2, :conditions => '1=1' }.freeze
+ assert_nothing_raised { Photo.tag_counts(options) }
+ end
+
def test_tag_counts_with_limit
assert_equal 2, Photo.tag_counts(:limit => 2).size
assert_equal 1, Post.tag_counts(:at_least => 4, :limit => 2).size
@@ -227,7 +241,7 @@ def test_tag_list_reset_on_reload
end
def test_instance_tag_counts
- assert_tag_counts posts(:jonathan_sky).tag_counts, :good => 4, :nature => 10
+ assert_tag_counts posts(:jonathan_sky).tag_counts, :good => 2, :nature => 7
end
def test_tag_list_populated_when_cache_nil
Please sign in to comment.
Something went wrong with that request. Please try again.