has_many_polymorphs 2.10 → 2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +0 -0
- data/CHANGELOG +2 -0
- data/Manifest +191 -56
- data/TODO +1 -0
- data/examples/hmph.rb +69 -0
- data/generators/commenting/commenting_generator.rb +94 -0
- data/generators/commenting/templates/comment.rb +33 -0
- data/generators/commenting/templates/comment_test.rb +12 -0
- data/generators/commenting/templates/commenting.rb +13 -0
- data/generators/commenting/templates/commenting_extensions.rb +30 -0
- data/generators/commenting/templates/commenting_test.rb +30 -0
- data/generators/commenting/templates/commentings.yml +23 -0
- data/generators/commenting/templates/comments.yml +13 -0
- data/generators/commenting/templates/migration.rb +28 -0
- data/generators/tagging/templates/tagging_extensions.rb +4 -8
- data/has_many_polymorphs.gemspec +19 -12
- data/lib/has_many_polymorphs.rb +3 -4
- data/lib/has_many_polymorphs/autoload.rb +4 -4
- data/lib/has_many_polymorphs/class_methods.rb +8 -8
- data/lib/has_many_polymorphs/debugging_tools.rb +2 -0
- data/lib/has_many_polymorphs/dependencies.rb +9 -4
- data/lib/has_many_polymorphs/support_methods.rb +3 -1
- data/test/fixtures/{aquatic/fish.yml → fish.yml} +0 -0
- data/test/fixtures/{aquatic/little_whale_pupils.yml → little_whale_pupils.yml} +0 -0
- data/test/fixtures/{aquatic/whales.yml → whales.yml} +0 -0
- data/test/integration/app/README +182 -0
- data/test/integration/app/Rakefile +19 -0
- data/test/integration/app/app/controllers/addresses_controller.rb +85 -0
- data/test/integration/app/app/controllers/application.rb +7 -0
- data/test/integration/app/app/controllers/sellers_controller.rb +85 -0
- data/test/integration/app/app/controllers/states_controller.rb +85 -0
- data/test/integration/app/app/controllers/users_controller.rb +85 -0
- data/test/integration/app/app/helpers/addresses_helper.rb +2 -0
- data/test/integration/app/app/helpers/application_helper.rb +3 -0
- data/test/integration/app/app/helpers/sellers_helper.rb +28 -0
- data/test/integration/app/app/helpers/states_helper.rb +2 -0
- data/test/integration/app/app/helpers/users_helper.rb +2 -0
- data/test/integration/app/app/models/address.rb +4 -0
- data/test/integration/app/app/models/citation.rb +3 -0
- data/test/integration/app/app/models/citations_item.rb +4 -0
- data/test/integration/app/app/models/seller.rb +4 -0
- data/test/integration/app/app/models/state.rb +3 -0
- data/test/integration/app/app/models/user.rb +4 -0
- data/test/integration/app/app/views/addresses/edit.html.erb +12 -0
- data/test/integration/app/app/views/addresses/index.html.erb +18 -0
- data/test/integration/app/app/views/addresses/new.html.erb +11 -0
- data/test/integration/app/app/views/addresses/show.html.erb +3 -0
- data/test/integration/app/app/views/layouts/addresses.html.erb +17 -0
- data/test/integration/app/app/views/layouts/sellers.html.erb +17 -0
- data/test/integration/app/app/views/layouts/states.html.erb +17 -0
- data/test/integration/app/app/views/layouts/users.html.erb +17 -0
- data/test/integration/app/app/views/sellers/edit.html.erb +12 -0
- data/test/integration/app/app/views/sellers/index.html.erb +20 -0
- data/test/integration/app/app/views/sellers/new.html.erb +11 -0
- data/test/integration/app/app/views/sellers/show.html.erb +3 -0
- data/test/integration/app/app/views/states/edit.html.erb +12 -0
- data/test/integration/app/app/views/states/index.html.erb +19 -0
- data/test/integration/app/app/views/states/new.html.erb +11 -0
- data/test/integration/app/app/views/states/show.html.erb +3 -0
- data/test/integration/app/app/views/users/edit.html.erb +12 -0
- data/test/integration/app/app/views/users/index.html.erb +22 -0
- data/test/integration/app/app/views/users/new.html.erb +11 -0
- data/test/integration/app/app/views/users/show.html.erb +3 -0
- data/test/integration/app/config/boot.rb +45 -0
- data/test/integration/app/config/database.yml +21 -0
- data/test/integration/app/config/environment.rb +13 -0
- data/test/integration/app/config/environments/development.rb +7 -0
- data/test/integration/app/config/environments/production.rb +18 -0
- data/test/integration/app/config/environments/test.rb +19 -0
- data/test/integration/app/config/locomotive.yml +6 -0
- data/test/integration/app/config/routes.rb +33 -0
- data/test/integration/app/config/ultrasphinx/default.base +56 -0
- data/test/integration/app/config/ultrasphinx/development.conf.canonical +155 -0
- data/test/integration/app/db/migrate/001_create_users.rb +16 -0
- data/test/integration/app/db/migrate/002_create_sellers.rb +14 -0
- data/test/integration/app/db/migrate/003_create_addresses.rb +19 -0
- data/test/integration/app/db/migrate/004_create_states.rb +12 -0
- data/test/integration/app/db/migrate/005_add_capitalization_to_seller.rb +9 -0
- data/test/integration/app/db/migrate/006_add_deleted_to_user.rb +9 -0
- data/test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb +11 -0
- data/test/integration/app/db/migrate/008_create_citations.rb +12 -0
- data/test/integration/app/db/migrate/009_create_citations_items.rb +14 -0
- data/test/integration/app/db/schema.rb +144 -0
- data/test/integration/app/doc/README_FOR_APP +2 -0
- data/test/integration/app/generated_models/aquatic_fish.rb +109 -0
- data/test/integration/app/generated_models/aquatic_pupils_whale.rb +13 -0
- data/test/integration/app/generated_models/aquatic_whale.rb +42 -0
- data/test/integration/app/generated_models/beautiful_fight_relationship.rb +25 -0
- data/test/integration/app/generated_models/citation.rb +40 -0
- data/test/integration/app/generated_models/citations_item.rb +12 -0
- data/test/integration/app/generated_models/dog.rb +183 -0
- data/test/integration/app/generated_models/eaters_foodstuff.rb +13 -0
- data/test/integration/app/generated_models/frog.rb +78 -0
- data/test/integration/app/generated_models/kitten.rb +161 -0
- data/test/integration/app/generated_models/parentship.rb +14 -0
- data/test/integration/app/generated_models/person.rb +53 -0
- data/test/integration/app/generated_models/petfood.rb +125 -0
- data/test/integration/app/generated_models/polymorph_test_some_model.rb +25 -0
- data/test/integration/app/generated_models/seller.rb +30 -0
- data/test/integration/app/generated_models/tabby.rb +26 -0
- data/test/integration/app/generated_models/user.rb +34 -0
- data/test/integration/app/generated_models/wild_boar.rb +87 -0
- data/test/integration/app/generators/commenting_generator_test.rb +83 -0
- data/test/integration/app/public/404.html +30 -0
- data/test/integration/app/public/500.html +30 -0
- data/test/integration/app/public/dispatch.cgi +10 -0
- data/test/integration/app/public/dispatch.fcgi +24 -0
- data/test/integration/app/public/dispatch.rb +10 -0
- data/test/integration/app/public/favicon.ico +0 -0
- data/test/integration/app/public/images/rails.png +0 -0
- data/test/integration/app/public/index.html +277 -0
- data/test/integration/app/public/javascripts/application.js +2 -0
- data/test/integration/app/public/javascripts/controls.js +833 -0
- data/test/integration/app/public/javascripts/dragdrop.js +942 -0
- data/test/integration/app/public/javascripts/effects.js +1088 -0
- data/test/integration/app/public/javascripts/prototype.js +2515 -0
- data/test/integration/app/public/robots.txt +1 -0
- data/test/integration/app/public/stylesheets/scaffold.css +74 -0
- data/test/integration/app/script/about +3 -0
- data/test/integration/app/script/breakpointer +3 -0
- data/test/integration/app/script/console +3 -0
- data/test/integration/app/script/destroy +3 -0
- data/test/integration/app/script/generate +3 -0
- data/test/integration/app/script/performance/benchmarker +3 -0
- data/test/integration/app/script/performance/profiler +3 -0
- data/test/integration/app/script/plugin +3 -0
- data/test/integration/app/script/process/inspector +3 -0
- data/test/integration/app/script/process/reaper +3 -0
- data/test/integration/app/script/process/spawner +3 -0
- data/test/integration/app/script/runner +3 -0
- data/test/integration/app/script/server +3 -0
- data/test/integration/app/test/fixtures/addresses.yml +13 -0
- data/test/integration/app/test/fixtures/citations.yml +9 -0
- data/test/integration/app/test/fixtures/citations_items.yml +9 -0
- data/test/integration/app/test/fixtures/sellers.yml +10 -0
- data/test/integration/app/test/fixtures/states.yml +216 -0
- data/test/integration/app/test/fixtures/users.yml +11 -0
- data/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
- data/test/integration/app/test/functional/sellers_controller_test.rb +57 -0
- data/test/integration/app/test/functional/states_controller_test.rb +57 -0
- data/test/integration/app/test/functional/users_controller_test.rb +57 -0
- data/test/integration/app/test/test_helper.rb +28 -0
- data/test/integration/app/test/unit/address_test.rb +10 -0
- data/test/integration/app/test/unit/citation_test.rb +10 -0
- data/test/integration/app/test/unit/citations_item_test.rb +10 -0
- data/test/integration/app/test/unit/seller_test.rb +10 -0
- data/test/integration/app/test/unit/state_test.rb +10 -0
- data/test/integration/app/test/unit/user_test.rb +10 -0
- data/test/models/aquatic/fish.rb +2 -1
- data/test/models/aquatic/whale.rb +2 -0
- data/test/setup.rb +10 -0
- data/test/test_all.rb +16 -0
- data/test/test_helper.rb +16 -12
- data/test/unit/polymorph_test.rb +35 -34
- metadata +239 -98
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
require 'sellers_controller'
|
|
3
|
+
|
|
4
|
+
# Re-raise errors caught by the controller.
|
|
5
|
+
class SellersController; def rescue_action(e) raise e end; end
|
|
6
|
+
|
|
7
|
+
class SellersControllerTest < Test::Unit::TestCase
|
|
8
|
+
fixtures :sellers
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
@controller = SellersController.new
|
|
12
|
+
@request = ActionController::TestRequest.new
|
|
13
|
+
@response = ActionController::TestResponse.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_should_get_index
|
|
17
|
+
get :index
|
|
18
|
+
assert_response :success
|
|
19
|
+
assert assigns(:sellers)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_should_get_new
|
|
23
|
+
get :new
|
|
24
|
+
assert_response :success
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_should_create_seller
|
|
28
|
+
assert_difference('Seller.count') do
|
|
29
|
+
post :create, :seller => { }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_redirected_to seller_path(assigns(:seller))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_should_show_seller
|
|
36
|
+
get :show, :id => 1
|
|
37
|
+
assert_response :success
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_should_get_edit
|
|
41
|
+
get :edit, :id => 1
|
|
42
|
+
assert_response :success
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_should_update_seller
|
|
46
|
+
put :update, :id => 1, :seller => { }
|
|
47
|
+
assert_redirected_to seller_path(assigns(:seller))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_should_destroy_seller
|
|
51
|
+
assert_difference('Seller.count', -1) do
|
|
52
|
+
delete :destroy, :id => 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
assert_redirected_to sellers_path
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
require 'states_controller'
|
|
3
|
+
|
|
4
|
+
# Re-raise errors caught by the controller.
|
|
5
|
+
class StatesController; def rescue_action(e) raise e end; end
|
|
6
|
+
|
|
7
|
+
class StatesControllerTest < Test::Unit::TestCase
|
|
8
|
+
fixtures :states
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
@controller = StatesController.new
|
|
12
|
+
@request = ActionController::TestRequest.new
|
|
13
|
+
@response = ActionController::TestResponse.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_should_get_index
|
|
17
|
+
get :index
|
|
18
|
+
assert_response :success
|
|
19
|
+
assert assigns(:states)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_should_get_new
|
|
23
|
+
get :new
|
|
24
|
+
assert_response :success
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_should_create_state
|
|
28
|
+
assert_difference('State.count') do
|
|
29
|
+
post :create, :state => { }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_redirected_to state_path(assigns(:state))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_should_show_state
|
|
36
|
+
get :show, :id => 1
|
|
37
|
+
assert_response :success
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_should_get_edit
|
|
41
|
+
get :edit, :id => 1
|
|
42
|
+
assert_response :success
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_should_update_state
|
|
46
|
+
put :update, :id => 1, :state => { }
|
|
47
|
+
assert_redirected_to state_path(assigns(:state))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_should_destroy_state
|
|
51
|
+
assert_difference('State.count', -1) do
|
|
52
|
+
delete :destroy, :id => 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
assert_redirected_to states_path
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
|
+
require 'users_controller'
|
|
3
|
+
|
|
4
|
+
# Re-raise errors caught by the controller.
|
|
5
|
+
class UsersController; def rescue_action(e) raise e end; end
|
|
6
|
+
|
|
7
|
+
class UsersControllerTest < Test::Unit::TestCase
|
|
8
|
+
fixtures :users
|
|
9
|
+
|
|
10
|
+
def setup
|
|
11
|
+
@controller = UsersController.new
|
|
12
|
+
@request = ActionController::TestRequest.new
|
|
13
|
+
@response = ActionController::TestResponse.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_should_get_index
|
|
17
|
+
get :index
|
|
18
|
+
assert_response :success
|
|
19
|
+
assert assigns(:users)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_should_get_new
|
|
23
|
+
get :new
|
|
24
|
+
assert_response :success
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_should_create_user
|
|
28
|
+
assert_difference('User.count') do
|
|
29
|
+
post :create, :user => { }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
assert_redirected_to user_path(assigns(:user))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_should_show_user
|
|
36
|
+
get :show, :id => 1
|
|
37
|
+
assert_response :success
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_should_get_edit
|
|
41
|
+
get :edit, :id => 1
|
|
42
|
+
assert_response :success
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def test_should_update_user
|
|
46
|
+
put :update, :id => 1, :user => { }
|
|
47
|
+
assert_redirected_to user_path(assigns(:user))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_should_destroy_user
|
|
51
|
+
assert_difference('User.count', -1) do
|
|
52
|
+
delete :destroy, :id => 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
assert_redirected_to users_path
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
|
3
|
+
require 'test_help'
|
|
4
|
+
|
|
5
|
+
class Test::Unit::TestCase
|
|
6
|
+
# Transactional fixtures accelerate your tests by wrapping each test method
|
|
7
|
+
# in a transaction that's rolled back on completion. This ensures that the
|
|
8
|
+
# test database remains unchanged so your fixtures don't have to be reloaded
|
|
9
|
+
# between every test method. Fewer database queries means faster tests.
|
|
10
|
+
#
|
|
11
|
+
# Read Mike Clark's excellent walkthrough at
|
|
12
|
+
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
|
13
|
+
#
|
|
14
|
+
# Every Active Record database supports transactions except MyISAM tables
|
|
15
|
+
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
|
16
|
+
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
|
17
|
+
# is recommended.
|
|
18
|
+
self.use_transactional_fixtures = true
|
|
19
|
+
|
|
20
|
+
# Instantiated fixtures are slow, but give you @david where otherwise you
|
|
21
|
+
# would need people(:david). If you don't want to migrate your existing
|
|
22
|
+
# test cases which use the @david style and don't mind the speed hit (each
|
|
23
|
+
# instantiated fixtures translates to a database query per test method),
|
|
24
|
+
# then set this back to true.
|
|
25
|
+
self.use_instantiated_fixtures = false
|
|
26
|
+
|
|
27
|
+
# Add more helper methods to be used by all tests here...
|
|
28
|
+
end
|
data/test/models/aquatic/fish.rb
CHANGED
data/test/setup.rb
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
# Setup integration system for the integration suite
|
|
3
|
+
|
|
4
|
+
Dir.chdir "#{File.dirname(__FILE__)}/integration/app/" do
|
|
5
|
+
Dir.chdir "vendor/plugins" do
|
|
6
|
+
system("rm has_many_polymorphs; ln -s ../../../../../ has_many_polymorphs")
|
|
7
|
+
end
|
|
8
|
+
system("rake db:create")
|
|
9
|
+
system("rake db:migrate db:fixtures:load")
|
|
10
|
+
end
|
data/test/test_all.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
# Run tests against all Rails versions
|
|
3
|
+
|
|
4
|
+
VENDOR_DIR = File.expand_path("~/Desktop/projects/vendor/rails")
|
|
5
|
+
|
|
6
|
+
HERE = File.expand_path(File.dirname(__FILE__))
|
|
7
|
+
|
|
8
|
+
Dir["#{VENDOR_DIR}/*"].each do |dir|
|
|
9
|
+
puts "\n\n**** #{dir} ****\n\n"
|
|
10
|
+
Dir.chdir "#{HERE}/integration/app/vendor" do
|
|
11
|
+
system("rm rails; ln -s #{dir} rails")
|
|
12
|
+
end
|
|
13
|
+
system("ruby #{HERE}/unit/polymorph_test.rb")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
system("rm #{HERE}/integration/app/vendor; svn up #{HERE}/integration/app/vendor")
|
data/test/test_helper.rb
CHANGED
|
@@ -6,20 +6,23 @@ begin
|
|
|
6
6
|
rescue Object
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
9
|
+
HERE = File.expand_path(File.dirname(__FILE__))
|
|
10
|
+
$LOAD_PATH << HERE
|
|
11
|
+
|
|
12
|
+
# require 'integration/app/config/environment'
|
|
13
|
+
require 'integration/app/test/test_helper'
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
def silently
|
|
16
|
+
stderr, $stderr = $stderr, StringIO.new
|
|
17
|
+
yield
|
|
18
|
+
$stderr = stderr
|
|
19
|
+
end
|
|
17
20
|
|
|
18
21
|
Inflector.inflections {|i| i.irregular 'fish', 'fish' }
|
|
19
22
|
|
|
20
|
-
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path =
|
|
21
|
-
$LOAD_PATH.unshift(
|
|
22
|
-
$LOAD_PATH.unshift(
|
|
23
|
+
$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path = HERE + "/fixtures")
|
|
24
|
+
$LOAD_PATH.unshift(HERE + "/models")
|
|
25
|
+
$LOAD_PATH.unshift(HERE + "/modules")
|
|
23
26
|
|
|
24
27
|
class Test::Unit::TestCase
|
|
25
28
|
self.use_transactional_fixtures = !(ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::MysqlAdapter rescue false)
|
|
@@ -27,5 +30,6 @@ class Test::Unit::TestCase
|
|
|
27
30
|
end
|
|
28
31
|
|
|
29
32
|
# test schema
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
silently do
|
|
34
|
+
load(HERE + "/schema.rb")
|
|
35
|
+
end
|
data/test/unit/polymorph_test.rb
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper'
|
|
2
2
|
|
|
3
|
+
require 'dog'
|
|
4
|
+
require 'wild_boar'
|
|
5
|
+
require 'frog'
|
|
6
|
+
require 'cat'
|
|
7
|
+
require 'kitten'
|
|
8
|
+
require 'aquatic/whale'
|
|
9
|
+
require 'aquatic/fish'
|
|
10
|
+
require 'aquatic/pupils_whale'
|
|
11
|
+
require 'beautiful_fight_relationship'
|
|
12
|
+
|
|
3
13
|
class PolymorphTest < Test::Unit::TestCase
|
|
4
14
|
|
|
15
|
+
set_fixture_class :bow_wows => Dog
|
|
16
|
+
set_fixture_class :keep_your_enemies_close => BeautifulFightRelationship
|
|
17
|
+
set_fixture_class :whales => Aquatic::Whale
|
|
18
|
+
set_fixture_class :fish => Aquatic::Fish
|
|
19
|
+
set_fixture_class :little_whale_pupils => Aquatic::PupilsWhale
|
|
20
|
+
|
|
5
21
|
fixtures :cats, :bow_wows, :frogs, :wild_boars, :eaters_foodstuffs, :petfoods,
|
|
6
|
-
:
|
|
7
|
-
:keep_your_enemies_close, :people
|
|
8
|
-
require 'beautiful_fight_relationship'
|
|
22
|
+
:fish, :whales, :little_whale_pupils, :keep_your_enemies_close, :people
|
|
9
23
|
|
|
10
24
|
def setup
|
|
11
25
|
@association_error = ActiveRecord::Associations::PolymorphicError
|
|
@@ -22,18 +36,12 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
22
36
|
@froggy = Frog.find(1)
|
|
23
37
|
|
|
24
38
|
@join_count = EatersFoodstuff.count
|
|
25
|
-
@
|
|
26
|
-
@
|
|
39
|
+
@kibbles_eaters_count = @kibbles.eaters.size
|
|
40
|
+
@bits_eaters_count = @bits.eaters.size
|
|
27
41
|
|
|
28
42
|
@double_join_count = BeautifulFightRelationship.count
|
|
29
|
-
@
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def d
|
|
33
|
-
require 'ruby-debug'
|
|
34
|
-
Debugger.start
|
|
35
|
-
debugger
|
|
36
|
-
end
|
|
43
|
+
@alice_enemies_count = @alice.enemies.size
|
|
44
|
+
end
|
|
37
45
|
|
|
38
46
|
def test_all_relationship_validities
|
|
39
47
|
# q = []
|
|
@@ -49,27 +57,20 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
49
57
|
WildBoar.reflect_on_all_associations.map &:check_validity!
|
|
50
58
|
Frog.reflect_on_all_associations.map &:check_validity!
|
|
51
59
|
Cat.reflect_on_all_associations.map &:check_validity!
|
|
52
|
-
Right.reflect_on_all_associations.map &:check_validity!
|
|
53
|
-
Left.reflect_on_all_associations.map &:check_validity!
|
|
54
|
-
DoubleJoin.reflect_on_all_associations.map &:check_validity!
|
|
55
60
|
BeautifulFightRelationship.reflect_on_all_associations.map &:check_validity!
|
|
56
61
|
Person.reflect_on_all_associations.map &:check_validity!
|
|
57
62
|
Parentship.reflect_on_all_associations.map &:check_validity!
|
|
58
63
|
Aquatic::Whale.reflect_on_all_associations.map &:check_validity!
|
|
59
64
|
Aquatic::PupilsWhale.reflect_on_all_associations.map &:check_validity!
|
|
60
|
-
Tagging.reflect_on_all_associations.map &:check_validity!
|
|
61
|
-
Recipe.reflect_on_all_associations.map &:check_validity!
|
|
62
|
-
Category.reflect_on_all_associations.map &:check_validity!
|
|
63
|
-
Tag.reflect_on_all_associations.map &:check_validity!
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
def test_assignment
|
|
67
68
|
assert @kibbles.eaters.blank?
|
|
68
69
|
assert @kibbles.eaters.push(Cat.find_by_name('Chloe'))
|
|
69
|
-
assert_equal @
|
|
70
|
+
assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count
|
|
70
71
|
|
|
71
72
|
@kibbles.reload
|
|
72
|
-
assert_equal @
|
|
73
|
+
assert_equal @kibbles_eaters_count, @kibbles.eaters.count
|
|
73
74
|
end
|
|
74
75
|
|
|
75
76
|
def test_duplicate_assignment
|
|
@@ -77,19 +78,19 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
77
78
|
@kibbles.eaters.push(@alice)
|
|
78
79
|
assert @kibbles.eaters.include?(@alice)
|
|
79
80
|
@kibbles.eaters.push(@alice)
|
|
80
|
-
assert_equal @
|
|
81
|
+
assert_equal @kibbles_eaters_count + 2, @kibbles.eaters.count
|
|
81
82
|
assert_equal @join_count + 2, EatersFoodstuff.count
|
|
82
83
|
end
|
|
83
84
|
|
|
84
85
|
def test_create_and_push
|
|
85
86
|
assert @kibbles.eaters.push(@spot)
|
|
86
|
-
assert_equal @
|
|
87
|
+
assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count
|
|
87
88
|
assert @kibbles.eaters << @rover
|
|
88
89
|
assert @kibbles.eaters << Kitten.create(:name => "Miranda")
|
|
89
|
-
assert_equal @
|
|
90
|
+
assert_equal @kibbles_eaters_count += 2, @kibbles.eaters.length
|
|
90
91
|
|
|
91
92
|
@kibbles.reload
|
|
92
|
-
assert_equal @
|
|
93
|
+
assert_equal @kibbles_eaters_count, @kibbles.eaters.length
|
|
93
94
|
|
|
94
95
|
# test that ids and new flags were set appropriately
|
|
95
96
|
assert_not_nil @kibbles.eaters[0].id
|
|
@@ -108,8 +109,8 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
108
109
|
assert join.id
|
|
109
110
|
assert_equal @join_count + 1, EatersFoodstuff.count
|
|
110
111
|
|
|
111
|
-
#assert_equal @
|
|
112
|
-
assert_equal @
|
|
112
|
+
#assert_equal @bits_eaters_count, @bits.eaters.size # Doesn't behave this way on latest edge anymore
|
|
113
|
+
assert_equal @bits_eaters_count + 1, @bits.eaters.count # SQL
|
|
113
114
|
|
|
114
115
|
# reload; is the new association there?
|
|
115
116
|
assert @bits.eaters.reload
|
|
@@ -133,17 +134,17 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
133
134
|
# # add an unsaved item
|
|
134
135
|
# assert @bits.eaters << Kitten.new(:name => "Bridget")
|
|
135
136
|
# assert_nil Kitten.find_by_name("Bridget")
|
|
136
|
-
# assert_equal @
|
|
137
|
+
# assert_equal @bits_eaters_count + 1, @bits.eaters.count
|
|
137
138
|
#
|
|
138
139
|
# assert @bits.save
|
|
139
140
|
# @bits.reload
|
|
140
|
-
# assert_equal @
|
|
141
|
+
# assert_equal @bits_eaters_count + 1, @bits.eaters.count
|
|
141
142
|
#
|
|
142
143
|
# end
|
|
143
144
|
|
|
144
145
|
def test_self_reference
|
|
145
146
|
assert @kibbles.eaters << @bits
|
|
146
|
-
assert_equal @
|
|
147
|
+
assert_equal @kibbles_eaters_count += 1, @kibbles.eaters.count
|
|
147
148
|
assert @kibbles.eaters.include?(@bits)
|
|
148
149
|
@kibbles.reload
|
|
149
150
|
assert @kibbles.foodstuffs_of_eaters.blank?
|
|
@@ -157,7 +158,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
157
158
|
assert @kibbles.eaters << @chloe
|
|
158
159
|
@kibbles.reload
|
|
159
160
|
assert @kibbles.eaters.delete(@kibbles.eaters[0])
|
|
160
|
-
assert_equal @
|
|
161
|
+
assert_equal @kibbles_eaters_count, @kibbles.eaters.count
|
|
161
162
|
end
|
|
162
163
|
|
|
163
164
|
def test_destroy
|
|
@@ -166,7 +167,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
166
167
|
assert @kibbles.eaters.length > 0
|
|
167
168
|
assert @kibbles.eaters[0].destroy
|
|
168
169
|
@kibbles.reload
|
|
169
|
-
assert_equal @
|
|
170
|
+
assert_equal @kibbles_eaters_count, @kibbles.eaters.count
|
|
170
171
|
end
|
|
171
172
|
|
|
172
173
|
def test_clear
|
|
@@ -233,7 +234,7 @@ class PolymorphTest < Test::Unit::TestCase
|
|
|
233
234
|
|
|
234
235
|
def test_self_referential_join_tables
|
|
235
236
|
# check that the self-reference join tables go the right ways
|
|
236
|
-
assert_equal @
|
|
237
|
+
assert_equal @kibbles_eaters_count, @kibbles.eaters_foodstuffs.count
|
|
237
238
|
assert_equal @kibbles.eaters_foodstuffs.count, @kibbles.eaters_foodstuffs_as_child.count
|
|
238
239
|
end
|
|
239
240
|
|