Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated has_many_polymorphs

  • Loading branch information...
commit 7e635af69729197d9cce7a1b74c62332a8321913 1 parent 0f218a1
@netzpirat netzpirat authored
Showing with 180 additions and 133 deletions.
  1. +1 −0  vendor/plugins/has_many_polymorphs/.gitignore
  2. +3 −0  vendor/plugins/has_many_polymorphs/CHANGELOG
  3. +1 −2  vendor/plugins/has_many_polymorphs/Manifest
  4. +1 −1  vendor/plugins/has_many_polymorphs/README
  5. +1 −1  vendor/plugins/has_many_polymorphs/generators/tagging/templates/tag_test.rb
  6. +48 −4 vendor/plugins/has_many_polymorphs/generators/tagging/templates/tagging_extensions.rb
  7. +5 −5 vendor/plugins/has_many_polymorphs/generators/tagging/templates/tagging_test.rb
  8. +1 −1  vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs.rb
  9. +8 −11 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/association.rb
  10. +3 −4 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/autoload.rb
  11. +8 −4 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/class_methods.rb
  12. +3 −6 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/reflection.rb
  13. +7 −3 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/support_methods.rb
  14. +1 −1  vendor/plugins/has_many_polymorphs/test/generator/tagging_generator_test.rb
  15. +2 −1  vendor/plugins/has_many_polymorphs/test/integration/app/config/environments/development.rb
  16. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/generators/commenting_generator_test.rb
  17. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/addresses_controller_test.rb
  18. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/sellers_controller_test.rb
  19. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/states_controller_test.rb
  20. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/users_controller_test.rb
  21. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/test_helper.rb
  22. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/bone_test.rb
  23. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/double_sti_parent_relationship_test.rb
  24. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/double_sti_parent_test.rb
  25. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/organic_substance_test.rb
  26. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/single_sti_parent_relationship_test.rb
  27. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/single_sti_parent_test.rb
  28. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/stick_test.rb
  29. +1 −1  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/stone_test.rb
  30. +2 −2 vendor/plugins/has_many_polymorphs/test/integration/server_test.rb
  31. +1 −3 vendor/plugins/has_many_polymorphs/test/models/eaters_foodstuff.rb
  32. +2 −2 vendor/plugins/has_many_polymorphs/test/setup.rb
  33. +5 −4 vendor/plugins/has_many_polymorphs/test/test_helper.rb
  34. +63 −64 vendor/plugins/has_many_polymorphs/test/unit/has_many_polymorphs_test.rb
View
1  vendor/plugins/has_many_polymorphs/.gitignore
@@ -0,0 +1 @@
+test/integration/app/log
View
3  vendor/plugins/has_many_polymorphs/CHANGELOG
@@ -1,3 +1,6 @@
+v2.2. Various fixes.
+
+v2.13. Merge various fixes for Rails 2.2.2.
v2.12. Improvements to the test suite; bugfixes for STI children (rsl). Remove fancy dependency system in favor of using Dispatcher::to_prepare every time.
View
3  vendor/plugins/has_many_polymorphs/Manifest
@@ -22,6 +22,7 @@ lib/has_many_polymorphs/support_methods.rb
lib/has_many_polymorphs.rb
LICENSE
Manifest
+Rakefile
README
test/fixtures/bow_wows.yml
test/fixtures/cats.yml
@@ -92,10 +93,8 @@ test/integration/app/db/migrate/006_create_double_sti_parents.rb
test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb
test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb
test/integration/app/db/migrate/009_create_library_model.rb
-test/integration/app/db/schema.rb
test/integration/app/doc/README_FOR_APP
test/integration/app/generators/commenting_generator_test.rb
-test/integration/app/hmp_development
test/integration/app/lib/library_model.rb
test/integration/app/public/404.html
test/integration/app/public/500.html
View
2  vendor/plugins/has_many_polymorphs/README
@@ -29,7 +29,7 @@ The plugin also includes a generator for a tagging system, a common use case (se
== Requirements
-* Rails 1.2.3 or greater
+* Rails 2.2.2 or greater
= Usage
View
2  vendor/plugins/has_many_polymorphs/generators/tagging/templates/tag_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class TagTest < Test::Unit::TestCase
+class TagTest < ActiveSupport::TestCase
fixtures <%= taggable_models[0..1].join(", ") -%>
def setup
View
52 vendor/plugins/has_many_polymorphs/generators/tagging/templates/tagging_extensions.rb
@@ -1,4 +1,3 @@
-
class ActiveRecord::Base #:nodoc:
# These extensions make models taggable. This file is automatically generated and required by your app if you run the tagging generator included with has_many_polymorphs.
@@ -13,7 +12,7 @@ def _add_tags incoming
begin
tag = Tag.find_or_create_by_name(tag_name)
raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record?
- tag.taggables << self
+ tags << tag
rescue ActiveRecord::StatementInvalid => e
raise unless e.to_s =~ /duplicate/i
end
@@ -66,7 +65,11 @@ def tag_list #:nodoc:
<%= parent_association_name -%>s.to_s
#:startdoc:
end
-
+
+ def tag_list=(value)
+ tag_with(value)
+ end
+
private
def tag_cast_to_string obj #:nodoc:
@@ -120,7 +123,7 @@ def tagged_with(*tag_list)
sql = "SELECT #{(scope && scope[:select]) || options[:select]} "
sql << "FROM #{(scope && scope[:from]) || options[:from]} "
- add_joins!(sql, options, scope)
+ add_joins!(sql, options[:joins], scope)
sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id "
sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' "
@@ -144,6 +147,47 @@ def tagged_with(*tag_list)
find_by_sql(sql)
end
+
+ def self.tagged_with_any(*tag_list)
+ options = tag_list.last.is_a?(Hash) ? tag_list.pop : {}
+ tag_list = parse_tags(tag_list)
+
+ scope = scope(:find)
+ options[:select] ||= "#{table_name}.*"
+ options[:from] ||= "#{table_name}, tags, taggings"
+
+ sql = "SELECT #{(scope && scope[:select]) || options[:select]} "
+ sql << "FROM #{(scope && scope[:from]) || options[:from]} "
+
+ add_joins!(sql, options, scope)
+
+ sql << "WHERE #{table_name}.#{primary_key} = taggings.taggable_id "
+ sql << "AND taggings.taggable_type = '#{ActiveRecord::Base.send(:class_name_of_active_record_descendant, self).to_s}' "
+ sql << "AND taggings.tag_id = tags.id "
+
+ sql << "AND ("
+ or_options = []
+ tag_list.each do |name|
+ or_options << "tags.name = '#{name}'"
+ end
+ or_options_joined = or_options.join(" OR ")
+ sql << "#{or_options_joined}) "
+
+
+ sql << "AND #{sanitize_sql(options[:conditions])} " if options[:conditions]
+
+ columns = column_names.map do |column|
+ "#{table_name}.#{column}"
+ end.join(", ")
+
+ sql << "GROUP BY #{columns} "
+
+ add_order!(sql, options[:order], scope)
+ add_limit!(sql, options, scope)
+ add_lock!(sql, options, scope)
+
+ find_by_sql(sql)
+ end
def parse_tags(tags)
return [] if tags.blank?
View
10 vendor/plugins/has_many_polymorphs/generators/tagging/templates/tagging_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class TaggingTest < Test::Unit::TestCase
+class TaggingTest < ActiveSupport::TestCase
fixtures :tags, :taggings, <%= taggable_models[0..1].join(", ") -%>
def setup
@@ -45,15 +45,15 @@ def test_find_tagged_with
<% if options[:self_referential] -%>
def test_self_referential_tag_with
@tag1.tag_with [1, 2]
- assert @tag1.tags.include?(@tag1)
- assert !@tag2.tags.include?(@tag1)
+ assert @tag1.tags.any? {|obj| obj == @tag1}
+ assert !@tag2.tags.any? {|obj| obj == @tag1}
end
<% end -%>
def test__add_tags
@obj1._add_tags "porter longneck"
- assert Tag.find_by_name("porter").taggables.include?(@obj1)
- assert Tag.find_by_name("longneck").taggables.include?(@obj1)
+ assert Tag.find_by_name("porter").taggables.any? {|obj| obj == @obj1}
+ assert Tag.find_by_name("longneck").taggables.any? {|obj| obj == @obj1}
assert_equal "longneck pale porter", @obj1.tag_list
@obj1._add_tags [2]
View
2  vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs.rb
@@ -14,7 +14,7 @@ class ActiveRecord::Base
extend ActiveRecord::Associations::PolymorphicClassMethods
end
-if ENV['HMP_DEBUG'] or ENV['RAILS_ENV'] =~ /development|test/ and ENV['USER'] == 'eweaver'
+if ENV['HMP_DEBUG'] || ENV['RAILS_ENV'] =~ /development|test/ && ENV['USER'] == 'eweaver'
require 'has_many_polymorphs/debugging_tools'
end
View
19 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/association.rb
@@ -22,11 +22,7 @@ def <<(*records)
@reflection.klass.transaction do
flatten_deeper(records).each do |record|
if @owner.new_record? or not record.respond_to?(:new_record?) or record.new_record?
- unless @owner.valid?
- raise PolymorphicError, "Invalid tag: #{@owner.name} - #{@owner.errors.full_messages}"
- else
- raise PolymorphicError, "You can't associate unsaved records."
- end
+ raise PolymorphicError, "You can't associate unsaved records."
end
next if @reflection.options[:skip_duplicates] and @target.include? record
@owner.send(@reflection.through_reflection.name).proxy_target << @reflection.klass.create!(construct_join_attributes(record))
@@ -92,18 +88,19 @@ def clear(klass = nil)
def construct_quoted_owner_attributes(*args) #:nodoc:
# no access to returning() here? why not?
type_key = @reflection.options[:foreign_type_key]
- {@reflection.primary_key_name => @owner.id,
- type_key=> (@owner.class.base_class.name if type_key)}
+ h = {@reflection.primary_key_name => @owner.id}
+ h[type_key] = @owner.class.base_class.name if type_key
+ h
end
def construct_from #:nodoc:
# build the FROM part of the query, in this case, the polymorphic join table
- @reflection.klass.table_name
+ @reflection.klass.quoted_table_name
end
def construct_owner #:nodoc:
# the table name for the owner object's class
- @owner.class.table_name
+ @owner.class.quoted_table_name
end
def construct_owner_key #:nodoc:
@@ -118,10 +115,10 @@ def construct_select(custom_select = nil) #:nodoc:
def construct_joins(custom_joins = nil) #:nodoc:
# build the string of default joins
- "JOIN #{construct_owner} polymorphic_parent ON #{construct_from}.#{@reflection.options[:foreign_key]} = polymorphic_parent.#{construct_owner_key} " +
+ "JOIN #{construct_owner} AS polymorphic_parent ON #{construct_from}.#{@reflection.options[:foreign_key]} = polymorphic_parent.#{construct_owner_key} " +
@reflection.options[:from].map do |plural|
klass = plural._as_class
- "LEFT JOIN #{klass.table_name} ON #{construct_from}.#{@reflection.options[:polymorphic_key]} = #{klass.table_name}.#{klass.primary_key} AND #{construct_from}.#{@reflection.options[:polymorphic_type_key]} = #{@reflection.klass.quote_value(klass.base_class.name)}"
+ "LEFT JOIN #{klass.quoted_table_name} ON #{construct_from}.#{@reflection.options[:polymorphic_key]} = #{klass.quoted_table_name}.#{klass.primary_key} AND #{construct_from}.#{@reflection.options[:polymorphic_type_key]} = #{@reflection.klass.quote_value(klass.base_class.name)}"
end.uniq.join(" ") + " #{custom_joins}"
end
View
7 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/autoload.rb
@@ -1,6 +1,5 @@
-
require 'initializer' unless defined? ::Rails::Initializer
-require 'dispatcher' unless defined? ::ActionController::Dispatcher
+require 'action_controller/dispatcher' unless defined? ::ActionController::Dispatcher
module HasManyPolymorphs
@@ -37,7 +36,7 @@ def self.autoload
require requirement
end
- Dir[options[:file_pattern]].each do |filename|
+ Dir.glob(options[:file_pattern]).each do |filename|
next if filename =~ /#{options[:file_exclusions].join("|")}/
open filename do |file|
if file.grep(/#{options[:methods].join("|")}/).any?
@@ -64,7 +63,7 @@ def after_initialize_with_autoload
alias_method_chain :after_initialize, :autoload
end
-Dispatcher.to_prepare(:has_many_polymorphs_autoload) do
+ActionController::Dispatcher.to_prepare(:has_many_polymorphs_autoload) do
# Make sure it gets loaded in the app
HasManyPolymorphs.autoload
end
View
12 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/class_methods.rb
@@ -360,10 +360,14 @@ def build_table_aliases(from)
begin
table = plural._as_class.table_name
rescue NameError => e
- raise PolymorphicError, "Could not find a valid class for #{plural.inspect}. If it's namespaced, be sure to specify it as :\"module/#{plural}\" instead."
+ raise PolymorphicError, "Could not find a valid class for #{plural.inspect} (tried #{plural.to_s._classify}). If it's namespaced, be sure to specify it as :\"module/#{plural}\" instead."
end
- plural._as_class.columns.map(&:name).each_with_index do |field, f_index|
- aliases["#{table}.#{field}"] = "t#{t_index}_r#{f_index}"
+ begin
+ plural._as_class.columns.map(&:name).each_with_index do |field, f_index|
+ aliases["#{table}.#{field}"] = "t#{t_index}_r#{f_index}"
+ end
+ rescue ActiveRecord::StatementInvalid => e
+ _logger_warn "Looks like your table doesn't exist for #{plural.to_s._classify}.\nError #{e}\nSkipping..."
end
end
end
@@ -394,7 +398,7 @@ def create_join_association(association_id, reflection)
}
if reflection.options[:foreign_type_key]
- type_check = "#{reflection.options[:foreign_type_key]} = #{quote_value(self.base_class.name)}"
+ type_check = "#{reflection.options[:join_class_name].constantize.quoted_table_name}.#{reflection.options[:foreign_type_key]} = #{quote_value(self.base_class.name)}"
conjunction = options[:conditions] ? " AND " : nil
options[:conditions] = "#{options[:conditions]}#{conjunction}#{type_check}"
options[:as] = reflection.options[:as]
View
9 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/reflection.rb
@@ -8,11 +8,8 @@ module ClassMethods #:nodoc:
def create_reflection(macro, name, options, active_record)
case macro
when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
- reflection = AssociationReflection.new(macro, name, options, active_record)
- #the following lines are only compatible with rails 2.2
- #klass = options[:through] ? ThroughReflection :
- AssociationReflection
- #reflection = klass.new(macro, name, options, active_record)
+ klass = options[:through] ? ThroughReflection : AssociationReflection
+ reflection = klass.new(macro, name, options, active_record)
when :composed_of
reflection = AggregateReflection.new(macro, name, options, active_record)
# added by has_many_polymorphs #
@@ -36,7 +33,7 @@ class PolymorphicError < ActiveRecordError #:nodoc:
=end
- class PolymorphicReflection < AssociationReflection
+ class PolymorphicReflection < ThroughReflection
# Stub out the validity check. Has_many_polymorphs checks validity on macro creation, not on reflection.
def check_validity!
# nothing
View
10 vendor/plugins/has_many_polymorphs/lib/has_many_polymorphs/support_methods.rb
@@ -45,9 +45,13 @@ class Hash
# An implementation of select that returns a Hash.
def _select
- Hash[*self.select do |key, value|
- yield key, value
- end._flatten_once]
+ if RUBY_VERSION >= "1.9"
+ Hash[*self.select {|k, v| yield k, v }.flatten]
+ else
+ Hash[*self.select do |key, value|
+ yield key, value
+ end._flatten_once]
+ end
end
end
View
2  vendor/plugins/has_many_polymorphs/test/generator/tagging_generator_test.rb
@@ -1,7 +1,7 @@
require 'fileutils'
require File.dirname(__FILE__) + '/../test_helper'
-class TaggingGeneratorTest < Test::Unit::TestCase
+class TaggingGeneratorTest < ActiveSupport::TestCase
def setup
Dir.chdir RAILS_ROOT do
View
3  vendor/plugins/has_many_polymorphs/test/integration/app/config/environments/development.rb
@@ -3,6 +3,7 @@
config.whiny_nils = true
config.action_controller.consider_all_requests_local = !ENV['PRODUCTION']
config.action_controller.perform_caching = ENV['PRODUCTION']
-config.action_view.cache_template_extensions = ENV['PRODUCTION']
+# The following has been deprecated in Rails 2.1 and removed in 2.2
+config.action_view.cache_template_extensions = ENV['PRODUCTION'] if Rails::VERSION::MAJOR < 2 or Rails::VERSION::MAJOR == 2 && Rails::VERSION::MINOR < 1
config.action_view.debug_rjs = !ENV['PRODUCTION']
config.action_mailer.raise_delivery_errors = false
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/generators/commenting_generator_test.rb
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
require 'fileutils'
-class CommentingGeneratorTest < Test::Unit::TestCase
+class CommentingGeneratorTest < ActiveSupport::TestCase
def test_ensure_comments_dont_exist
# make sure the comments are already defined
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/addresses_controller_test.rb
@@ -4,7 +4,7 @@
# Re-raise errors caught by the controller.
class AddressesController; def rescue_action(e) raise e end; end
-class AddressesControllerTest < Test::Unit::TestCase
+class AddressesControllerTest < ActiveSupport::TestCase
fixtures :addresses
def setup
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/sellers_controller_test.rb
@@ -4,7 +4,7 @@
# Re-raise errors caught by the controller.
class SellersController; def rescue_action(e) raise e end; end
-class SellersControllerTest < Test::Unit::TestCase
+class SellersControllerTest < ActiveSupport::TestCase
fixtures :sellers
def setup
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/states_controller_test.rb
@@ -4,7 +4,7 @@
# Re-raise errors caught by the controller.
class StatesController; def rescue_action(e) raise e end; end
-class StatesControllerTest < Test::Unit::TestCase
+class StatesControllerTest < ActiveSupport::TestCase
fixtures :states
def setup
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/functional/users_controller_test.rb
@@ -4,7 +4,7 @@
# Re-raise errors caught by the controller.
class UsersController; def rescue_action(e) raise e end; end
-class UsersControllerTest < Test::Unit::TestCase
+class UsersControllerTest < ActiveSupport::TestCase
fixtures :users
def setup
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/test_helper.rb
@@ -2,7 +2,7 @@
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
-class Test::Unit::TestCase
+class ActiveSupport::TestCase
self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
end
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/bone_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class BoneTest < Test::Unit::TestCase
+class BoneTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/double_sti_parent_relationship_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class DoubleStiParentRelationshipTest < Test::Unit::TestCase
+class DoubleStiParentRelationshipTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/double_sti_parent_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class DoubleStiParentTest < Test::Unit::TestCase
+class DoubleStiParentTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/organic_substance_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class OrganicSubstanceTest < Test::Unit::TestCase
+class OrganicSubstanceTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/single_sti_parent_relationship_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class SingleStiParentRelationshipTest < Test::Unit::TestCase
+class SingleStiParentRelationshipTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/single_sti_parent_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class SingleStiParentTest < Test::Unit::TestCase
+class SingleStiParentTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/stick_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class StickTest < Test::Unit::TestCase
+class StickTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
2  vendor/plugins/has_many_polymorphs/test/integration/app/test/unit/stone_test.rb
@@ -1,6 +1,6 @@
require File.dirname(__FILE__) + '/../test_helper'
-class StoneTest < Test::Unit::TestCase
+class StoneTest < ActiveSupport::TestCase
# Replace this with your real tests.
def test_truth
assert true
View
4 vendor/plugins/has_many_polymorphs/test/integration/server_test.rb
@@ -4,7 +4,7 @@
# Start the server
-class ServerTest < Test::Unit::TestCase
+class ServerTest < ActiveSupport::TestCase
PORT = 43040
URL = "http://localhost:#{PORT}/"
@@ -40,4 +40,4 @@ def test_verify_autoload_gets_invoked_in_console
# XXX Probably can use script/runner to test this
end
-end
+end
View
4 vendor/plugins/has_many_polymorphs/test/models/eaters_foodstuff.rb
@@ -3,8 +3,6 @@ class EatersFoodstuff < ActiveRecord::Base
belongs_to :foodstuff, :class_name => "Petfood", :foreign_key => "foodstuff_id"
belongs_to :eater, :polymorphic => true
- def before_save
- self.some_attribute = 3
- end
+ before_save { |record| record.some_attribute = 3 }
end
View
4 vendor/plugins/has_many_polymorphs/test/setup.rb
@@ -6,8 +6,8 @@
system("rm has_many_polymorphs; ln -s ../../../../../ has_many_polymorphs")
end
- system "rake db:drop --trace RAILS_GEM_VERSION=2.0.2 "
- system "rake db:create --trace RAILS_GEM_VERSION=2.0.2 "
+ system "rake db:drop --trace RAILS_GEM_VERSION=2.2.2 "
+ system "rake db:create --trace RAILS_GEM_VERSION=2.2.2 "
system "rake db:migrate --trace"
system "rake db:fixtures:load --trace"
end
View
9 vendor/plugins/has_many_polymorphs/test/test_helper.rb
@@ -1,10 +1,11 @@
$VERBOSE = nil
require 'rubygems'
+require 'rake' # echoe relies on Rake being present but doesn't require it itself
require 'echoe'
require 'test/unit'
require 'multi_rails_init'
-require 'ruby-debug'
+#require 'ruby-debug' # uncomment if needed (for Ruby >= 1.9 use require 'debug' where needed)
if defined? ENV['MULTIRAILS_RAILS_VERSION']
ENV['RAILS_GEM_VERSION'] = ENV['MULTIRAILS_RAILS_VERSION']
@@ -23,13 +24,13 @@
require 'integration/app/config/environment'
require 'test_help'
-Inflector.inflections {|i| i.irregular 'fish', 'fish' }
+ActiveSupport::Inflector.inflections {|i| i.irregular 'fish', 'fish' }
-$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path = HERE + "/fixtures")
+$LOAD_PATH.unshift(ActiveSupport::TestCase.fixture_path = HERE + "/fixtures")
$LOAD_PATH.unshift(HERE + "/models")
$LOAD_PATH.unshift(HERE + "/modules")
-class Test::Unit::TestCase
+class ActiveSupport::TestCase
self.use_transactional_fixtures = !(ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::MysqlAdapter rescue false)
self.use_instantiated_fixtures = false
end
View
127 vendor/plugins/has_many_polymorphs/test/unit/has_many_polymorphs_test.rb
@@ -10,7 +10,7 @@
require 'aquatic/pupils_whale'
require 'beautiful_fight_relationship'
-class PolymorphTest < Test::Unit::TestCase
+class PolymorphTest < ActiveSupport::TestCase
set_fixture_class :bow_wows => Dog
set_fixture_class :keep_your_enemies_close => BeautifulFightRelationship
@@ -76,7 +76,7 @@ def test_assignment
def test_duplicate_assignment
# try to add a duplicate item when :ignore_duplicates is false
@kibbles.eaters.push(@alice)
- assert @kibbles.eaters.include?(@alice)
+ assert @kibbles.eaters.any? {|obj| obj == @alice}
@kibbles.eaters.push(@alice)
assert_equal @kibbles_eaters_count + 2, @kibbles.eaters.count
assert_equal @join_count + 2, EatersFoodstuff.count
@@ -114,7 +114,7 @@ def test_add_join_record
# reload; is the new association there?
assert @bits.eaters.reload
- assert @bits.eaters.include?(@chloe)
+ assert @bits.eaters.any? {|obj| obj == @chloe}
end
def test_build_join_record_on_association
@@ -126,7 +126,7 @@ def test_build_join_record_on_association
assert_equal @join_count + 1, EatersFoodstuff.count
assert @bits.eaters.reload
- assert @bits.eaters.include?(@chloe)
+ assert @bits.eaters.any? {|obj| obj == @chloe}
end
# not supporting this, since has_many :through doesn't support it either
@@ -145,12 +145,12 @@ def test_build_join_record_on_association
def test_self_reference
assert @kibbles.eaters << @bits
assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count
- assert @kibbles.eaters.include?(@bits)
+ assert @kibbles.eaters.any? {|obj| obj == @bits}
@kibbles.reload
assert @kibbles.foodstuffs_of_eaters.blank?
@bits.reload
- assert @bits.foodstuffs_of_eaters.include?(@kibbles)
+ assert @bits.foodstuffs_of_eaters.any? {|obj| obj == @kibbles}
assert_equal [@kibbles], @bits.foodstuffs_of_eaters
end
@@ -190,9 +190,9 @@ def test_individual_collections
def test_individual_collections_push
assert_equal [@chloe], (@kibbles.eater_kittens << @chloe)
@kibbles.reload
- assert @kibbles.eaters.include?(@chloe)
- assert @kibbles.eater_kittens.include?(@chloe)
- assert !@kibbles.eater_dogs.include?(@chloe)
+ assert @kibbles.eaters.any? {|obj| obj == @chloe}
+ assert @kibbles.eater_kittens.any? {|obj| obj == @chloe}
+ assert !@kibbles.eater_dogs.any? {|obj| obj == @chloe}
end
def test_individual_collections_delete
@@ -204,7 +204,7 @@ def test_individual_collections_delete
@kibbles.reload
assert @kibbles.eater_kittens.empty?
- assert @kibbles.eater_dogs.include?(@spot)
+ assert @kibbles.eater_dogs.any? {|obj| obj == @spot}
end
def test_individual_collections_clear
@@ -217,14 +217,14 @@ def test_individual_collections_clear
assert @kibbles.eater_kittens.empty?
assert_equal 2, @kibbles.eaters.size
- assert !@kibbles.eater_kittens.include?(@chloe)
- assert !@kibbles.eaters.include?(@chloe)
+ assert !@kibbles.eater_kittens.any? {|obj| obj == @chloe}
+ assert !@kibbles.eaters.any? {|obj| obj == @chloe}
@kibbles.reload
assert @kibbles.eater_kittens.empty?
assert_equal 2, @kibbles.eaters.size
- assert !@kibbles.eater_kittens.include?(@chloe)
- assert !@kibbles.eaters.include?(@chloe)
+ assert !@kibbles.eater_kittens.any? {|obj| obj == @chloe}
+ assert !@kibbles.eaters.any? {|obj| obj == @chloe}
end
def test_childrens_individual_collections
@@ -316,13 +316,13 @@ def test_creating_namespaced_relationship
def test_namespaced_polymorphic_collection
@shamu.aquatic_pupils << @swimmy
- assert @shamu.aquatic_pupils.include?(@swimmy)
+ assert @shamu.aquatic_pupils.any? {|obj| obj == @swimmy}
@shamu.reload
- assert @shamu.aquatic_pupils.include?(@swimmy)
+ assert @shamu.aquatic_pupils.any? {|obj| obj == @swimmy}
@shamu.aquatic_pupils << @spot
- assert @shamu.dogs.include?(@spot)
- assert @shamu.aquatic_pupils.include?(@swimmy)
+ assert @shamu.dogs.any? {|obj| obj == @spot}
+ assert @shamu.aquatic_pupils.any? {|obj| obj == @swimmy}
assert_equal @swimmy, @shamu.aquatic_fish.first
assert_equal 10, @shamu.aquatic_fish.first.speed
end
@@ -333,8 +333,8 @@ def test_deleting_namespaced_relationship
@shamu.reload
@shamu.aquatic_pupils.delete @spot
- assert !@shamu.dogs.include?(@spot)
- assert !@shamu.aquatic_pupils.include?(@spot)
+ assert !@shamu.dogs.any? {|obj| obj == @spot}
+ assert !@shamu.aquatic_pupils.any? {|obj| obj == @spot}
assert_equal 1, @shamu.aquatic_pupils.length
end
@@ -357,9 +357,9 @@ def test_double_collection_assignment
@alice.enemies << @spot
@alice.reload
@spot.reload
- assert @spot.protectors.include?(@alice)
- assert @alice.enemies.include?(@spot)
- assert !@alice.protectors.include?(@alice)
+ assert @spot.protectors.any? {|obj| obj == @alice}
+ assert @alice.enemies.any? {|obj| obj == @spot}
+ assert !@alice.protectors.any? {|obj| obj == @alice}
assert_equal 1, @alice.beautiful_fight_relationships_as_protector.size
assert_equal 0, @alice.beautiful_fight_relationships_as_enemy.size
assert_equal 1, @alice.beautiful_fight_relationships.size
@@ -367,7 +367,7 @@ def test_double_collection_assignment
# self reference
assert_equal 1, @alice.enemies.length
@alice.enemies.push @alice
- assert @alice.enemies.include?(@alice)
+ assert @alice.enemies.any? {|obj| obj == @alice}
assert_equal 2, @alice.enemies.length
@alice.reload
assert_equal 2, @alice.beautiful_fight_relationships_as_protector.size
@@ -386,7 +386,7 @@ def test_double_collection_build_join_record_on_association
assert_equal @double_join_count + 1, BeautifulFightRelationship.count
assert @alice.enemies.reload
- assert @alice.enemies.include?(@spot)
+ assert @alice.enemies.any? {|obj| obj == @spot}
end
def test_double_dependency_injection
@@ -396,12 +396,12 @@ def test_double_dependency_injection
def test_double_collection_deletion
@alice.enemies << @spot
@alice.reload
- assert @alice.enemies.include?(@spot)
+ assert @alice.enemies.any? {|obj| obj == @spot}
@alice.enemies.delete(@spot)
- assert !@alice.enemies.include?(@spot)
+ assert !@alice.enemies.any? {|obj| obj == @spot}
assert @alice.enemies.empty?
@alice.reload
- assert !@alice.enemies.include?(@spot)
+ assert !@alice.enemies.any? {|obj| obj == @spot}
assert @alice.enemies.empty?
assert_equal 0, @alice.beautiful_fight_relationships.size
end
@@ -409,12 +409,12 @@ def test_double_collection_deletion
def test_double_collection_deletion_from_opposite_side
@alice.protectors << @puma
@alice.reload
- assert @alice.protectors.include?(@puma)
+ assert @alice.protectors.any? {|obj| obj == @puma}
@alice.protectors.delete(@puma)
- assert !@alice.protectors.include?(@puma)
+ assert !@alice.protectors.any? {|obj| obj == @puma}
assert @alice.protectors.empty?
@alice.reload
- assert !@alice.protectors.include?(@puma)
+ assert !@alice.protectors.any? {|obj| obj == @puma}
assert @alice.protectors.empty?
assert_equal 0, @alice.beautiful_fight_relationships.size
end
@@ -423,59 +423,58 @@ def test_individual_collections_created_for_double_relationship
assert @alice.dogs.empty?
@alice.enemies << @spot
- assert @alice.enemies.include?(@spot)
- assert !@alice.kittens.include?(@alice)
+ assert @alice.enemies.any? {|obj| obj == @spot}
+ assert !@alice.kittens.any? {|obj| obj == @alice}
- assert !@alice.dogs.include?(@spot)
+ assert !@alice.dogs.any? {|obj| obj == @spot}
@alice.reload
- assert @alice.dogs.include?(@spot)
- assert !WildBoar.find(@alice.id).dogs.include?(@spot) # make sure the parent type is checked
+ assert @alice.dogs.any? {|obj| obj == @spot}
+ assert !WildBoar.find(@alice.id).dogs.any? {|obj| obj == @spot} # make sure the parent type is checked
end
def test_individual_collections_created_for_double_relationship_from_opposite_side
assert @alice.wild_boars.empty?
@alice.protectors << @puma
-
- assert @alice.protectors.include?(@puma)
- assert !@alice.wild_boars.include?(@puma)
@alice.reload
- assert @alice.wild_boars.include?(@puma)
+
+ assert @alice.protectors.any? {|obj| obj == @puma}
+ assert @alice.wild_boars.any? {|obj| obj == @puma}
- assert !Dog.find(@alice.id).wild_boars.include?(@puma) # make sure the parent type is checked
+ assert !Dog.find(@alice.id).wild_boars.any? {|obj| obj == @puma} # make sure the parent type is checked
end
def test_self_referential_individual_collections_created_for_double_relationship
@alice.enemies << @alice
@alice.reload
- assert @alice.enemy_kittens.include?(@alice)
- assert @alice.protector_kittens.include?(@alice)
- assert @alice.kittens.include?(@alice)
+ assert @alice.enemy_kittens.any? {|obj| obj == @alice}
+ assert @alice.protector_kittens.any? {|obj| obj == @alice}
+ assert @alice.kittens.any? {|obj| obj == @alice}
assert_equal 2, @alice.kittens.size
@alice.enemies << (@chloe = Kitten.find_by_name('Chloe'))
@alice.reload
- assert @alice.enemy_kittens.include?(@chloe)
- assert !@alice.protector_kittens.include?(@chloe)
- assert @alice.kittens.include?(@chloe)
+ assert @alice.enemy_kittens.any? {|obj| obj == @chloe}
+ assert !@alice.protector_kittens.any? {|obj| obj == @chloe}
+ assert @alice.kittens.any? {|obj| obj == @chloe}
assert_equal 3, @alice.kittens.size
end
def test_child_of_polymorphic_join_can_reach_parent
@alice.enemies << @spot
@alice.reload
- assert @spot.protectors.include?(@alice)
+ assert @spot.protectors.any? {|obj| obj == @alice}
end
def test_double_collection_deletion_from_child_polymorphic_join
@alice.enemies << @spot
@spot.protectors.delete(@alice)
- assert !@spot.protectors.include?(@alice)
+ assert !@spot.protectors.any? {|obj| obj == @alice}
@alice.reload
- assert !@alice.enemies.include?(@spot)
+ assert !@alice.enemies.any? {|obj| obj == @spot}
BeautifulFightRelationship.create(:protector_id => 2, :protector_type => "Dog", :enemy_id => @spot.id, :enemy_type => @spot.class.name)
@alice.enemies << @spot
@spot.protectors.delete(@alice)
- assert !@spot.protectors.include?(@alice)
+ assert !@spot.protectors.any? {|obj| obj == @alice}
end
def test_collection_query_on_unsaved_record
@@ -486,15 +485,15 @@ def test_collection_query_on_unsaved_record
def test_double_individual_collections_push
assert_equal [@chloe], (@spot.protector_kittens << @chloe)
@spot.reload
- assert @spot.protectors.include?(@chloe)
- assert @spot.protector_kittens.include?(@chloe)
- assert !@spot.protector_dogs.include?(@chloe)
+ assert @spot.protectors.any? {|obj| obj == @chloe}
+ assert @spot.protector_kittens.any? {|obj| obj == @chloe}
+ assert !@spot.protector_dogs.any? {|obj| obj == @chloe}
assert_equal [@froggy], (@spot.frogs << @froggy)
@spot.reload
- assert @spot.enemies.include?(@froggy)
- assert @spot.frogs.include?(@froggy)
- assert !@spot.enemy_dogs.include?(@froggy)
+ assert @spot.enemies.any? {|obj| obj == @froggy}
+ assert @spot.frogs.any? {|obj| obj == @froggy}
+ assert !@spot.enemy_dogs.any? {|obj| obj == @froggy}
end
def test_double_individual_collections_delete
@@ -506,7 +505,7 @@ def test_double_individual_collections_delete
@spot.reload
assert @spot.protector_kittens.empty?
- assert @spot.wild_boars.include?(@puma)
+ assert @spot.wild_boars.any? {|obj| obj == @puma}
end
def test_double_individual_collections_clear
@@ -518,12 +517,12 @@ def test_double_individual_collections_clear
@spot.reload
assert @spot.protector_kittens.empty?
assert_equal 1, @spot.protectors.size
- assert !@spot.protector_kittens.include?(@chloe)
- assert !@spot.protectors.include?(@chloe)
- assert !@spot.protector_kittens.include?(@alice)
- assert !@spot.protectors.include?(@alice)
- assert @spot.protectors.include?(@puma)
- assert @spot.wild_boars.include?(@puma)
+ assert !@spot.protector_kittens.any? {|obj| obj == @chloe}
+ assert !@spot.protectors.any? {|obj| obj == @chloe}
+ assert !@spot.protector_kittens.any? {|obj| obj == @alice}
+ assert !@spot.protectors.any? {|obj| obj == @alice}
+ assert @spot.protectors.any? {|obj| obj == @puma}
+ assert @spot.wild_boars.any? {|obj| obj == @puma}
end
def test_single_extensions
Please sign in to comment.
Something went wrong with that request. Please try again.