test/aliases_test.rb in josevalim-inherited_resources-0.8.5 vs test/aliases_test.rb in josevalim-inherited_resources-0.9.0
- old
+ new
@@ -2,12 +2,17 @@
class Student;
def self.human_name; 'Student'; end
end
+class ApplicationController < ActionController::Base
+ include InheritedResources::DSL
+end
+
class StudentsController < ApplicationController
inherit_resources
+ respond_to :html, :xml
def edit
edit! do |format|
format.xml { render :text => 'Render XML' }
end
@@ -16,30 +21,23 @@
def new
@something = 'magical'
new!
end
- def create
- create! do |success, failure|
- success.html { render :text => "I won't redirect!" }
- failure.xml { render :text => "I shouldn't be rendered" }
- end
+ create!(:location => "http://test.host/") do |success, failure|
+ success.html { render :text => "I won't redirect!" }
+ failure.xml { render :text => "I shouldn't be rendered" }
end
- def update
- update! do |success, failure|
- success.html { redirect_to(resource_url) }
- failure.html { render :text => "I won't render!" }
- end
+ update! do |success, failure|
+ success.html { redirect_to(resource_url) }
+ failure.html { render :text => "I won't render!" }
end
- def destroy
- destroy! do |format|
- format.html { render :text => "Destroyed!" }
- end
+ destroy! do |format|
+ format.html { render :text => "Destroyed!" }
end
-
end
class AliasesTest < ActionController::TestCase
tests StudentsController
@@ -87,28 +85,28 @@
assert_equal "I won't redirect!", @response.body
end
def test_dumb_responder_quietly_receives_everything_on_failure
@request.accept = 'text/html'
- Student.stubs(:new).returns(mock_student(:save => false, :errors => []))
+ Student.stubs(:new).returns(mock_student(:save => false, :errors => {:some => :error}))
@controller.stubs(:resource_url).returns('http://test.host/')
post :create
assert_response :success
assert_equal "New HTML", @response.body.strip
end
def test_html_is_the_default_when_only_xml_is_overwriten
@request.accept = '*/*'
- Student.stubs(:new).returns(mock_student(:save => false, :errors => []))
+ Student.stubs(:new).returns(mock_student(:save => false, :errors => {:some => :error}))
@controller.stubs(:resource_url).returns('http://test.host/')
post :create
assert_response :success
assert_equal "New HTML", @response.body.strip
end
def test_wont_render_edit_template_on_update_with_failure_if_failure_block_is_given
- Student.stubs(:find).returns(mock_student(:update_attributes => false, :errors => []))
+ Student.stubs(:find).returns(mock_student(:update_attributes => false))
put :update
assert_response :success
assert_equal "I won't render!", @response.body
end
@@ -122,9 +120,16 @@
def test_block_is_called_when_student_is_destroyed
Student.stubs(:find).returns(mock_student(:destroy => true))
delete :destroy
assert_response :success
assert_equal "Destroyed!", @response.body
+ end
+
+ def test_options_are_used_in_respond_with
+ @request.accept = "application/xml"
+ Student.stubs(:new).returns(mock_student(:save => true, :to_xml => "XML"))
+ post :create
+ assert_equal "http://test.host/", @response.location
end
protected
def mock_student(stubs={})
@mock_student ||= mock(stubs)