From c4d1075bd366e89a070afd5d6bf859af276c9507 Mon Sep 17 00:00:00 2001
From: Yehuda Katz
Date: Tue, 28 Jul 2009 19:04:34 -0700
Subject: Add support for error_messages_for(@obj)
---
actionpack/test/template/active_record_helper_i18n_test.rb | 7 +++++--
actionpack/test/template/active_record_helper_test.rb | 10 ++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/template/active_record_helper_i18n_test.rb b/actionpack/test/template/active_record_helper_i18n_test.rb
index 63032e4e5c..047f81be29 100644
--- a/actionpack/test/template/active_record_helper_i18n_test.rb
+++ b/actionpack/test/template/active_record_helper_i18n_test.rb
@@ -3,11 +3,14 @@ require 'abstract_unit'
class ActiveRecordHelperI18nTest < Test::Unit::TestCase
include ActionView::Context
include ActionView::Helpers::ActiveModelHelper
-
+
attr_reader :request
def setup
@object = stub :errors => stub(:count => 1, :full_messages => ['full_messages'])
+ @object.stubs :to_model => @object
+ @object.stubs :class => stub(:model_name => stub(:human => ""))
+
@object_name = 'book_seller'
@object_name_without_underscore = 'book seller'
@@ -39,7 +42,7 @@ class ActiveRecordHelperI18nTest < Test::Unit::TestCase
I18n.expects(:t).with('', :default => '', :count => 1, :scope => [:activerecord, :models]).once.returns ''
error_messages_for(:object => @object, :locale => 'en')
end
-
+
def test_error_messages_for_given_object_name_it_translates_object_name
I18n.expects(:t).with(:header, :locale => 'en', :scope => [:activerecord, :errors, :template], :count => 1, :model => @object_name_without_underscore).returns "1 error prohibited this #{@object_name_without_underscore} from being saved"
I18n.expects(:t).with(@object_name, :default => @object_name_without_underscore, :count => 1, :scope => [:activerecord, :models]).once.returns @object_name_without_underscore
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index b07ce6cf5d..ec3384f15d 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -295,6 +295,16 @@ class ActiveRecordHelperTest < ActionView::TestCase
assert_equal '', error_messages_for('user', :object => nil)
end
+ def test_error_messages_for_model_objects
+ error = error_messages_for(@post)
+ assert_dom_equal %(1 error prohibited this post from being saved
There were problems with the following fields:
- Author name can't be empty
),
+ error
+
+ error = error_messages_for(@user, @post)
+ assert_dom_equal %(2 errors prohibited this user from being saved
There were problems with the following fields:
- User email can't be empty
- Author name can't be empty
),
+ error
+ end
+
def test_form_with_string_multipart
assert_dom_equal(
%(
),
--
cgit v1.2.3
From 3f445b316d34a49a8b6f27bde72979828baefaa8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Tue, 28 Jul 2009 15:49:59 +0200
Subject: Refactor Responder to only calculate available mime types. Those are
sent to the controller that knows what to do with it (render a block or call
default render).
Signed-off-by: Yehuda Katz
---
actionpack/test/controller/mime_responds_test.rb | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 93ca34c41c..bee327998b 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -436,9 +436,9 @@ class MimeControllerTest < ActionController::TestCase
def test_render_action_for_html
@controller.instance_eval do
def render(*args)
- unless args.empty?
- @action = args.first[:action] || action_name
- end
+ @action = args.first[:action] unless args.empty?
+ @action ||= action_name
+
response.body = "#{@action} - #{@template.formats}"
end
end
--
cgit v1.2.3
From 3e8ba616efdd453dcfdd8fba78ed35fc3c1885de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Tue, 28 Jul 2009 21:29:29 +0200
Subject: Refactor even more Responder. Move mime negotiation to request and
added respond_to class method.
Signed-off-by: Yehuda Katz
---
actionpack/test/controller/mime_responds_test.rb | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index bee327998b..f2c20417f8 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -86,6 +86,7 @@ class RespondToController < ActionController::Base
type.mobile { render :text => "Mobile" }
end
ensure
+ Mime::SET.delete(:mobile)
Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
end
@@ -98,6 +99,7 @@ class RespondToController < ActionController::Base
end
ensure
+ Mime::SET.delete(:mobile)
Mime.module_eval { remove_const :MOBILE if const_defined?(:MOBILE) }
end
@@ -132,6 +134,7 @@ class RespondToController < ActionController::Base
end
ensure
+ Mime::SET.delete(:iphone)
Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
@@ -145,6 +148,7 @@ class RespondToController < ActionController::Base
end
ensure
+ Mime::SET.delete(:iphone)
Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
@@ -467,7 +471,13 @@ class MimeControllerTest < ActionController::TestCase
end
end
+class ClassRespondToController < ActionController::Base
+
+end
+
class AbstractPostController < ActionController::Base
+ respond_to :html, :iphone
+
self.view_paths = File.dirname(__FILE__) + "/../fixtures/post_test/"
end
@@ -476,10 +486,7 @@ class PostController < AbstractPostController
around_filter :with_iphone
def index
- respond_to do |type|
- type.html
- type.iphone
- end
+ respond_to # It will use formats declared above
end
protected
@@ -489,17 +496,12 @@ protected
request.format = "iphone" if request.env["HTTP_ACCEPT"] == "text/iphone"
yield
ensure
+ Mime::SET.delete(:iphone)
Mime.module_eval { remove_const :IPHONE if const_defined?(:IPHONE) }
end
end
class SuperPostController < PostController
- def index
- respond_to do |type|
- type.html
- type.iphone
- end
- end
end
class MimeControllerLayoutsTest < ActionController::TestCase
--
cgit v1.2.3
From b51632d34d99ee9cae3287c60887b25fdf7a3618 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 29 Jul 2009 09:53:02 +0200
Subject: Improve request test coverage by adding formats and negotiate_mime
tests.
Signed-off-by: Yehuda Katz
---
actionpack/test/dispatch/request_test.rb | 39 ++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 3a85db8aa5..948eeeb001 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -396,10 +396,49 @@ class RequestTest < ActiveSupport::TestCase
assert_equal({"bar" => 2}, request.query_parameters)
end
+ test "formats" do
+ request = stub_request 'HTTP_ACCEPT' => 'text/html'
+ request.expects(:parameters).at_least_once.returns({})
+ assert_equal [ Mime::HTML ], request.formats
+
+ request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
+ request.expects(:parameters).at_least_once.returns({})
+ assert_equal with_set(Mime::XML, Mime::HTML), request.formats
+
+ begin
+ ActionController::Base.use_accept_header, old =
+ false, ActionController::Base.use_accept_header
+
+ request = stub_request
+ request.expects(:parameters).at_least_once.returns({ :format => :txt })
+ assert_equal with_set(Mime::TEXT), request.formats
+ ensure
+ ActionController::Base.use_accept_header = old
+ end
+ end
+
+ test "negotiate_mime" do
+ request = stub_request 'HTTP_ACCEPT' => 'text/html'
+ request.expects(:parameters).at_least_once.returns({})
+
+ assert_equal nil, request.negotiate_mime([Mime::XML, Mime::JSON])
+ assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::HTML])
+ assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::ALL])
+
+ request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
+ request.expects(:parameters).at_least_once.returns({})
+ assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV])
+ assert_equal Mime::CSV, request.negotiate_mime([Mime::CSV, Mime::YAML])
+ end
+
protected
def stub_request(env={})
ActionDispatch::Request.new(env)
end
+ def with_set(*args)
+ args + Mime::SET
+ end
+
end
--
cgit v1.2.3
From 67b2d08c0a64ddec3a0c4e1c0b5d96bd418cceef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 29 Jul 2009 10:09:21 +0200
Subject: Ensure that the proper accept header value is set during tests.
Signed-off-by: Yehuda Katz
---
actionpack/test/dispatch/request_test.rb | 56 ++++++++++++++++----------------
1 file changed, 28 insertions(+), 28 deletions(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb
index 948eeeb001..8ebf9aa186 100644
--- a/actionpack/test/dispatch/request_test.rb
+++ b/actionpack/test/dispatch/request_test.rb
@@ -338,16 +338,11 @@ class RequestTest < ActiveSupport::TestCase
end
test "XMLHttpRequest" do
- begin
- ActionController::Base.use_accept_header, old =
- false, ActionController::Base.use_accept_header
-
+ with_accept_header false do
request = stub_request 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'
request.expects(:parameters).at_least_once.returns({})
assert request.xhr?
assert_equal Mime::JS, request.format
- ensure
- ActionController::Base.use_accept_header = old
end
end
@@ -396,39 +391,38 @@ class RequestTest < ActiveSupport::TestCase
assert_equal({"bar" => 2}, request.query_parameters)
end
- test "formats" do
- request = stub_request 'HTTP_ACCEPT' => 'text/html'
- request.expects(:parameters).at_least_once.returns({})
- assert_equal [ Mime::HTML ], request.formats
-
- request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
- request.expects(:parameters).at_least_once.returns({})
- assert_equal with_set(Mime::XML, Mime::HTML), request.formats
+ test "formats with accept header" do
+ with_accept_header true do
+ request = stub_request 'HTTP_ACCEPT' => 'text/html'
+ request.expects(:parameters).at_least_once.returns({})
+ assert_equal [ Mime::HTML ], request.formats
- begin
- ActionController::Base.use_accept_header, old =
- false, ActionController::Base.use_accept_header
+ request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
+ request.expects(:parameters).at_least_once.returns({})
+ assert_equal with_set(Mime::XML, Mime::HTML), request.formats
+ end
+ with_accept_header false do
request = stub_request
request.expects(:parameters).at_least_once.returns({ :format => :txt })
assert_equal with_set(Mime::TEXT), request.formats
- ensure
- ActionController::Base.use_accept_header = old
end
end
test "negotiate_mime" do
- request = stub_request 'HTTP_ACCEPT' => 'text/html'
- request.expects(:parameters).at_least_once.returns({})
+ with_accept_header true do
+ request = stub_request 'HTTP_ACCEPT' => 'text/html'
+ request.expects(:parameters).at_least_once.returns({})
- assert_equal nil, request.negotiate_mime([Mime::XML, Mime::JSON])
- assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::HTML])
- assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::ALL])
+ assert_equal nil, request.negotiate_mime([Mime::XML, Mime::JSON])
+ assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::HTML])
+ assert_equal Mime::HTML, request.negotiate_mime([Mime::XML, Mime::ALL])
- request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
- request.expects(:parameters).at_least_once.returns({})
- assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV])
- assert_equal Mime::CSV, request.negotiate_mime([Mime::CSV, Mime::YAML])
+ request = stub_request 'CONTENT_TYPE' => 'application/xml; charset=UTF-8'
+ request.expects(:parameters).at_least_once.returns({})
+ assert_equal Mime::XML, request.negotiate_mime([Mime::XML, Mime::CSV])
+ assert_equal Mime::CSV, request.negotiate_mime([Mime::CSV, Mime::YAML])
+ end
end
protected
@@ -441,4 +435,10 @@ protected
args + Mime::SET
end
+ def with_accept_header(value)
+ ActionController::Base.use_accept_header, old = value, ActionController::Base.use_accept_header
+ yield
+ ensure
+ ActionController::Base.use_accept_header = old
+ end
end
--
cgit v1.2.3
From bbe86077c2148559f7548520303b2e683ff86119 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 29 Jul 2009 11:13:08 +0200
Subject: Added tests for respond_to class method.
Signed-off-by: Yehuda Katz
---
actionpack/test/controller/mime_responds_test.rb | 70 +++++++++++++++++++++-
.../fixtures/respond_with/using_defaults.html.erb | 1 +
.../fixtures/respond_with/using_defaults.js.rjs | 1 +
.../using_defaults_with_type_list.js.rjs | 1 +
.../using_defaults_with_type_list.xml.builder | 1 +
5 files changed, 72 insertions(+), 2 deletions(-)
create mode 100644 actionpack/test/fixtures/respond_with/using_defaults.html.erb
create mode 100644 actionpack/test/fixtures/respond_with/using_defaults.js.rjs
create mode 100644 actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
create mode 100644 actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index f2c20417f8..48b343272e 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -166,7 +166,7 @@ class RespondToController < ActionController::Base
end
end
-class MimeControllerTest < ActionController::TestCase
+class RespondToControllerTest < ActionController::TestCase
tests RespondToController
def setup
@@ -471,8 +471,74 @@ class MimeControllerTest < ActionController::TestCase
end
end
-class ClassRespondToController < ActionController::Base
+class RespondWithController < ActionController::Base
+ respond_to :html
+ respond_to :xml, :except => :using_defaults
+ respond_to :js, :only => :using_defaults
+ def using_defaults
+ respond_to do |format|
+ format.csv { render :text => "CSV" }
+ end
+ end
+
+ def using_defaults_with_type_list
+ respond_to(:js, :xml)
+ end
+end
+
+class RespondWithControllerTest < ActionController::TestCase
+ tests RespondWithController
+
+ def setup
+ super
+ ActionController::Base.use_accept_header = true
+ @request.host = "www.example.com"
+ end
+
+ def teardown
+ super
+ ActionController::Base.use_accept_header = false
+ end
+
+ def test_using_defaults
+ @request.accept = "*/*"
+ get :using_defaults
+ assert_equal "text/html", @response.content_type
+ assert_equal 'Hello world!', @response.body
+
+ @request.accept = "text/csv"
+ get :using_defaults
+ assert_equal "text/csv", @response.content_type
+ assert_equal "CSV", @response.body
+
+ @request.accept = "text/javascript"
+ get :using_defaults
+ assert_equal "text/javascript", @response.content_type
+ assert_equal '$("body").visualEffect("highlight");', @response.body
+ end
+
+ def test_using_defaults_with_type_list
+ @request.accept = "*/*"
+ get :using_defaults_with_type_list
+ assert_equal "text/javascript", @response.content_type
+ assert_equal '$("body").visualEffect("highlight");', @response.body
+
+ @request.accept = "application/xml"
+ get :using_defaults_with_type_list
+ assert_equal "application/xml", @response.content_type
+ assert_equal "Hello world!
\n", @response.body
+ end
+
+ def test_not_acceptable
+ @request.accept = "application/xml"
+ get :using_defaults
+ assert_equal 406, @response.status
+
+ @request.accept = "text/html"
+ get :using_defaults_with_type_list
+ assert_equal 406, @response.status
+ end
end
class AbstractPostController < ActionController::Base
diff --git a/actionpack/test/fixtures/respond_with/using_defaults.html.erb b/actionpack/test/fixtures/respond_with/using_defaults.html.erb
new file mode 100644
index 0000000000..6769dd60bd
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults.html.erb
@@ -0,0 +1 @@
+Hello world!
\ No newline at end of file
diff --git a/actionpack/test/fixtures/respond_with/using_defaults.js.rjs b/actionpack/test/fixtures/respond_with/using_defaults.js.rjs
new file mode 100644
index 0000000000..469fcd8e15
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults.js.rjs
@@ -0,0 +1 @@
+page[:body].visual_effect :highlight
\ No newline at end of file
diff --git a/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
new file mode 100644
index 0000000000..469fcd8e15
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.js.rjs
@@ -0,0 +1 @@
+page[:body].visual_effect :highlight
\ No newline at end of file
diff --git a/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
new file mode 100644
index 0000000000..598d62e2fc
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_defaults_with_type_list.xml.builder
@@ -0,0 +1 @@
+xml.p "Hello world!"
\ No newline at end of file
--
cgit v1.2.3
From 09de34ca56598ae5d0302a14715b2a11b6cc9845 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 29 Jul 2009 12:18:03 +0200
Subject: Added respond_with.
Signed-off-by: Yehuda Katz
---
actionpack/test/controller/mime_responds_test.rb | 70 +++++++++++++++++++++-
.../fixtures/respond_with/using_resource.html.erb | 1 +
2 files changed, 70 insertions(+), 1 deletion(-)
create mode 100644 actionpack/test/fixtures/respond_with/using_resource.html.erb
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 48b343272e..369d683d23 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -471,8 +471,20 @@ class RespondToControllerTest < ActionController::TestCase
end
end
+class RespondResource
+ undef_method :to_json
+
+ def to_xml
+ "XML"
+ end
+
+ def to_js
+ "JS"
+ end
+end
+
class RespondWithController < ActionController::Base
- respond_to :html
+ respond_to :html, :json
respond_to :xml, :except => :using_defaults
respond_to :js, :only => :using_defaults
@@ -485,6 +497,23 @@ class RespondWithController < ActionController::Base
def using_defaults_with_type_list
respond_to(:js, :xml)
end
+
+ def using_resource
+ respond_with(RespondResource.new)
+ end
+
+ def using_resource_with_options
+ respond_with(RespondResource.new, :status => :unprocessable_entity) do |format|
+ format.js
+ end
+ end
+
+protected
+
+ def _render_js(js, options)
+ self.content_type ||= Mime::JS
+ self.response_body = js.respond_to?(:to_js) ? js.to_js : js
+ end
end
class RespondWithControllerTest < ActionController::TestCase
@@ -530,6 +559,37 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal "Hello world!
\n", @response.body
end
+ def test_using_resource
+ @request.accept = "text/html"
+ get :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal "Hello world!", @response.body
+
+ @request.accept = "application/xml"
+ get :using_resource
+ assert_equal "application/xml", @response.content_type
+ assert_equal "XML", @response.body
+
+ @request.accept = "application/json"
+ assert_raise ActionView::MissingTemplate do
+ get :using_resource
+ end
+ end
+
+ def test_using_resource_with_options
+ @request.accept = "application/xml"
+ get :using_resource_with_options
+ assert_equal "application/xml", @response.content_type
+ assert_equal 422, @response.status
+ assert_equal "XML", @response.body
+
+ @request.accept = "text/javascript"
+ get :using_resource_with_options
+ assert_equal "text/javascript", @response.content_type
+ assert_equal 422, @response.status
+ assert_equal "JS", @response.body
+ end
+
def test_not_acceptable
@request.accept = "application/xml"
get :using_defaults
@@ -538,6 +598,14 @@ class RespondWithControllerTest < ActionController::TestCase
@request.accept = "text/html"
get :using_defaults_with_type_list
assert_equal 406, @response.status
+
+ @request.accept = "application/json"
+ get :using_defaults_with_type_list
+ assert_equal 406, @response.status
+
+ @request.accept = "text/javascript"
+ get :using_resource
+ assert_equal 406, @response.status
end
end
diff --git a/actionpack/test/fixtures/respond_with/using_resource.html.erb b/actionpack/test/fixtures/respond_with/using_resource.html.erb
new file mode 100644
index 0000000000..6769dd60bd
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_resource.html.erb
@@ -0,0 +1 @@
+Hello world!
\ No newline at end of file
--
cgit v1.2.3
From fa0cf663fe6a6393a3ba117505703e587da4ddc5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 29 Jul 2009 14:32:56 +0200
Subject: Add a couple more tests to respond_with.
Signed-off-by: Yehuda Katz
---
actionpack/test/controller/mime_responds_test.rb | 38 ++++++++++++++++++++++++
1 file changed, 38 insertions(+)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 369d683d23..558fc47695 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -508,6 +508,12 @@ class RespondWithController < ActionController::Base
end
end
+ def default_overwritten
+ respond_to do |format|
+ format.html { render :text => "HTML" }
+ end
+ end
+
protected
def _render_js(js, options)
@@ -516,6 +522,17 @@ protected
end
end
+class InheritedRespondWithController < RespondWithController
+ clear_respond_to
+ respond_to :xml, :json
+
+ def index
+ respond_with(RespondResource.new) do |format|
+ format.json { render :text => "JSON" }
+ end
+ end
+end
+
class RespondWithControllerTest < ActionController::TestCase
tests RespondWithController
@@ -590,6 +607,27 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal "JS", @response.body
end
+ def test_default_overwritten
+ get :default_overwritten
+ assert_equal "text/html", @response.content_type
+ assert_equal "HTML", @response.body
+ end
+
+ def test_clear_respond_to
+ @controller = InheritedRespondWithController.new
+ @request.accept = "text/html"
+ get :index
+ assert_equal 406, @response.status
+ end
+
+ def test_first_in_respond_to_has_higher_priority
+ @controller = InheritedRespondWithController.new
+ @request.accept = "*/*"
+ get :index
+ assert_equal "application/xml", @response.content_type
+ assert_equal "XML", @response.body
+ end
+
def test_not_acceptable
@request.accept = "application/xml"
get :using_defaults
--
cgit v1.2.3
From d209aea7d88849b7c7a080d729045ce7c051ef1f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?=
Date: Wed, 29 Jul 2009 19:31:03 +0200
Subject: Remove last TODO.
Signed-off-by: Yehuda Katz
---
actionpack/test/controller/mime_responds_test.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'actionpack/test')
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 558fc47695..117f4ea4f0 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -443,7 +443,7 @@ class RespondToControllerTest < ActionController::TestCase
@action = args.first[:action] unless args.empty?
@action ||= action_name
- response.body = "#{@action} - #{@template.formats}"
+ response.body = "#{@action} - #{formats}"
end
end
--
cgit v1.2.3