diff options
author | José Valim <jose.valim@gmail.com> | 2010-04-06 00:22:33 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-04-06 00:22:33 +0200 |
commit | 3b53468a1c9fb17c5ff50027642b853a85aea4bd (patch) | |
tree | 9a8798d6f9aca84e6e1ffbbe3aec8c3963c8dd60 | |
parent | ea2c5fa8046e2f953b366adc94f0610ccfea0828 (diff) | |
parent | 570c54c39acc702eefcee9589ebe02d85173a1c1 (diff) | |
download | rails-3b53468a1c9fb17c5ff50027642b853a85aea4bd.tar.gz rails-3b53468a1c9fb17c5ff50027642b853a85aea4bd.tar.bz2 rails-3b53468a1c9fb17c5ff50027642b853a85aea4bd.zip |
Merge branch 'master' of gitproxy:rails/rails
-rw-r--r-- | actionpack/lib/action_dispatch/testing/integration.rb | 28 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 14 | ||||
-rw-r--r-- | actionpack/test/controller/integration_test.rb | 45 | ||||
-rw-r--r-- | actionpack/test/template/erb/form_for_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 18 |
5 files changed, 81 insertions, 26 deletions
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 286797ba20..64eb6d8de7 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -137,7 +137,10 @@ module ActionDispatch end # The hostname used in the last request. - attr_accessor :host + def host + @host || DEFAULT_HOST + end + attr_writer :host # The remote_addr used in the last request. attr_accessor :remote_addr @@ -148,7 +151,7 @@ module ActionDispatch # A map of the cookies returned by the last response, and which will be # sent with the next request. def cookies - @mock_session.cookie_jar + _mock_session.cookie_jar end # A reference to the controller instance used by the last request. @@ -189,8 +192,8 @@ module ActionDispatch # session.reset! def reset! @https = false - @mock_session = Rack::MockSession.new(@app, DEFAULT_HOST) @controller = @request = @response = nil + @_mock_session = nil @request_count = 0 self.host = DEFAULT_HOST @@ -234,6 +237,9 @@ module ActionDispatch end private + def _mock_session + @_mock_session ||= Rack::MockSession.new(@app, host) + end # Performs the actual request. def process(method, path, parameters = nil, rack_environment = nil) @@ -254,7 +260,7 @@ module ActionDispatch :method => method, :params => parameters, - "SERVER_NAME" => host, + "SERVER_NAME" => host.split(':')[0], "SERVER_PORT" => (https? ? "443" : "80"), "HTTPS" => https? ? "on" : "off", "rack.url_scheme" => https? ? "https" : "http", @@ -266,17 +272,25 @@ module ActionDispatch "HTTP_ACCEPT" => accept } - session = Rack::Test::Session.new(@mock_session) + session = Rack::Test::Session.new(_mock_session) (rack_environment || {}).each do |key, value| env[key] = value end - session.request(path, env) + # NOTE: rack-test v0.5 doesn't build a default uri correctly + # Make sure requested path is always a full uri + uri = URI.parse('/') + uri.scheme ||= env['rack.url_scheme'] + uri.host ||= env['SERVER_NAME'] + uri.port ||= env['SERVER_PORT'].try(:to_i) + uri += path + + session.request(uri.to_s, env) @request_count += 1 @request = ActionDispatch::Request.new(session.last_request.env) - response = @mock_session.last_response + response = _mock_session.last_response @response = ActionDispatch::TestResponse.new(response.status, response.headers, response.body) @html_document = nil diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index e44b43300d..45f41edcac 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -300,16 +300,16 @@ module ActionView case record_or_name_or_array when String, Symbol - ActiveSupport::Deprecation.warn("Use the option :object_name => ... instead of a Symbol or String as a the first argument", caller) + ActiveSupport::Deprecation.warn("Using form_for(:name, @resource) is deprecated. Please use form_for(@resource, :as => :name) instead.", caller) unless args.empty? object_name = record_or_name_or_array when Array object = record_or_name_or_array.last - object_name = options[:object_name] || ActionController::RecordIdentifier.singular_class_name(object) + object_name = options[:as] || ActionController::RecordIdentifier.singular_class_name(object) apply_form_for_options!(record_or_name_or_array, options) args.unshift object else object = record_or_name_or_array - object_name = options[:object_name] || ActionController::RecordIdentifier.singular_class_name(object) + object_name = options[:as] || ActionController::RecordIdentifier.singular_class_name(object) apply_form_for_options!([object], options) args.unshift object end @@ -327,12 +327,12 @@ module ActionView html_options = if object.respond_to?(:persisted?) && object.persisted? - { :class => options[:object_name] ? "#{options[:object_name]}_edit" : dom_class(object, :edit), - :id => options[:object_name] ? "#{options[:object_name]}_edit" : dom_id(object, :edit), + { :class => options[:as] ? "#{options[:as]}_edit" : dom_class(object, :edit), + :id => options[:as] ? "#{options[:as]}_edit" : dom_id(object, :edit), :method => :put } else - { :class => options[:object_name] ? "#{options[:object_name]}_new" : dom_class(object, :new), - :id => options[:object_name] ? "#{options[:object_name]}_new" : dom_id(object), + { :class => options[:as] ? "#{options[:as]}_new" : dom_class(object, :new), + :id => options[:as] ? "#{options[:as]}_new" : dom_id(object), :method => :post } end diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index 14c0c3708b..20dc96d38d 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -245,6 +245,15 @@ class IntegrationProcessTest < ActionController::IntegrationTest render :text => "Gone", :status => 410 end + def set_cookie + cookies["foo"] = 'bar' + head :ok + end + + def get_cookie + render :text => cookies["foo"] + end + def redirect redirect_to :action => "get" end @@ -292,6 +301,42 @@ class IntegrationProcessTest < ActionController::IntegrationTest end end + test 'cookie persist to next request' do + with_test_route_set do + get '/set_cookie' + assert_response :success + + assert_equal "foo=bar; path=/", headers["Set-Cookie"] + assert_equal({"foo"=>"bar"}, cookies.to_hash) + + get '/get_cookie' + assert_response :success + assert_equal "bar", body + + assert_equal nil, headers["Set-Cookie"] + assert_equal({"foo"=>"bar"}, cookies.to_hash) + end + end + + test 'cookie persist to next request on another domain' do + with_test_route_set do + host! "37s.backpack.test" + + get '/set_cookie' + assert_response :success + + assert_equal "foo=bar; path=/", headers["Set-Cookie"] + assert_equal({"foo"=>"bar"}, cookies.to_hash) + + get '/get_cookie' + assert_response :success + assert_equal "bar", body + + assert_equal nil, headers["Set-Cookie"] + assert_equal({"foo"=>"bar"}, cookies.to_hash) + end + end + def test_redirect with_test_route_set do get '/redirect' diff --git a/actionpack/test/template/erb/form_for_test.rb b/actionpack/test/template/erb/form_for_test.rb index 482dbb0287..ec6e872735 100644 --- a/actionpack/test/template/erb/form_for_test.rb +++ b/actionpack/test/template/erb/form_for_test.rb @@ -8,4 +8,4 @@ module ERBTest assert_equal "<form action=\"/blah/update\" method=\"post\"></form>", output end end -end
\ No newline at end of file +end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index f6401985cc..88014a6564 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -440,7 +440,7 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_with_symbol_object_name - form_for(@post, :object_name => "other_name", :html => { :id => 'create-post' }) do |f| + form_for(@post, :as => "other_name", :html => { :id => 'create-post' }) do |f| concat f.label(:title) concat f.text_field(:title) concat f.text_area(:body) @@ -504,12 +504,10 @@ class FormHelperTest < ActionView::TestCase end def test_form_for_without_object - assert_deprecated do - form_for(:post, :html => { :id => 'create-post' }) do |f| - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) - end + form_for(:post, :html => { :id => 'create-post' }) do |f| + concat f.text_field(:title) + concat f.text_area(:body) + concat f.check_box(:secret) end expected = @@ -603,10 +601,8 @@ class FormHelperTest < ActionView::TestCase def test_submit_without_object_and_locale_strings old_locale, I18n.locale = I18n.locale, :submit - assert_deprecated do - form_for(:post) do |f| - concat f.submit :class => "extra" - end + form_for(:post) do |f| + concat f.submit :class => "extra" end expected = "<form action='http://www.example.com' method='post'>" + |