PageRenderTime 109ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/plugins/acts_as_taggable_on_steroids/test/abstract_unit.rb

https://github.com/bricooke/my-biz-expenses
Ruby | 67 lines | 51 code | 13 blank | 3 comment | 4 complexity | c4431a8764999ff290ea01928b97d162 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, BSD-3-Clause
  1. require 'test/unit'
  2. begin
  3. require File.dirname(__FILE__) + '/../../../../config/boot'
  4. require 'active_record'
  5. rescue LoadError
  6. require 'rubygems'
  7. require_gem 'activerecord'
  8. end
  9. require 'active_record/fixtures'
  10. require File.dirname(__FILE__) + '/../lib/acts_as_taggable'
  11. require File.dirname(__FILE__) + '/../lib/tag'
  12. require File.dirname(__FILE__) + '/../lib/tagging'
  13. ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
  14. config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
  15. ActiveRecord::Base.configurations = config
  16. ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'mysql'])
  17. load(File.dirname(__FILE__) + '/schema.rb')
  18. Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + '/fixtures/'
  19. $LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
  20. class Test::Unit::TestCase #:nodoc:
  21. def create_fixtures(*table_names)
  22. if block_given?
  23. Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
  24. else
  25. Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
  26. end
  27. end
  28. # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
  29. self.use_transactional_fixtures = true
  30. # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
  31. self.use_instantiated_fixtures = false
  32. def assert_equivalent(expected, actual, message = nil)
  33. if expected.first.is_a?(ActiveRecord::Base)
  34. assert_equal expected.sort_by(&:id), actual.sort_by(&:id), message
  35. else
  36. assert_equal expected.sort, actual.sort, message
  37. end
  38. end
  39. def assert_tag_counts(tags, expected_values)
  40. # Map the tag fixture names to real tag names
  41. expected_values = expected_values.inject({}) do |hash, (tag, count)|
  42. hash[tags(tag).name] = count
  43. hash
  44. end
  45. tags.each do |tag|
  46. value = expected_values.delete(tag.name)
  47. assert_not_nil value, "Expected count for #{tag.name} was not provided" if value.nil?
  48. assert_equal value, tag.count, "Expected value of #{value} for #{tag.name}, but was #{tag.count}"
  49. end
  50. unless expected_values.empty?
  51. assert false, "The following tag counts were not present: #{expected_values.inspect}"
  52. end
  53. end
  54. end