Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…able_on_steroids@325 20afb1e0-9c0e-0410-9884-91ed27886737
  • Loading branch information
jonathan committed Sep 28, 2007
1 parent 10e8b15 commit 789dbd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 7 additions & 3 deletions lib/acts_as_taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def acts_as_taggable(options = {})
include ActiveRecord::Acts::Taggable::InstanceMethods
extend ActiveRecord::Acts::Taggable::SingletonMethods

alias_method :reload_without_tag_list, :reload
alias_method :reload, :reload_with_tag_list
alias_method_chain :reload, :tag_list
end

def cached_tag_list_column_name
Expand Down Expand Up @@ -77,6 +76,8 @@ def find_options_for_find_tagged_with(tags, options = {})
}.update(options)
end

# Calculate the tag counts for all tags.
#
# Options:
# :start_at - Restrict the tags to those created after a certain time
# :end_at - Restrict the tags to those created before a certain time
Expand Down Expand Up @@ -164,8 +165,11 @@ def save_tags
true
end

# Calculate the tag counts for the tags used by this model.
#
# 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 => ["#{Tag.table_name}.name IN (?)", tag_list] }.reverse_merge!(options))
end

def reload_with_tag_list(*args)
Expand Down
15 changes: 7 additions & 8 deletions test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
require File.dirname(__FILE__) + '/../../../../config/environment'
rescue LoadError
require 'rubygems'
require_gem 'activerecord'
require_gem 'actionpack'
gem 'activerecord'
gem 'actionpack'
require 'active_record'
require 'action_controller'
end

# Search for fixtures first
fixture_path = File.dirname(__FILE__) + '/fixtures/'
begin
Dependencies.load_paths.insert(0, fixture_path)
rescue
$LOAD_PATH.unshift(fixture_path)
end
Dependencies.load_paths.insert(0, fixture_path)

require 'active_record/fixtures'

Expand Down Expand Up @@ -50,7 +48,8 @@ def assert_tag_counts(tags, expected_values)

tags.each do |tag|
value = expected_values.delete(tag.name)
assert_not_nil value, "Expected count for #{tag.name} was not provided" if value.nil?

assert_not_nil value, "Expected count for #{tag.name} was not provided"
assert_equal value, tag.count, "Expected value of #{value} for #{tag.name}, but was #{tag.count}"
end

Expand Down

0 comments on commit 789dbd5

Please sign in to comment.