Permalink
Browse files

Merge branch 'master' into erbout

  • Loading branch information...
2 parents f55ad96 + 82e96eb commit 53bcbfbdc1eed45cc6615e59d36baf018ab43d96 @jeremy jeremy committed Jun 4, 2008
Showing with 1,750 additions and 1,551 deletions.
  1. +6 −0 actionpack/CHANGELOG
  2. +1 −1 actionpack/lib/action_controller/assertions/response_assertions.rb
  3. +17 −3 actionpack/lib/action_controller/caching/actions.rb
  4. +1 −1 actionpack/lib/action_controller/dispatcher.rb
  5. +5 −4 actionpack/lib/action_controller/request.rb
  6. +1 −1 actionpack/lib/action_controller/routing.rb
  7. +20 −3 actionpack/test/controller/action_pack_assertions_test.rb
  8. +15 −0 actionpack/test/controller/caching_test.rb
  9. +2 −2 actionpack/test/controller/dispatcher_test.rb
  10. +1 −1 actionpack/test/controller/integration_upload_test.rb
  11. +3 −0 actionpack/test/controller/request_test.rb
  12. +2 −2 actionpack/test/controller/routing_test.rb
  13. +1 −1 activerecord/lib/active_record/base.rb
  14. +2 −2 activerecord/lib/active_record/callbacks.rb
  15. +10 −10 activerecord/test/cases/attribute_methods_test.rb
  16. +14 −14 activerecord/test/cases/base_test.rb
  17. +38 −0 activerecord/test/cases/callbacks_observers_test.rb
  18. +2 −2 activerecord/test/cases/inheritance_test.rb
  19. +1 −1 activerecord/test/cases/multiple_db_test.rb
  20. +6 −0 activesupport/CHANGELOG
  21. +6 −0 activesupport/lib/active_support.rb
  22. +393 −392 activesupport/lib/active_support/dependencies.rb
  23. +25 −7 activesupport/lib/active_support/deprecation.rb
  24. +51 −49 activesupport/lib/active_support/inflections.rb
  25. +264 −262 activesupport/lib/active_support/inflector.rb
  26. +14 −0 activesupport/lib/active_support/ordered_hash.rb
  27. +14 −12 activesupport/lib/active_support/ordered_options.rb
  28. +9 −0 activesupport/lib/active_support/string_questioneer.rb
  29. +348 −346 activesupport/lib/active_support/values/time_zone.rb
  30. +12 −14 activesupport/test/core_ext/array_ext_test.rb
  31. +7 −7 activesupport/test/core_ext/date_ext_test.rb
  32. +12 −12 activesupport/test/core_ext/date_time_ext_test.rb
  33. +4 −4 activesupport/test/core_ext/duration_test.rb
  34. +14 −14 activesupport/test/core_ext/time_ext_test.rb
  35. +120 −120 activesupport/test/core_ext/time_with_zone_test.rb
  36. +120 −120 activesupport/test/dependencies_test.rb
  37. +10 −0 activesupport/test/deprecation_test.rb
  38. +63 −63 activesupport/test/inflector_test.rb
  39. +19 −0 activesupport/test/ordered_hash_test.rb
  40. +3 −3 activesupport/test/ordered_options_test.rb
  41. +15 −0 activesupport/test/string_questioneer_test.rb
  42. +67 −68 activesupport/test/time_zone_test.rb
  43. +2 −0 railties/CHANGELOG
  44. +8 −8 railties/lib/initializer.rb
  45. +2 −2 railties/lib/rails/plugin/loader.rb
View
@@ -1,3 +1,9 @@
+*Edge*
+
+* Fixed Request#remote_ip to only raise hell if the HTTP_CLIENT_IP and HTTP_X_FORWARDED_FOR doesn't match (not just if they're both present) [Mark Imbriaco, Bradford Folkens]
+
+* Allow caches_action to accept a layout option [José Valim]
+
* Added Rack processor [Ezra Zygmuntowicz, Josh Peek]
@@ -97,7 +97,7 @@ def assert_redirected_to(options = {}, message=nil)
value['controller'] = value['controller'].to_s
if key == :actual && value['controller'].first != '/' && !value['controller'].include?('/')
new_controller_path = ActionController::Routing.controller_relative_to(value['controller'], @controller.class.controller_path)
- value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path)
+ value['controller'] = new_controller_path if value['controller'] != new_controller_path && ActionController::Routing.possible_controllers.include?(new_controller_path) && @response.redirected_to.is_a?(Hash)
end
value['controller'] = value['controller'][1..-1] if value['controller'].first == '/' # strip leading hash
end
@@ -40,6 +40,8 @@ module Caching
# controller.send(:list_url, c.params[:id]) }
# end
#
+ # If you pass :layout => false, it will only cache your action content. It is useful when your layout has dynamic information.
+ #
module Actions
def self.included(base) #:nodoc:
base.extend(ClassMethods)
@@ -54,7 +56,8 @@ module ClassMethods
def caches_action(*actions)
return unless cache_configured?
options = actions.extract_options!
- around_filter(ActionCacheFilter.new(:cache_path => options.delete(:cache_path)), {:only => actions}.merge(options))
+ cache_filter = ActionCacheFilter.new(:layout => options.delete(:layout), :cache_path => options.delete(:cache_path))
+ around_filter(cache_filter, {:only => actions}.merge(options))
end
end
@@ -81,7 +84,9 @@ def before(controller)
if cache = controller.read_fragment(cache_path.path)
controller.rendered_action_cache = true
set_content_type!(controller, cache_path.extension)
- controller.send!(:render_for_text, cache)
+ options = { :text => cache }
+ options.merge!(:layout => true) if cache_layout?
+ controller.send!(:render, options)
false
else
controller.action_cache_path = cache_path
@@ -90,7 +95,8 @@ def before(controller)
def after(controller)
return if controller.rendered_action_cache || !caching_allowed(controller)
- controller.write_fragment(controller.action_cache_path.path, controller.response.body)
+ action_content = cache_layout? ? content_for_layout(controller) : controller.response.body
+ controller.write_fragment(controller.action_cache_path.path, action_content)
end
private
@@ -105,6 +111,14 @@ def path_options_for(controller, options)
def caching_allowed(controller)
controller.request.get? && controller.response.headers['Status'].to_i == 200
end
+
+ def cache_layout?
+ @options[:layout] == false
+ end
+
+ def content_for_layout(controller)
+ controller.response.layout && controller.response.template.instance_variable_get('@content_for_layout')
+ end
end
class ActionCachePath
@@ -141,7 +141,7 @@ def reload_application
# be reloaded on the next request without restarting the server.
def cleanup_application
ActiveRecord::Base.reset_subclasses if defined?(ActiveRecord)
- Dependencies.clear
+ ActiveSupport::Dependencies.clear
ActiveRecord::Base.clear_reloadable_connections! if defined?(ActiveRecord)
end
@@ -134,26 +134,27 @@ def xml_http_request?
# REMOTE_ADDR is a proxy. HTTP_X_FORWARDED_FOR may be a comma-
# delimited list in the case of multiple chained proxies; the last
# address which is not trusted is the originating IP.
-
def remote_ip
if TRUSTED_PROXIES !~ @env['REMOTE_ADDR']
return @env['REMOTE_ADDR']
end
+ remote_ips = @env['HTTP_X_FORWARDED_FOR'] && @env['HTTP_X_FORWARDED_FOR'].split(',')
+
if @env.include? 'HTTP_CLIENT_IP'
- if @env.include? 'HTTP_X_FORWARDED_FOR'
+ if remote_ips && !remote_ips.include?(@env['HTTP_CLIENT_IP'])
# We don't know which came from the proxy, and which from the user
raise ActionControllerError.new(<<EOM)
IP spoofing attack?!
HTTP_CLIENT_IP=#{@env['HTTP_CLIENT_IP'].inspect}
HTTP_X_FORWARDED_FOR=#{@env['HTTP_X_FORWARDED_FOR'].inspect}
EOM
end
+
return @env['HTTP_CLIENT_IP']
end
- if @env.include? 'HTTP_X_FORWARDED_FOR' then
- remote_ips = @env['HTTP_X_FORWARDED_FOR'].split(',')
+ if remote_ips
while remote_ips.size > 1 && TRUSTED_PROXIES =~ remote_ips.last.strip
remote_ips.pop
end
@@ -369,7 +369,7 @@ def controller_relative_to(controller, previous)
Routes = RouteSet.new
- ::Inflector.module_eval do
+ ActiveSupport::Inflector.module_eval do
# Ensures that routes are reloaded when Rails inflections are updated.
def inflections_with_route_reloading(&block)
returning(inflections_without_route_reloading(&block)) {
@@ -137,6 +137,9 @@ def show
end
end
+class UserController < ActionController::Base
+end
+
module Admin
class InnerModuleController < ActionController::Base
def index
@@ -174,7 +177,7 @@ class ActionPackAssertionsControllerTest < Test::Unit::TestCase
# let's get this party started
def setup
ActionController::Routing::Routes.reload
- ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module content admin/user))
+ ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
@controller = ActionPackAssertionsController.new
@request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
end
@@ -268,7 +271,7 @@ def test_assert_redirect_to_nested_named_route
assert_redirected_to admin_inner_module_path
end
end
-
+
def test_assert_redirected_to_top_level_named_route_from_nested_controller
with_routing do |set|
set.draw do |map|
@@ -277,11 +280,25 @@ def test_assert_redirected_to_top_level_named_route_from_nested_controller
end
@controller = Admin::InnerModuleController.new
process :redirect_to_top_level_named_route
- # passes -> assert_redirected_to "http://test.host/action_pack_assertions/foo"
+ # assert_redirected_to "http://test.host/action_pack_assertions/foo" would pass because of exact match early return
assert_redirected_to "/action_pack_assertions/foo"
end
end
+ def test_assert_redirected_to_top_level_named_route_with_same_controller_name_in_both_namespaces
+ with_routing do |set|
+ set.draw do |map|
+ # this controller exists in the admin namespace as well which is the only difference from previous test
+ map.top_level '/user/:id', :controller => 'user', :action => 'index'
+ map.connect ':controller/:action/:id'
+ end
+ @controller = Admin::InnerModuleController.new
+ process :redirect_to_top_level_named_route
+ # assert_redirected_to top_level_url('foo') would pass because of exact match early return
+ assert_redirected_to top_level_path('foo')
+ end
+ end
+
# -- standard request/response object testing --------------------------------
# make sure that the template objects exist
@@ -156,6 +156,7 @@ class ActionCachingTestController < ActionController::Base
caches_action :show, :cache_path => 'http://test.host/custom/show'
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
caches_action :with_layout
+ caches_action :layout_false, :layout => false
layout 'talk_from_action.erb'
@@ -181,6 +182,7 @@ def with_layout
alias_method :show, :index
alias_method :edit, :index
alias_method :destroy, :index
+ alias_method :layout_false, :with_layout
def expire
expire_action :controller => 'action_caching_test', :action => 'index'
@@ -263,6 +265,19 @@ def test_action_cache_with_layout
assert_equal @response.body, read_fragment('hostname.com/action_caching_test/with_layout')
end
+ def test_action_cache_with_layout_and_layout_cache_false
+ get :layout_false
+ cached_time = content_to_cache
+ assert_not_equal cached_time, @response.body
+ assert fragment_exist?('hostname.com/action_caching_test/layout_false')
+ reset!
+
+ get :layout_false
+ assert_not_equal cached_time, @response.body
+
+ assert_equal cached_time, read_fragment('hostname.com/action_caching_test/layout_false')
+ end
+
def test_action_cache_conditional_options
@request.env['HTTP_ACCEPT'] = 'application/json'
get :index
@@ -27,14 +27,14 @@ def teardown
def test_clears_dependencies_after_dispatch_if_in_loading_mode
ActionController::Routing::Routes.expects(:reload).once
- Dependencies.expects(:clear).once
+ ActiveSupport::Dependencies.expects(:clear).once
dispatch(@output, false)
end
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
ActionController::Routing::Routes.expects(:reload).never
- Dependencies.expects(:clear).never
+ ActiveSupport::Dependencies.expects(:clear).never
dispatch
end
@@ -28,7 +28,7 @@ class << self
# end
def test_post_with_upload
uses_mocha "test_post_with_upload" do
- Dependencies.stubs(:load?).returns(false)
+ ActiveSupport::Dependencies.stubs(:load?).returns(false)
with_routing do |set|
set.draw do |map|
map.update 'update', :controller => "upload_test", :action => "update", :method => :post
@@ -59,6 +59,9 @@ def test_remote_ip
assert_match /HTTP_X_FORWARDED_FOR="9.9.9.9, 3.4.5.6, 10.0.0.1, 172.31.4.4"/, e.message
assert_match /HTTP_CLIENT_IP="8.8.8.8"/, e.message
+ @request.env['HTTP_X_FORWARDED_FOR'] = '8.8.8.8, 9.9.9.9'
+ assert_equal '8.8.8.8', @request.remote_ip
+
@request.env.delete 'HTTP_CLIENT_IP'
@request.env.delete 'HTTP_X_FORWARDED_FOR'
end
@@ -2392,10 +2392,10 @@ def test_bang_forces_reload
end
def test_adding_inflections_forces_reload
- Inflector::Inflections.instance.expects(:uncountable).with('equipment')
+ ActiveSupport::Inflector::Inflections.instance.expects(:uncountable).with('equipment')
routes.expects(:reload!)
- Inflector.inflections { |inflect| inflect.uncountable('equipment') }
+ ActiveSupport::Inflector.inflections { |inflect| inflect.uncountable('equipment') }
end
def test_load_with_configuration
@@ -372,7 +372,7 @@ def self.inherited(child) #:nodoc:
def self.reset_subclasses #:nodoc:
nonreloadables = []
subclasses.each do |klass|
- unless Dependencies.autoloaded? klass
+ unless ActiveSupport::Dependencies.autoloaded? klass
nonreloadables << klass
next
end
@@ -293,14 +293,14 @@ def destroy_with_callbacks #:nodoc:
private
def callback(method)
- notify(method)
-
result = run_callbacks(method) { |result, object| result == false }
if result != false && respond_to_without_attributes?(method)
result = send(method)
end
+ notify(method)
+
return result
end
@@ -137,15 +137,15 @@ def test_accessing_cached_attributes_caches_the_converted_values_and_nothing_els
end
end
end
-
+
def test_time_attributes_are_retrieved_in_current_time_zone
in_time_zone "Pacific Time (US & Canada)" do
utc_time = Time.utc(2008, 1, 1)
record = @target.new
record[:written_on] = utc_time
assert_equal utc_time, record.written_on # record.written on is equal to (i.e., simultaneous with) utc_time
assert_kind_of ActiveSupport::TimeWithZone, record.written_on # but is a TimeWithZone
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone # and is in the current Time.zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone # and is in the current Time.zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time # and represents time values adjusted accordingly
end
end
@@ -156,7 +156,7 @@ def test_setting_time_zone_aware_attribute_to_utc
record = @target.new
record.written_on = utc_time
assert_equal utc_time, record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
@@ -168,7 +168,7 @@ def test_setting_time_zone_aware_attribute_in_other_time_zone
record = @target.new
record.written_on = cst_time
assert_equal utc_time, record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
@@ -181,12 +181,12 @@ def test_setting_time_zone_aware_attribute_with_string
record = @target.new
record.written_on = time_string
assert_equal Time.zone.parse(time_string), record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
end
-
+
def test_setting_time_zone_aware_attribute_to_blank_string_returns_nil
in_time_zone "Pacific Time (US & Canada)" do
record = @target.new
@@ -202,7 +202,7 @@ def test_setting_time_zone_aware_attribute_interprets_time_zone_unaware_string_i
record = @target.new
record.written_on = time_string
assert_equal Time.zone.parse(time_string), record.written_on
- assert_equal TimeZone[timezone_offset], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone[timezone_offset], record.written_on.time_zone
assert_equal Time.utc(2008, 1, 1), record.written_on.time
end
end
@@ -214,7 +214,7 @@ def test_setting_time_zone_aware_attribute_in_current_time_zone
record = @target.new
record.written_on = utc_time.in_time_zone
assert_equal utc_time, record.written_on
- assert_equal TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
+ assert_equal ActiveSupport::TimeZone["Pacific Time (US & Canada)"], record.written_on.time_zone
assert_equal Time.utc(2007, 12, 31, 16), record.written_on.time
end
end
@@ -223,12 +223,12 @@ def test_setting_time_zone_aware_attribute_in_current_time_zone
def time_related_columns_on_topic
Topic.columns.select{|c| [:time, :date, :datetime, :timestamp].include?(c.type)}.map(&:name)
end
-
+
def in_time_zone(zone)
old_zone = Time.zone
old_tz = ActiveRecord::Base.time_zone_aware_attributes
- Time.zone = zone ? TimeZone[zone] : nil
+ Time.zone = zone ? ActiveSupport::TimeZone[zone] : nil
ActiveRecord::Base.time_zone_aware_attributes = !zone.nil?
yield
ensure
Oops, something went wrong.

0 comments on commit 53bcbfb

Please sign in to comment.