actionpack 1.12.2 → 1.12.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,3 +1,12 @@
1
+ *1.12.3* (June 28th, 2006)
2
+
3
+ * Fix broken traverse_to_controller. We now:
4
+ Look for a _controller.rb file under RAILS_ROOT to load.
5
+ If we find it, we require_dependency it and return the controller it defined. (If none was defined we stop looking.)
6
+ If we don't find it, we look for a .rb file under RAILS_ROOT to load. If we find it, and it loads a constant we keep looking.
7
+ Otherwise we check to see if a directory of the same name exists, and if it does we create a module for it.
8
+
9
+
1
10
  *1.12.2* (June 27th, 2006)
2
11
 
3
12
  * Refinement to avoid exceptions in traverse_to_controller.
@@ -224,44 +224,70 @@ module ActionController
224
224
  length = segments.length
225
225
  index = start_at
226
226
  mod_name = controller_name = segment = nil
227
-
228
227
  while index < length
229
228
  return nil unless /\A[A-Za-z][A-Za-z\d_]*\Z/ =~ (segment = segments[index])
230
229
  index += 1
231
230
 
232
231
  mod_name = segment.camelize
233
232
  controller_name = "#{mod_name}Controller"
233
+ path_suffix = File.join(segments[start_at..(index - 1)])
234
+ next_mod = nil
234
235
 
235
- begin
236
- # We use eval instead of const_get to avoid obtaining values from parent modules.
237
- controller = eval("mod::#{controller_name}", nil, __FILE__, __LINE__)
238
- expected_name = "#{mod.name}::#{controller_name}"
239
-
240
- # Detect the case when const_get returns an object from a parent namespace.
241
- if controller.is_a?(Class) && controller.ancestors.include?(ActionController::Base) && (mod == Object || controller.name == expected_name)
242
- return controller, (index - start_at)
243
- end
244
- rescue NameError => e
245
- raise unless /^uninitialized constant .*#{controller_name}$/ =~ e.message
236
+ # If the controller is already present, or if we load it, return it.
237
+ if mod.const_defined?(controller_name) || attempt_load(mod, controller_name, path_suffix + "_controller") == :defined
238
+ controller = mod.const_get(controller_name)
239
+ return nil unless controller.is_a?(Class) && controller.ancestors.include?(ActionController::Base) # it's not really a controller?
240
+ return [controller, (index - start_at)]
246
241
  end
247
242
 
243
+ # No controller? Look for the module
248
244
  if mod.const_defined? mod_name
249
245
  next_mod = mod.send(:const_get, mod_name)
250
246
  next_mod = nil unless next_mod.is_a?(Module)
251
247
  else
252
- suffix = File.join(segments[start_at..index])
253
- $:.each do |base|
254
- path = File.join(base, suffix)
255
- next unless File.directory? path
256
- next_mod = Module.new
257
- mod.send(:const_set, mod_name, next_mod)
258
- break
248
+ # Try to load a file that defines the module we want.
249
+ case attempt_load(mod, mod_name, path_suffix)
250
+ when :defined then next_mod = mod.const_get mod_name
251
+ when :dir then # We didn't find a file, but there's a dir.
252
+ next_mod = Module.new # So create a module for the directory
253
+ mod.send :const_set, mod_name, next_mod
254
+ else
255
+ return nil
259
256
  end
260
257
  end
261
258
  mod = next_mod
262
259
 
263
- return nil unless mod
260
+ return nil unless mod && mod.is_a?(Module)
261
+ end
262
+ nil
263
+ end
264
+
265
+ protected
266
+ def safe_load_paths #:nodoc:
267
+ if defined?(RAILS_ROOT)
268
+ $LOAD_PATH.select do |base|
269
+ base = File.expand_path(base)
270
+ extended_root = File.expand_path(RAILS_ROOT)
271
+ base[0, extended_root.length] == extended_root || base =~ %r{rails-[\d.]+/builtin}
272
+ end
273
+ else
274
+ $LOAD_PATH
275
+ end
276
+ end
277
+
278
+ def attempt_load(mod, const_name, path)
279
+ has_dir = false
280
+ safe_load_paths.each do |load_path|
281
+ full_path = File.join(load_path, path)
282
+ file_path = full_path + '.rb'
283
+ if File.file?(file_path) # Found a .rb file? Load it up
284
+ require_dependency(file_path)
285
+ return :defined if mod.const_defined? const_name
286
+ else
287
+ has_dir ||= File.directory?(full_path)
288
+ end
264
289
  end
290
+ return (has_dir ? :dir : nil)
265
291
  end
266
292
  end
267
293
  end
@@ -2,7 +2,7 @@ module ActionPack #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 12
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -977,15 +977,73 @@ class ControllerComponentTest < Test::Unit::TestCase
977
977
  load_path = $:.dup
978
978
  base = File.dirname(File.dirname(File.expand_path(__FILE__)))
979
979
  $: << File.join(base, 'fixtures')
980
+ Object.send :const_set, :RAILS_ROOT, File.join(base, 'fixtures/application_root')
980
981
  assert_equal nil, ActionController::Routing::ControllerComponent.traverse_to_controller(%w(dont_load pretty please))
981
982
  ensure
982
983
  $:[0..-1] = load_path
984
+ Object.send :remove_const, :RAILS_ROOT
983
985
  end
984
986
 
985
987
  def test_traverse_should_not_trip_on_non_module_constants
986
988
  assert_equal nil, ActionController::Routing::ControllerComponent.traverse_to_controller(%w(admin some_constant a))
987
989
  end
988
990
 
991
+ # This is evil, but people do it.
992
+ def test_traverse_to_controller_should_pass_thru_classes
993
+ load_path = $:.dup
994
+ base = File.dirname(File.dirname(File.expand_path(__FILE__)))
995
+ $: << File.join(base, 'fixtures')
996
+ $: << File.join(base, 'fixtures/application_root/app/controllers')
997
+ $: << File.join(base, 'fixtures/application_root/app/models')
998
+ Object.send :const_set, :RAILS_ROOT, File.join(base, 'fixtures/application_root')
999
+ pair = ActionController::Routing::ControllerComponent.traverse_to_controller(%w(a_class_that_contains_a_controller poorly_placed))
1000
+
1001
+ # Make sure the container class was loaded properly
1002
+ assert defined?(AClassThatContainsAController)
1003
+ assert_kind_of Class, AClassThatContainsAController
1004
+ assert_equal :you_know_it, AClassThatContainsAController.is_special?
1005
+
1006
+ # Make sure the controller was too
1007
+ assert_kind_of Array, pair
1008
+ assert_equal 2, pair[1]
1009
+ klass = pair.first
1010
+ assert_kind_of Class, klass
1011
+ assert_equal :decidedly_so, klass.is_evil?
1012
+ assert klass.ancestors.include?(ActionController::Base)
1013
+ assert defined?(AClassThatContainsAController::PoorlyPlacedController)
1014
+ assert_equal klass, AClassThatContainsAController::PoorlyPlacedController
1015
+ ensure
1016
+ $:[0..-1] = load_path
1017
+ Object.send :remove_const, :RAILS_ROOT
1018
+ end
1019
+
1020
+ def test_traverse_to_nested_controller
1021
+ load_path = $:.dup
1022
+ base = File.dirname(File.dirname(File.expand_path(__FILE__)))
1023
+ $: << File.join(base, 'fixtures')
1024
+ $: << File.join(base, 'fixtures/application_root/app/controllers')
1025
+ Object.send :const_set, :RAILS_ROOT, File.join(base, 'fixtures/application_root')
1026
+ pair = ActionController::Routing::ControllerComponent.traverse_to_controller(%w(module_that_holds_controllers nested))
1027
+
1028
+ assert_not_equal nil, pair
1029
+
1030
+ # Make sure that we created a module for the dir
1031
+ assert defined?(ModuleThatHoldsControllers)
1032
+ assert_kind_of Module, ModuleThatHoldsControllers
1033
+
1034
+ # Make sure the controller is ok
1035
+ assert_kind_of Array, pair
1036
+ assert_equal 2, pair[1]
1037
+ klass = pair.first
1038
+ assert_kind_of Class, klass
1039
+ assert klass.ancestors.include?(ActionController::Base)
1040
+ assert defined?(ModuleThatHoldsControllers::NestedController)
1041
+ assert_equal klass, ModuleThatHoldsControllers::NestedController
1042
+ ensure
1043
+ $:[0..-1] = load_path
1044
+ Object.send :remove_const, :RAILS_ROOT
1045
+ end
1046
+
989
1047
  end
990
1048
 
991
1049
  end
@@ -0,0 +1,7 @@
1
+ class AClassThatContainsAController::PoorlyPlacedController < ActionController::Base
2
+
3
+ def self.is_evil?
4
+ :decidedly_so
5
+ end
6
+
7
+ end
@@ -0,0 +1,3 @@
1
+ class ModuleThatHoldsControllers::NestedController < ActionController::Base
2
+
3
+ end
@@ -0,0 +1,7 @@
1
+ class AClassThatContainsAController #often < ActiveRecord::Base
2
+
3
+ def self.is_special?
4
+ :you_know_it
5
+ end
6
+
7
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: actionpack
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.12.2
7
- date: 2006-06-27 00:00:00 -05:00
6
+ version: 1.12.3
7
+ date: 2006-06-29 00:00:00 -05:00
8
8
  summary: Web-flow and rendering framework putting the VC in MVC.
9
9
  require_paths:
10
10
  - lib
@@ -180,6 +180,7 @@ files:
180
180
  - test/controller/verification_test.rb
181
181
  - test/controller/webservice_test.rb
182
182
  - test/fixtures/addresses
183
+ - test/fixtures/application_root
183
184
  - test/fixtures/companies.yml
184
185
  - test/fixtures/company.rb
185
186
  - test/fixtures/db_definitions
@@ -203,6 +204,14 @@ files:
203
204
  - test/fixtures/topic.rb
204
205
  - test/fixtures/topics.yml
205
206
  - test/fixtures/addresses/list.rhtml
207
+ - test/fixtures/application_root/app
208
+ - test/fixtures/application_root/app/controllers
209
+ - test/fixtures/application_root/app/models
210
+ - test/fixtures/application_root/app/controllers/a_class_that_contains_a_controller
211
+ - test/fixtures/application_root/app/controllers/module_that_holds_controllers
212
+ - test/fixtures/application_root/app/controllers/a_class_that_contains_a_controller/poorly_placed_controller.rb
213
+ - test/fixtures/application_root/app/controllers/module_that_holds_controllers/nested_controller.rb
214
+ - test/fixtures/application_root/app/models/a_class_that_contains_a_controller.rb
206
215
  - test/fixtures/db_definitions/sqlite.sql
207
216
  - test/fixtures/fun/games
208
217
  - test/fixtures/fun/games/hello_world.rhtml