has_many_polymorphs 2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +86 -0
- data/LICENSE +184 -0
- data/Manifest +173 -0
- data/README +205 -0
- data/Rakefile +28 -0
- data/TODO +2 -0
- data/examples/hmph.rb +69 -0
- data/generators/tagging/tagging_generator.rb +97 -0
- data/generators/tagging/templates/migration.rb +28 -0
- data/generators/tagging/templates/tag.rb +39 -0
- data/generators/tagging/templates/tag_test.rb +15 -0
- data/generators/tagging/templates/tagging.rb +16 -0
- data/generators/tagging/templates/tagging_extensions.rb +203 -0
- data/generators/tagging/templates/tagging_test.rb +85 -0
- data/generators/tagging/templates/taggings.yml +23 -0
- data/generators/tagging/templates/tags.yml +7 -0
- data/has_many_polymorphs.gemspec +36 -0
- data/init.rb +2 -0
- data/lib/has_many_polymorphs/association.rb +160 -0
- data/lib/has_many_polymorphs/autoload.rb +69 -0
- data/lib/has_many_polymorphs/base.rb +60 -0
- data/lib/has_many_polymorphs/class_methods.rb +600 -0
- data/lib/has_many_polymorphs/configuration.rb +19 -0
- data/lib/has_many_polymorphs/debugging_tools.rb +103 -0
- data/lib/has_many_polymorphs/rake_task_redefine_task.rb +35 -0
- data/lib/has_many_polymorphs/reflection.rb +58 -0
- data/lib/has_many_polymorphs/support_methods.rb +88 -0
- data/lib/has_many_polymorphs.rb +27 -0
- data/test/fixtures/bow_wows.yml +10 -0
- data/test/fixtures/cats.yml +18 -0
- data/test/fixtures/eaters_foodstuffs.yml +0 -0
- data/test/fixtures/fish.yml +12 -0
- data/test/fixtures/frogs.yml +5 -0
- data/test/fixtures/keep_your_enemies_close.yml +0 -0
- data/test/fixtures/little_whale_pupils.yml +0 -0
- data/test/fixtures/people.yml +7 -0
- data/test/fixtures/petfoods.yml +11 -0
- data/test/fixtures/whales.yml +5 -0
- data/test/fixtures/wild_boars.yml +10 -0
- data/test/generator/tagging_generator_test.rb +42 -0
- data/test/integration/app/README +182 -0
- data/test/integration/app/Rakefile +19 -0
- data/test/integration/app/app/controllers/application.rb +7 -0
- data/test/integration/app/app/controllers/bones_controller.rb +5 -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/bones_helper.rb +2 -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/bone.rb +2 -0
- data/test/integration/app/app/models/double_sti_parent.rb +2 -0
- data/test/integration/app/app/models/double_sti_parent_relationship.rb +2 -0
- data/test/integration/app/app/models/organic_substance.rb +2 -0
- data/test/integration/app/app/models/single_sti_parent.rb +4 -0
- data/test/integration/app/app/models/single_sti_parent_relationship.rb +4 -0
- data/test/integration/app/app/models/stick.rb +2 -0
- data/test/integration/app/app/models/stone.rb +2 -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/bones/index.rhtml +5 -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 +110 -0
- data/test/integration/app/config/database.yml +17 -0
- data/test/integration/app/config/environment.rb +19 -0
- data/test/integration/app/config/environment.rb.canonical +19 -0
- data/test/integration/app/config/environments/development.rb +9 -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_sticks.rb +11 -0
- data/test/integration/app/db/migrate/002_create_stones.rb +11 -0
- data/test/integration/app/db/migrate/003_create_organic_substances.rb +11 -0
- data/test/integration/app/db/migrate/004_create_bones.rb +8 -0
- data/test/integration/app/db/migrate/005_create_single_sti_parents.rb +11 -0
- data/test/integration/app/db/migrate/006_create_double_sti_parents.rb +11 -0
- data/test/integration/app/db/migrate/007_create_single_sti_parent_relationships.rb +13 -0
- data/test/integration/app/db/migrate/008_create_double_sti_parent_relationships.rb +14 -0
- data/test/integration/app/db/migrate/009_create_library_model.rb +11 -0
- data/test/integration/app/doc/README_FOR_APP +2 -0
- data/test/integration/app/generators/commenting_generator_test.rb +83 -0
- data/test/integration/app/lib/library_model.rb +2 -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/double_sti_parent_relationships.yml +7 -0
- data/test/integration/app/test/fixtures/double_sti_parents.yml +7 -0
- data/test/integration/app/test/fixtures/organic_substances.yml +5 -0
- data/test/integration/app/test/fixtures/single_sti_parent_relationships.yml +7 -0
- data/test/integration/app/test/fixtures/single_sti_parents.yml +7 -0
- data/test/integration/app/test/fixtures/sticks.yml +7 -0
- data/test/integration/app/test/fixtures/stones.yml +7 -0
- data/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
- data/test/integration/app/test/functional/bones_controller_test.rb +8 -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 +8 -0
- data/test/integration/app/test/unit/bone_test.rb +8 -0
- data/test/integration/app/test/unit/double_sti_parent_relationship_test.rb +8 -0
- data/test/integration/app/test/unit/double_sti_parent_test.rb +8 -0
- data/test/integration/app/test/unit/organic_substance_test.rb +8 -0
- data/test/integration/app/test/unit/single_sti_parent_relationship_test.rb +8 -0
- data/test/integration/app/test/unit/single_sti_parent_test.rb +8 -0
- data/test/integration/app/test/unit/stick_test.rb +8 -0
- data/test/integration/app/test/unit/stone_test.rb +8 -0
- data/test/integration/server_test.rb +43 -0
- data/test/models/aquatic/fish.rb +5 -0
- data/test/models/aquatic/pupils_whale.rb +7 -0
- data/test/models/aquatic/whale.rb +15 -0
- data/test/models/beautiful_fight_relationship.rb +26 -0
- data/test/models/canine.rb +9 -0
- data/test/models/cat.rb +5 -0
- data/test/models/dog.rb +18 -0
- data/test/models/eaters_foodstuff.rb +8 -0
- data/test/models/frog.rb +4 -0
- data/test/models/kitten.rb +3 -0
- data/test/models/parentship.rb +4 -0
- data/test/models/person.rb +9 -0
- data/test/models/petfood.rb +39 -0
- data/test/models/tabby.rb +2 -0
- data/test/models/wild_boar.rb +3 -0
- data/test/modules/extension_module.rb +9 -0
- data/test/modules/other_extension_module.rb +9 -0
- data/test/patches/symlinked_plugins_1.2.6.diff +46 -0
- data/test/schema.rb +87 -0
- data/test/setup.rb +14 -0
- data/test/test_helper.rb +52 -0
- data/test/unit/has_many_polymorphs_test.rb +713 -0
- data.tar.gz.sig +1 -0
- metadata +279 -0
- metadata.gz.sig +0 -0
data/test/models/frog.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# see http://dev.rubyonrails.org/ticket/5935
|
2
|
+
require 'eaters_foodstuff'
|
3
|
+
require 'petfood'
|
4
|
+
require 'cat'
|
5
|
+
module Aquatic; end
|
6
|
+
require 'aquatic/fish'
|
7
|
+
require 'dog'
|
8
|
+
require 'wild_boar'
|
9
|
+
require 'kitten'
|
10
|
+
require 'tabby'
|
11
|
+
require 'extension_module'
|
12
|
+
require 'other_extension_module'
|
13
|
+
|
14
|
+
class Petfood < ActiveRecord::Base
|
15
|
+
set_primary_key 'the_petfood_primary_key'
|
16
|
+
has_many_polymorphs :eaters,
|
17
|
+
:from => [:dogs, :petfoods, :wild_boars, :kittens,
|
18
|
+
:tabbies, :"aquatic/fish"],
|
19
|
+
# :dependent => :destroy, :destroy is now the default
|
20
|
+
:rename_individual_collections => true,
|
21
|
+
:as => :foodstuff,
|
22
|
+
:foreign_key => "foodstuff_id",
|
23
|
+
:ignore_duplicates => false,
|
24
|
+
:conditions => "NULL IS NULL",
|
25
|
+
:order => "eaters_foodstuffs.updated_at ASC",
|
26
|
+
:parent_order => "petfoods.the_petfood_primary_key DESC",
|
27
|
+
:parent_conditions => "petfoods.name IS NULL OR petfoods.name != 'Snausages'",
|
28
|
+
:extend => [ExtensionModule, OtherExtensionModule, proc {}],
|
29
|
+
:join_extend => proc {
|
30
|
+
def a_method
|
31
|
+
:correct_join_result
|
32
|
+
end
|
33
|
+
},
|
34
|
+
:parent_extend => proc {
|
35
|
+
def a_method
|
36
|
+
:correct_parent_proc_result
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
Index: /trunk/railties/lib/rails_generator/lookup.rb
|
2
|
+
===================================================================
|
3
|
+
--- /trunk/railties/lib/rails_generator/lookup.rb (revision 4310)
|
4
|
+
+++ /trunk/railties/lib/rails_generator/lookup.rb (revision 6101)
|
5
|
+
@@ -101,5 +101,5 @@
|
6
|
+
sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators")
|
7
|
+
sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators")
|
8
|
+
- sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/**/generators")
|
9
|
+
+ sources << PathSource.new(:plugins, "#{::RAILS_ROOT}/vendor/plugins/*/**/generators")
|
10
|
+
end
|
11
|
+
sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators")
|
12
|
+
Index: /trunk/railties/lib/tasks/rails.rb
|
13
|
+
===================================================================
|
14
|
+
--- /trunk/railties/lib/tasks/rails.rb (revision 5469)
|
15
|
+
+++ /trunk/railties/lib/tasks/rails.rb (revision 6101)
|
16
|
+
@@ -6,3 +6,3 @@
|
17
|
+
# Load any custom rakefile extensions
|
18
|
+
Dir["#{RAILS_ROOT}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
|
19
|
+
-Dir["#{RAILS_ROOT}/vendor/plugins/**/tasks/**/*.rake"].sort.each { |ext| load ext }
|
20
|
+
+Dir["#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
|
21
|
+
Index: /trunk/railties/lib/tasks/testing.rake
|
22
|
+
===================================================================
|
23
|
+
--- /trunk/railties/lib/tasks/testing.rake (revision 5263)
|
24
|
+
+++ /trunk/railties/lib/tasks/testing.rake (revision 6101)
|
25
|
+
@@ -109,9 +109,9 @@
|
26
|
+
t.pattern = "vendor/plugins/#{ENV['PLUGIN']}/test/**/*_test.rb"
|
27
|
+
else
|
28
|
+
- t.pattern = 'vendor/plugins/**/test/**/*_test.rb'
|
29
|
+
+ t.pattern = 'vendor/plugins/*/**/test/**/*_test.rb'
|
30
|
+
end
|
31
|
+
|
32
|
+
t.verbose = true
|
33
|
+
end
|
34
|
+
- Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)"
|
35
|
+
+ Rake::Task['test:plugins'].comment = "Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)"
|
36
|
+
end
|
37
|
+
Index: /trunk/railties/CHANGELOG
|
38
|
+
===================================================================
|
39
|
+
--- /trunk/railties/CHANGELOG (revision 6069)
|
40
|
+
+++ /trunk/railties/CHANGELOG (revision 6101)
|
41
|
+
@@ -1,3 +1,5 @@
|
42
|
+
*SVN*
|
43
|
+
+
|
44
|
+
+* Plugins may be symlinked in vendor/plugins. #4245 [brandon, progrium@gmail.com]
|
45
|
+
|
46
|
+
* Resource generator depends on the model generator rather than duplicating it. #7269 [bscofield]
|
data/test/schema.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 0) do
|
2
|
+
create_table :petfoods, :force => true, :primary_key => :the_petfood_primary_key do |t|
|
3
|
+
t.column :name, :string
|
4
|
+
t.column :created_at, :datetime, :null => false
|
5
|
+
t.column :updated_at, :datetime, :null => false
|
6
|
+
end
|
7
|
+
|
8
|
+
create_table :bow_wows, :force => true do |t|
|
9
|
+
t.column :name, :string
|
10
|
+
t.column :created_at, :datetime, :null => false
|
11
|
+
t.column :updated_at, :datetime, :null => false
|
12
|
+
end
|
13
|
+
|
14
|
+
create_table :cats, :force => true do |t|
|
15
|
+
t.column :name, :string
|
16
|
+
t.column :cat_type, :string
|
17
|
+
t.column :created_at, :datetime, :null => false
|
18
|
+
t.column :updated_at, :datetime, :null => false
|
19
|
+
end
|
20
|
+
|
21
|
+
create_table :frogs, :force => true do |t|
|
22
|
+
t.column :name, :string
|
23
|
+
t.column :created_at, :datetime, :null => false
|
24
|
+
t.column :updated_at, :datetime, :null => false
|
25
|
+
end
|
26
|
+
|
27
|
+
create_table :wild_boars, :force => true do |t|
|
28
|
+
t.column :name, :string
|
29
|
+
t.column :created_at, :datetime, :null => false
|
30
|
+
t.column :updated_at, :datetime, :null => false
|
31
|
+
end
|
32
|
+
|
33
|
+
create_table :eaters_foodstuffs, :force => true do |t|
|
34
|
+
t.column :foodstuff_id, :integer
|
35
|
+
t.column :eater_id, :integer
|
36
|
+
t.column :some_attribute, :integer, :default => 0
|
37
|
+
t.column :eater_type, :string
|
38
|
+
t.column :created_at, :datetime, :null => false
|
39
|
+
t.column :updated_at, :datetime, :null => false
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table :fish, :force => true do |t|
|
43
|
+
t.column :name, :string
|
44
|
+
t.column :speed, :integer
|
45
|
+
t.column :created_at, :datetime, :null => false
|
46
|
+
t.column :updated_at, :datetime, :null => false
|
47
|
+
end
|
48
|
+
|
49
|
+
create_table :whales, :force => true do |t|
|
50
|
+
t.column :name, :string
|
51
|
+
t.column :created_at, :datetime, :null => false
|
52
|
+
t.column :updated_at, :datetime, :null => false
|
53
|
+
end
|
54
|
+
|
55
|
+
create_table :little_whale_pupils, :force => true do |t|
|
56
|
+
t.column :whale_id, :integer
|
57
|
+
t.column :aquatic_pupil_id, :integer
|
58
|
+
t.column :aquatic_pupil_type, :string
|
59
|
+
t.column :created_at, :datetime, :null => false
|
60
|
+
t.column :updated_at, :datetime, :null => false
|
61
|
+
end
|
62
|
+
|
63
|
+
create_table :keep_your_enemies_close, :force => true do |t|
|
64
|
+
t.column :enemy_id, :integer
|
65
|
+
t.column :enemy_type, :string
|
66
|
+
t.column :protector_id, :integer
|
67
|
+
t.column :protector_type, :string
|
68
|
+
t.column :created_at, :datetime, :null => false
|
69
|
+
t.column :updated_at, :datetime, :null => false
|
70
|
+
end
|
71
|
+
|
72
|
+
create_table :parentships, :force => true do |t|
|
73
|
+
t.column :parent_id, :integer
|
74
|
+
t.column :child_type, :string
|
75
|
+
t.column :kid_id, :integer
|
76
|
+
t.column :created_at, :datetime, :null => false
|
77
|
+
t.column :updated_at, :datetime, :null => false
|
78
|
+
end
|
79
|
+
|
80
|
+
create_table :people, :force => true do |t|
|
81
|
+
t.column :name, :string
|
82
|
+
t.column :age, :integer
|
83
|
+
t.column :created_at, :datetime, :null => false
|
84
|
+
t.column :updated_at, :datetime, :null => false
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/test/setup.rb
ADDED
@@ -0,0 +1,14 @@
|
|
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
|
+
|
9
|
+
system "rake db:drop --trace RAILS_GEM_VERSION=2.2.2 "
|
10
|
+
system "rake db:create --trace RAILS_GEM_VERSION=2.2.2 "
|
11
|
+
system "rake db:migrate --trace"
|
12
|
+
system "rake db:fixtures:load --trace"
|
13
|
+
end
|
14
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
$VERBOSE = nil
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake' # echoe relies on Rake being present but doesn't require it itself
|
5
|
+
require 'echoe'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'multi_rails_init'
|
8
|
+
#require 'ruby-debug' # uncomment if needed (for Ruby >= 1.9 use require 'debug' where needed)
|
9
|
+
|
10
|
+
if defined? ENV['MULTIRAILS_RAILS_VERSION']
|
11
|
+
ENV['RAILS_GEM_VERSION'] = ENV['MULTIRAILS_RAILS_VERSION']
|
12
|
+
end
|
13
|
+
|
14
|
+
Echoe.silence do
|
15
|
+
HERE = File.expand_path(File.dirname(__FILE__))
|
16
|
+
$LOAD_PATH << HERE
|
17
|
+
# $LOAD_PATH << "#{HERE}/integration/app"
|
18
|
+
end
|
19
|
+
|
20
|
+
LOG = "#{HERE}/integration/app/log/development.log"
|
21
|
+
|
22
|
+
### For unit tests
|
23
|
+
|
24
|
+
require 'integration/app/config/environment'
|
25
|
+
require 'test_help'
|
26
|
+
|
27
|
+
ActiveSupport::Inflector.inflections {|i| i.irregular 'fish', 'fish' }
|
28
|
+
|
29
|
+
$LOAD_PATH.unshift(ActiveSupport::TestCase.fixture_path = HERE + "/fixtures")
|
30
|
+
$LOAD_PATH.unshift(HERE + "/models")
|
31
|
+
$LOAD_PATH.unshift(HERE + "/modules")
|
32
|
+
|
33
|
+
class ActiveSupport::TestCase
|
34
|
+
self.use_transactional_fixtures = !(ActiveRecord::Base.connection.is_a? ActiveRecord::ConnectionAdapters::MysqlAdapter rescue false)
|
35
|
+
self.use_instantiated_fixtures = false
|
36
|
+
end
|
37
|
+
|
38
|
+
Echoe.silence do
|
39
|
+
load(HERE + "/schema.rb")
|
40
|
+
end
|
41
|
+
|
42
|
+
### For integration tests
|
43
|
+
|
44
|
+
def truncate
|
45
|
+
system("> #{LOG}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def log
|
49
|
+
File.open(LOG, 'r') do |f|
|
50
|
+
f.read
|
51
|
+
end
|
52
|
+
end
|