has_many_polymorphs 2.10 → 2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +2 -0
  3. data/Manifest +191 -56
  4. data/TODO +1 -0
  5. data/examples/hmph.rb +69 -0
  6. data/generators/commenting/commenting_generator.rb +94 -0
  7. data/generators/commenting/templates/comment.rb +33 -0
  8. data/generators/commenting/templates/comment_test.rb +12 -0
  9. data/generators/commenting/templates/commenting.rb +13 -0
  10. data/generators/commenting/templates/commenting_extensions.rb +30 -0
  11. data/generators/commenting/templates/commenting_test.rb +30 -0
  12. data/generators/commenting/templates/commentings.yml +23 -0
  13. data/generators/commenting/templates/comments.yml +13 -0
  14. data/generators/commenting/templates/migration.rb +28 -0
  15. data/generators/tagging/templates/tagging_extensions.rb +4 -8
  16. data/has_many_polymorphs.gemspec +19 -12
  17. data/lib/has_many_polymorphs.rb +3 -4
  18. data/lib/has_many_polymorphs/autoload.rb +4 -4
  19. data/lib/has_many_polymorphs/class_methods.rb +8 -8
  20. data/lib/has_many_polymorphs/debugging_tools.rb +2 -0
  21. data/lib/has_many_polymorphs/dependencies.rb +9 -4
  22. data/lib/has_many_polymorphs/support_methods.rb +3 -1
  23. data/test/fixtures/{aquatic/fish.yml → fish.yml} +0 -0
  24. data/test/fixtures/{aquatic/little_whale_pupils.yml → little_whale_pupils.yml} +0 -0
  25. data/test/fixtures/{aquatic/whales.yml → whales.yml} +0 -0
  26. data/test/integration/app/README +182 -0
  27. data/test/integration/app/Rakefile +19 -0
  28. data/test/integration/app/app/controllers/addresses_controller.rb +85 -0
  29. data/test/integration/app/app/controllers/application.rb +7 -0
  30. data/test/integration/app/app/controllers/sellers_controller.rb +85 -0
  31. data/test/integration/app/app/controllers/states_controller.rb +85 -0
  32. data/test/integration/app/app/controllers/users_controller.rb +85 -0
  33. data/test/integration/app/app/helpers/addresses_helper.rb +2 -0
  34. data/test/integration/app/app/helpers/application_helper.rb +3 -0
  35. data/test/integration/app/app/helpers/sellers_helper.rb +28 -0
  36. data/test/integration/app/app/helpers/states_helper.rb +2 -0
  37. data/test/integration/app/app/helpers/users_helper.rb +2 -0
  38. data/test/integration/app/app/models/address.rb +4 -0
  39. data/test/integration/app/app/models/citation.rb +3 -0
  40. data/test/integration/app/app/models/citations_item.rb +4 -0
  41. data/test/integration/app/app/models/seller.rb +4 -0
  42. data/test/integration/app/app/models/state.rb +3 -0
  43. data/test/integration/app/app/models/user.rb +4 -0
  44. data/test/integration/app/app/views/addresses/edit.html.erb +12 -0
  45. data/test/integration/app/app/views/addresses/index.html.erb +18 -0
  46. data/test/integration/app/app/views/addresses/new.html.erb +11 -0
  47. data/test/integration/app/app/views/addresses/show.html.erb +3 -0
  48. data/test/integration/app/app/views/layouts/addresses.html.erb +17 -0
  49. data/test/integration/app/app/views/layouts/sellers.html.erb +17 -0
  50. data/test/integration/app/app/views/layouts/states.html.erb +17 -0
  51. data/test/integration/app/app/views/layouts/users.html.erb +17 -0
  52. data/test/integration/app/app/views/sellers/edit.html.erb +12 -0
  53. data/test/integration/app/app/views/sellers/index.html.erb +20 -0
  54. data/test/integration/app/app/views/sellers/new.html.erb +11 -0
  55. data/test/integration/app/app/views/sellers/show.html.erb +3 -0
  56. data/test/integration/app/app/views/states/edit.html.erb +12 -0
  57. data/test/integration/app/app/views/states/index.html.erb +19 -0
  58. data/test/integration/app/app/views/states/new.html.erb +11 -0
  59. data/test/integration/app/app/views/states/show.html.erb +3 -0
  60. data/test/integration/app/app/views/users/edit.html.erb +12 -0
  61. data/test/integration/app/app/views/users/index.html.erb +22 -0
  62. data/test/integration/app/app/views/users/new.html.erb +11 -0
  63. data/test/integration/app/app/views/users/show.html.erb +3 -0
  64. data/test/integration/app/config/boot.rb +45 -0
  65. data/test/integration/app/config/database.yml +21 -0
  66. data/test/integration/app/config/environment.rb +13 -0
  67. data/test/integration/app/config/environments/development.rb +7 -0
  68. data/test/integration/app/config/environments/production.rb +18 -0
  69. data/test/integration/app/config/environments/test.rb +19 -0
  70. data/test/integration/app/config/locomotive.yml +6 -0
  71. data/test/integration/app/config/routes.rb +33 -0
  72. data/test/integration/app/config/ultrasphinx/default.base +56 -0
  73. data/test/integration/app/config/ultrasphinx/development.conf.canonical +155 -0
  74. data/test/integration/app/db/migrate/001_create_users.rb +16 -0
  75. data/test/integration/app/db/migrate/002_create_sellers.rb +14 -0
  76. data/test/integration/app/db/migrate/003_create_addresses.rb +19 -0
  77. data/test/integration/app/db/migrate/004_create_states.rb +12 -0
  78. data/test/integration/app/db/migrate/005_add_capitalization_to_seller.rb +9 -0
  79. data/test/integration/app/db/migrate/006_add_deleted_to_user.rb +9 -0
  80. data/test/integration/app/db/migrate/007_add_lat_and_long_to_address.rb +11 -0
  81. data/test/integration/app/db/migrate/008_create_citations.rb +12 -0
  82. data/test/integration/app/db/migrate/009_create_citations_items.rb +14 -0
  83. data/test/integration/app/db/schema.rb +144 -0
  84. data/test/integration/app/doc/README_FOR_APP +2 -0
  85. data/test/integration/app/generated_models/aquatic_fish.rb +109 -0
  86. data/test/integration/app/generated_models/aquatic_pupils_whale.rb +13 -0
  87. data/test/integration/app/generated_models/aquatic_whale.rb +42 -0
  88. data/test/integration/app/generated_models/beautiful_fight_relationship.rb +25 -0
  89. data/test/integration/app/generated_models/citation.rb +40 -0
  90. data/test/integration/app/generated_models/citations_item.rb +12 -0
  91. data/test/integration/app/generated_models/dog.rb +183 -0
  92. data/test/integration/app/generated_models/eaters_foodstuff.rb +13 -0
  93. data/test/integration/app/generated_models/frog.rb +78 -0
  94. data/test/integration/app/generated_models/kitten.rb +161 -0
  95. data/test/integration/app/generated_models/parentship.rb +14 -0
  96. data/test/integration/app/generated_models/person.rb +53 -0
  97. data/test/integration/app/generated_models/petfood.rb +125 -0
  98. data/test/integration/app/generated_models/polymorph_test_some_model.rb +25 -0
  99. data/test/integration/app/generated_models/seller.rb +30 -0
  100. data/test/integration/app/generated_models/tabby.rb +26 -0
  101. data/test/integration/app/generated_models/user.rb +34 -0
  102. data/test/integration/app/generated_models/wild_boar.rb +87 -0
  103. data/test/integration/app/generators/commenting_generator_test.rb +83 -0
  104. data/test/integration/app/public/404.html +30 -0
  105. data/test/integration/app/public/500.html +30 -0
  106. data/test/integration/app/public/dispatch.cgi +10 -0
  107. data/test/integration/app/public/dispatch.fcgi +24 -0
  108. data/test/integration/app/public/dispatch.rb +10 -0
  109. data/test/integration/app/public/favicon.ico +0 -0
  110. data/test/integration/app/public/images/rails.png +0 -0
  111. data/test/integration/app/public/index.html +277 -0
  112. data/test/integration/app/public/javascripts/application.js +2 -0
  113. data/test/integration/app/public/javascripts/controls.js +833 -0
  114. data/test/integration/app/public/javascripts/dragdrop.js +942 -0
  115. data/test/integration/app/public/javascripts/effects.js +1088 -0
  116. data/test/integration/app/public/javascripts/prototype.js +2515 -0
  117. data/test/integration/app/public/robots.txt +1 -0
  118. data/test/integration/app/public/stylesheets/scaffold.css +74 -0
  119. data/test/integration/app/script/about +3 -0
  120. data/test/integration/app/script/breakpointer +3 -0
  121. data/test/integration/app/script/console +3 -0
  122. data/test/integration/app/script/destroy +3 -0
  123. data/test/integration/app/script/generate +3 -0
  124. data/test/integration/app/script/performance/benchmarker +3 -0
  125. data/test/integration/app/script/performance/profiler +3 -0
  126. data/test/integration/app/script/plugin +3 -0
  127. data/test/integration/app/script/process/inspector +3 -0
  128. data/test/integration/app/script/process/reaper +3 -0
  129. data/test/integration/app/script/process/spawner +3 -0
  130. data/test/integration/app/script/runner +3 -0
  131. data/test/integration/app/script/server +3 -0
  132. data/test/integration/app/test/fixtures/addresses.yml +13 -0
  133. data/test/integration/app/test/fixtures/citations.yml +9 -0
  134. data/test/integration/app/test/fixtures/citations_items.yml +9 -0
  135. data/test/integration/app/test/fixtures/sellers.yml +10 -0
  136. data/test/integration/app/test/fixtures/states.yml +216 -0
  137. data/test/integration/app/test/fixtures/users.yml +11 -0
  138. data/test/integration/app/test/functional/addresses_controller_test.rb +57 -0
  139. data/test/integration/app/test/functional/sellers_controller_test.rb +57 -0
  140. data/test/integration/app/test/functional/states_controller_test.rb +57 -0
  141. data/test/integration/app/test/functional/users_controller_test.rb +57 -0
  142. data/test/integration/app/test/test_helper.rb +28 -0
  143. data/test/integration/app/test/unit/address_test.rb +10 -0
  144. data/test/integration/app/test/unit/citation_test.rb +10 -0
  145. data/test/integration/app/test/unit/citations_item_test.rb +10 -0
  146. data/test/integration/app/test/unit/seller_test.rb +10 -0
  147. data/test/integration/app/test/unit/state_test.rb +10 -0
  148. data/test/integration/app/test/unit/user_test.rb +10 -0
  149. data/test/models/aquatic/fish.rb +2 -1
  150. data/test/models/aquatic/whale.rb +2 -0
  151. data/test/setup.rb +10 -0
  152. data/test/test_all.rb +16 -0
  153. data/test/test_helper.rb +16 -12
  154. data/test/unit/polymorph_test.rb +35 -34
  155. metadata +239 -98
  156. metadata.gz.sig +0 -0
@@ -0,0 +1,19 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
11
+
12
+ namespace :test do
13
+ desc "a new rake task to include generators"
14
+ Rake::TestTask.new(:generators) do |t|
15
+ t.libs << 'lib'
16
+ t.test_files = FileList['test/generators/*_test.rb']
17
+ t.verbose = true
18
+ end
19
+ end
@@ -0,0 +1,85 @@
1
+ class AddressesController < ApplicationController
2
+ # GET /addresses
3
+ # GET /addresses.xml
4
+ def index
5
+ @addresses = Address.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @addresses }
10
+ end
11
+ end
12
+
13
+ # GET /addresses/1
14
+ # GET /addresses/1.xml
15
+ def show
16
+ @address = Address.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @address }
21
+ end
22
+ end
23
+
24
+ # GET /addresses/new
25
+ # GET /addresses/new.xml
26
+ def new
27
+ @address = Address.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @address }
32
+ end
33
+ end
34
+
35
+ # GET /addresses/1/edit
36
+ def edit
37
+ @address = Address.find(params[:id])
38
+ end
39
+
40
+ # POST /addresses
41
+ # POST /addresses.xml
42
+ def create
43
+ @address = Address.new(params[:address])
44
+
45
+ respond_to do |format|
46
+ if @address.save
47
+ flash[:notice] = 'Address was successfully created.'
48
+ format.html { redirect_to(@address) }
49
+ format.xml { render :xml => @address, :status => :created, :location => @address }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @address.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT /addresses/1
58
+ # PUT /addresses/1.xml
59
+ def update
60
+ @address = Address.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @address.update_attributes(params[:address])
64
+ flash[:notice] = 'Address was successfully updated.'
65
+ format.html { redirect_to(@address) }
66
+ format.xml { head :ok }
67
+ else
68
+ format.html { render :action => "edit" }
69
+ format.xml { render :xml => @address.errors, :status => :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /addresses/1
75
+ # DELETE /addresses/1.xml
76
+ def destroy
77
+ @address = Address.find(params[:id])
78
+ @address.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to(addresses_url) }
82
+ format.xml { head :ok }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,7 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ # Pick a unique cookie name to distinguish our session data from others'
6
+ session :session_key => '_testapp_session_id'
7
+ end
@@ -0,0 +1,85 @@
1
+ class SellersController < ApplicationController
2
+ # GET /sellers
3
+ # GET /sellers.xml
4
+ def index
5
+ @sellers = Seller.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @sellers }
10
+ end
11
+ end
12
+
13
+ # GET /sellers/1
14
+ # GET /sellers/1.xml
15
+ def show
16
+ @seller = Seller.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @seller }
21
+ end
22
+ end
23
+
24
+ # GET /sellers/new
25
+ # GET /sellers/new.xml
26
+ def new
27
+ @seller = Seller.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @seller }
32
+ end
33
+ end
34
+
35
+ # GET /sellers/1/edit
36
+ def edit
37
+ @seller = Seller.find(params[:id])
38
+ end
39
+
40
+ # POST /sellers
41
+ # POST /sellers.xml
42
+ def create
43
+ @seller = Seller.new(params[:seller])
44
+
45
+ respond_to do |format|
46
+ if @seller.save
47
+ flash[:notice] = 'Seller was successfully created.'
48
+ format.html { redirect_to(@seller) }
49
+ format.xml { render :xml => @seller, :status => :created, :location => @seller }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @seller.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT /sellers/1
58
+ # PUT /sellers/1.xml
59
+ def update
60
+ @seller = Seller.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @seller.update_attributes(params[:seller])
64
+ flash[:notice] = 'Seller was successfully updated.'
65
+ format.html { redirect_to(@seller) }
66
+ format.xml { head :ok }
67
+ else
68
+ format.html { render :action => "edit" }
69
+ format.xml { render :xml => @seller.errors, :status => :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /sellers/1
75
+ # DELETE /sellers/1.xml
76
+ def destroy
77
+ @seller = Seller.find(params[:id])
78
+ @seller.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to(sellers_url) }
82
+ format.xml { head :ok }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,85 @@
1
+ class StatesController < ApplicationController
2
+ # GET /states
3
+ # GET /states.xml
4
+ def index
5
+ @states = State.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @states }
10
+ end
11
+ end
12
+
13
+ # GET /states/1
14
+ # GET /states/1.xml
15
+ def show
16
+ @state = State.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @state }
21
+ end
22
+ end
23
+
24
+ # GET /states/new
25
+ # GET /states/new.xml
26
+ def new
27
+ @state = State.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @state }
32
+ end
33
+ end
34
+
35
+ # GET /states/1/edit
36
+ def edit
37
+ @state = State.find(params[:id])
38
+ end
39
+
40
+ # POST /states
41
+ # POST /states.xml
42
+ def create
43
+ @state = State.new(params[:state])
44
+
45
+ respond_to do |format|
46
+ if @state.save
47
+ flash[:notice] = 'State was successfully created.'
48
+ format.html { redirect_to(@state) }
49
+ format.xml { render :xml => @state, :status => :created, :location => @state }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @state.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT /states/1
58
+ # PUT /states/1.xml
59
+ def update
60
+ @state = State.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @state.update_attributes(params[:state])
64
+ flash[:notice] = 'State was successfully updated.'
65
+ format.html { redirect_to(@state) }
66
+ format.xml { head :ok }
67
+ else
68
+ format.html { render :action => "edit" }
69
+ format.xml { render :xml => @state.errors, :status => :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /states/1
75
+ # DELETE /states/1.xml
76
+ def destroy
77
+ @state = State.find(params[:id])
78
+ @state.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to(states_url) }
82
+ format.xml { head :ok }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,85 @@
1
+ class UsersController < ApplicationController
2
+ # GET /users
3
+ # GET /users.xml
4
+ def index
5
+ @users = User.find(:all)
6
+
7
+ respond_to do |format|
8
+ format.html # index.html.erb
9
+ format.xml { render :xml => @users }
10
+ end
11
+ end
12
+
13
+ # GET /users/1
14
+ # GET /users/1.xml
15
+ def show
16
+ @user = User.find(params[:id])
17
+
18
+ respond_to do |format|
19
+ format.html # show.html.erb
20
+ format.xml { render :xml => @user }
21
+ end
22
+ end
23
+
24
+ # GET /users/new
25
+ # GET /users/new.xml
26
+ def new
27
+ @user = User.new
28
+
29
+ respond_to do |format|
30
+ format.html # new.html.erb
31
+ format.xml { render :xml => @user }
32
+ end
33
+ end
34
+
35
+ # GET /users/1/edit
36
+ def edit
37
+ @user = User.find(params[:id])
38
+ end
39
+
40
+ # POST /users
41
+ # POST /users.xml
42
+ def create
43
+ @user = User.new(params[:user])
44
+
45
+ respond_to do |format|
46
+ if @user.save
47
+ flash[:notice] = 'User was successfully created.'
48
+ format.html { redirect_to(@user) }
49
+ format.xml { render :xml => @user, :status => :created, :location => @user }
50
+ else
51
+ format.html { render :action => "new" }
52
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
53
+ end
54
+ end
55
+ end
56
+
57
+ # PUT /users/1
58
+ # PUT /users/1.xml
59
+ def update
60
+ @user = User.find(params[:id])
61
+
62
+ respond_to do |format|
63
+ if @user.update_attributes(params[:user])
64
+ flash[:notice] = 'User was successfully updated.'
65
+ format.html { redirect_to(@user) }
66
+ format.xml { head :ok }
67
+ else
68
+ format.html { render :action => "edit" }
69
+ format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /users/1
75
+ # DELETE /users/1.xml
76
+ def destroy
77
+ @user = User.find(params[:id])
78
+ @user.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to(users_url) }
82
+ format.xml { head :ok }
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,2 @@
1
+ module AddressesHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,28 @@
1
+ module SellersHelper
2
+
3
+ def display_address(seller)
4
+ logger.info "Seller Data ===================="
5
+ logger.info seller.inspect
6
+ logger.info "Seller responds to address " + seller.respond_to?("address").to_s
7
+ logger.info "Seller responds to address= " + seller.respond_to?("address=").to_s
8
+ # logger.info seller.methods.sort.inspect
9
+ logger.info "User Data ===================="
10
+ logger.info seller.user.inspect
11
+ logger.info "User responds to address " + seller.user.respond_to?("address").to_s
12
+ logger.info "User responds to address= " + seller.user.respond_to?("address=").to_s
13
+ # logger.info seller.user.methods.sort.inspect
14
+ display_address = Array.new
15
+ if seller.address
16
+ display_address << seller.address.city if seller.address.city
17
+ display_address << seller.address.state.abbreviation if seller.address.state && seller.address.state.abbreviation
18
+ display_address << seller.address.zip_postal_code if seller.address.zip_postal_code
19
+ end
20
+
21
+ unless display_address.empty?
22
+ "Location: " + display_address.join(", ")
23
+ else
24
+ "Location: unknown"
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,2 @@
1
+ module StatesHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class Address < ActiveRecord::Base
2
+ belongs_to :user
3
+ belongs_to :state
4
+ end
@@ -0,0 +1,3 @@
1
+ class Citation < ActiveRecord::Base
2
+ has_many_polymorphs :items, :from => [:users, :sellers]
3
+ end
@@ -0,0 +1,4 @@
1
+ class CitationsItem < ActiveRecord::Base
2
+ belongs_to :citation
3
+ belongs_to :item, :polymorphic => true
4
+ end
@@ -0,0 +1,4 @@
1
+ class Seller < ActiveRecord::Base
2
+ belongs_to :user
3
+ delegate :address, :to => :user
4
+ end
@@ -0,0 +1,3 @@
1
+ class State < ActiveRecord::Base
2
+ has_many :addresses
3
+ end
@@ -0,0 +1,4 @@
1
+ class User < ActiveRecord::Base
2
+ has_one :seller
3
+ has_one :address
4
+ end