Rails 2.0 RC1を使うようになったせいかどうかはわからないのですが、何故か僕の環境では acts_as_taggable_on_steroids のplugin testでFailureが一つ出るようになっていたので、修正してみました。

こんなエラーが出る

  1) Failure:
test_tag_destroyed_when_unused(ActsAsTaggableOnSteroidsTest)
    [./test/abstract_unit.rb:81:in \`assert_difference'
     /home/takiuchi/blog/vendor/rails/activerecord/lib/active_record/\
callbacks.rb:309:in \`each_with_index'
     ./test/abstract_unit.rb:80:in \`each'
     ./test/abstract_unit.rb:80:in \`each_with_index'
     ./test/abstract_unit.rb:80:in \`assert_difference'
     ./test/acts_as_taggable_test.rb:328:in \`test_tag_destroyed_when_unused']:
<5> expected but was
<6>.

修正箇所は以下のとおり。

vendor/plugins/acts_as_taggable_on_steroids/lib/acts_as_taggable.rb (L167-184)

ruby>>
def save_tags
return unless @tag_list

  new_tag_names = @tag_list - tags.map(&:name)
  old_tags = tags.reject { |tag| @tag_list.include?(tag.name) }

  self.class.transaction do
    tags.delete(*old_tags) if old_tags.any?
    # added by takiuchi to make all tests green.
    old_tags.each{|tag| tag.destroy} if Tag.destroy_unused
      new_tag_names.each do |new_tag_name|
      tags << Tag.find_or_create_with_like_by_name(new_tag_name)
    end
  end

  true
end

<<--

Tag.destroy_unused が指定されている場合、old_tagsdestroy
するようにしました。これで上記の Failure は出なくなりました。

posted by genki genki on Thu 15 Nov 2007 at 01:47 with 0 comments