mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-07 16:24:21 +01:00
Update has_many_polymorphs to 421dd0bd60b246652bbbafd64724ebf1efa27607
This commit is contained in:
parent
804d59c542
commit
144e74682b
49 changed files with 189 additions and 126 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
# Filters added to this controller apply to all controllers in the application.
|
||||
# Likewise, all the methods added will be available for all controllers.
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
# Pick a unique cookie name to distinguish our session data from others'
|
||||
session :session_key => '_testapp_session_id'
|
||||
end
|
||||
|
|
@ -3,6 +3,7 @@ config.cache_classes = ENV['PRODUCTION']
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
0
vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.cgi
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.cgi
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.fcgi
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.fcgi
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.rb
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.rb
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/about
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/about
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/breakpointer
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/breakpointer
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/console
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/console
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/destroy
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/destroy
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/generate
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/generate
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/performance/benchmarker
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/performance/benchmarker
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/performance/profiler
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/performance/profiler
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/plugin
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/plugin
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/process/inspector
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/process/inspector
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/process/reaper
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/process/reaper
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/process/spawner
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/process/spawner
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/runner
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/runner
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/server
vendored
Normal file → Executable file
0
vendor/plugins/has_many_polymorphs/test/integration/app/script/server
vendored
Normal file → Executable file
|
|
@ -4,7 +4,7 @@ require 'addresses_controller'
|
|||
# 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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'sellers_controller'
|
|||
# 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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'states_controller'
|
|||
# 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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'users_controller'
|
|||
# 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
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ ENV["RAILS_ENV"] = "development"
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ require 'open-uri'
|
|||
|
||||
# Start the server
|
||||
|
||||
class ServerTest < Test::Unit::TestCase
|
||||
class ServerTest < ActiveSupport::TestCase
|
||||
|
||||
PORT = 43040
|
||||
URL = "http://localhost:#{PORT}/"
|
||||
|
|
@ -40,4 +40,4 @@ class ServerTest < Test::Unit::TestCase
|
|||
# XXX Probably can use script/runner to test this
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ Dir.chdir "#{File.dirname(__FILE__)}/integration/app/" do
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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 @@ LOG = "#{HERE}/integration/app/log/development.log"
|
|||
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
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ require 'aquatic/fish'
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
|
||||
# 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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
|
||||
@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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
|
||||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
|
||||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
|
||||
@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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
@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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
# 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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
|
||||
@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 @@ class PolymorphTest < Test::Unit::TestCase
|
|||
@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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue