aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/mime_responds_test.rb89
-rw-r--r--actionpack/test/controller/render_test.rb15
-rw-r--r--actionpack/test/fixtures/respond_with/edit.html.erb1
-rw-r--r--actionpack/test/fixtures/respond_with/new.html.erb1
-rw-r--r--actionpack/test/fixtures/respond_with/using_resource.html.erb1
-rw-r--r--actionpack/test/fixtures/respond_with/using_resource.js.rjs1
6 files changed, 91 insertions, 17 deletions
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 1d27e749ae..e9c8a3c10f 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -493,6 +493,10 @@ class RespondResource
def errors
[]
end
+
+ def destroyed?
+ false
+ end
end
class ParentResource
@@ -508,7 +512,7 @@ end
class RespondWithController < ActionController::Base
respond_to :html, :json
respond_to :xml, :except => :using_defaults
- respond_to :js, :only => :using_defaults
+ respond_to :js, :only => [ :using_defaults, :using_resource ]
def using_defaults
respond_to do |format|
@@ -547,12 +551,16 @@ protected
self.response_body = js.respond_to?(:to_js) ? js.to_js : js
end
+ def resources_url
+ request.host + "/resources"
+ end
+
def resource_url(resource)
- request.host + "/resource/#{resource.to_param}"
+ request.host + "/resources/#{resource.to_param}"
end
def parent_resource_url(parent, resource)
- request.host + "/parent/#{parent.to_param}/resource/#{resource.to_param}"
+ request.host + "/parents/#{parent.to_param}/resources/#{resource.to_param}"
end
end
@@ -617,10 +625,10 @@ class RespondWithControllerTest < ActionController::TestCase
end
def test_using_resource
- @request.accept = "text/html"
+ @request.accept = "text/javascript"
get :using_resource
- assert_equal "text/html", @response.content_type
- assert_equal "Hello world!", @response.body
+ assert_equal "text/javascript", @response.content_type
+ assert_equal '$("body").visualEffect("highlight");', @response.body
@request.accept = "application/xml"
get :using_resource
@@ -633,14 +641,30 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
- def test_using_resource_for_post
+ def test_using_resource_for_post_with_html
+ post :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "www.example.com/resources/13", @response.location
+ assert @response.redirect?
+
+ errors = { :name => :invalid }
+ RespondResource.any_instance.stubs(:errors).returns(errors)
+ post :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "New world!\n", @response.body
+ assert_nil @response.location
+ end
+
+ def test_using_resource_for_post_with_xml
@request.accept = "application/xml"
post :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "XML", @response.body
- assert_equal "www.example.com/resource/13", @response.location
+ assert_equal "www.example.com/resources/13", @response.location
errors = { :name => :invalid }
RespondResource.any_instance.stubs(:errors).returns(errors)
@@ -651,14 +675,30 @@ class RespondWithControllerTest < ActionController::TestCase
assert_nil @response.location
end
- def test_using_resource_for_put
+ def test_using_resource_for_put_with_html
+ put :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "www.example.com/resources/13", @response.location
+ assert @response.redirect?
+
+ errors = { :name => :invalid }
+ RespondResource.any_instance.stubs(:errors).returns(errors)
+ put :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "Edit world!\n", @response.body
+ assert_nil @response.location
+ end
+
+ def test_using_resource_for_put_with_xml
@request.accept = "application/xml"
put :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 200, @response.status
assert_equal " ", @response.body
- assert_nil @response.location
+ assert_equal "www.example.com/resources/13", @response.location
errors = { :name => :invalid }
RespondResource.any_instance.stubs(:errors).returns(errors)
@@ -666,16 +706,25 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal "application/xml", @response.content_type
assert_equal 422, @response.status
assert_equal errors.to_xml, @response.body
- assert_nil @response.location
+ assert_nil @response.location
end
- def test_using_resource_for_delete
+ def test_using_resource_for_delete_with_html
+ RespondResource.any_instance.stubs(:destroyed?).returns(true)
+ delete :using_resource
+ assert_equal "text/html", @response.content_type
+ assert_equal 302, @response.status
+ assert_equal "www.example.com/resources", @response.location
+ end
+
+ def test_using_resource_for_delete_with_xml
+ RespondResource.any_instance.stubs(:destroyed?).returns(true)
@request.accept = "application/xml"
delete :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 200, @response.status
assert_equal " ", @response.body
- assert_nil @response.location
+ assert_equal "www.example.com/resources", @response.location
end
def test_using_resource_with_options
@@ -692,14 +741,22 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal "JS", @response.body
end
- def test_using_resource_with_parent
+ def test_using_resource_with_parent_for_get
+ @request.accept = "application/xml"
+ get :using_resource_with_parent
+ assert_equal "application/xml", @response.content_type
+ assert_equal 200, @response.status
+ assert_equal "XML", @response.body
+ end
+
+ def test_using_resource_with_parent_for_post
@request.accept = "application/xml"
post :using_resource_with_parent
assert_equal "application/xml", @response.content_type
assert_equal 201, @response.status
assert_equal "XML", @response.body
- assert_equal "www.example.com/parent/11/resource/13", @response.location
+ assert_equal "www.example.com/parents/11/resources/13", @response.location
errors = { :name => :invalid }
RespondResource.any_instance.stubs(:errors).returns(errors)
@@ -739,7 +796,7 @@ class RespondWithControllerTest < ActionController::TestCase
assert_equal 406, @response.status
@request.accept = "text/javascript"
- get :using_resource
+ get :default_overwritten
assert_equal 406, @response.status
end
end
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 947ffa9ea6..f2cd6dbb85 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -458,6 +458,10 @@ class TestController < ActionController::Base
head :location => "/foo"
end
+ def head_with_location_object
+ head :location => Customer.new("david")
+ end
+
def head_with_symbolic_status
head :status => params[:status].intern
end
@@ -618,6 +622,10 @@ class TestController < ActionController::Base
end
private
+ def customer_url(customer)
+ request.host + "/customers/1"
+ end
+
def determine_layout
case action_name
when "hello_world", "layout_test", "rendering_without_layout",
@@ -1084,6 +1092,13 @@ class RenderTest < ActionController::TestCase
assert_response :ok
end
+ def test_head_with_location_object
+ get :head_with_location_object
+ assert @response.body.blank?
+ assert_equal "www.nextangle.com/customers/1", @response.headers["Location"]
+ assert_response :ok
+ end
+
def test_head_with_custom_header
get :head_with_custom_header
assert @response.body.blank?
diff --git a/actionpack/test/fixtures/respond_with/edit.html.erb b/actionpack/test/fixtures/respond_with/edit.html.erb
new file mode 100644
index 0000000000..ae82dfa4fc
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/edit.html.erb
@@ -0,0 +1 @@
+Edit world!
diff --git a/actionpack/test/fixtures/respond_with/new.html.erb b/actionpack/test/fixtures/respond_with/new.html.erb
new file mode 100644
index 0000000000..96c8f1b88b
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/new.html.erb
@@ -0,0 +1 @@
+New world!
diff --git a/actionpack/test/fixtures/respond_with/using_resource.html.erb b/actionpack/test/fixtures/respond_with/using_resource.html.erb
deleted file mode 100644
index 6769dd60bd..0000000000
--- a/actionpack/test/fixtures/respond_with/using_resource.html.erb
+++ /dev/null
@@ -1 +0,0 @@
-Hello world! \ No newline at end of file
diff --git a/actionpack/test/fixtures/respond_with/using_resource.js.rjs b/actionpack/test/fixtures/respond_with/using_resource.js.rjs
new file mode 100644
index 0000000000..737c175a4e
--- /dev/null
+++ b/actionpack/test/fixtures/respond_with/using_resource.js.rjs
@@ -0,0 +1 @@
+page[:body].visual_effect :highlight